1 | var __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 | };
|
7 | var __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 | };
|
12 | var _DuoyunBannerElement_instances, _DuoyunBannerElement_icon_get;
|
13 |
|
14 | import { adoptedStyle, customElement, attribute, emitter, property, boolattribute, } from '@mantou/gem/lib/decorators';
|
15 | import { GemElement, html } from '@mantou/gem/lib/element';
|
16 | import { createCSSSheet, css } from '@mantou/gem/lib/utils';
|
17 | import { theme } from '../lib/theme';
|
18 | import { icons } from '../lib/icons';
|
19 | import { commonHandle } from '../lib/hotkeys';
|
20 | import './use';
|
21 | import './divider';
|
22 | const style = createCSSSheet(css `
|
23 | :host(:where(:not([hidden]))) {
|
24 | display: flex;
|
25 | align-items: flex-start;
|
26 | background: ${theme.neutralColor};
|
27 | color: #fff;
|
28 | padding: 0.8em;
|
29 | line-height: 1.5;
|
30 | gap: 0.5em;
|
31 | }
|
32 | :host > * {
|
33 | flex-shrink: 0;
|
34 | }
|
35 | :host([status='positive']) {
|
36 | background: ${theme.positiveColor};
|
37 | }
|
38 | :host([status='notice']) {
|
39 | background: ${theme.noticeColor};
|
40 | }
|
41 | :host([status='negative']) {
|
42 | background: ${theme.negativeColor};
|
43 | }
|
44 | .icon {
|
45 | width: 1.5em;
|
46 | }
|
47 | .content {
|
48 | flex-grow: 1;
|
49 | }
|
50 | .action {
|
51 | color: inherit;
|
52 | background: transparent;
|
53 | border-radius: 10em;
|
54 | border: 2px solid #fff9;
|
55 | padding: 0 1em;
|
56 | font-size: 1em;
|
57 | line-height: 1.5;
|
58 | margin-block: -2px;
|
59 | margin-inline-end: 0.5em;
|
60 | font-weight: 500;
|
61 | }
|
62 | .action:hover {
|
63 | border-color: #fff;
|
64 | }
|
65 | .divider {
|
66 | align-self: stretch;
|
67 | }
|
68 | .close {
|
69 | width: 1.2em;
|
70 | padding: 0.15em;
|
71 | opacity: 0.8;
|
72 | }
|
73 | .close:hover {
|
74 | opacity: 1;
|
75 | }
|
76 | `);
|
77 |
|
78 |
|
79 |
|
80 | let DuoyunBannerElement = class DuoyunBannerElement extends GemElement {
|
81 | constructor() {
|
82 | super({ delegatesFocus: true });
|
83 | _DuoyunBannerElement_instances.add(this);
|
84 | this.render = () => {
|
85 | const icon = __classPrivateFieldGet(this, _DuoyunBannerElement_instances, "a", _DuoyunBannerElement_icon_get);
|
86 | return html `
|
87 | ${icon ? html `<dy-use class="icon" .element=${icon}></dy-use>` : ''}
|
88 | <div class="content">
|
89 | <slot></slot>
|
90 | </div>
|
91 | ${this.action
|
92 | ? html `
|
93 | <button class="action" @keydown=${commonHandle} @click=${this.action.handle}>${this.action.text}</button>
|
94 | `
|
95 | : ''}
|
96 | ${this.closable
|
97 | ? html `
|
98 | <dy-divider class="divider" orientation="vertical"></dy-divider>
|
99 | <dy-use
|
100 | role="button"
|
101 | class="close"
|
102 | tabindex="0"
|
103 | .element=${icons.close}
|
104 | @click=${() => this.close(null)}
|
105 | @keydown=${commonHandle}
|
106 | ></dy-use>
|
107 | `
|
108 | : ''}
|
109 | `;
|
110 | };
|
111 | this.internals.role = 'banner';
|
112 | }
|
113 | };
|
114 | _DuoyunBannerElement_instances = new WeakSet(), _DuoyunBannerElement_icon_get = function _DuoyunBannerElement_icon_get() {
|
115 | switch (this.status) {
|
116 | case 'positive':
|
117 | return icons.success;
|
118 | case 'notice':
|
119 | return icons.warning;
|
120 | case 'negative':
|
121 | return icons.error;
|
122 | }
|
123 | };
|
124 | __decorate([
|
125 | boolattribute
|
126 | ], DuoyunBannerElement.prototype, "closable", void 0);
|
127 | __decorate([
|
128 | attribute
|
129 | ], DuoyunBannerElement.prototype, "status", void 0);
|
130 | __decorate([
|
131 | property
|
132 | ], DuoyunBannerElement.prototype, "action", void 0);
|
133 | __decorate([
|
134 | emitter
|
135 | ], DuoyunBannerElement.prototype, "close", void 0);
|
136 | DuoyunBannerElement = __decorate([
|
137 | customElement('dy-banner'),
|
138 | adoptedStyle(style)
|
139 | ], DuoyunBannerElement);
|
140 | export { DuoyunBannerElement };
|
141 |
|
\ | No newline at end of file |