juxscript 1.1.4 → 1.1.6
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/index.d.ts +10 -10
- package/index.d.ts.map +1 -0
- package/lib/components/alert.d.ts +32 -0
- package/lib/components/alert.d.ts.map +1 -0
- package/lib/components/alert.js +153 -0
- package/lib/components/alert.ts +200 -0
- package/lib/components/app.d.ts +89 -0
- package/lib/components/app.d.ts.map +1 -0
- package/lib/components/app.js +175 -0
- package/lib/components/app.ts +247 -0
- package/lib/components/badge.d.ts +27 -0
- package/lib/components/badge.d.ts.map +1 -0
- package/lib/components/badge.js +70 -0
- package/lib/components/badge.ts +101 -0
- package/lib/components/base/BaseComponent.d.ts +142 -0
- package/lib/components/base/BaseComponent.d.ts.map +1 -0
- package/lib/components/base/BaseComponent.js +363 -0
- package/lib/components/base/BaseComponent.ts +421 -0
- package/lib/components/base/FormInput.d.ts +73 -0
- package/lib/components/base/FormInput.d.ts.map +1 -0
- package/lib/components/base/FormInput.js +163 -0
- package/lib/components/base/FormInput.ts +227 -0
- package/lib/components/button.d.ts +48 -0
- package/lib/components/button.d.ts.map +1 -0
- package/lib/components/button.js +121 -0
- package/lib/components/button.ts +178 -0
- package/lib/components/card.d.ts +34 -0
- package/lib/components/card.d.ts.map +1 -0
- package/lib/components/card.js +127 -0
- package/lib/components/card.ts +173 -0
- package/lib/components/chart.d.ts +45 -0
- package/lib/components/chart.d.ts.map +1 -0
- package/lib/components/chart.js +186 -0
- package/lib/components/chart.ts +231 -0
- package/lib/components/checkbox.d.ts +31 -0
- package/lib/components/checkbox.d.ts.map +1 -0
- package/lib/components/checkbox.js +185 -0
- package/lib/components/checkbox.ts +242 -0
- package/lib/components/code.d.ts +24 -0
- package/lib/components/code.d.ts.map +1 -0
- package/lib/components/code.js +88 -0
- package/lib/components/code.ts +123 -0
- package/lib/components/container.d.ts +42 -0
- package/lib/components/container.d.ts.map +1 -0
- package/lib/components/container.js +93 -0
- package/lib/components/container.ts +140 -0
- package/lib/components/data.d.ts +36 -0
- package/lib/components/data.d.ts.map +1 -0
- package/lib/components/data.js +110 -0
- package/lib/components/data.ts +135 -0
- package/lib/components/datepicker.d.ts +38 -0
- package/lib/components/datepicker.d.ts.map +1 -0
- package/lib/components/datepicker.js +177 -0
- package/lib/components/datepicker.ts +234 -0
- package/lib/components/dialog.d.ts +38 -0
- package/lib/components/dialog.d.ts.map +1 -0
- package/lib/components/dialog.js +126 -0
- package/lib/components/dialog.ts +172 -0
- package/lib/components/divider.d.ts +30 -0
- package/lib/components/divider.d.ts.map +1 -0
- package/lib/components/divider.js +69 -0
- package/lib/components/divider.ts +100 -0
- package/lib/components/dropdown.d.ts +39 -0
- package/lib/components/dropdown.d.ts.map +1 -0
- package/lib/components/dropdown.js +133 -0
- package/lib/components/dropdown.ts +186 -0
- package/lib/components/element.d.ts +50 -0
- package/lib/components/element.d.ts.map +1 -0
- package/lib/components/element.js +206 -0
- package/lib/components/element.ts +267 -0
- package/lib/components/fileupload.d.ts +40 -0
- package/lib/components/fileupload.d.ts.map +1 -0
- package/lib/components/fileupload.js +241 -0
- package/lib/components/fileupload.ts +309 -0
- package/lib/components/grid.d.ts +87 -0
- package/lib/components/grid.d.ts.map +1 -0
- package/lib/components/grid.js +205 -0
- package/lib/components/grid.ts +291 -0
- package/lib/components/guard.d.ts +41 -0
- package/lib/components/guard.d.ts.map +1 -0
- package/lib/components/guard.js +56 -0
- package/lib/components/guard.ts +92 -0
- package/lib/components/heading.d.ts +24 -0
- package/lib/components/heading.d.ts.map +1 -0
- package/lib/components/heading.js +67 -0
- package/lib/components/heading.ts +96 -0
- package/lib/components/helpers.d.ts +9 -0
- package/lib/components/helpers.d.ts.map +1 -0
- package/lib/components/helpers.js +30 -0
- package/lib/components/helpers.ts +41 -0
- package/lib/components/hero.d.ts +45 -0
- package/lib/components/hero.d.ts.map +1 -0
- package/lib/components/hero.js +165 -0
- package/lib/components/hero.ts +224 -0
- package/lib/components/icon.d.ts +35 -0
- package/lib/components/icon.d.ts.map +1 -0
- package/lib/components/icon.js +132 -0
- package/lib/components/icon.ts +178 -0
- package/lib/components/icons.d.ts +25 -0
- package/lib/components/icons.d.ts.map +1 -0
- package/lib/components/icons.js +440 -0
- package/lib/components/icons.ts +464 -0
- package/lib/components/include.d.ts +120 -0
- package/lib/components/include.d.ts.map +1 -0
- package/lib/components/include.js +350 -0
- package/lib/components/include.ts +410 -0
- package/lib/components/input.d.ts +83 -0
- package/lib/components/input.d.ts.map +1 -0
- package/lib/components/input.js +348 -0
- package/lib/components/input.ts +457 -0
- package/lib/components/list.d.ts +82 -0
- package/lib/components/list.d.ts.map +1 -0
- package/lib/components/list.js +311 -0
- package/lib/components/list.ts +419 -0
- package/lib/components/loading.d.ts +24 -0
- package/lib/components/loading.d.ts.map +1 -0
- package/lib/components/loading.js +73 -0
- package/lib/components/loading.ts +100 -0
- package/lib/components/menu.d.ts +37 -0
- package/lib/components/menu.d.ts.map +1 -0
- package/lib/components/menu.js +202 -0
- package/lib/components/menu.ts +275 -0
- package/lib/components/modal.d.ts +51 -0
- package/lib/components/modal.d.ts.map +1 -0
- package/lib/components/modal.js +227 -0
- package/lib/components/modal.ts +284 -0
- package/lib/components/nav.d.ts +45 -0
- package/lib/components/nav.d.ts.map +1 -0
- package/lib/components/nav.js +190 -0
- package/lib/components/nav.ts +257 -0
- package/lib/components/paragraph.d.ts +21 -0
- package/lib/components/paragraph.d.ts.map +1 -0
- package/lib/components/paragraph.js +70 -0
- package/lib/components/paragraph.ts +97 -0
- package/lib/components/progress.d.ts +39 -0
- package/lib/components/progress.d.ts.map +1 -0
- package/lib/components/progress.js +113 -0
- package/lib/components/progress.ts +159 -0
- package/lib/components/radio.d.ts +41 -0
- package/lib/components/radio.d.ts.map +1 -0
- package/lib/components/radio.js +203 -0
- package/lib/components/radio.ts +278 -0
- package/lib/components/req.d.ts +155 -0
- package/lib/components/req.d.ts.map +1 -0
- package/lib/components/req.js +253 -0
- package/lib/components/req.ts +303 -0
- package/lib/components/script.d.ts +14 -0
- package/lib/components/script.d.ts.map +1 -0
- package/lib/components/script.js +33 -0
- package/lib/components/script.ts +41 -0
- package/lib/components/select.d.ts +40 -0
- package/lib/components/select.d.ts.map +1 -0
- package/lib/components/select.js +183 -0
- package/lib/components/select.ts +252 -0
- package/lib/components/sidebar.d.ts +48 -0
- package/lib/components/sidebar.d.ts.map +1 -0
- package/lib/components/sidebar.js +207 -0
- package/lib/components/sidebar.ts +275 -0
- package/lib/components/style.d.ts +14 -0
- package/lib/components/style.d.ts.map +1 -0
- package/lib/components/style.js +33 -0
- package/lib/components/style.ts +41 -0
- package/lib/components/switch.d.ts +32 -0
- package/lib/components/switch.d.ts.map +1 -0
- package/lib/components/switch.js +186 -0
- package/lib/components/switch.ts +246 -0
- package/lib/components/table.d.ts +137 -0
- package/lib/components/table.d.ts.map +1 -0
- package/lib/components/table.js +1045 -0
- package/lib/components/table.ts +1249 -0
- package/lib/components/tabs.d.ts +36 -0
- package/lib/components/tabs.d.ts.map +1 -0
- package/lib/components/tabs.js +198 -0
- package/lib/components/tabs.ts +250 -0
- package/lib/components/theme-toggle.d.ts +44 -0
- package/lib/components/theme-toggle.d.ts.map +1 -0
- package/lib/components/theme-toggle.js +215 -0
- package/lib/components/theme-toggle.ts +293 -0
- package/lib/components/tooltip.d.ts +30 -0
- package/lib/components/tooltip.d.ts.map +1 -0
- package/lib/components/tooltip.js +109 -0
- package/lib/components/tooltip.ts +144 -0
- package/lib/components/view.d.ts +48 -0
- package/lib/components/view.d.ts.map +1 -0
- package/lib/components/view.js +149 -0
- package/lib/components/view.ts +190 -0
- package/lib/components/write.d.ts +107 -0
- package/lib/components/write.d.ts.map +1 -0
- package/lib/components/write.js +222 -0
- package/lib/components/write.ts +272 -0
- package/lib/layouts/default.css +260 -0
- package/lib/layouts/figma.css +334 -0
- package/lib/reactivity/state.d.ts +36 -0
- package/lib/reactivity/state.d.ts.map +1 -0
- package/lib/reactivity/state.js +67 -0
- package/lib/reactivity/state.ts +78 -0
- package/lib/utils/fetch.d.ts +176 -0
- package/lib/utils/fetch.d.ts.map +1 -0
- package/lib/utils/fetch.js +427 -0
- package/lib/utils/fetch.ts +553 -0
- package/machinery/compiler3.js +78 -0
- package/machinery/doc-generator.js +136 -0
- package/machinery/imports.js +155 -0
- package/machinery/ts-shim.js +46 -0
- package/package.json +9 -15
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
export interface Tab {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
content: string | HTMLElement;
|
|
6
|
+
icon?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TabsOptions {
|
|
9
|
+
tabs?: Tab[];
|
|
10
|
+
activeTab?: string;
|
|
11
|
+
variant?: 'default' | 'pills' | 'underline';
|
|
12
|
+
style?: string;
|
|
13
|
+
class?: string;
|
|
14
|
+
}
|
|
15
|
+
type TabsState = {
|
|
16
|
+
tabs: Tab[];
|
|
17
|
+
activeTab: string;
|
|
18
|
+
variant: string;
|
|
19
|
+
style: string;
|
|
20
|
+
class: string;
|
|
21
|
+
};
|
|
22
|
+
export declare class Tabs extends BaseComponent<TabsState> {
|
|
23
|
+
constructor(id: string, options?: TabsOptions);
|
|
24
|
+
protected getTriggerEvents(): readonly string[];
|
|
25
|
+
protected getCallbackEvents(): readonly string[];
|
|
26
|
+
tabs(value: Tab[]): this;
|
|
27
|
+
addTab(tab: Tab): this;
|
|
28
|
+
activeTab(value: string): this;
|
|
29
|
+
variant(value: 'default' | 'pills' | 'underline'): this;
|
|
30
|
+
private _updateActiveTab;
|
|
31
|
+
render(targetId?: string): this;
|
|
32
|
+
private _switchTab;
|
|
33
|
+
}
|
|
34
|
+
export declare function tabs(id: string, options?: TabsOptions): Tabs;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.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;CAcnB;AAED,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI,CAEhE"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
// Event definitions
|
|
3
|
+
const TRIGGER_EVENTS = [];
|
|
4
|
+
const CALLBACK_EVENTS = ['tabChange'];
|
|
5
|
+
export class Tabs extends BaseComponent {
|
|
6
|
+
constructor(id, options = {}) {
|
|
7
|
+
super(id, {
|
|
8
|
+
tabs: options.tabs ?? [],
|
|
9
|
+
activeTab: options.activeTab ?? (options.tabs?.[0]?.id ?? ''),
|
|
10
|
+
variant: options.variant ?? 'default',
|
|
11
|
+
style: options.style ?? '',
|
|
12
|
+
class: options.class ?? ''
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
getTriggerEvents() {
|
|
16
|
+
return TRIGGER_EVENTS;
|
|
17
|
+
}
|
|
18
|
+
getCallbackEvents() {
|
|
19
|
+
return CALLBACK_EVENTS;
|
|
20
|
+
}
|
|
21
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
22
|
+
* FLUENT API
|
|
23
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
24
|
+
// ✅ Inherited from BaseComponent
|
|
25
|
+
tabs(value) {
|
|
26
|
+
this.state.tabs = value;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
addTab(tab) {
|
|
30
|
+
this.state.tabs = [...this.state.tabs, tab];
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
activeTab(value) {
|
|
34
|
+
this.state.activeTab = value;
|
|
35
|
+
this._updateActiveTab();
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
variant(value) {
|
|
39
|
+
this.state.variant = value;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
_updateActiveTab() {
|
|
43
|
+
if (!this.container)
|
|
44
|
+
return;
|
|
45
|
+
const wrapper = this.container.querySelector(`#${this._id}`);
|
|
46
|
+
if (!wrapper)
|
|
47
|
+
return;
|
|
48
|
+
wrapper.querySelectorAll('.jux-tabs-button').forEach(btn => {
|
|
49
|
+
btn.classList.toggle('jux-tabs-button-active', btn.getAttribute('data-tab') === this.state.activeTab);
|
|
50
|
+
});
|
|
51
|
+
wrapper.querySelectorAll('.jux-tabs-panel').forEach(panel => {
|
|
52
|
+
const isActive = panel.getAttribute('data-tab') === this.state.activeTab;
|
|
53
|
+
panel.classList.toggle('jux-tabs-panel-active', isActive);
|
|
54
|
+
panel.style.display = isActive ? 'block' : 'none';
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
58
|
+
* RENDER
|
|
59
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
60
|
+
render(targetId) {
|
|
61
|
+
const container = this._setupContainer(targetId);
|
|
62
|
+
const { tabs, activeTab, variant, style, class: className } = this.state;
|
|
63
|
+
const hasActiveTabSync = this._syncBindings.some(b => b.property === 'activeTab');
|
|
64
|
+
const wrapper = document.createElement('div');
|
|
65
|
+
wrapper.className = `jux-tabs jux-tabs-${variant}`;
|
|
66
|
+
wrapper.id = this._id;
|
|
67
|
+
if (className)
|
|
68
|
+
wrapper.className += ` ${className}`;
|
|
69
|
+
if (style)
|
|
70
|
+
wrapper.setAttribute('style', style);
|
|
71
|
+
const tabList = document.createElement('div');
|
|
72
|
+
tabList.className = 'jux-tabs-list';
|
|
73
|
+
const tabPanels = document.createElement('div');
|
|
74
|
+
tabPanels.className = 'jux-tabs-panels';
|
|
75
|
+
tabs.forEach(tab => {
|
|
76
|
+
const tabButton = document.createElement('button');
|
|
77
|
+
tabButton.className = 'jux-tabs-button';
|
|
78
|
+
tabButton.setAttribute('data-tab', tab.id);
|
|
79
|
+
if (tab.id === activeTab)
|
|
80
|
+
tabButton.classList.add('jux-tabs-button-active');
|
|
81
|
+
tabButton.textContent = tab.label;
|
|
82
|
+
tabList.appendChild(tabButton);
|
|
83
|
+
const tabPanel = document.createElement('div');
|
|
84
|
+
tabPanel.className = 'jux-tabs-panel';
|
|
85
|
+
tabPanel.setAttribute('data-tab', tab.id);
|
|
86
|
+
if (tab.id === activeTab) {
|
|
87
|
+
tabPanel.classList.add('jux-tabs-panel-active');
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
tabPanel.style.display = 'none';
|
|
91
|
+
}
|
|
92
|
+
if (typeof tab.content === 'string') {
|
|
93
|
+
tabPanel.innerHTML = tab.content;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
tabPanel.appendChild(tab.content);
|
|
97
|
+
}
|
|
98
|
+
tabPanels.appendChild(tabPanel);
|
|
99
|
+
});
|
|
100
|
+
wrapper.appendChild(tabList);
|
|
101
|
+
wrapper.appendChild(tabPanels);
|
|
102
|
+
if (!hasActiveTabSync) {
|
|
103
|
+
tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
|
|
104
|
+
button.addEventListener('click', () => {
|
|
105
|
+
const tabId = button.getAttribute('data-tab');
|
|
106
|
+
this.state.activeTab = tabId;
|
|
107
|
+
this._switchTab(tabId, wrapper);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
this._wireStandardEvents(wrapper);
|
|
112
|
+
this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
|
|
113
|
+
if (property === 'activeTab') {
|
|
114
|
+
const transformToState = toState || ((v) => String(v));
|
|
115
|
+
const transformToComponent = toComponent || ((v) => String(v));
|
|
116
|
+
let isUpdating = false;
|
|
117
|
+
stateObj.subscribe((val) => {
|
|
118
|
+
if (isUpdating)
|
|
119
|
+
return;
|
|
120
|
+
const transformed = transformToComponent(val);
|
|
121
|
+
this.state.activeTab = transformed;
|
|
122
|
+
this._switchTab(transformed, wrapper);
|
|
123
|
+
});
|
|
124
|
+
tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
|
|
125
|
+
button.addEventListener('click', () => {
|
|
126
|
+
if (isUpdating)
|
|
127
|
+
return;
|
|
128
|
+
isUpdating = true;
|
|
129
|
+
const tabId = button.getAttribute('data-tab');
|
|
130
|
+
this.state.activeTab = tabId;
|
|
131
|
+
this._switchTab(tabId, wrapper);
|
|
132
|
+
const transformed = transformToState(tabId);
|
|
133
|
+
stateObj.set(transformed);
|
|
134
|
+
setTimeout(() => { isUpdating = false; }, 0);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else if (property === 'tabs') {
|
|
139
|
+
const transform = toComponent || ((v) => v);
|
|
140
|
+
stateObj.subscribe((val) => {
|
|
141
|
+
const transformed = transform(val);
|
|
142
|
+
this.state.tabs = transformed;
|
|
143
|
+
tabList.innerHTML = '';
|
|
144
|
+
tabPanels.innerHTML = '';
|
|
145
|
+
transformed.forEach((tab) => {
|
|
146
|
+
const tabButton = document.createElement('button');
|
|
147
|
+
tabButton.className = 'jux-tabs-button';
|
|
148
|
+
tabButton.setAttribute('data-tab', tab.id);
|
|
149
|
+
if (tab.id === this.state.activeTab)
|
|
150
|
+
tabButton.classList.add('jux-tabs-button-active');
|
|
151
|
+
tabButton.textContent = tab.label;
|
|
152
|
+
tabList.appendChild(tabButton);
|
|
153
|
+
const tabPanel = document.createElement('div');
|
|
154
|
+
tabPanel.className = 'jux-tabs-panel';
|
|
155
|
+
tabPanel.setAttribute('data-tab', tab.id);
|
|
156
|
+
if (tab.id === this.state.activeTab) {
|
|
157
|
+
tabPanel.classList.add('jux-tabs-panel-active');
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
tabPanel.style.display = 'none';
|
|
161
|
+
}
|
|
162
|
+
if (typeof tab.content === 'string') {
|
|
163
|
+
tabPanel.innerHTML = tab.content;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
tabPanel.appendChild(tab.content);
|
|
167
|
+
}
|
|
168
|
+
tabPanels.appendChild(tabPanel);
|
|
169
|
+
});
|
|
170
|
+
tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
|
|
171
|
+
button.addEventListener('click', () => {
|
|
172
|
+
const tabId = button.getAttribute('data-tab');
|
|
173
|
+
this.state.activeTab = tabId;
|
|
174
|
+
this._switchTab(tabId, wrapper);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
container.appendChild(wrapper);
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
_switchTab(tabId, wrapper) {
|
|
184
|
+
wrapper.querySelectorAll('.jux-tabs-button').forEach(btn => {
|
|
185
|
+
btn.classList.toggle('jux-tabs-button-active', btn.getAttribute('data-tab') === tabId);
|
|
186
|
+
});
|
|
187
|
+
wrapper.querySelectorAll('.jux-tabs-panel').forEach(panel => {
|
|
188
|
+
const isActive = panel.getAttribute('data-tab') === tabId;
|
|
189
|
+
panel.classList.toggle('jux-tabs-panel-active', isActive);
|
|
190
|
+
panel.style.display = isActive ? 'block' : 'none';
|
|
191
|
+
});
|
|
192
|
+
// 🎯 Fire the tabChange callback event
|
|
193
|
+
this._triggerCallback('tabChange', tabId);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export function tabs(id, options = {}) {
|
|
197
|
+
return new Tabs(id, options);
|
|
198
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
|
|
3
|
+
// Event definitions
|
|
4
|
+
const TRIGGER_EVENTS = [] as const;
|
|
5
|
+
const CALLBACK_EVENTS = ['tabChange'] as const;
|
|
6
|
+
|
|
7
|
+
export interface Tab {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
content: string | HTMLElement;
|
|
11
|
+
icon?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TabsOptions {
|
|
15
|
+
tabs?: Tab[];
|
|
16
|
+
activeTab?: string;
|
|
17
|
+
variant?: 'default' | 'pills' | 'underline';
|
|
18
|
+
style?: string;
|
|
19
|
+
class?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type TabsState = {
|
|
23
|
+
tabs: Tab[];
|
|
24
|
+
activeTab: string;
|
|
25
|
+
variant: string;
|
|
26
|
+
style: string;
|
|
27
|
+
class: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class Tabs extends BaseComponent<TabsState> {
|
|
31
|
+
constructor(id: string, options: TabsOptions = {}) {
|
|
32
|
+
super(id, {
|
|
33
|
+
tabs: options.tabs ?? [],
|
|
34
|
+
activeTab: options.activeTab ?? (options.tabs?.[0]?.id ?? ''),
|
|
35
|
+
variant: options.variant ?? 'default',
|
|
36
|
+
style: options.style ?? '',
|
|
37
|
+
class: options.class ?? ''
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected getTriggerEvents(): readonly string[] {
|
|
42
|
+
return TRIGGER_EVENTS;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
protected getCallbackEvents(): readonly string[] {
|
|
46
|
+
return CALLBACK_EVENTS;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
50
|
+
* FLUENT API
|
|
51
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
52
|
+
|
|
53
|
+
// ✅ Inherited from BaseComponent
|
|
54
|
+
|
|
55
|
+
tabs(value: Tab[]): this {
|
|
56
|
+
this.state.tabs = value;
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
addTab(tab: Tab): this {
|
|
61
|
+
this.state.tabs = [...this.state.tabs, tab];
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
activeTab(value: string): this {
|
|
66
|
+
this.state.activeTab = value;
|
|
67
|
+
this._updateActiveTab();
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
variant(value: 'default' | 'pills' | 'underline'): this {
|
|
72
|
+
this.state.variant = value;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private _updateActiveTab(): void {
|
|
77
|
+
if (!this.container) return;
|
|
78
|
+
const wrapper = this.container.querySelector(`#${this._id}`);
|
|
79
|
+
if (!wrapper) return;
|
|
80
|
+
|
|
81
|
+
wrapper.querySelectorAll('.jux-tabs-button').forEach(btn => {
|
|
82
|
+
btn.classList.toggle('jux-tabs-button-active', btn.getAttribute('data-tab') === this.state.activeTab);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
wrapper.querySelectorAll('.jux-tabs-panel').forEach(panel => {
|
|
86
|
+
const isActive = panel.getAttribute('data-tab') === this.state.activeTab;
|
|
87
|
+
panel.classList.toggle('jux-tabs-panel-active', isActive);
|
|
88
|
+
(panel as HTMLElement).style.display = isActive ? 'block' : 'none';
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
93
|
+
* RENDER
|
|
94
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
95
|
+
|
|
96
|
+
render(targetId?: string): this {
|
|
97
|
+
const container = this._setupContainer(targetId);
|
|
98
|
+
|
|
99
|
+
const { tabs, activeTab, variant, style, class: className } = this.state;
|
|
100
|
+
const hasActiveTabSync = this._syncBindings.some(b => b.property === 'activeTab');
|
|
101
|
+
|
|
102
|
+
const wrapper = document.createElement('div');
|
|
103
|
+
wrapper.className = `jux-tabs jux-tabs-${variant}`;
|
|
104
|
+
wrapper.id = this._id;
|
|
105
|
+
if (className) wrapper.className += ` ${className}`;
|
|
106
|
+
if (style) wrapper.setAttribute('style', style);
|
|
107
|
+
|
|
108
|
+
const tabList = document.createElement('div');
|
|
109
|
+
tabList.className = 'jux-tabs-list';
|
|
110
|
+
|
|
111
|
+
const tabPanels = document.createElement('div');
|
|
112
|
+
tabPanels.className = 'jux-tabs-panels';
|
|
113
|
+
|
|
114
|
+
tabs.forEach(tab => {
|
|
115
|
+
const tabButton = document.createElement('button');
|
|
116
|
+
tabButton.className = 'jux-tabs-button';
|
|
117
|
+
tabButton.setAttribute('data-tab', tab.id);
|
|
118
|
+
if (tab.id === activeTab) tabButton.classList.add('jux-tabs-button-active');
|
|
119
|
+
tabButton.textContent = tab.label;
|
|
120
|
+
tabList.appendChild(tabButton);
|
|
121
|
+
|
|
122
|
+
const tabPanel = document.createElement('div');
|
|
123
|
+
tabPanel.className = 'jux-tabs-panel';
|
|
124
|
+
tabPanel.setAttribute('data-tab', tab.id);
|
|
125
|
+
if (tab.id === activeTab) {
|
|
126
|
+
tabPanel.classList.add('jux-tabs-panel-active');
|
|
127
|
+
} else {
|
|
128
|
+
tabPanel.style.display = 'none';
|
|
129
|
+
}
|
|
130
|
+
if (typeof tab.content === 'string') {
|
|
131
|
+
tabPanel.innerHTML = tab.content;
|
|
132
|
+
} else {
|
|
133
|
+
tabPanel.appendChild(tab.content);
|
|
134
|
+
}
|
|
135
|
+
tabPanels.appendChild(tabPanel);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
wrapper.appendChild(tabList);
|
|
139
|
+
wrapper.appendChild(tabPanels);
|
|
140
|
+
|
|
141
|
+
if (!hasActiveTabSync) {
|
|
142
|
+
tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
|
|
143
|
+
button.addEventListener('click', () => {
|
|
144
|
+
const tabId = button.getAttribute('data-tab')!;
|
|
145
|
+
this.state.activeTab = tabId;
|
|
146
|
+
this._switchTab(tabId, wrapper);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this._wireStandardEvents(wrapper);
|
|
152
|
+
|
|
153
|
+
this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
|
|
154
|
+
if (property === 'activeTab') {
|
|
155
|
+
const transformToState = toState || ((v: any) => String(v));
|
|
156
|
+
const transformToComponent = toComponent || ((v: any) => String(v));
|
|
157
|
+
|
|
158
|
+
let isUpdating = false;
|
|
159
|
+
|
|
160
|
+
stateObj.subscribe((val: any) => {
|
|
161
|
+
if (isUpdating) return;
|
|
162
|
+
const transformed = transformToComponent(val);
|
|
163
|
+
this.state.activeTab = transformed;
|
|
164
|
+
this._switchTab(transformed, wrapper);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
|
|
168
|
+
button.addEventListener('click', () => {
|
|
169
|
+
if (isUpdating) return;
|
|
170
|
+
isUpdating = true;
|
|
171
|
+
|
|
172
|
+
const tabId = button.getAttribute('data-tab')!;
|
|
173
|
+
this.state.activeTab = tabId;
|
|
174
|
+
this._switchTab(tabId, wrapper);
|
|
175
|
+
|
|
176
|
+
const transformed = transformToState(tabId);
|
|
177
|
+
stateObj.set(transformed);
|
|
178
|
+
|
|
179
|
+
setTimeout(() => { isUpdating = false; }, 0);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else if (property === 'tabs') {
|
|
184
|
+
const transform = toComponent || ((v: any) => v);
|
|
185
|
+
|
|
186
|
+
stateObj.subscribe((val: any) => {
|
|
187
|
+
const transformed = transform(val);
|
|
188
|
+
this.state.tabs = transformed;
|
|
189
|
+
|
|
190
|
+
tabList.innerHTML = '';
|
|
191
|
+
tabPanels.innerHTML = '';
|
|
192
|
+
|
|
193
|
+
transformed.forEach((tab: any) => {
|
|
194
|
+
const tabButton = document.createElement('button');
|
|
195
|
+
tabButton.className = 'jux-tabs-button';
|
|
196
|
+
tabButton.setAttribute('data-tab', tab.id);
|
|
197
|
+
if (tab.id === this.state.activeTab) tabButton.classList.add('jux-tabs-button-active');
|
|
198
|
+
tabButton.textContent = tab.label;
|
|
199
|
+
tabList.appendChild(tabButton);
|
|
200
|
+
|
|
201
|
+
const tabPanel = document.createElement('div');
|
|
202
|
+
tabPanel.className = 'jux-tabs-panel';
|
|
203
|
+
tabPanel.setAttribute('data-tab', tab.id);
|
|
204
|
+
if (tab.id === this.state.activeTab) {
|
|
205
|
+
tabPanel.classList.add('jux-tabs-panel-active');
|
|
206
|
+
} else {
|
|
207
|
+
tabPanel.style.display = 'none';
|
|
208
|
+
}
|
|
209
|
+
if (typeof tab.content === 'string') {
|
|
210
|
+
tabPanel.innerHTML = tab.content;
|
|
211
|
+
} else {
|
|
212
|
+
tabPanel.appendChild(tab.content);
|
|
213
|
+
}
|
|
214
|
+
tabPanels.appendChild(tabPanel);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
tabList.querySelectorAll('.jux-tabs-button').forEach(button => {
|
|
218
|
+
button.addEventListener('click', () => {
|
|
219
|
+
const tabId = button.getAttribute('data-tab')!;
|
|
220
|
+
this.state.activeTab = tabId;
|
|
221
|
+
this._switchTab(tabId, wrapper);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
container.appendChild(wrapper);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private _switchTab(tabId: string, wrapper: HTMLElement): void {
|
|
233
|
+
wrapper.querySelectorAll('.jux-tabs-button').forEach(btn => {
|
|
234
|
+
btn.classList.toggle('jux-tabs-button-active', btn.getAttribute('data-tab') === tabId);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
wrapper.querySelectorAll('.jux-tabs-panel').forEach(panel => {
|
|
238
|
+
const isActive = panel.getAttribute('data-tab') === tabId;
|
|
239
|
+
panel.classList.toggle('jux-tabs-panel-active', isActive);
|
|
240
|
+
(panel as HTMLElement).style.display = isActive ? 'block' : 'none';
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// 🎯 Fire the tabChange callback event
|
|
244
|
+
this._triggerCallback('tabChange', tabId);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function tabs(id: string, options: TabsOptions = {}): Tabs {
|
|
249
|
+
return new Tabs(id, options);
|
|
250
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
+
export interface Theme {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
icon?: string;
|
|
6
|
+
iconCollection?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ThemeToggleOptions {
|
|
9
|
+
themes?: Theme[];
|
|
10
|
+
defaultTheme?: string;
|
|
11
|
+
storageKey?: string;
|
|
12
|
+
showLabel?: boolean;
|
|
13
|
+
variant?: 'button' | 'dropdown' | 'cycle';
|
|
14
|
+
style?: string;
|
|
15
|
+
class?: string;
|
|
16
|
+
}
|
|
17
|
+
type ThemeToggleState = {
|
|
18
|
+
themes: Theme[];
|
|
19
|
+
currentTheme: string;
|
|
20
|
+
storageKey: string;
|
|
21
|
+
showLabel: boolean;
|
|
22
|
+
variant: string;
|
|
23
|
+
style: string;
|
|
24
|
+
class: string;
|
|
25
|
+
};
|
|
26
|
+
export declare class ThemeToggle extends BaseComponent<ThemeToggleState> {
|
|
27
|
+
constructor(id: string, options?: ThemeToggleOptions);
|
|
28
|
+
protected getTriggerEvents(): readonly string[];
|
|
29
|
+
protected getCallbackEvents(): readonly string[];
|
|
30
|
+
private static detectTheme;
|
|
31
|
+
themes(value: Theme[]): this;
|
|
32
|
+
variant(value: 'button' | 'dropdown' | 'cycle'): this;
|
|
33
|
+
showLabel(value: boolean): this;
|
|
34
|
+
setTheme(themeId: string): this;
|
|
35
|
+
getTheme(): string;
|
|
36
|
+
addTheme(theme: Theme): this;
|
|
37
|
+
private applyTheme;
|
|
38
|
+
private cycleTheme;
|
|
39
|
+
private _updateDOM;
|
|
40
|
+
render(targetId?: string): this;
|
|
41
|
+
}
|
|
42
|
+
export declare function themeToggle(id: string, options?: ThemeToggleOptions): ThemeToggle;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=theme-toggle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-toggle.d.ts","sourceRoot":"","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