From c2dd5599f4af0a1bb73022b2b9d36f2047291027 Mon Sep 17 00:00:00 2001
From: mantou132 <709922234@qq.com>
Date: Mon, 29 Jul 2024 08:12:01 +0800
Subject: [PATCH] [gem] Share styles
---
packages/gem/src/elements/base/link.ts | 38 ++++++++++++++------------
packages/gem/src/elements/base/use.ts | 29 +++++++++++---------
2 files changed, 36 insertions(+), 31 deletions(-)
diff --git a/packages/gem/src/elements/base/link.ts b/packages/gem/src/elements/base/link.ts
index 9c46fa26..5700b203 100644
--- a/packages/gem/src/elements/base/link.ts
+++ b/packages/gem/src/elements/base/link.ts
@@ -1,7 +1,7 @@
-import { GemElement, html } from '../../lib/element';
-import { attribute, property, state, part, connectStore, shadow, aria } from '../../lib/decorators';
+import { createCSSSheet, GemElement, html } from '../../lib/element';
+import { attribute, property, state, part, connectStore, shadow, aria, adoptedStyle } from '../../lib/decorators';
import { history, basePathStore } from '../../lib/history';
-import { absoluteLocation } from '../../lib/utils';
+import { absoluteLocation, css } from '../../lib/utils';
import { ifDefined } from '../../lib/directives';
import { matchPath, RouteItem, RouteOptions, createHistoryParams, createPath } from './route';
@@ -10,6 +10,22 @@ function isExternal(path: string) {
return !path.startsWith('/');
}
+const styles = createCSSSheet(css`
+ :host {
+ /* link default style */
+ cursor: pointer;
+ color: blue;
+ text-decoration: underline;
+ }
+ a {
+ all: unset;
+ display: contents;
+ }
+ a:visited {
+ color: unset;
+ }
+`);
+
/**
* @customElement gem-link
* @attr href
@@ -25,6 +41,7 @@ function isExternal(path: string) {
* Bug: print `` https://github.com/mantou132/gem/issues/36
*/
@connectStore(basePathStore)
+@adoptedStyle(styles)
@shadow()
@aria({ focusable: true })
export class GemLinkElement extends GemElement {
@@ -125,21 +142,6 @@ export class GemLinkElement extends GemElement {
render() {
return html`
-
();
/**
@@ -12,6 +25,7 @@ const eleCache = new Map();
* @attr selector
*/
@shadow()
+@adoptedStyle(styles)
export class GemUseElement extends GemElement {
@attribute selector: string; // CSS 选择器
@property root?: HTMLElement | Document | ShadowRoot;
@@ -38,17 +52,6 @@ export class GemUseElement extends GemElement {
render() {
return html`
-
${this.#getContent()}
`;