juxscript 1.1.2 → 1.1.4
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/machinery/build3.js +7 -91
- package/machinery/compiler3.js +3 -209
- package/machinery/config.js +93 -6
- package/machinery/serve.js +255 -0
- package/machinery/watcher.js +49 -161
- package/package.json +19 -5
- package/lib/components/alert.ts +0 -200
- package/lib/components/app.ts +0 -247
- package/lib/components/badge.ts +0 -101
- package/lib/components/base/BaseComponent.ts +0 -421
- package/lib/components/base/FormInput.ts +0 -227
- package/lib/components/button.ts +0 -178
- package/lib/components/card.ts +0 -173
- package/lib/components/chart.ts +0 -231
- package/lib/components/checkbox.ts +0 -242
- package/lib/components/code.ts +0 -123
- package/lib/components/container.ts +0 -140
- package/lib/components/data.ts +0 -135
- package/lib/components/datepicker.ts +0 -234
- package/lib/components/dialog.ts +0 -172
- package/lib/components/divider.ts +0 -100
- package/lib/components/dropdown.ts +0 -186
- package/lib/components/element.ts +0 -267
- package/lib/components/fileupload.ts +0 -309
- package/lib/components/grid.ts +0 -291
- package/lib/components/guard.ts +0 -92
- package/lib/components/heading.ts +0 -96
- package/lib/components/helpers.ts +0 -41
- package/lib/components/hero.ts +0 -224
- package/lib/components/icon.ts +0 -178
- package/lib/components/icons.ts +0 -464
- package/lib/components/include.ts +0 -410
- package/lib/components/input.ts +0 -457
- package/lib/components/list.ts +0 -419
- package/lib/components/loading.ts +0 -100
- package/lib/components/menu.ts +0 -275
- package/lib/components/modal.ts +0 -284
- package/lib/components/nav.ts +0 -257
- package/lib/components/paragraph.ts +0 -97
- package/lib/components/progress.ts +0 -159
- package/lib/components/radio.ts +0 -278
- package/lib/components/req.ts +0 -303
- package/lib/components/script.ts +0 -41
- package/lib/components/select.ts +0 -252
- package/lib/components/sidebar.ts +0 -275
- package/lib/components/style.ts +0 -41
- package/lib/components/switch.ts +0 -246
- package/lib/components/table.ts +0 -1249
- package/lib/components/tabs.ts +0 -250
- package/lib/components/theme-toggle.ts +0 -293
- package/lib/components/tooltip.ts +0 -144
- package/lib/components/view.ts +0 -190
- package/lib/components/write.ts +0 -272
- package/lib/layouts/default.css +0 -260
- package/lib/layouts/figma.css +0 -334
- package/lib/reactivity/state.ts +0 -78
- package/lib/utils/fetch.ts +0 -553
- package/machinery/ast.js +0 -347
- package/machinery/build.js +0 -466
- package/machinery/bundleAssets.js +0 -0
- package/machinery/bundleJux.js +0 -0
- package/machinery/bundleVendors.js +0 -0
- package/machinery/doc-generator.js +0 -136
- package/machinery/imports.js +0 -155
- package/machinery/server.js +0 -166
- package/machinery/ts-shim.js +0 -46
- package/machinery/validators/file-validator.js +0 -123
package/lib/components/tabs.ts
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
-
import { renderIcon } from './icons.js';
|
|
3
|
-
|
|
4
|
-
// Event definitions
|
|
5
|
-
const TRIGGER_EVENTS = [] as const;
|
|
6
|
-
const CALLBACK_EVENTS = ['themeChange'] as const;
|
|
7
|
-
|
|
8
|
-
export interface Theme {
|
|
9
|
-
id: string;
|
|
10
|
-
label: string;
|
|
11
|
-
icon?: string;
|
|
12
|
-
iconCollection?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface ThemeToggleOptions {
|
|
16
|
-
themes?: Theme[];
|
|
17
|
-
defaultTheme?: string;
|
|
18
|
-
storageKey?: string;
|
|
19
|
-
showLabel?: boolean;
|
|
20
|
-
variant?: 'button' | 'dropdown' | 'cycle';
|
|
21
|
-
style?: string;
|
|
22
|
-
class?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type ThemeToggleState = {
|
|
26
|
-
themes: Theme[];
|
|
27
|
-
currentTheme: string;
|
|
28
|
-
storageKey: string;
|
|
29
|
-
showLabel: boolean;
|
|
30
|
-
variant: string;
|
|
31
|
-
style: string;
|
|
32
|
-
class: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export class ThemeToggle extends BaseComponent<ThemeToggleState> {
|
|
36
|
-
constructor(id: string, options: ThemeToggleOptions = {}) {
|
|
37
|
-
const defaultThemes: Theme[] = [
|
|
38
|
-
{ id: 'light', label: 'Light', icon: '☀️' },
|
|
39
|
-
{ id: 'dark', label: 'Dark', icon: '🌙' }
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
super(id, {
|
|
43
|
-
themes: options.themes ?? defaultThemes,
|
|
44
|
-
currentTheme: options.defaultTheme ?? ThemeToggle.detectTheme(options.storageKey),
|
|
45
|
-
storageKey: options.storageKey ?? 'jux-theme',
|
|
46
|
-
showLabel: options.showLabel ?? false,
|
|
47
|
-
variant: options.variant ?? 'button',
|
|
48
|
-
style: options.style ?? '',
|
|
49
|
-
class: options.class ?? ''
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// Apply theme on initialization
|
|
53
|
-
this.applyTheme(this.state.currentTheme);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
protected getTriggerEvents(): readonly string[] {
|
|
57
|
-
return TRIGGER_EVENTS;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
protected getCallbackEvents(): readonly string[] {
|
|
61
|
-
return CALLBACK_EVENTS;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
65
|
-
* STATIC METHODS
|
|
66
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
67
|
-
|
|
68
|
-
private static detectTheme(storageKey = 'jux-theme'): string {
|
|
69
|
-
if (typeof window === 'undefined') return 'light';
|
|
70
|
-
|
|
71
|
-
const stored = localStorage.getItem(storageKey);
|
|
72
|
-
if (stored) return stored;
|
|
73
|
-
|
|
74
|
-
const current = document.body.getAttribute('data-theme');
|
|
75
|
-
if (current) return current;
|
|
76
|
-
|
|
77
|
-
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
78
|
-
return 'dark';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return 'light';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
85
|
-
* FLUENT API
|
|
86
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
87
|
-
|
|
88
|
-
// ✅ Inherited from BaseComponent
|
|
89
|
-
|
|
90
|
-
themes(value: Theme[]): this {
|
|
91
|
-
this.state.themes = value;
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
variant(value: 'button' | 'dropdown' | 'cycle'): this {
|
|
96
|
-
this.state.variant = value;
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
showLabel(value: boolean): this {
|
|
101
|
-
this.state.showLabel = value;
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
setTheme(themeId: string): this {
|
|
106
|
-
const theme = this.state.themes.find(t => t.id === themeId);
|
|
107
|
-
|
|
108
|
-
if (!theme) {
|
|
109
|
-
console.warn(`Theme "${themeId}" not found in available themes`);
|
|
110
|
-
return this;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
this.state.currentTheme = themeId;
|
|
114
|
-
this.applyTheme(themeId);
|
|
115
|
-
this._updateDOM();
|
|
116
|
-
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
getTheme(): string {
|
|
121
|
-
return this.state.currentTheme;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
addTheme(theme: Theme): this {
|
|
125
|
-
if (!this.state.themes.find(t => t.id === theme.id)) {
|
|
126
|
-
this.state.themes.push(theme);
|
|
127
|
-
}
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
132
|
-
* PRIVATE METHODS
|
|
133
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
134
|
-
|
|
135
|
-
private applyTheme(themeId: string): void {
|
|
136
|
-
if (typeof document === 'undefined') return;
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
document.body.setAttribute('data-theme', themeId);
|
|
140
|
-
document.documentElement.setAttribute('data-theme', themeId);
|
|
141
|
-
localStorage.setItem(this.state.storageKey, themeId);
|
|
142
|
-
|
|
143
|
-
window.dispatchEvent(new CustomEvent('themechange', {
|
|
144
|
-
detail: { theme: themeId }
|
|
145
|
-
}));
|
|
146
|
-
|
|
147
|
-
// 🎯 Fire the themeChange callback event
|
|
148
|
-
this._triggerCallback('themeChange', themeId);
|
|
149
|
-
|
|
150
|
-
console.log(`🎨 Theme applied: ${themeId}`);
|
|
151
|
-
} catch (error: any) {
|
|
152
|
-
throw new Error(`Failed to apply theme "${themeId}": ${error.message}`);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private cycleTheme(): void {
|
|
157
|
-
const currentIndex = this.state.themes.findIndex(t => t.id === this.state.currentTheme);
|
|
158
|
-
const nextIndex = (currentIndex + 1) % this.state.themes.length;
|
|
159
|
-
const nextTheme = this.state.themes[nextIndex];
|
|
160
|
-
|
|
161
|
-
this.setTheme(nextTheme.id);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private _updateDOM(): void {
|
|
165
|
-
if (!this.container) return;
|
|
166
|
-
|
|
167
|
-
const toggle = this.container.querySelector(`#${this._id}`);
|
|
168
|
-
if (!toggle) return;
|
|
169
|
-
|
|
170
|
-
const currentTheme = this.state.themes.find(t => t.id === this.state.currentTheme);
|
|
171
|
-
if (!currentTheme) return;
|
|
172
|
-
|
|
173
|
-
if (this.state.variant === 'button' || this.state.variant === 'cycle') {
|
|
174
|
-
const button = toggle.querySelector('button');
|
|
175
|
-
if (button && currentTheme.icon) {
|
|
176
|
-
button.innerHTML = '';
|
|
177
|
-
const iconElement = renderIcon(currentTheme.icon, currentTheme.iconCollection);
|
|
178
|
-
button.appendChild(iconElement);
|
|
179
|
-
|
|
180
|
-
if (this.state.showLabel) {
|
|
181
|
-
const labelSpan = document.createElement('span');
|
|
182
|
-
labelSpan.textContent = ` ${currentTheme.label}`;
|
|
183
|
-
button.appendChild(labelSpan);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
requestAnimationFrame(() => {
|
|
187
|
-
if ((window as any).Iconify) {
|
|
188
|
-
(window as any).Iconify.scan();
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (this.state.variant === 'dropdown') {
|
|
195
|
-
const select = toggle.querySelector('select') as HTMLSelectElement;
|
|
196
|
-
if (select) {
|
|
197
|
-
select.value = this.state.currentTheme;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
203
|
-
* RENDER
|
|
204
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
205
|
-
|
|
206
|
-
render(targetId?: string): this {
|
|
207
|
-
const container = this._setupContainer(targetId);
|
|
208
|
-
|
|
209
|
-
const { themes, currentTheme, showLabel, variant, style, class: className } = this.state;
|
|
210
|
-
|
|
211
|
-
const wrapper = document.createElement('div');
|
|
212
|
-
wrapper.className = `jux-theme-toggle`;
|
|
213
|
-
wrapper.id = this._id;
|
|
214
|
-
|
|
215
|
-
if (className) {
|
|
216
|
-
wrapper.className += ` ${className}`;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (style) {
|
|
220
|
-
wrapper.setAttribute('style', style);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const theme = themes.find(t => t.id === currentTheme);
|
|
224
|
-
|
|
225
|
-
if (variant === 'button' || variant === 'cycle') {
|
|
226
|
-
const button = document.createElement('button');
|
|
227
|
-
button.className = 'jux-theme-toggle-button';
|
|
228
|
-
button.type = 'button';
|
|
229
|
-
button.setAttribute('aria-label', 'Toggle theme');
|
|
230
|
-
|
|
231
|
-
if (theme?.icon) {
|
|
232
|
-
const iconElement = renderIcon(theme.icon, theme.iconCollection);
|
|
233
|
-
button.appendChild(iconElement);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (showLabel) {
|
|
237
|
-
const labelSpan = document.createElement('span');
|
|
238
|
-
labelSpan.textContent = ` ${theme?.label || currentTheme}`;
|
|
239
|
-
button.appendChild(labelSpan);
|
|
240
|
-
} else if (!theme?.icon) {
|
|
241
|
-
button.textContent = theme?.label || currentTheme;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
button.addEventListener('click', () => {
|
|
245
|
-
this.cycleTheme();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
wrapper.appendChild(button);
|
|
249
|
-
|
|
250
|
-
} else if (variant === 'dropdown') {
|
|
251
|
-
const select = document.createElement('select');
|
|
252
|
-
select.className = 'jux-theme-toggle-select';
|
|
253
|
-
select.setAttribute('aria-label', 'Select theme');
|
|
254
|
-
|
|
255
|
-
themes.forEach(t => {
|
|
256
|
-
const option = document.createElement('option');
|
|
257
|
-
option.value = t.id;
|
|
258
|
-
option.textContent = showLabel
|
|
259
|
-
? `${t.icon || ''} ${t.label}`.trim()
|
|
260
|
-
: t.icon || t.label;
|
|
261
|
-
|
|
262
|
-
if (t.id === currentTheme) {
|
|
263
|
-
option.selected = true;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
select.appendChild(option);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
select.addEventListener('change', (e) => {
|
|
270
|
-
const target = e.target as HTMLSelectElement;
|
|
271
|
-
this.setTheme(target.value);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
wrapper.appendChild(select);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
this._wireStandardEvents(wrapper);
|
|
278
|
-
|
|
279
|
-
container.appendChild(wrapper);
|
|
280
|
-
|
|
281
|
-
requestAnimationFrame(() => {
|
|
282
|
-
if ((window as any).Iconify) {
|
|
283
|
-
(window as any).Iconify.scan();
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
return this;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export function themeToggle(id: string, options: ThemeToggleOptions = {}): ThemeToggle {
|
|
292
|
-
return new ThemeToggle(id, options);
|
|
293
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { BaseComponent } from './base/BaseComponent.js';
|
|
2
|
-
|
|
3
|
-
// Event definitions
|
|
4
|
-
const TRIGGER_EVENTS = [] as const;
|
|
5
|
-
const CALLBACK_EVENTS = [] as const;
|
|
6
|
-
|
|
7
|
-
export interface TooltipOptions {
|
|
8
|
-
text?: string;
|
|
9
|
-
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
10
|
-
style?: string;
|
|
11
|
-
class?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type TooltipState = {
|
|
15
|
-
text: string;
|
|
16
|
-
position: string;
|
|
17
|
-
style: string;
|
|
18
|
-
class: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export class Tooltip extends BaseComponent<TooltipState> {
|
|
22
|
-
private _tooltip: HTMLElement | null = null;
|
|
23
|
-
private _target: HTMLElement | null = null;
|
|
24
|
-
|
|
25
|
-
constructor(id: string, options: TooltipOptions = {}) {
|
|
26
|
-
super(id, {
|
|
27
|
-
text: options.text ?? '',
|
|
28
|
-
position: options.position ?? 'top',
|
|
29
|
-
style: options.style ?? '',
|
|
30
|
-
class: options.class ?? ''
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected getTriggerEvents(): readonly string[] {
|
|
35
|
-
return TRIGGER_EVENTS;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected getCallbackEvents(): readonly string[] {
|
|
39
|
-
return CALLBACK_EVENTS;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
43
|
-
* FLUENT API
|
|
44
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
45
|
-
|
|
46
|
-
text(value: string): this {
|
|
47
|
-
this.state.text = value;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
position(value: 'top' | 'bottom' | 'left' | 'right'): this {
|
|
52
|
-
this.state.position = value;
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
attachTo(target: HTMLElement | null): this {
|
|
57
|
-
if (!target) return this;
|
|
58
|
-
|
|
59
|
-
this._target = target;
|
|
60
|
-
this._setupTooltip();
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/* ═════════════════════════════════════════════════════════════════
|
|
65
|
-
* RENDER
|
|
66
|
-
* ═════════════════════════════════════════════════════════════════ */
|
|
67
|
-
|
|
68
|
-
private _setupTooltip(): void {
|
|
69
|
-
if (!this._target) return;
|
|
70
|
-
|
|
71
|
-
const { text, position, style, class: className } = this.state;
|
|
72
|
-
|
|
73
|
-
// Create tooltip element
|
|
74
|
-
const tooltip = document.createElement('div');
|
|
75
|
-
tooltip.className = `jux-tooltip jux-tooltip-${position}`;
|
|
76
|
-
tooltip.id = this._id;
|
|
77
|
-
if (className) tooltip.className += ` ${className}`;
|
|
78
|
-
if (style) tooltip.setAttribute('style', style);
|
|
79
|
-
tooltip.textContent = text;
|
|
80
|
-
tooltip.style.display = 'none';
|
|
81
|
-
this._tooltip = tooltip;
|
|
82
|
-
|
|
83
|
-
document.body.appendChild(tooltip);
|
|
84
|
-
|
|
85
|
-
// Show on hover
|
|
86
|
-
this._target.addEventListener('mouseenter', () => {
|
|
87
|
-
this._show();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
this._target.addEventListener('mouseleave', () => {
|
|
91
|
-
this._hide();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private _show(): void {
|
|
97
|
-
if (!this._tooltip || !this._target) return;
|
|
98
|
-
|
|
99
|
-
const targetRect = this._target.getBoundingClientRect();
|
|
100
|
-
const tooltipRect = this._tooltip.getBoundingClientRect();
|
|
101
|
-
|
|
102
|
-
let top = 0;
|
|
103
|
-
let left = 0;
|
|
104
|
-
|
|
105
|
-
switch (this.state.position) {
|
|
106
|
-
case 'top':
|
|
107
|
-
top = targetRect.top - tooltipRect.height - 8;
|
|
108
|
-
left = targetRect.left + (targetRect.width - tooltipRect.width) / 2;
|
|
109
|
-
break;
|
|
110
|
-
case 'bottom':
|
|
111
|
-
top = targetRect.bottom + 8;
|
|
112
|
-
left = targetRect.left + (targetRect.width - tooltipRect.width) / 2;
|
|
113
|
-
break;
|
|
114
|
-
case 'left':
|
|
115
|
-
top = targetRect.top + (targetRect.height - tooltipRect.height) / 2;
|
|
116
|
-
left = targetRect.left - tooltipRect.width - 8;
|
|
117
|
-
break;
|
|
118
|
-
case 'right':
|
|
119
|
-
top = targetRect.top + (targetRect.height - tooltipRect.height) / 2;
|
|
120
|
-
left = targetRect.right + 8;
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
this._tooltip.style.top = `${top}px`;
|
|
125
|
-
this._tooltip.style.left = `${left}px`;
|
|
126
|
-
this._tooltip.style.display = 'block';
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private _hide(): void {
|
|
130
|
-
if (this._tooltip) {
|
|
131
|
-
this._tooltip.style.display = 'none';
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
render(targetId?: string): this {
|
|
136
|
-
// Tooltips don't render to containers, they attach to targets
|
|
137
|
-
console.warn('Tooltip: Use .attachTo(element) instead of .render()');
|
|
138
|
-
return this;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function tooltip(id: string, options: TooltipOptions = {}): Tooltip {
|
|
143
|
-
return new Tooltip(id, options);
|
|
144
|
-
}
|