cronixui 1.0.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/dist/cronixui.css +2048 -0
- package/dist/cronixui.js +809 -0
- package/dist/cronixui.min.css +1 -0
- package/dist/cronixui.min.js +629 -0
- package/package.json +25 -0
- package/src/cronixui.css +1959 -0
- package/src/cronixui.js +809 -0
- package/src/variables.css +93 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
(function(global) {
|
|
2
|
+
'use strict';
|
|
3
|
+
function $(selector, context = document) {
|
|
4
|
+
return context.querySelector(selector);
|
|
5
|
+
}
|
|
6
|
+
function $$(selector, context = document) {
|
|
7
|
+
return Array.from(context.querySelectorAll(selector));
|
|
8
|
+
}
|
|
9
|
+
function createEl(tag, className, attrs = {}) {
|
|
10
|
+
const el = document.createElement(tag);
|
|
11
|
+
if (className) el.className = className;
|
|
12
|
+
Object.entries(attrs).forEach(([key, val]) => {
|
|
13
|
+
if (key === 'text') el.textContent = val;
|
|
14
|
+
else if (key === 'html') el.innerHTML = val;
|
|
15
|
+
else el.setAttribute(key, val);
|
|
16
|
+
});
|
|
17
|
+
return el;
|
|
18
|
+
}
|
|
19
|
+
class CronixToggle {
|
|
20
|
+
constructor(el) {
|
|
21
|
+
this.el = el;
|
|
22
|
+
this.input = el.querySelector('input');
|
|
23
|
+
this.box = el.querySelector('.cn-toggle-box');
|
|
24
|
+
if (this.el.tagName === 'DIV' && !this.input) {
|
|
25
|
+
el.addEventListener('click', () => this.toggle());
|
|
26
|
+
}
|
|
27
|
+
el._cnToggle = this;
|
|
28
|
+
}
|
|
29
|
+
toggle() {
|
|
30
|
+
this.el.classList.toggle('on');
|
|
31
|
+
this.el.dispatchEvent(new CustomEvent('change', {
|
|
32
|
+
detail: { value: this.isOn() }
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
isOn() {
|
|
36
|
+
return this.el.classList.contains('on');
|
|
37
|
+
}
|
|
38
|
+
setOn(on) {
|
|
39
|
+
this.el.classList.toggle('on', on);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function initToggles() {
|
|
43
|
+
$$('.cn-toggle').forEach(el => {
|
|
44
|
+
if (!el._cnToggle) new CronixToggle(el);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
class CronixNav {
|
|
48
|
+
constructor(el) {
|
|
49
|
+
this.el = el;
|
|
50
|
+
this.items = $$('.cn-nav-item', el);
|
|
51
|
+
this.items.forEach(item => {
|
|
52
|
+
item.addEventListener('click', () => this.setActive(item));
|
|
53
|
+
});
|
|
54
|
+
el._cnNav = this;
|
|
55
|
+
}
|
|
56
|
+
setActive(activeItem) {
|
|
57
|
+
this.items.forEach(item => item.classList.remove('cn-nav-active'));
|
|
58
|
+
activeItem.classList.add('cn-nav-active');
|
|
59
|
+
this.el.dispatchEvent(new CustomEvent('change', {
|
|
60
|
+
detail: { item: activeItem }
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function initNavs() {
|
|
65
|
+
$$('.cn-nav').forEach(el => {
|
|
66
|
+
if (!el._cnNav) new CronixNav(el);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
class CronixTabs {
|
|
70
|
+
constructor(el) {
|
|
71
|
+
this.el = el;
|
|
72
|
+
this.tabs = $$('.cn-tab', el);
|
|
73
|
+
this.panels = $$('.cn-tab-panel', el.parentElement);
|
|
74
|
+
this.tabs.forEach((tab, i) => {
|
|
75
|
+
tab.addEventListener('click', () => this.setActive(i));
|
|
76
|
+
});
|
|
77
|
+
el._cnTabs = this;
|
|
78
|
+
}
|
|
79
|
+
setActive(index) {
|
|
80
|
+
this.tabs.forEach((tab, i) => {
|
|
81
|
+
tab.classList.toggle('cn-tab-active', i === index);
|
|
82
|
+
});
|
|
83
|
+
this.panels.forEach((panel, i) => {
|
|
84
|
+
panel.classList.toggle('cn-tab-panel-active', i === index);
|
|
85
|
+
});
|
|
86
|
+
this.el.dispatchEvent(new CustomEvent('change', {
|
|
87
|
+
detail: { index }
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function initTabs() {
|
|
92
|
+
$$('.cn-tabs').forEach(el => {
|
|
93
|
+
if (!el._cnTabs) new CronixTabs(el);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
class CronixAccordion {
|
|
97
|
+
constructor(el) {
|
|
98
|
+
this.el = el;
|
|
99
|
+
this.items = $$('.cn-accordion-item', el);
|
|
100
|
+
this.multi = el.dataset.multi === 'true';
|
|
101
|
+
this.items.forEach(item => {
|
|
102
|
+
const header = $('.cn-accordion-header', item);
|
|
103
|
+
header.addEventListener('click', () => this.toggle(item));
|
|
104
|
+
});
|
|
105
|
+
el._cnAccordion = this;
|
|
106
|
+
}
|
|
107
|
+
toggle(item) {
|
|
108
|
+
const isOpen = item.classList.contains('cn-accordion-open');
|
|
109
|
+
if (!this.multi) {
|
|
110
|
+
this.items.forEach(i => i.classList.remove('cn-accordion-open'));
|
|
111
|
+
}
|
|
112
|
+
item.classList.toggle('cn-accordion-open', !isOpen);
|
|
113
|
+
}
|
|
114
|
+
openAll() {
|
|
115
|
+
this.items.forEach(item => item.classList.add('cn-accordion-open'));
|
|
116
|
+
}
|
|
117
|
+
closeAll() {
|
|
118
|
+
this.items.forEach(item => item.classList.remove('cn-accordion-open'));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function initAccordions() {
|
|
122
|
+
$$('.cn-accordion').forEach(el => {
|
|
123
|
+
if (!el._cnAccordion) new CronixAccordion(el);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
class CronixModal {
|
|
127
|
+
constructor(el) {
|
|
128
|
+
this.el = el;
|
|
129
|
+
this.modal = $('.cn-modal', el);
|
|
130
|
+
this.closeBtn = $('.cn-modal-close', el);
|
|
131
|
+
this.onKeydown = this.onKeydown.bind(this);
|
|
132
|
+
if (this.closeBtn) {
|
|
133
|
+
this.closeBtn.addEventListener('click', () => this.close());
|
|
134
|
+
}
|
|
135
|
+
el.addEventListener('click', (e) => {
|
|
136
|
+
if (e.target === el) this.close();
|
|
137
|
+
});
|
|
138
|
+
el._cnModal = this;
|
|
139
|
+
}
|
|
140
|
+
open() {
|
|
141
|
+
this.el.classList.add('cn-modal-open');
|
|
142
|
+
document.body.style.overflow = 'hidden';
|
|
143
|
+
document.addEventListener('keydown', this.onKeydown);
|
|
144
|
+
this.el.dispatchEvent(new CustomEvent('open'));
|
|
145
|
+
}
|
|
146
|
+
close() {
|
|
147
|
+
this.el.classList.remove('cn-modal-open');
|
|
148
|
+
document.body.style.overflow = '';
|
|
149
|
+
document.removeEventListener('keydown', this.onKeydown);
|
|
150
|
+
this.el.dispatchEvent(new CustomEvent('close'));
|
|
151
|
+
}
|
|
152
|
+
onKeydown(e) {
|
|
153
|
+
if (e.key === 'Escape') this.close();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function initModals() {
|
|
157
|
+
$$('.cn-modal-backdrop').forEach(el => {
|
|
158
|
+
if (!el._cnModal) new CronixModal(el);
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
class CronixDropdown {
|
|
162
|
+
constructor(el) {
|
|
163
|
+
this.el = el;
|
|
164
|
+
this.trigger = $('.cn-dropdown-trigger', el) || el.querySelector('[data-dropdown-trigger]') || el;
|
|
165
|
+
this.menu = $('.cn-dropdown-menu', el);
|
|
166
|
+
this.onDocClick = this.onDocClick.bind(this);
|
|
167
|
+
this.trigger.addEventListener('click', (e) => {
|
|
168
|
+
e.stopPropagation();
|
|
169
|
+
this.toggle();
|
|
170
|
+
});
|
|
171
|
+
this.menu.addEventListener('click', () => this.close());
|
|
172
|
+
el._cnDropdown = this;
|
|
173
|
+
}
|
|
174
|
+
open() {
|
|
175
|
+
this.el.classList.add('cn-dropdown-open');
|
|
176
|
+
document.addEventListener('click', this.onDocClick);
|
|
177
|
+
}
|
|
178
|
+
close() {
|
|
179
|
+
this.el.classList.remove('cn-dropdown-open');
|
|
180
|
+
document.removeEventListener('click', this.onDocClick);
|
|
181
|
+
}
|
|
182
|
+
toggle() {
|
|
183
|
+
if (this.el.classList.contains('cn-dropdown-open')) {
|
|
184
|
+
this.close();
|
|
185
|
+
} else {
|
|
186
|
+
this.open();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
onDocClick(e) {
|
|
190
|
+
if (!this.el.contains(e.target)) {
|
|
191
|
+
this.close();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function initDropdowns() {
|
|
196
|
+
$$('.cn-dropdown').forEach(el => {
|
|
197
|
+
if (!el._cnDropdown) new CronixDropdown(el);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
class CronixToast {
|
|
201
|
+
constructor(container) {
|
|
202
|
+
this.container = container || this.getOrCreateContainer();
|
|
203
|
+
}
|
|
204
|
+
getOrCreateContainer() {
|
|
205
|
+
let container = $('.cn-toast-container');
|
|
206
|
+
if (!container) {
|
|
207
|
+
container = createEl('div', 'cn-toast-container');
|
|
208
|
+
document.body.appendChild(container);
|
|
209
|
+
}
|
|
210
|
+
return container;
|
|
211
|
+
}
|
|
212
|
+
show(options) {
|
|
213
|
+
const {
|
|
214
|
+
title,
|
|
215
|
+
message,
|
|
216
|
+
type = 'info',
|
|
217
|
+
duration = 4000,
|
|
218
|
+
closable = true
|
|
219
|
+
} = options;
|
|
220
|
+
const toast = createEl('div', `cn-toast cn-toast-${type}`);
|
|
221
|
+
toast.innerHTML = `
|
|
222
|
+
<div class="cn-alert-icon">
|
|
223
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
224
|
+
${this.getIcon(type)}
|
|
225
|
+
</svg>
|
|
226
|
+
</div>
|
|
227
|
+
<div class="cn-alert-content">
|
|
228
|
+
${title ? `<div class="cn-alert-title">${title}</div>` : ''}
|
|
229
|
+
${message ? `<div class="cn-alert-message">${message}</div>` : ''}
|
|
230
|
+
</div>
|
|
231
|
+
${closable ? `
|
|
232
|
+
<button class="cn-alert-close">
|
|
233
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
|
|
234
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
235
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
236
|
+
</svg>
|
|
237
|
+
</button>
|
|
238
|
+
` : ''}
|
|
239
|
+
`;
|
|
240
|
+
if (closable) {
|
|
241
|
+
$('.cn-alert-close', toast).addEventListener('click', () => this.hide(toast));
|
|
242
|
+
}
|
|
243
|
+
this.container.appendChild(toast);
|
|
244
|
+
if (duration > 0) {
|
|
245
|
+
setTimeout(() => this.hide(toast), duration);
|
|
246
|
+
}
|
|
247
|
+
return toast;
|
|
248
|
+
}
|
|
249
|
+
hide(toast) {
|
|
250
|
+
toast.classList.add('cn-toast-leaving');
|
|
251
|
+
setTimeout(() => toast.remove(), 200);
|
|
252
|
+
}
|
|
253
|
+
getIcon(type) {
|
|
254
|
+
const icons = {
|
|
255
|
+
success: '<polyline points="20 6 9 17 4 12"></polyline>',
|
|
256
|
+
error: '<circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line>',
|
|
257
|
+
warning: '<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line>',
|
|
258
|
+
info: '<circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line>'
|
|
259
|
+
};
|
|
260
|
+
return icons[type] || icons.info;
|
|
261
|
+
}
|
|
262
|
+
success(message, title) { return this.show({ message, title, type: 'success' }); }
|
|
263
|
+
error(message, title) { return this.show({ message, title, type: 'error' }); }
|
|
264
|
+
warning(message, title) { return this.show({ message, title, type: 'warning' }); }
|
|
265
|
+
info(message, title) { return this.show({ message, title, type: 'info' }); }
|
|
266
|
+
}
|
|
267
|
+
class CronixCommandPalette {
|
|
268
|
+
constructor(el) {
|
|
269
|
+
this.el = el;
|
|
270
|
+
this.input = $('.cn-command-palette-input', el);
|
|
271
|
+
this.results = $('.cn-command-palette-results', el);
|
|
272
|
+
this.items = [];
|
|
273
|
+
this.activeIndex = -1;
|
|
274
|
+
this.onKeydown = this.onKeydown.bind(this);
|
|
275
|
+
this.input.addEventListener('input', () => this.filter());
|
|
276
|
+
this.input.addEventListener('keydown', (e) => this.onKeydown(e));
|
|
277
|
+
el.addEventListener('click', (e) => {
|
|
278
|
+
if (e.target === el) this.close();
|
|
279
|
+
});
|
|
280
|
+
el._cnCommandPalette = this;
|
|
281
|
+
}
|
|
282
|
+
setItems(items) {
|
|
283
|
+
this.items = items;
|
|
284
|
+
this.render();
|
|
285
|
+
}
|
|
286
|
+
render() {
|
|
287
|
+
const query = this.input.value.toLowerCase();
|
|
288
|
+
const filtered = this.items.filter(item =>
|
|
289
|
+
item.title.toLowerCase().includes(query) ||
|
|
290
|
+
(item.subtitle && item.subtitle.toLowerCase().includes(query))
|
|
291
|
+
);
|
|
292
|
+
this.results.innerHTML = filtered.map((item, i) => `
|
|
293
|
+
<div class="cn-command-item${i === 0 ? ' cn-command-item-active' : ''}" data-index="${i}">
|
|
294
|
+
${item.icon ? `<div class="cn-command-item-icon">${item.icon}</div>` : ''}
|
|
295
|
+
<div class="cn-command-item-content">
|
|
296
|
+
<div class="cn-command-item-title">${item.title}</div>
|
|
297
|
+
${item.subtitle ? `<div class="cn-command-item-subtitle">${item.subtitle}</div>` : ''}
|
|
298
|
+
</div>
|
|
299
|
+
${item.kbd ? `<div class="cn-command-item-kbd">${item.kbd}</div>` : ''}
|
|
300
|
+
</div>
|
|
301
|
+
`).join('');
|
|
302
|
+
$$('.cn-command-item', this.results).forEach((item, i) => {
|
|
303
|
+
item.addEventListener('click', () => this.select(filtered[i]));
|
|
304
|
+
item.addEventListener('mouseenter', () => this.setActive(i));
|
|
305
|
+
});
|
|
306
|
+
this.activeIndex = filtered.length > 0 ? 0 : -1;
|
|
307
|
+
}
|
|
308
|
+
filter() {
|
|
309
|
+
this.render();
|
|
310
|
+
}
|
|
311
|
+
onKeydown(e) {
|
|
312
|
+
const items = $$('.cn-command-item', this.results);
|
|
313
|
+
if (e.key === 'ArrowDown') {
|
|
314
|
+
e.preventDefault();
|
|
315
|
+
this.setActive(Math.min(this.activeIndex + 1, items.length - 1));
|
|
316
|
+
} else if (e.key === 'ArrowUp') {
|
|
317
|
+
e.preventDefault();
|
|
318
|
+
this.setActive(Math.max(this.activeIndex - 1, 0));
|
|
319
|
+
} else if (e.key === 'Enter' && this.activeIndex >= 0) {
|
|
320
|
+
e.preventDefault();
|
|
321
|
+
items[this.activeIndex].click();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
setActive(index) {
|
|
325
|
+
const items = $$('.cn-command-item', this.results);
|
|
326
|
+
items.forEach((item, i) => item.classList.toggle('cn-command-item-active', i === index));
|
|
327
|
+
this.activeIndex = index;
|
|
328
|
+
}
|
|
329
|
+
select(item) {
|
|
330
|
+
if (item.action) item.action();
|
|
331
|
+
this.close();
|
|
332
|
+
this.el.dispatchEvent(new CustomEvent('select', { detail: item }));
|
|
333
|
+
}
|
|
334
|
+
open() {
|
|
335
|
+
this.el.classList.add('cn-command-palette-open');
|
|
336
|
+
this.input.value = '';
|
|
337
|
+
this.render();
|
|
338
|
+
setTimeout(() => this.input.focus(), 100);
|
|
339
|
+
document.body.style.overflow = 'hidden';
|
|
340
|
+
document.addEventListener('keydown', this.handleEscape);
|
|
341
|
+
}
|
|
342
|
+
close() {
|
|
343
|
+
this.el.classList.remove('cn-command-palette-open');
|
|
344
|
+
document.body.style.overflow = '';
|
|
345
|
+
document.removeEventListener('keydown', this.handleEscape);
|
|
346
|
+
}
|
|
347
|
+
handleEscape = (e) => {
|
|
348
|
+
if (e.key === 'Escape') this.close();
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function initCommandPalettes() {
|
|
352
|
+
$$('.cn-command-palette').forEach(el => {
|
|
353
|
+
if (!el._cnCommandPalette) new CronixCommandPalette(el);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
class CronixSearch {
|
|
357
|
+
constructor(el) {
|
|
358
|
+
this.el = el;
|
|
359
|
+
this.input = $('.cn-search-input', el);
|
|
360
|
+
this.results = $('.cn-search-results', el);
|
|
361
|
+
this.onDocClick = this.onDocClick.bind(this);
|
|
362
|
+
this.input.addEventListener('focus', () => this.open());
|
|
363
|
+
this.input.addEventListener('input', () => this.filter());
|
|
364
|
+
el.addEventListener('click', (e) => e.stopPropagation());
|
|
365
|
+
el._cnSearch = this;
|
|
366
|
+
}
|
|
367
|
+
setItems(items) {
|
|
368
|
+
this.items = items;
|
|
369
|
+
}
|
|
370
|
+
filter() {
|
|
371
|
+
const query = this.input.value.toLowerCase();
|
|
372
|
+
if (!query) {
|
|
373
|
+
this.close();
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const filtered = this.items.filter(item =>
|
|
377
|
+
item.title.toLowerCase().includes(query) ||
|
|
378
|
+
(item.subtitle && item.subtitle.toLowerCase().includes(query))
|
|
379
|
+
);
|
|
380
|
+
this.results.innerHTML = filtered.map(item => `
|
|
381
|
+
<div class="cn-search-result">
|
|
382
|
+
<div class="cn-search-result-title">${item.title}</div>
|
|
383
|
+
${item.subtitle ? `<div class="cn-search-result-subtitle">${item.subtitle}</div>` : ''}
|
|
384
|
+
</div>
|
|
385
|
+
`).join('');
|
|
386
|
+
$$('.cn-search-result', this.results).forEach((result, i) => {
|
|
387
|
+
result.addEventListener('click', () => {
|
|
388
|
+
this.select(filtered[i]);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
this.open();
|
|
392
|
+
}
|
|
393
|
+
select(item) {
|
|
394
|
+
this.input.value = item.title;
|
|
395
|
+
this.close();
|
|
396
|
+
this.el.dispatchEvent(new CustomEvent('select', { detail: item }));
|
|
397
|
+
if (item.action) item.action();
|
|
398
|
+
}
|
|
399
|
+
open() {
|
|
400
|
+
this.el.classList.add('cn-search-open');
|
|
401
|
+
document.addEventListener('click', this.onDocClick);
|
|
402
|
+
}
|
|
403
|
+
close() {
|
|
404
|
+
this.el.classList.remove('cn-search-open');
|
|
405
|
+
document.removeEventListener('click', this.onDocClick);
|
|
406
|
+
}
|
|
407
|
+
onDocClick(e) {
|
|
408
|
+
if (!this.el.contains(e.target)) {
|
|
409
|
+
this.close();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function initSearch() {
|
|
414
|
+
$$('.cn-search').forEach(el => {
|
|
415
|
+
if (!el._cnSearch) new CronixSearch(el);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
class CronixAlert {
|
|
419
|
+
constructor(el) {
|
|
420
|
+
this.el = el;
|
|
421
|
+
this.closeBtn = $('.cn-alert-close', el);
|
|
422
|
+
if (this.closeBtn) {
|
|
423
|
+
this.closeBtn.addEventListener('click', () => this.close());
|
|
424
|
+
}
|
|
425
|
+
el._cnAlert = this;
|
|
426
|
+
}
|
|
427
|
+
close() {
|
|
428
|
+
this.el.style.opacity = '0';
|
|
429
|
+
setTimeout(() => this.el.remove(), 200);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
function initAlerts() {
|
|
433
|
+
$$('.cn-alert').forEach(el => {
|
|
434
|
+
if (!el._cnAlert) new CronixAlert(el);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
class CronixTable {
|
|
438
|
+
constructor(el) {
|
|
439
|
+
this.el = el;
|
|
440
|
+
this.table = $('table', el) || el;
|
|
441
|
+
this.headers = $$('th[data-sort]', this.table);
|
|
442
|
+
this.headers.forEach(header => {
|
|
443
|
+
header.addEventListener('click', () => this.sort(header));
|
|
444
|
+
});
|
|
445
|
+
el._cnTable = this;
|
|
446
|
+
}
|
|
447
|
+
sort(header) {
|
|
448
|
+
const key = header.dataset.sort;
|
|
449
|
+
const tbody = $('tbody', this.table);
|
|
450
|
+
const rows = $$('tr', tbody);
|
|
451
|
+
const order = header.dataset.order === 'asc' ? 'desc' : 'asc';
|
|
452
|
+
this.headers.forEach(h => delete h.dataset.order);
|
|
453
|
+
header.dataset.order = order;
|
|
454
|
+
const index = Array.from(header.parentElement.children).indexOf(header);
|
|
455
|
+
rows.sort((a, b) => {
|
|
456
|
+
const aVal = a.children[index].textContent.trim();
|
|
457
|
+
const bVal = b.children[index].textContent.trim();
|
|
458
|
+
const aNum = parseFloat(aVal);
|
|
459
|
+
const bNum = parseFloat(bVal);
|
|
460
|
+
if (!isNaN(aNum) && !isNaN(bNum)) {
|
|
461
|
+
return order === 'asc' ? aNum - bNum : bNum - aNum;
|
|
462
|
+
}
|
|
463
|
+
return order === 'asc'
|
|
464
|
+
? aVal.localeCompare(bVal)
|
|
465
|
+
: bVal.localeCompare(aVal);
|
|
466
|
+
});
|
|
467
|
+
rows.forEach(row => tbody.appendChild(row));
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function initTables() {
|
|
471
|
+
$$('.cn-table-sortable').forEach(el => {
|
|
472
|
+
if (!el._cnTable) new CronixTable(el);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
class CronixPagination {
|
|
476
|
+
constructor(el, options = {}) {
|
|
477
|
+
this.el = el;
|
|
478
|
+
this.total = options.total || 1;
|
|
479
|
+
this.current = options.current || 1;
|
|
480
|
+
this.onChange = options.onChange || (() => {});
|
|
481
|
+
this.render();
|
|
482
|
+
el._cnPagination = this;
|
|
483
|
+
}
|
|
484
|
+
render() {
|
|
485
|
+
const pages = this.getPages();
|
|
486
|
+
this.el.innerHTML = `
|
|
487
|
+
<button class="cn-pagination-item" data-page="prev" ${this.current === 1 ? 'disabled' : ''}>
|
|
488
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
|
|
489
|
+
<polyline points="15 18 9 12 15 6"></polyline>
|
|
490
|
+
</svg>
|
|
491
|
+
</button>
|
|
492
|
+
${pages.map(p => `
|
|
493
|
+
<button class="cn-pagination-item${p === this.current ? ' cn-pagination-active' : ''}" data-page="${p}">
|
|
494
|
+
${p}
|
|
495
|
+
</button>
|
|
496
|
+
`).join('')}
|
|
497
|
+
<button class="cn-pagination-item" data-page="next" ${this.current === this.total ? 'disabled' : ''}>
|
|
498
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16">
|
|
499
|
+
<polyline points="9 18 15 12 9 6"></polyline>
|
|
500
|
+
</svg>
|
|
501
|
+
</button>
|
|
502
|
+
`;
|
|
503
|
+
$$('.cn-pagination-item', this.el).forEach(btn => {
|
|
504
|
+
btn.addEventListener('click', () => {
|
|
505
|
+
const page = btn.dataset.page;
|
|
506
|
+
if (page === 'prev' && this.current > 1) {
|
|
507
|
+
this.goTo(this.current - 1);
|
|
508
|
+
} else if (page === 'next' && this.current < this.total) {
|
|
509
|
+
this.goTo(this.current + 1);
|
|
510
|
+
} else if (!isNaN(page)) {
|
|
511
|
+
this.goTo(parseInt(page));
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
getPages() {
|
|
517
|
+
const pages = [];
|
|
518
|
+
const maxVisible = 5;
|
|
519
|
+
if (this.total <= maxVisible) {
|
|
520
|
+
for (let i = 1; i <= this.total; i++) pages.push(i);
|
|
521
|
+
} else {
|
|
522
|
+
if (this.current <= 3) {
|
|
523
|
+
for (let i = 1; i <= 4; i++) pages.push(i);
|
|
524
|
+
pages.push('...');
|
|
525
|
+
pages.push(this.total);
|
|
526
|
+
} else if (this.current >= this.total - 2) {
|
|
527
|
+
pages.push(1);
|
|
528
|
+
pages.push('...');
|
|
529
|
+
for (let i = this.total - 3; i <= this.total; i++) pages.push(i);
|
|
530
|
+
} else {
|
|
531
|
+
pages.push(1);
|
|
532
|
+
pages.push('...');
|
|
533
|
+
for (let i = this.current - 1; i <= this.current + 1; i++) pages.push(i);
|
|
534
|
+
pages.push('...');
|
|
535
|
+
pages.push(this.total);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return pages;
|
|
539
|
+
}
|
|
540
|
+
goTo(page) {
|
|
541
|
+
if (page >= 1 && page <= this.total && page !== this.current) {
|
|
542
|
+
this.current = page;
|
|
543
|
+
this.render();
|
|
544
|
+
this.onChange(page);
|
|
545
|
+
this.el.dispatchEvent(new CustomEvent('change', { detail: { page } }));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
class CronixFileInput {
|
|
550
|
+
constructor(el) {
|
|
551
|
+
this.el = el;
|
|
552
|
+
this.input = $('input[type="file"]', el);
|
|
553
|
+
this.label = $('.cn-file-input-label', el);
|
|
554
|
+
this.textEl = $('.cn-file-input-text', el);
|
|
555
|
+
this.originalText = this.textEl ? this.textEl.innerHTML : '';
|
|
556
|
+
this.input.addEventListener('change', (e) => this.handleChange(e));
|
|
557
|
+
el._cnFileInput = this;
|
|
558
|
+
}
|
|
559
|
+
handleChange(e) {
|
|
560
|
+
const files = this.input.files;
|
|
561
|
+
if (files.length > 0) {
|
|
562
|
+
const names = Array.from(files).map(f => f.name).join(', ');
|
|
563
|
+
if (this.textEl) {
|
|
564
|
+
this.textEl.innerHTML = `<span>${names}</span>`;
|
|
565
|
+
}
|
|
566
|
+
this.el.classList.add('cn-file-input-has-file');
|
|
567
|
+
this.el.dispatchEvent(new CustomEvent('change', { detail: { files } }));
|
|
568
|
+
} else {
|
|
569
|
+
this.reset();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
reset() {
|
|
573
|
+
this.input.value = '';
|
|
574
|
+
if (this.textEl) this.textEl.innerHTML = this.originalText;
|
|
575
|
+
this.el.classList.remove('cn-file-input-has-file');
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function initFileInputs() {
|
|
579
|
+
$$('.cn-file-input').forEach(el => {
|
|
580
|
+
if (!el._cnFileInput) new CronixFileInput(el);
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
function init() {
|
|
584
|
+
initToggles();
|
|
585
|
+
initNavs();
|
|
586
|
+
initTabs();
|
|
587
|
+
initAccordions();
|
|
588
|
+
initModals();
|
|
589
|
+
initDropdowns();
|
|
590
|
+
initCommandPalettes();
|
|
591
|
+
initSearch();
|
|
592
|
+
initAlerts();
|
|
593
|
+
initTables();
|
|
594
|
+
initFileInputs();
|
|
595
|
+
}
|
|
596
|
+
if (document.readyState === 'loading') {
|
|
597
|
+
document.addEventListener('DOMContentLoaded', init);
|
|
598
|
+
} else {
|
|
599
|
+
init();
|
|
600
|
+
}
|
|
601
|
+
const CronixUI = {
|
|
602
|
+
init,
|
|
603
|
+
Toggle: CronixToggle,
|
|
604
|
+
Nav: CronixNav,
|
|
605
|
+
Tabs: CronixTabs,
|
|
606
|
+
Accordion: CronixAccordion,
|
|
607
|
+
Modal: CronixModal,
|
|
608
|
+
Dropdown: CronixDropdown,
|
|
609
|
+
Toast: new CronixToast(),
|
|
610
|
+
CommandPalette: CronixCommandPalette,
|
|
611
|
+
Search: CronixSearch,
|
|
612
|
+
Alert: CronixAlert,
|
|
613
|
+
Table: CronixTable,
|
|
614
|
+
Pagination: CronixPagination,
|
|
615
|
+
FileInput: CronixFileInput,
|
|
616
|
+
$,
|
|
617
|
+
$$,
|
|
618
|
+
createEl
|
|
619
|
+
};
|
|
620
|
+
if (typeof define === 'function' && define.amd) {
|
|
621
|
+
define(() => CronixUI);
|
|
622
|
+
}
|
|
623
|
+
else if (typeof module !== 'undefined' && module.exports) {
|
|
624
|
+
module.exports = CronixUI;
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
global.CronixUI = CronixUI;
|
|
628
|
+
}
|
|
629
|
+
})(typeof globalThis !== 'undefined' ? globalThis : window);
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cronixui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CronixUI - A dark-themed UI toolkit with crimson accents and Outfit typography",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ui",
|
|
7
|
+
"css",
|
|
8
|
+
"dark-mode",
|
|
9
|
+
"design-system",
|
|
10
|
+
"components"
|
|
11
|
+
],
|
|
12
|
+
"license": "GPL-3.0",
|
|
13
|
+
"author": "CazyUndee",
|
|
14
|
+
"type": "commonjs",
|
|
15
|
+
"main": "dist/cronixui.js",
|
|
16
|
+
"style": "dist/cronixui.css",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist/",
|
|
19
|
+
"src/"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "node scripts/build.js",
|
|
23
|
+
"dev": "npx live-server demo"
|
|
24
|
+
}
|
|
25
|
+
}
|