UNPKG

4.86 kBJavaScriptView Raw
1var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5 return c > 3 && r && Object.defineProperty(target, key, r), r;
6};
7var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9 if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11};
12var _DuoyunTagElement_instances, _DuoyunTagElement_color_get, _DuoyunTagElement_mode_get, _DuoyunTagElement_onClose;
13import { connectStore, adoptedStyle, customElement, attribute, emitter, boolattribute, } from '@mantou/gem/lib/decorators';
14import { GemElement, html } from '@mantou/gem/lib/element';
15import { createCSSSheet, css } from '@mantou/gem/lib/utils';
16import { icons } from '../lib/icons';
17import { theme, getSemanticColor } from '../lib/theme';
18import { commonHandle } from '../lib/hotkeys';
19import { focusStyle } from '../lib/styles';
20import './use';
21const style = createCSSSheet(css `
22 :host(:where(:not([hidden]))) {
23 display: inline-flex;
24 align-items: center;
25 justify-content: center;
26 gap: 0.3em;
27 font-size: 0.875em;
28 line-height: 1.2;
29 padding: 0.5em 0.6em;
30 border-radius: ${theme.normalRound};
31 border-width: 1px;
32 border-style: solid;
33 }
34 :host([small]) {
35 font-size: 0.75em;
36 }
37 .close {
38 width: 1.2em;
39 opacity: 0.7;
40 flex-shrink: 0;
41 }
42 .close:hover {
43 opacity: 1;
44 }
45`);
46/**
47 * @customElement dy-tag
48 * @attr small
49 * @fires close
50 */
51let DuoyunTagElement = class DuoyunTagElement extends GemElement {
52 constructor() {
53 super({ delegatesFocus: true });
54 _DuoyunTagElement_instances.add(this);
55 _DuoyunTagElement_onClose.set(this, (e) => {
56 e.stopPropagation();
57 this.close(null);
58 });
59 this.render = () => {
60 const isSolid = __classPrivateFieldGet(this, _DuoyunTagElement_instances, "a", _DuoyunTagElement_mode_get) === 'solid';
61 const isDefault = this.color === 'default' || this.color === '';
62 return html `
63 <style>
64 :host {
65 color: ${isDefault ? theme.textColor : isSolid ? theme.backgroundColor : __classPrivateFieldGet(this, _DuoyunTagElement_instances, "a", _DuoyunTagElement_color_get)};
66 background-color: ${isSolid ? __classPrivateFieldGet(this, _DuoyunTagElement_instances, "a", _DuoyunTagElement_color_get) : 'transparent'};
67 border-color: ${__classPrivateFieldGet(this, _DuoyunTagElement_instances, "a", _DuoyunTagElement_color_get)};
68 }
69 </style>
70 <slot></slot>
71 ${this.closable
72 ? html `
73 <dy-use
74 tabindex="0"
75 role="button"
76 class="close"
77 @keydown=${commonHandle}
78 @click=${__classPrivateFieldGet(this, _DuoyunTagElement_onClose, "f")}
79 .element=${icons.close}
80 ></dy-use>
81 `
82 : ''}
83 `;
84 };
85 this.internals.role = 'mark';
86 }
87};
88_DuoyunTagElement_onClose = new WeakMap(), _DuoyunTagElement_instances = new WeakSet(), _DuoyunTagElement_color_get = function _DuoyunTagElement_color_get() {
89 const semanticColor = getSemanticColor(this.color);
90 if (semanticColor)
91 return semanticColor;
92 switch (this.color) {
93 case '':
94 case 'default':
95 return theme.hoverBackgroundColor;
96 default:
97 return this.color;
98 }
99}, _DuoyunTagElement_mode_get = function _DuoyunTagElement_mode_get() {
100 return this.mode || 'solid';
101};
102__decorate([
103 boolattribute
104], DuoyunTagElement.prototype, "closable", void 0);
105__decorate([
106 attribute
107], DuoyunTagElement.prototype, "color", void 0);
108__decorate([
109 attribute
110], DuoyunTagElement.prototype, "mode", void 0);
111__decorate([
112 boolattribute
113], DuoyunTagElement.prototype, "small", void 0);
114__decorate([
115 emitter
116], DuoyunTagElement.prototype, "close", void 0);
117DuoyunTagElement = __decorate([
118 customElement('dy-tag'),
119 adoptedStyle(style),
120 adoptedStyle(focusStyle),
121 connectStore(icons)
122], DuoyunTagElement);
123export { DuoyunTagElement };
124//# sourceMappingURL=tag.js.map
\No newline at end of file