snice 1.14.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/templates/base/tsconfig.json +5 -4
- package/components/accordion/demo.html +403 -0
- package/components/accordion/snice-accordion-item.css +85 -0
- package/components/accordion/snice-accordion-item.ts +226 -0
- package/components/accordion/snice-accordion.css +31 -0
- package/components/accordion/snice-accordion.ts +182 -0
- package/components/accordion/snice-accordion.types.ts +32 -0
- package/components/alert/demo.html +445 -0
- package/components/alert/snice-alert.css +195 -0
- package/components/alert/snice-alert.ts +141 -0
- package/components/alert/snice-alert.types.ts +12 -0
- package/components/avatar/demo.html +598 -0
- package/components/avatar/snice-avatar.css +131 -0
- package/components/avatar/snice-avatar.ts +136 -0
- package/components/avatar/snice-avatar.types.ts +13 -0
- package/components/badge/demo.html +523 -0
- package/components/badge/snice-badge.css +161 -0
- package/components/badge/snice-badge.ts +117 -0
- package/components/badge/snice-badge.types.ts +16 -0
- package/components/breadcrumbs/demo.html +404 -0
- package/components/breadcrumbs/snice-breadcrumbs.css +133 -0
- package/components/breadcrumbs/snice-breadcrumbs.ts +191 -0
- package/components/breadcrumbs/snice-breadcrumbs.types.ts +26 -0
- package/components/breadcrumbs/snice-crumb.ts +26 -0
- package/components/button/demo.html +42 -0
- package/components/button/snice-button.css +230 -0
- package/components/button/snice-button.ts +169 -0
- package/components/button/snice-button.types.ts +25 -0
- package/components/card/demo.html +525 -0
- package/components/card/snice-card.css +140 -0
- package/components/card/snice-card.ts +102 -0
- package/components/card/snice-card.types.ts +10 -0
- package/components/checkbox/demo.html +253 -0
- package/components/checkbox/snice-checkbox.css +164 -0
- package/components/checkbox/snice-checkbox.ts +223 -0
- package/components/checkbox/snice-checkbox.types.ts +22 -0
- package/components/chip/demo.html +383 -0
- package/components/chip/snice-chip.css +195 -0
- package/components/chip/snice-chip.ts +139 -0
- package/components/chip/snice-chip.types.ts +15 -0
- package/components/date-picker/README.md +233 -0
- package/components/date-picker/demo.html +191 -0
- package/components/date-picker/snice-date-picker.css +330 -0
- package/components/date-picker/snice-date-picker.ts +777 -0
- package/components/date-picker/snice-date-picker.types.ts +83 -0
- package/components/divider/demo.html +233 -0
- package/components/divider/snice-divider.css +155 -0
- package/components/divider/snice-divider.ts +69 -0
- package/components/divider/snice-divider.types.ts +15 -0
- package/components/drawer/demo.html +328 -0
- package/components/drawer/snice-drawer.css +476 -0
- package/components/drawer/snice-drawer.ts +287 -0
- package/components/drawer/snice-drawer.types.ts +17 -0
- package/components/global.d.ts +14 -0
- package/components/input/demo.html +303 -0
- package/components/input/snice-input.css +257 -0
- package/components/input/snice-input.ts +442 -0
- package/components/input/snice-input.types.ts +59 -0
- package/components/input/test.html +77 -0
- package/components/layout/README.md +260 -0
- package/components/layout/demo.html +538 -0
- package/components/layout/snice-layout-blog.css +129 -0
- package/components/layout/snice-layout-blog.ts +48 -0
- package/components/layout/snice-layout-card.css +104 -0
- package/components/layout/snice-layout-card.ts +35 -0
- package/components/layout/snice-layout-centered.css +51 -0
- package/components/layout/snice-layout-centered.ts +22 -0
- package/components/layout/snice-layout-dashboard.css +98 -0
- package/components/layout/snice-layout-dashboard.ts +45 -0
- package/components/layout/snice-layout-fullscreen.css +72 -0
- package/components/layout/snice-layout-fullscreen.ts +34 -0
- package/components/layout/snice-layout-landing.css +92 -0
- package/components/layout/snice-layout-landing.ts +47 -0
- package/components/layout/snice-layout-minimal.css +16 -0
- package/components/layout/snice-layout-minimal.ts +19 -0
- package/components/layout/snice-layout-sidebar.css +117 -0
- package/components/layout/snice-layout-sidebar.ts +48 -0
- package/components/layout/snice-layout-split.css +103 -0
- package/components/layout/snice-layout-split.ts +29 -0
- package/components/layout/snice-layout.css +72 -0
- package/components/layout/snice-layout.ts +35 -0
- package/components/layout/snice-layout.types.ts +5 -0
- package/components/login/demo-auth-controller.ts +185 -0
- package/components/login/demo.html +470 -0
- package/components/login/snice-login.css +204 -0
- package/components/login/snice-login.ts +337 -0
- package/components/login/snice-login.types.ts +34 -0
- package/components/modal/demo.html +291 -0
- package/components/modal/snice-modal.css +203 -0
- package/components/modal/snice-modal.ts +233 -0
- package/components/modal/snice-modal.types.ts +21 -0
- package/components/pagination/demo.html +395 -0
- package/components/pagination/snice-pagination.ts +333 -0
- package/components/pagination/snice-pagination.types.ts +21 -0
- package/components/progress/demo.html +510 -0
- package/components/progress/snice-progress.css +267 -0
- package/components/progress/snice-progress.ts +247 -0
- package/components/progress/snice-progress.types.ts +19 -0
- package/components/radio/demo.html +287 -0
- package/components/radio/snice-radio.css +171 -0
- package/components/radio/snice-radio.ts +218 -0
- package/components/radio/snice-radio.types.ts +21 -0
- package/components/select/demo.html +511 -0
- package/components/select/snice-option.ts +52 -0
- package/components/select/snice-option.types.ts +14 -0
- package/components/select/snice-select.css +392 -0
- package/components/select/snice-select.ts +796 -0
- package/components/select/snice-select.types.ts +55 -0
- package/components/skeleton/demo.html +514 -0
- package/components/skeleton/snice-skeleton.css +109 -0
- package/components/skeleton/snice-skeleton.ts +126 -0
- package/components/skeleton/snice-skeleton.types.ts +11 -0
- package/components/switch/demo.html +284 -0
- package/components/switch/snice-switch.css +221 -0
- package/components/switch/snice-switch.ts +229 -0
- package/components/switch/snice-switch.types.ts +23 -0
- package/components/symbols.ts +23 -0
- package/components/table/demo-table-controller.ts +100 -0
- package/components/table/demo.html +480 -0
- package/components/table/snice-cell-boolean.ts +112 -0
- package/components/table/snice-cell-date.ts +210 -0
- package/components/table/snice-cell-duration.ts +91 -0
- package/components/table/snice-cell-filesize.ts +90 -0
- package/components/table/snice-cell-number.ts +165 -0
- package/components/table/snice-cell-progress.ts +83 -0
- package/components/table/snice-cell-rating.ts +82 -0
- package/components/table/snice-cell-sparkline.ts +253 -0
- package/components/table/snice-cell-text.ts +125 -0
- package/components/table/snice-cell.css +296 -0
- package/components/table/snice-cell.ts +473 -0
- package/components/table/snice-column.ts +353 -0
- package/components/table/snice-header.css +243 -0
- package/components/table/snice-header.ts +261 -0
- package/components/table/snice-progress.ts +66 -0
- package/components/table/snice-rating.ts +45 -0
- package/components/table/snice-row.css +255 -0
- package/components/table/snice-row.ts +331 -0
- package/components/table/snice-table.css +241 -0
- package/components/table/snice-table.ts +737 -0
- package/components/table/snice-table.types.ts +158 -0
- package/components/tabs/demo.html +487 -0
- package/components/tabs/snice-tab-panel.css +264 -0
- package/components/tabs/snice-tab-panel.ts +47 -0
- package/components/tabs/snice-tab.css +96 -0
- package/components/tabs/snice-tab.ts +65 -0
- package/components/tabs/snice-tabs.css +189 -0
- package/components/tabs/snice-tabs.ts +332 -0
- package/components/tabs/snice-tabs.types.ts +28 -0
- package/components/theme/theme.css +234 -0
- package/components/toast/demo.html +329 -0
- package/components/toast/snice-toast-container.ts +256 -0
- package/components/toast/snice-toast.css +213 -0
- package/components/toast/snice-toast.ts +276 -0
- package/components/toast/snice-toast.types.ts +35 -0
- package/components/tooltip/demo.html +350 -0
- package/components/tooltip/snice-tooltip-portal.css +79 -0
- package/components/tooltip/snice-tooltip.css +117 -0
- package/components/tooltip/snice-tooltip.ts +612 -0
- package/components/tooltip/snice-tooltip.types.ts +32 -0
- package/components/transitions.ts +94 -0
- package/components/tsconfig.json +18 -0
- package/dist/index.cjs +441 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.cjs.min.map +1 -1
- package/dist/index.esm.js +441 -329
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +3 -3
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +441 -329
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +3 -3
- package/dist/index.iife.min.js.map +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/transitions.esm.js +1 -1
- package/dist/types/controller.d.ts +1 -1
- package/dist/types/element.d.ts +10 -10
- package/dist/types/events.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/observe.d.ts +1 -1
- package/dist/types/request-response.d.ts +2 -3
- package/dist/types/router.d.ts +1 -1
- package/package.json +9 -3
- package/dist/index.cjs.min +0 -15
- package/dist/symbols.cjs +0 -103
- package/dist/transitions.cjs +0 -219
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { element, property, query, queryAll, on, watch, ready, dispatch } from 'snice';
|
|
2
|
+
import css from './snice-tabs.css?inline';
|
|
3
|
+
import type { TabsPlacement, SniceTabElement, SniceTabPanelElement, TabChangeDetail, TabSelectDetail } from './snice-tabs.types';
|
|
4
|
+
import { transitions } from '../transitions';
|
|
5
|
+
|
|
6
|
+
@element('snice-tabs')
|
|
7
|
+
export class SniceTabs extends HTMLElement {
|
|
8
|
+
@property({ reflect: true })
|
|
9
|
+
placement: TabsPlacement = 'top';
|
|
10
|
+
|
|
11
|
+
@property({ reflect: true })
|
|
12
|
+
selected = 0;
|
|
13
|
+
|
|
14
|
+
@property({ type: Boolean, reflect: true })
|
|
15
|
+
noScrollControls = false;
|
|
16
|
+
|
|
17
|
+
@property({ reflect: true })
|
|
18
|
+
transition = 'none';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@query('.tabs__nav')
|
|
23
|
+
nav?: HTMLElement;
|
|
24
|
+
|
|
25
|
+
@query('.tabs__nav-track')
|
|
26
|
+
navTrack?: HTMLElement;
|
|
27
|
+
|
|
28
|
+
@query('.tabs__indicator')
|
|
29
|
+
indicator?: HTMLElement;
|
|
30
|
+
|
|
31
|
+
@query('.tabs__scroll-button--start')
|
|
32
|
+
scrollButtonStart?: HTMLButtonElement;
|
|
33
|
+
|
|
34
|
+
@query('.tabs__scroll-button--end')
|
|
35
|
+
scrollButtonEnd?: HTMLButtonElement;
|
|
36
|
+
|
|
37
|
+
@query('.tabs')
|
|
38
|
+
tabsContainer?: HTMLElement;
|
|
39
|
+
|
|
40
|
+
@queryAll('snice-tab[slot="nav"]', { light: true, shadow: false })
|
|
41
|
+
tabs?: NodeListOf<SniceTabElement>;
|
|
42
|
+
|
|
43
|
+
@queryAll('snice-tab-panel', { light: true, shadow: false })
|
|
44
|
+
panels?: NodeListOf<SniceTabPanelElement>;
|
|
45
|
+
|
|
46
|
+
@query('.tabs__panels')
|
|
47
|
+
panelsContainer?: HTMLElement;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
html() {
|
|
51
|
+
return /*html*/`
|
|
52
|
+
<div class="tabs tabs--${this.placement}" part="base">
|
|
53
|
+
<div class="tabs__nav-container" part="nav-container">
|
|
54
|
+
${!this.noScrollControls ? /*html*/`
|
|
55
|
+
<button class="tabs__scroll-button tabs__scroll-button--start" part="scroll-button scroll-button-start" tabindex="-1" aria-label="Scroll left">
|
|
56
|
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
|
57
|
+
<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" fill="currentColor"/>
|
|
58
|
+
</svg>
|
|
59
|
+
</button>
|
|
60
|
+
` : ''}
|
|
61
|
+
|
|
62
|
+
<div class="tabs__nav" part="nav" role="tablist">
|
|
63
|
+
<div class="tabs__nav-track">
|
|
64
|
+
<slot name="nav"></slot>
|
|
65
|
+
<div class="tabs__indicator" part="indicator"></div>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
${!this.noScrollControls ? /*html*/`
|
|
70
|
+
<button class="tabs__scroll-button tabs__scroll-button--end" part="scroll-button scroll-button-end" tabindex="-1" aria-label="Scroll right">
|
|
71
|
+
<svg viewBox="0 0 24 24" width="16" height="16">
|
|
72
|
+
<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" fill="currentColor"/>
|
|
73
|
+
</svg>
|
|
74
|
+
</button>
|
|
75
|
+
` : ''}
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<div class="tabs__panels" part="panels">
|
|
79
|
+
<slot></slot>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
css() {
|
|
86
|
+
return css;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ready()
|
|
90
|
+
init() {
|
|
91
|
+
this.setupTabs();
|
|
92
|
+
this.updateScrollButtons();
|
|
93
|
+
|
|
94
|
+
// Update scroll buttons on resize
|
|
95
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
96
|
+
this.updateScrollButtons();
|
|
97
|
+
this.updateIndicator();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (this.nav) {
|
|
101
|
+
resizeObserver.observe(this.nav);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@watch('selected')
|
|
106
|
+
handleSelectedChange() {
|
|
107
|
+
this.updateSelection();
|
|
108
|
+
this.updateIndicator();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@watch('placement')
|
|
112
|
+
handlePlacementChange() {
|
|
113
|
+
if (!this.tabsContainer) return;
|
|
114
|
+
|
|
115
|
+
// Remove all placement classes
|
|
116
|
+
this.tabsContainer.classList.remove('tabs--top', 'tabs--bottom', 'tabs--start', 'tabs--end');
|
|
117
|
+
// Add the new placement class
|
|
118
|
+
this.tabsContainer.classList.add(`tabs--${this.placement}`);
|
|
119
|
+
// Update indicator position
|
|
120
|
+
this.updateIndicator();
|
|
121
|
+
// Update scroll buttons visibility
|
|
122
|
+
this.updateScrollButtons();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@on('click', '.tabs__scroll-button--start')
|
|
126
|
+
scrollStart() {
|
|
127
|
+
if (!this.nav) return;
|
|
128
|
+
|
|
129
|
+
const isHorizontal = this.placement === 'top' || this.placement === 'bottom';
|
|
130
|
+
if (isHorizontal) {
|
|
131
|
+
this.nav.scrollBy({ left: -200, behavior: 'smooth' });
|
|
132
|
+
} else {
|
|
133
|
+
this.nav.scrollBy({ top: -200, behavior: 'smooth' });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@on('click', '.tabs__scroll-button--end')
|
|
138
|
+
scrollEnd() {
|
|
139
|
+
if (!this.nav) return;
|
|
140
|
+
|
|
141
|
+
const isHorizontal = this.placement === 'top' || this.placement === 'bottom';
|
|
142
|
+
if (isHorizontal) {
|
|
143
|
+
this.nav.scrollBy({ left: 200, behavior: 'smooth' });
|
|
144
|
+
} else {
|
|
145
|
+
this.nav.scrollBy({ top: 200, behavior: 'smooth' });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@on('scroll', '.tabs__nav')
|
|
150
|
+
handleScroll() {
|
|
151
|
+
this.updateScrollButtons();
|
|
152
|
+
this.updateIndicator();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@on('@snice/tab-select')
|
|
156
|
+
handleTabSelect(event: CustomEvent<TabSelectDetail>) {
|
|
157
|
+
if (!this.tabs) return;
|
|
158
|
+
const tab = event.detail.tab;
|
|
159
|
+
const index = Array.from(this.tabs).indexOf(tab);
|
|
160
|
+
if (index >= 0) {
|
|
161
|
+
this.selectTab(index);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setupTabs() {
|
|
166
|
+
this.updateSelection();
|
|
167
|
+
// Delay indicator update to ensure DOM is ready
|
|
168
|
+
requestAnimationFrame(() => {
|
|
169
|
+
this.updateIndicator();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@dispatch('@snice/tab-change', { bubbles: true, composed: true })
|
|
174
|
+
selectTab(index: number): TabChangeDetail | undefined {
|
|
175
|
+
if (!this.tabs || !this.panels || index < 0 || index >= this.tabs.length) return;
|
|
176
|
+
|
|
177
|
+
const oldIndex = this.selected;
|
|
178
|
+
this.selected = index;
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
index,
|
|
182
|
+
oldIndex,
|
|
183
|
+
tab: this.tabs[index],
|
|
184
|
+
panel: this.panels[index]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private previousSelected = -1;
|
|
189
|
+
|
|
190
|
+
updateSelection() {
|
|
191
|
+
if (!this.tabs || !this.panels) return;
|
|
192
|
+
|
|
193
|
+
this.tabs.forEach((tab, index) => {
|
|
194
|
+
const isSelected = index === this.selected;
|
|
195
|
+
tab.setAttribute('aria-selected', String(isSelected));
|
|
196
|
+
tab.setAttribute('tabindex', isSelected ? '0' : '-1');
|
|
197
|
+
tab.classList.toggle('snice-tab--active', isSelected);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Handle panel transitions
|
|
201
|
+
const oldPanel = this.previousSelected >= 0 ? this.panels[this.previousSelected] : null;
|
|
202
|
+
const newPanel = this.panels[this.selected];
|
|
203
|
+
|
|
204
|
+
if (this.transition && this.transition !== 'none' && oldPanel && newPanel && oldPanel !== newPanel) {
|
|
205
|
+
// Get transition config and set CSS variables for timing
|
|
206
|
+
const transitionConfig = transitions[this.transition];
|
|
207
|
+
const outDuration = transitionConfig?.outDuration || 300;
|
|
208
|
+
const inDuration = transitionConfig?.inDuration || 300;
|
|
209
|
+
const maxDuration = Math.max(outDuration, inDuration);
|
|
210
|
+
|
|
211
|
+
// Update CSS custom property for transition duration
|
|
212
|
+
this.style.setProperty('--snice-tabs-transition-duration', `${maxDuration}ms`);
|
|
213
|
+
|
|
214
|
+
// Lock container height BEFORE any changes to prevent ANY reflow
|
|
215
|
+
if (this.panelsContainer) {
|
|
216
|
+
const currentHeight = this.panelsContainer.offsetHeight;
|
|
217
|
+
this.panelsContainer.style.height = `${currentHeight}px`;
|
|
218
|
+
this.panelsContainer.style.overflow = 'hidden';
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Now show new panel to measure it
|
|
222
|
+
newPanel.hidden = false;
|
|
223
|
+
newPanel.setAttribute('transition-in', this.transition);
|
|
224
|
+
oldPanel.setAttribute('transition-out', this.transition);
|
|
225
|
+
|
|
226
|
+
// Pass timing info to panels via properties
|
|
227
|
+
(newPanel as any).transitionDuration = inDuration;
|
|
228
|
+
(oldPanel as any).transitionDuration = outDuration;
|
|
229
|
+
|
|
230
|
+
// Hide old panel well before transition completes to avoid flicker
|
|
231
|
+
setTimeout(() => {
|
|
232
|
+
oldPanel.hidden = true;
|
|
233
|
+
oldPanel.removeAttribute('transition-out');
|
|
234
|
+
}, outDuration - 50); // Hide 50ms early to prevent flicker
|
|
235
|
+
|
|
236
|
+
// Clean up new panel transition attribute and unlock height
|
|
237
|
+
setTimeout(() => {
|
|
238
|
+
newPanel.removeAttribute('transition-in');
|
|
239
|
+
if (this.panelsContainer) {
|
|
240
|
+
// Reset to auto height without animation to prevent bounce
|
|
241
|
+
this.panelsContainer.style.height = '';
|
|
242
|
+
this.panelsContainer.style.overflow = '';
|
|
243
|
+
}
|
|
244
|
+
}, maxDuration);
|
|
245
|
+
} else {
|
|
246
|
+
// No transition - immediate switch
|
|
247
|
+
this.panels.forEach((panel, index) => {
|
|
248
|
+
const isSelected = index === this.selected;
|
|
249
|
+
panel.setAttribute('aria-hidden', String(!isSelected));
|
|
250
|
+
panel.hidden = !isSelected;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Update aria attributes
|
|
255
|
+
this.panels.forEach((panel, index) => {
|
|
256
|
+
panel.setAttribute('aria-hidden', String(index !== this.selected));
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
this.previousSelected = this.selected;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
updateIndicator() {
|
|
263
|
+
if (!this.indicator || !this.tabs || !this.tabs.length || !this.navTrack) return;
|
|
264
|
+
|
|
265
|
+
const activeTab = this.tabs[this.selected];
|
|
266
|
+
if (!activeTab) return;
|
|
267
|
+
|
|
268
|
+
const isHorizontal = this.placement === 'top' || this.placement === 'bottom';
|
|
269
|
+
|
|
270
|
+
// Get the position of the active tab relative to the nav track container
|
|
271
|
+
// We need to calculate this manually since tabs are in light DOM and indicator is in shadow DOM
|
|
272
|
+
let offset = 0;
|
|
273
|
+
|
|
274
|
+
// Sum up the widths/heights of all tabs before the active one
|
|
275
|
+
for (let i = 0; i < this.selected; i++) {
|
|
276
|
+
if (isHorizontal) {
|
|
277
|
+
offset += this.tabs[i].offsetWidth;
|
|
278
|
+
} else {
|
|
279
|
+
offset += this.tabs[i].offsetHeight;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (isHorizontal) {
|
|
284
|
+
this.indicator.style.width = `${activeTab.offsetWidth}px`;
|
|
285
|
+
this.indicator.style.height = '2px';
|
|
286
|
+
this.indicator.style.transform = `translateX(${offset}px)`;
|
|
287
|
+
} else {
|
|
288
|
+
this.indicator.style.width = '2px';
|
|
289
|
+
this.indicator.style.height = `${activeTab.offsetHeight}px`;
|
|
290
|
+
this.indicator.style.transform = `translateY(${offset}px)`;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
updateScrollButtons() {
|
|
295
|
+
if (!this.nav || this.noScrollControls) return;
|
|
296
|
+
|
|
297
|
+
const isHorizontal = this.placement === 'top' || this.placement === 'bottom';
|
|
298
|
+
|
|
299
|
+
const hasOverflow = isHorizontal
|
|
300
|
+
? this.nav.scrollWidth > this.nav.clientWidth
|
|
301
|
+
: this.nav.scrollHeight > this.nav.clientHeight;
|
|
302
|
+
|
|
303
|
+
const canScrollStart = isHorizontal
|
|
304
|
+
? this.nav.scrollLeft > 0
|
|
305
|
+
: this.nav.scrollTop > 0;
|
|
306
|
+
|
|
307
|
+
const canScrollEnd = isHorizontal
|
|
308
|
+
? this.nav.scrollLeft < this.nav.scrollWidth - this.nav.clientWidth
|
|
309
|
+
: this.nav.scrollTop < this.nav.scrollHeight - this.nav.clientHeight;
|
|
310
|
+
|
|
311
|
+
// Show/hide buttons based on overflow
|
|
312
|
+
this.scrollButtonStart?.classList.toggle('tabs__scroll-button--visible', hasOverflow);
|
|
313
|
+
this.scrollButtonEnd?.classList.toggle('tabs__scroll-button--visible', hasOverflow);
|
|
314
|
+
|
|
315
|
+
// Disable buttons when can't scroll in that direction
|
|
316
|
+
this.scrollButtonStart?.classList.toggle('tabs__scroll-button--disabled', !canScrollStart);
|
|
317
|
+
this.scrollButtonEnd?.classList.toggle('tabs__scroll-button--disabled', !canScrollEnd);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
show(index: number) {
|
|
322
|
+
this.selectTab(index);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
getTab(index: number): SniceTabElement | undefined {
|
|
326
|
+
return this.tabs?.[index];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
getPanel(index: number): SniceTabPanelElement | undefined {
|
|
330
|
+
return this.panels?.[index];
|
|
331
|
+
}
|
|
332
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type TabsPlacement = 'top' | 'bottom' | 'start' | 'end';
|
|
2
|
+
|
|
3
|
+
export interface SniceTabElement extends HTMLElement {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
closable: boolean;
|
|
6
|
+
focus(options?: FocusOptions): void;
|
|
7
|
+
blur(): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SniceTabPanelElement extends HTMLElement {
|
|
11
|
+
name: string;
|
|
12
|
+
hidden: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TabChangeDetail {
|
|
16
|
+
index: number;
|
|
17
|
+
oldIndex: number;
|
|
18
|
+
tab: SniceTabElement;
|
|
19
|
+
panel: SniceTabPanelElement;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TabSelectDetail {
|
|
23
|
+
tab: SniceTabElement;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface TabCloseDetail {
|
|
27
|
+
tab: SniceTabElement;
|
|
28
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
/* Color primitives */
|
|
3
|
+
--snice-color-gray-50: 250 250 250;
|
|
4
|
+
--snice-color-gray-100: 241 241 241;
|
|
5
|
+
--snice-color-gray-200: 226 226 226;
|
|
6
|
+
--snice-color-gray-300: 204 204 204;
|
|
7
|
+
--snice-color-gray-400: 163 163 163;
|
|
8
|
+
--snice-color-gray-500: 115 115 115;
|
|
9
|
+
--snice-color-gray-600: 82 82 82;
|
|
10
|
+
--snice-color-gray-700: 64 64 64;
|
|
11
|
+
--snice-color-gray-800: 38 38 38;
|
|
12
|
+
--snice-color-gray-900: 23 23 23;
|
|
13
|
+
--snice-color-gray-950: 10 10 10;
|
|
14
|
+
|
|
15
|
+
--snice-color-blue-50: 239 246 255;
|
|
16
|
+
--snice-color-blue-100: 219 234 254;
|
|
17
|
+
--snice-color-blue-200: 191 219 254;
|
|
18
|
+
--snice-color-blue-300: 147 197 253;
|
|
19
|
+
--snice-color-blue-400: 96 165 250;
|
|
20
|
+
--snice-color-blue-500: 59 130 246;
|
|
21
|
+
--snice-color-blue-600: 37 99 235;
|
|
22
|
+
--snice-color-blue-700: 29 78 216;
|
|
23
|
+
--snice-color-blue-800: 30 64 175;
|
|
24
|
+
--snice-color-blue-900: 30 58 138;
|
|
25
|
+
--snice-color-blue-950: 23 37 84;
|
|
26
|
+
|
|
27
|
+
--snice-color-green-50: 240 253 244;
|
|
28
|
+
--snice-color-green-100: 220 252 231;
|
|
29
|
+
--snice-color-green-200: 187 247 208;
|
|
30
|
+
--snice-color-green-300: 134 239 172;
|
|
31
|
+
--snice-color-green-400: 74 222 128;
|
|
32
|
+
--snice-color-green-500: 34 197 94;
|
|
33
|
+
--snice-color-green-600: 22 163 74;
|
|
34
|
+
--snice-color-green-700: 21 128 61;
|
|
35
|
+
--snice-color-green-800: 22 101 52;
|
|
36
|
+
--snice-color-green-900: 20 83 45;
|
|
37
|
+
--snice-color-green-950: 5 46 22;
|
|
38
|
+
|
|
39
|
+
--snice-color-red-50: 254 242 242;
|
|
40
|
+
--snice-color-red-100: 254 226 226;
|
|
41
|
+
--snice-color-red-200: 254 202 202;
|
|
42
|
+
--snice-color-red-300: 252 165 165;
|
|
43
|
+
--snice-color-red-400: 248 113 113;
|
|
44
|
+
--snice-color-red-500: 239 68 68;
|
|
45
|
+
--snice-color-red-600: 220 38 38;
|
|
46
|
+
--snice-color-red-700: 185 28 28;
|
|
47
|
+
--snice-color-red-800: 153 27 27;
|
|
48
|
+
--snice-color-red-900: 127 29 29;
|
|
49
|
+
--snice-color-red-950: 69 10 10;
|
|
50
|
+
|
|
51
|
+
--snice-color-yellow-50: 254 252 232;
|
|
52
|
+
--snice-color-yellow-100: 254 249 195;
|
|
53
|
+
--snice-color-yellow-200: 254 240 138;
|
|
54
|
+
--snice-color-yellow-300: 253 224 71;
|
|
55
|
+
--snice-color-yellow-400: 250 204 21;
|
|
56
|
+
--snice-color-yellow-500: 234 179 8;
|
|
57
|
+
--snice-color-yellow-600: 202 138 4;
|
|
58
|
+
--snice-color-yellow-700: 161 98 7;
|
|
59
|
+
--snice-color-yellow-800: 133 77 14;
|
|
60
|
+
--snice-color-yellow-900: 113 63 18;
|
|
61
|
+
--snice-color-yellow-950: 66 32 6;
|
|
62
|
+
|
|
63
|
+
/* Light theme (default) */
|
|
64
|
+
--snice-color-primary: rgb(var(--snice-color-blue-600));
|
|
65
|
+
--snice-color-success: rgb(var(--snice-color-green-600));
|
|
66
|
+
--snice-color-warning: rgb(var(--snice-color-yellow-600));
|
|
67
|
+
--snice-color-danger: rgb(var(--snice-color-red-600));
|
|
68
|
+
--snice-color-neutral: rgb(var(--snice-color-gray-600));
|
|
69
|
+
|
|
70
|
+
--snice-color-primary-hover: rgb(var(--snice-color-blue-700));
|
|
71
|
+
--snice-color-success-hover: rgb(var(--snice-color-green-700));
|
|
72
|
+
--snice-color-warning-hover: rgb(var(--snice-color-yellow-700));
|
|
73
|
+
--snice-color-danger-hover: rgb(var(--snice-color-red-700));
|
|
74
|
+
--snice-color-neutral-hover: rgb(var(--snice-color-gray-700));
|
|
75
|
+
|
|
76
|
+
/* Semantic colors */
|
|
77
|
+
--snice-color-text: rgb(var(--snice-color-gray-900));
|
|
78
|
+
--snice-color-text-secondary: rgb(var(--snice-color-gray-600));
|
|
79
|
+
--snice-color-text-tertiary: rgb(var(--snice-color-gray-500));
|
|
80
|
+
--snice-color-text-inverse: rgb(var(--snice-color-gray-50));
|
|
81
|
+
|
|
82
|
+
--snice-color-background: rgb(255 255 255);
|
|
83
|
+
--snice-color-background-secondary: rgb(var(--snice-color-gray-50));
|
|
84
|
+
--snice-color-background-tertiary: rgb(var(--snice-color-gray-100));
|
|
85
|
+
--snice-color-background-element: rgb(252 251 249);
|
|
86
|
+
|
|
87
|
+
--snice-color-border: rgb(var(--snice-color-gray-200));
|
|
88
|
+
--snice-color-border-hover: rgb(var(--snice-color-gray-300));
|
|
89
|
+
--snice-color-border-focus: rgb(var(--snice-color-blue-500));
|
|
90
|
+
|
|
91
|
+
/* Spacing */
|
|
92
|
+
--snice-spacing-3xs: 0.125rem; /* 2px */
|
|
93
|
+
--snice-spacing-2xs: 0.25rem; /* 4px */
|
|
94
|
+
--snice-spacing-xs: 0.5rem; /* 8px */
|
|
95
|
+
--snice-spacing-sm: 0.75rem; /* 12px */
|
|
96
|
+
--snice-spacing-md: 1rem; /* 16px */
|
|
97
|
+
--snice-spacing-lg: 1.5rem; /* 24px */
|
|
98
|
+
--snice-spacing-xl: 2rem; /* 32px */
|
|
99
|
+
--snice-spacing-2xl: 3rem; /* 48px */
|
|
100
|
+
--snice-spacing-3xl: 4rem; /* 64px */
|
|
101
|
+
|
|
102
|
+
/* Typography */
|
|
103
|
+
--snice-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
|
|
104
|
+
--snice-font-family-mono: SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
|
|
105
|
+
|
|
106
|
+
--snice-font-size-2xs: 0.625rem; /* 10px */
|
|
107
|
+
--snice-font-size-xs: 0.75rem; /* 12px */
|
|
108
|
+
--snice-font-size-sm: 0.875rem; /* 14px */
|
|
109
|
+
--snice-font-size-md: 1rem; /* 16px */
|
|
110
|
+
--snice-font-size-lg: 1.125rem; /* 18px */
|
|
111
|
+
--snice-font-size-xl: 1.25rem; /* 20px */
|
|
112
|
+
--snice-font-size-2xl: 1.5rem; /* 24px */
|
|
113
|
+
--snice-font-size-3xl: 1.875rem; /* 30px */
|
|
114
|
+
--snice-font-size-4xl: 2.25rem; /* 36px */
|
|
115
|
+
|
|
116
|
+
--snice-font-weight-light: 300;
|
|
117
|
+
--snice-font-weight-normal: 400;
|
|
118
|
+
--snice-font-weight-medium: 500;
|
|
119
|
+
--snice-font-weight-semibold: 600;
|
|
120
|
+
--snice-font-weight-bold: 700;
|
|
121
|
+
|
|
122
|
+
--snice-line-height-dense: 1.25;
|
|
123
|
+
--snice-line-height-normal: 1.5;
|
|
124
|
+
--snice-line-height-loose: 1.75;
|
|
125
|
+
|
|
126
|
+
/* Border radius */
|
|
127
|
+
--snice-border-radius-sm: 0.125rem; /* 2px */
|
|
128
|
+
--snice-border-radius-md: 0.25rem; /* 4px */
|
|
129
|
+
--snice-border-radius-lg: 0.5rem; /* 8px */
|
|
130
|
+
--snice-border-radius-xl: 1rem; /* 16px */
|
|
131
|
+
--snice-border-radius-circle: 50%;
|
|
132
|
+
--snice-border-radius-pill: 9999px;
|
|
133
|
+
|
|
134
|
+
/* Shadows */
|
|
135
|
+
--snice-shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
|
|
136
|
+
--snice-shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
|
|
137
|
+
--snice-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
|
138
|
+
--snice-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
|
|
139
|
+
--snice-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
|
|
140
|
+
--snice-shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
|
|
141
|
+
|
|
142
|
+
/* Transitions */
|
|
143
|
+
--snice-transition-fast: 150ms;
|
|
144
|
+
--snice-transition-medium: 250ms;
|
|
145
|
+
--snice-transition-slow: 350ms;
|
|
146
|
+
|
|
147
|
+
/* Z-index */
|
|
148
|
+
--snice-z-index-dropdown: 1000;
|
|
149
|
+
--snice-z-index-sticky: 1020;
|
|
150
|
+
--snice-z-index-fixed: 1030;
|
|
151
|
+
--snice-z-index-modal-backdrop: 1040;
|
|
152
|
+
--snice-z-index-modal: 1050;
|
|
153
|
+
--snice-z-index-popover: 1060;
|
|
154
|
+
--snice-z-index-tooltip: 1070;
|
|
155
|
+
|
|
156
|
+
/* Focus */
|
|
157
|
+
--snice-focus-ring-width: 2px;
|
|
158
|
+
--snice-focus-ring-color: rgb(var(--snice-color-blue-500) / 0.5);
|
|
159
|
+
--snice-focus-ring-offset: 2px;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* Dark theme */
|
|
163
|
+
[data-theme="dark"] {
|
|
164
|
+
--snice-color-primary: rgb(var(--snice-color-blue-500));
|
|
165
|
+
--snice-color-success: rgb(var(--snice-color-green-500));
|
|
166
|
+
--snice-color-warning: rgb(var(--snice-color-yellow-500));
|
|
167
|
+
--snice-color-danger: rgb(var(--snice-color-red-500));
|
|
168
|
+
--snice-color-neutral: rgb(var(--snice-color-gray-400));
|
|
169
|
+
|
|
170
|
+
--snice-color-primary-hover: rgb(var(--snice-color-blue-400));
|
|
171
|
+
--snice-color-success-hover: rgb(var(--snice-color-green-400));
|
|
172
|
+
--snice-color-warning-hover: rgb(var(--snice-color-yellow-400));
|
|
173
|
+
--snice-color-danger-hover: rgb(var(--snice-color-red-400));
|
|
174
|
+
--snice-color-neutral-hover: rgb(var(--snice-color-gray-300));
|
|
175
|
+
|
|
176
|
+
--snice-color-text: rgb(var(--snice-color-gray-50));
|
|
177
|
+
--snice-color-text-secondary: rgb(var(--snice-color-gray-300));
|
|
178
|
+
--snice-color-text-tertiary: rgb(var(--snice-color-gray-400));
|
|
179
|
+
--snice-color-text-inverse: rgb(var(--snice-color-gray-900));
|
|
180
|
+
|
|
181
|
+
--snice-color-background: rgb(var(--snice-color-gray-900));
|
|
182
|
+
--snice-color-background-secondary: rgb(var(--snice-color-gray-800));
|
|
183
|
+
--snice-color-background-tertiary: rgb(var(--snice-color-gray-700));
|
|
184
|
+
--snice-color-background-element: rgb(47 45 43);
|
|
185
|
+
|
|
186
|
+
--snice-color-border: rgb(var(--snice-color-gray-700));
|
|
187
|
+
--snice-color-border-hover: rgb(var(--snice-color-gray-600));
|
|
188
|
+
--snice-color-border-focus: rgb(var(--snice-color-blue-400));
|
|
189
|
+
|
|
190
|
+
--snice-shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.1);
|
|
191
|
+
--snice-shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.15), 0 1px 2px -1px rgb(0 0 0 / 0.15);
|
|
192
|
+
--snice-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.15), 0 2px 4px -2px rgb(0 0 0 / 0.15);
|
|
193
|
+
--snice-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.15), 0 4px 6px -4px rgb(0 0 0 / 0.15);
|
|
194
|
+
--snice-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.15), 0 8px 10px -6px rgb(0 0 0 / 0.15);
|
|
195
|
+
--snice-shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.35);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/* Auto dark theme based on system preference */
|
|
199
|
+
@media (prefers-color-scheme: dark) {
|
|
200
|
+
:root:not([data-theme="light"]) {
|
|
201
|
+
--snice-color-primary: rgb(var(--snice-color-blue-500));
|
|
202
|
+
--snice-color-success: rgb(var(--snice-color-green-500));
|
|
203
|
+
--snice-color-warning: rgb(var(--snice-color-yellow-500));
|
|
204
|
+
--snice-color-danger: rgb(var(--snice-color-red-500));
|
|
205
|
+
--snice-color-neutral: rgb(var(--snice-color-gray-400));
|
|
206
|
+
|
|
207
|
+
--snice-color-primary-hover: rgb(var(--snice-color-blue-400));
|
|
208
|
+
--snice-color-success-hover: rgb(var(--snice-color-green-400));
|
|
209
|
+
--snice-color-warning-hover: rgb(var(--snice-color-yellow-400));
|
|
210
|
+
--snice-color-danger-hover: rgb(var(--snice-color-red-400));
|
|
211
|
+
--snice-color-neutral-hover: rgb(var(--snice-color-gray-300));
|
|
212
|
+
|
|
213
|
+
--snice-color-text: rgb(var(--snice-color-gray-50));
|
|
214
|
+
--snice-color-text-secondary: rgb(var(--snice-color-gray-300));
|
|
215
|
+
--snice-color-text-tertiary: rgb(var(--snice-color-gray-400));
|
|
216
|
+
--snice-color-text-inverse: rgb(var(--snice-color-gray-900));
|
|
217
|
+
|
|
218
|
+
--snice-color-background: rgb(var(--snice-color-gray-900));
|
|
219
|
+
--snice-color-background-secondary: rgb(var(--snice-color-gray-800));
|
|
220
|
+
--snice-color-background-tertiary: rgb(var(--snice-color-gray-700));
|
|
221
|
+
--snice-color-background-element: rgb(47 45 43);
|
|
222
|
+
|
|
223
|
+
--snice-color-border: rgb(var(--snice-color-gray-700));
|
|
224
|
+
--snice-color-border-hover: rgb(var(--snice-color-gray-600));
|
|
225
|
+
--snice-color-border-focus: rgb(var(--snice-color-blue-400));
|
|
226
|
+
|
|
227
|
+
--snice-shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.1);
|
|
228
|
+
--snice-shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.15), 0 1px 2px -1px rgb(0 0 0 / 0.15);
|
|
229
|
+
--snice-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.15), 0 2px 4px -2px rgb(0 0 0 / 0.15);
|
|
230
|
+
--snice-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.15), 0 4px 6px -4px rgb(0 0 0 / 0.15);
|
|
231
|
+
--snice-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.15), 0 8px 10px -6px rgb(0 0 0 / 0.15);
|
|
232
|
+
--snice-shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.35);
|
|
233
|
+
}
|
|
234
|
+
}
|