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 _DuoyunTabsElement_instances, _DuoyunTabsElement_orientation_get;
|
13 | var DuoyunTabsElement_1;
|
14 | import { adoptedStyle, customElement, emitter, property, boolattribute, attribute, part, state, } from '@mantou/gem/lib/decorators';
|
15 | import { GemElement, html } from '@mantou/gem/lib/element';
|
16 | import { createCSSSheet, css, partMap, classMap } from '@mantou/gem/lib/utils';
|
17 | import { theme } from '../lib/theme';
|
18 | import { commonHandle } from '../lib/hotkeys';
|
19 | import { focusStyle } from '../lib/styles';
|
20 | import { DuoyunScrollBaseElement } from './base/scroll';
|
21 | import './use';
|
22 | import './compartment';
|
23 | import './divider';
|
24 | const style = createCSSSheet(css `
|
25 | :host(:where(:not([hidden]))) {
|
26 | display: flex;
|
27 | flex-direction: column;
|
28 | }
|
29 | :host([orientation='vertical']) {
|
30 | flex-direction: row;
|
31 | }
|
32 | .tabs {
|
33 | display: flex;
|
34 | font-size: 0.875em;
|
35 | gap: 2em;
|
36 | flex-shrink: 0;
|
37 | max-width: 100%;
|
38 | }
|
39 | :host([orientation='vertical']) .tabs {
|
40 | flex-direction: column;
|
41 | gap: 0;
|
42 | }
|
43 | .divider {
|
44 | flex-shrink: 0;
|
45 | }
|
46 | :host([center]) .tabs {
|
47 | justify-content: center;
|
48 | }
|
49 | .tab {
|
50 | position: relative;
|
51 | cursor: pointer;
|
52 | display: flex;
|
53 | align-items: center;
|
54 | line-height: 1.5;
|
55 | padding: 0.8em 0;
|
56 | gap: 0.3em;
|
57 | color: ${theme.describeColor};
|
58 | }
|
59 | :host([orientation='vertical']) .tab {
|
60 | padding-inline-end: 1em;
|
61 | }
|
62 | .icon {
|
63 | width: 1.2em;
|
64 | }
|
65 | .tab:hover,
|
66 | .current {
|
67 | color: ${theme.primaryColor};
|
68 | }
|
69 | .marker {
|
70 | position: absolute;
|
71 | top: 100%;
|
72 | left: 0;
|
73 | right: 0;
|
74 | }
|
75 | :host([orientation='vertical']) .marker {
|
76 | top: 0;
|
77 | left: 100%;
|
78 | height: 100%;
|
79 | }
|
80 | `);
|
81 |
|
82 |
|
83 |
|
84 | let DuoyunTabsElement = DuoyunTabsElement_1 = class DuoyunTabsElement extends GemElement {
|
85 | constructor() {
|
86 | super({ delegatesFocus: true });
|
87 | _DuoyunTabsElement_instances.add(this);
|
88 | this.render = () => {
|
89 | if (!this.data)
|
90 | return html ``;
|
91 | let currentContent = '';
|
92 | return html `
|
93 | <div part=${DuoyunTabsElement_1.tabs} class="tabs">
|
94 | ${this.data.map(({ value, tab, icon, getContent }, index) => {
|
95 | const isCurrent = (value !== null && value !== void 0 ? value : index) === this.value;
|
96 | if (isCurrent)
|
97 | currentContent = (getContent === null || getContent === void 0 ? void 0 : getContent()) || '';
|
98 | return html `
|
99 | <div
|
100 | role="tab"
|
101 | class=${classMap({ tab: true, current: isCurrent })}
|
102 | part=${partMap({ [DuoyunTabsElement_1.tab]: true, [DuoyunTabsElement_1.currentTab]: isCurrent })}
|
103 | @click=${() => this.change(value !== null && value !== void 0 ? value : index)}
|
104 | >
|
105 | ${icon ? html `<dy-use part=${DuoyunTabsElement_1.icon} class="icon" .element=${icon}></dy-use>` : ''}
|
106 | <span tabindex="0" @keydown=${commonHandle}>${tab}</span>
|
107 | ${isCurrent
|
108 | ? html `
|
109 | <dy-divider
|
110 | part=${DuoyunTabsElement_1.marker}
|
111 | class="marker"
|
112 | size="medium"
|
113 | orientation=${__classPrivateFieldGet(this, _DuoyunTabsElement_instances, "a", _DuoyunTabsElement_orientation_get)}
|
114 | .color=${theme.primaryColor}
|
115 | ></dy-divider>
|
116 | `
|
117 | : ''}
|
118 | </div>
|
119 | `;
|
120 | })}
|
121 | </div>
|
122 | <dy-divider
|
123 | part=${DuoyunTabsElement_1.divider}
|
124 | class="divider"
|
125 | size="medium"
|
126 | orientation=${__classPrivateFieldGet(this, _DuoyunTabsElement_instances, "a", _DuoyunTabsElement_orientation_get)}
|
127 | ></dy-divider>
|
128 | <dy-compartment
|
129 | .content=${html `
|
130 | <style>
|
131 | dy-tab-panel::-webkit-scrollbar {
|
132 | width: 0;
|
133 | }
|
134 | </style>
|
135 | ${currentContent}
|
136 | `}
|
137 | ></dy-compartment>
|
138 | `;
|
139 | };
|
140 | this.internals.role = 'tablist';
|
141 | }
|
142 | };
|
143 | _DuoyunTabsElement_instances = new WeakSet(), _DuoyunTabsElement_orientation_get = function _DuoyunTabsElement_orientation_get() {
|
144 | return this.orientation || 'horizontal';
|
145 | };
|
146 | __decorate([
|
147 | boolattribute
|
148 | ], DuoyunTabsElement.prototype, "center", void 0);
|
149 | __decorate([
|
150 | attribute
|
151 | ], DuoyunTabsElement.prototype, "orientation", void 0);
|
152 | __decorate([
|
153 | property
|
154 | ], DuoyunTabsElement.prototype, "data", void 0);
|
155 | __decorate([
|
156 | property
|
157 | ], DuoyunTabsElement.prototype, "value", void 0);
|
158 | __decorate([
|
159 | emitter
|
160 | ], DuoyunTabsElement.prototype, "change", void 0);
|
161 | __decorate([
|
162 | part
|
163 | ], DuoyunTabsElement, "tabs", void 0);
|
164 | __decorate([
|
165 | part
|
166 | ], DuoyunTabsElement, "tab", void 0);
|
167 | __decorate([
|
168 | part
|
169 | ], DuoyunTabsElement, "currentTab", void 0);
|
170 | __decorate([
|
171 | part
|
172 | ], DuoyunTabsElement, "icon", void 0);
|
173 | __decorate([
|
174 | part
|
175 | ], DuoyunTabsElement, "marker", void 0);
|
176 | __decorate([
|
177 | part
|
178 | ], DuoyunTabsElement, "divider", void 0);
|
179 | DuoyunTabsElement = DuoyunTabsElement_1 = __decorate([
|
180 | customElement('dy-tabs'),
|
181 | adoptedStyle(style),
|
182 | adoptedStyle(focusStyle)
|
183 | ], DuoyunTabsElement);
|
184 | export { DuoyunTabsElement };
|
185 | const panelStyle = createCSSSheet(css `
|
186 | :host(:where(:not([hidden]))) {
|
187 | display: block;
|
188 | flex-shrink: 1;
|
189 | flex-grow: 1;
|
190 | line-height: 1.5;
|
191 | margin-block-start: 1em;
|
192 | }
|
193 | :host(:where([data-vertical], :state(vertical))) {
|
194 | margin-inline-start: 1em;
|
195 | margin-block-start: 0em;
|
196 | }
|
197 | `);
|
198 |
|
199 |
|
200 |
|
201 | let DuoyunTabPanelElement = class DuoyunTabPanelElement extends DuoyunScrollBaseElement {
|
202 | constructor() {
|
203 | super();
|
204 | this.internals.role = 'tabpanel';
|
205 | this.addEventListener('change', (e) => e.stopPropagation());
|
206 | this.effect(() => {
|
207 | var _a;
|
208 | this.vertical = ((_a = this.closestElement(DuoyunTabsElement)) === null || _a === void 0 ? void 0 : _a.orientation) === 'vertical';
|
209 | });
|
210 | }
|
211 | };
|
212 | __decorate([
|
213 | state
|
214 | ], DuoyunTabPanelElement.prototype, "vertical", void 0);
|
215 | DuoyunTabPanelElement = __decorate([
|
216 | customElement('dy-tab-panel'),
|
217 | adoptedStyle(panelStyle)
|
218 | ], DuoyunTabPanelElement);
|
219 | export { DuoyunTabPanelElement };
|
220 |
|
\ | No newline at end of file |