@joniguerini/lume 0.0.0-stage → 1.9.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/LICENSE +25 -0
- package/README.md +62 -2
- package/base.css +165 -0
- package/bin/lumeui.mjs +163 -0
- package/components/alert.css +156 -0
- package/components/banner.css +98 -0
- package/components/button.css +291 -0
- package/components/calendar.css +532 -0
- package/components/carousel.css +175 -0
- package/components/chart.css +813 -0
- package/components/chat.css +670 -0
- package/components/checkbox.css +212 -0
- package/components/chip.css +224 -0
- package/components/code.css +36 -0
- package/components/color-picker.css +192 -0
- package/components/command.css +148 -0
- package/components/content.css +211 -0
- package/components/editor.css +174 -0
- package/components/feedback.css +320 -0
- package/components/filters.css +103 -0
- package/components/form.css +455 -0
- package/components/image-viewer.css +237 -0
- package/components/layers.css +138 -0
- package/components/link.css +87 -0
- package/components/loading.css +260 -0
- package/components/menu.css +180 -0
- package/components/modal.css +209 -0
- package/components/navigation.css +507 -0
- package/components/notifications.css +186 -0
- package/components/number-field.css +52 -0
- package/components/otp.css +119 -0
- package/components/panel.css +208 -0
- package/components/picker.css +207 -0
- package/components/rating.css +143 -0
- package/components/resizable.css +173 -0
- package/components/scrollbar.css +110 -0
- package/components/select.css +477 -0
- package/components/shell.css +837 -0
- package/components/slider.css +189 -0
- package/components/sortable.css +287 -0
- package/components/surfaces.css +182 -0
- package/components/switch.css +115 -0
- package/components/table.css +228 -0
- package/components/tabs.css +190 -0
- package/components/tags.css +83 -0
- package/components/toast.css +164 -0
- package/components/toolbar.css +80 -0
- package/components/upload.css +181 -0
- package/ds.css +48 -0
- package/fonts/Geist-LICENSE.txt +92 -0
- package/fonts/Geist-Variable.woff2 +0 -0
- package/fonts/GeistSerif-Regular.woff2 +0 -0
- package/fonts/JetBrainsMono-LICENSE.txt +93 -0
- package/fonts/JetBrainsMono-Variable.woff2 +0 -0
- package/fonts.css +29 -0
- package/icons/icons.d.ts +5 -0
- package/icons/icons.js +266 -0
- package/js/back-to-top.d.ts +2 -0
- package/js/back-to-top.js +62 -0
- package/js/banner.js +87 -0
- package/js/calendar.d.ts +3 -0
- package/js/calendar.js +472 -0
- package/js/carousel.d.ts +2 -0
- package/js/carousel.js +258 -0
- package/js/charts/bar.js +361 -0
- package/js/charts/core.js +604 -0
- package/js/charts/donut.js +206 -0
- package/js/charts/figures.js +97 -0
- package/js/charts/heatmap.js +410 -0
- package/js/charts/line.js +268 -0
- package/js/charts/scatter.js +211 -0
- package/js/charts.d.ts +12 -0
- package/js/charts.js +27 -0
- package/js/code-block.d.ts +3 -0
- package/js/code-block.js +32 -0
- package/js/color-picker.d.ts +4 -0
- package/js/color-picker.js +448 -0
- package/js/command-palette.js +233 -0
- package/js/composer.js +573 -0
- package/js/context-menu.d.ts +2 -0
- package/js/context-menu.js +154 -0
- package/js/date-picker.d.ts +2 -0
- package/js/date-picker.js +430 -0
- package/js/drawer.js +48 -0
- package/js/editor.d.ts +5 -0
- package/js/editor.js +615 -0
- package/js/field-support.js +77 -0
- package/js/file-upload.d.ts +2 -0
- package/js/file-upload.js +230 -0
- package/js/filters.js +266 -0
- package/js/form.d.ts +2 -0
- package/js/form.js +409 -0
- package/js/i18n.d.ts +14 -0
- package/js/i18n.js +83 -0
- package/js/image-viewer.d.ts +4 -0
- package/js/image-viewer.js +275 -0
- package/js/menu.d.ts +4 -0
- package/js/menu.js +237 -0
- package/js/messages.js +908 -0
- package/js/modal.d.ts +7 -0
- package/js/modal.js +183 -0
- package/js/notifications.d.ts +4 -0
- package/js/notifications.js +204 -0
- package/js/number-field.d.ts +2 -0
- package/js/number-field.js +175 -0
- package/js/otp-field.d.ts +2 -0
- package/js/otp-field.js +107 -0
- package/js/pagination.d.ts +3 -0
- package/js/pagination.js +143 -0
- package/js/popover.d.ts +2 -0
- package/js/popover.js +155 -0
- package/js/progress-ring.js +48 -0
- package/js/rating.d.ts +3 -0
- package/js/rating.js +130 -0
- package/js/resizable.d.ts +2 -0
- package/js/resizable.js +311 -0
- package/js/scrollbar.d.ts +2 -0
- package/js/scrollbar.js +273 -0
- package/js/segmented.js +60 -0
- package/js/select.d.ts +3 -0
- package/js/select.js +784 -0
- package/js/shell.d.ts +6 -0
- package/js/shell.js +373 -0
- package/js/slider.d.ts +2 -0
- package/js/slider.js +89 -0
- package/js/sortable.d.ts +5 -0
- package/js/sortable.js +463 -0
- package/js/stepper.d.ts +2 -0
- package/js/stepper.js +72 -0
- package/js/tabs.js +99 -0
- package/js/tag-field.d.ts +2 -0
- package/js/tag-field.js +177 -0
- package/js/theme.d.ts +9 -0
- package/js/theme.js +114 -0
- package/js/time-picker.d.ts +2 -0
- package/js/time-picker.js +279 -0
- package/js/toast.d.ts +17 -0
- package/js/toast.js +171 -0
- package/js/toolbar.d.ts +2 -0
- package/js/toolbar.js +107 -0
- package/js/tooltip.d.ts +2 -0
- package/js/tooltip.js +208 -0
- package/js/tree.d.ts +2 -0
- package/js/tree.js +168 -0
- package/lume.css +11574 -0
- package/lume.d.ts +104 -0
- package/lume.js +67 -0
- package/package.json +66 -4
- package/react/Alert.d.ts +24 -0
- package/react/Alert.js +21 -0
- package/react/AppShell.d.ts +67 -0
- package/react/AppShell.js +94 -0
- package/react/Avatar.d.ts +39 -0
- package/react/Avatar.js +40 -0
- package/react/Badge.d.ts +17 -0
- package/react/Badge.js +10 -0
- package/react/Button.d.ts +32 -0
- package/react/Button.js +17 -0
- package/react/Calendar.d.ts +48 -0
- package/react/Calendar.js +67 -0
- package/react/Carousel.d.ts +30 -0
- package/react/Carousel.js +38 -0
- package/react/Charts.d.ts +186 -0
- package/react/Charts.js +58 -0
- package/react/Chip.d.ts +34 -0
- package/react/Chip.js +26 -0
- package/react/Choice.d.ts +72 -0
- package/react/Choice.js +51 -0
- package/react/ColorPicker.d.ts +43 -0
- package/react/ColorPicker.js +73 -0
- package/react/Content.d.ts +58 -0
- package/react/Content.js +42 -0
- package/react/Controls.d.ts +97 -0
- package/react/Controls.js +118 -0
- package/react/Editor.d.ts +28 -0
- package/react/Editor.js +57 -0
- package/react/Field.d.ts +90 -0
- package/react/Field.js +65 -0
- package/react/Form.d.ts +36 -0
- package/react/Form.js +45 -0
- package/react/Icon.d.ts +13 -0
- package/react/Icon.js +8 -0
- package/react/IconButton.d.ts +19 -0
- package/react/IconButton.js +12 -0
- package/react/ImageViewer.d.ts +20 -0
- package/react/ImageViewer.js +22 -0
- package/react/InlineAction.d.ts +15 -0
- package/react/InlineAction.js +12 -0
- package/react/Layers.d.ts +118 -0
- package/react/Layers.js +115 -0
- package/react/Link.d.ts +32 -0
- package/react/Link.js +26 -0
- package/react/Loading.d.ts +67 -0
- package/react/Loading.js +49 -0
- package/react/Navigation.d.ts +181 -0
- package/react/Navigation.js +197 -0
- package/react/Notices.d.ts +43 -0
- package/react/Notices.js +89 -0
- package/react/Panel.d.ts +57 -0
- package/react/Panel.js +33 -0
- package/react/Pickers.d.ts +83 -0
- package/react/Pickers.js +70 -0
- package/react/Rating.d.ts +39 -0
- package/react/Rating.js +41 -0
- package/react/Resizable.d.ts +44 -0
- package/react/Resizable.js +30 -0
- package/react/Select.d.ts +53 -0
- package/react/Select.js +79 -0
- package/react/Sortable.d.ts +52 -0
- package/react/Sortable.js +113 -0
- package/react/Table.d.ts +60 -0
- package/react/Table.js +34 -0
- package/react/Toolbar.d.ts +45 -0
- package/react/Toolbar.js +45 -0
- package/react/cx.d.ts +2 -0
- package/react/cx.js +5 -0
- package/react/icon-names.d.ts +1 -0
- package/react/icon-names.js +2 -0
- package/react/index.d.ts +42 -0
- package/react/index.js +52 -0
- package/react/useController.d.ts +8 -0
- package/react/useController.js +16 -0
- package/react/useLocale.d.ts +5 -0
- package/react/useLocale.js +15 -0
- package/tokens.css +739 -0
- package/tokens.js +4911 -0
package/js/tag-field.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Campo de tags — vários valores livres dentro de um campo só.
|
|
3
|
+
*
|
|
4
|
+
* <div class="ds-field ds-tags"><input class="ds-field__input" id="assuntos" name="assuntos" type="text"></div>
|
|
5
|
+
*
|
|
6
|
+
* const tags = createTagField(document.querySelector('#assuntos'), {
|
|
7
|
+
* value: ['design', 'tokens'],
|
|
8
|
+
* max: 5, // no máximo 5 tags
|
|
9
|
+
* validate: (text) => (text.length > 20 ? 'Use até 20 caracteres.' : null),
|
|
10
|
+
* onChange: (values) => …,
|
|
11
|
+
* });
|
|
12
|
+
* tags.value; tags.setValue([…]); tags.add('novo'); tags.remove('novo'); tags.destroy();
|
|
13
|
+
*
|
|
14
|
+
* O formulário recebe os valores separados por vírgula, num input oculto com o name do campo.
|
|
15
|
+
* Enter ou vírgula criam a tag; colar uma lista cria várias. Backspace com o campo vazio marca a última
|
|
16
|
+
* tag e, de novo, apaga. Cada tag tem um botão de remover com nome próprio, e as mudanças são anunciadas.
|
|
17
|
+
*/
|
|
18
|
+
import { icon } from '../icons/icons.js';
|
|
19
|
+
import { msg } from './i18n.js';
|
|
20
|
+
import { hiddenValue, setFieldError } from './field-support.js';
|
|
21
|
+
|
|
22
|
+
const escape = (s) => String(s ?? '').replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
|
23
|
+
|
|
24
|
+
export function createTagField(input, options = {}) {
|
|
25
|
+
const o = { ...options };
|
|
26
|
+
const field = input.closest('.ds-field');
|
|
27
|
+
const hidden = input.name ? hiddenValue(input) : null;
|
|
28
|
+
input.autocomplete = 'off';
|
|
29
|
+
|
|
30
|
+
let values = [...(o.value ?? [])];
|
|
31
|
+
let armed = false; // a última tag está marcada para sair
|
|
32
|
+
|
|
33
|
+
const list = document.createElement('ul');
|
|
34
|
+
list.className = 'ds-tags__list';
|
|
35
|
+
list.setAttribute('role', 'list');
|
|
36
|
+
input.before(list);
|
|
37
|
+
|
|
38
|
+
const live = document.createElement('span');
|
|
39
|
+
live.className = 'ds-visually-hidden';
|
|
40
|
+
live.setAttribute('role', 'status');
|
|
41
|
+
field.after(live);
|
|
42
|
+
|
|
43
|
+
function render() {
|
|
44
|
+
list.innerHTML = values
|
|
45
|
+
.map(
|
|
46
|
+
(v, i) => `<li class="ds-tags__tag"${armed && i === values.length - 1 ? ' data-armed' : ''}>
|
|
47
|
+
<span class="ds-tags__text">${escape(v)}</span>
|
|
48
|
+
<button type="button" class="ds-tags__remove" data-remove="${i}" aria-label="${escape(msg('common.remove', v))}"${input.disabled ? ' disabled' : ''}>${icon('x', { size: 14 })}</button>
|
|
49
|
+
</li>`,
|
|
50
|
+
)
|
|
51
|
+
.join('');
|
|
52
|
+
list.hidden = !values.length;
|
|
53
|
+
if (hidden) hidden.value = values.join(',');
|
|
54
|
+
if (values.length) input.dataset.dsFilled = values.join(',');
|
|
55
|
+
else delete input.dataset.dsFilled;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function changed() {
|
|
59
|
+
render();
|
|
60
|
+
o.onChange?.([...values]);
|
|
61
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Cria as tags do texto (várias, se vier uma lista). Devolve false se alguma foi recusada. */
|
|
65
|
+
function addText(text) {
|
|
66
|
+
const pieces = text.split(/[,;\n]/).map((s) => s.trim()).filter(Boolean);
|
|
67
|
+
let error = null;
|
|
68
|
+
let added = false;
|
|
69
|
+
for (const piece of pieces) {
|
|
70
|
+
if (values.some((v) => v.toLocaleLowerCase() === piece.toLocaleLowerCase())) error = msg('tags.duplicate', piece);
|
|
71
|
+
else if (o.max && values.length >= o.max) error = msg('tags.max', o.max);
|
|
72
|
+
else {
|
|
73
|
+
const refused = o.validate?.(piece);
|
|
74
|
+
if (refused) error = refused;
|
|
75
|
+
else {
|
|
76
|
+
values.push(piece);
|
|
77
|
+
added = true;
|
|
78
|
+
live.textContent = msg('tags.added', piece);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
setFieldError(input, error);
|
|
83
|
+
if (added) changed();
|
|
84
|
+
return !error;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function removeAt(index) {
|
|
88
|
+
const [gone] = values.splice(index, 1);
|
|
89
|
+
armed = false;
|
|
90
|
+
setFieldError(input, null);
|
|
91
|
+
live.textContent = msg('tags.removed', gone);
|
|
92
|
+
changed();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const disarm = () => {
|
|
96
|
+
if (armed) {
|
|
97
|
+
armed = false;
|
|
98
|
+
render();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const onKey = (event) => {
|
|
103
|
+
if (event.key === 'Enter' || event.key === ',') {
|
|
104
|
+
if (!input.value.trim()) {
|
|
105
|
+
if (event.key === ',') event.preventDefault();
|
|
106
|
+
return; // Enter vazio envia o formulário normalmente
|
|
107
|
+
}
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
if (addText(input.value)) input.value = '';
|
|
110
|
+
} else if (event.key === 'Backspace' && !input.value && values.length) {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
if (armed) removeAt(values.length - 1);
|
|
113
|
+
else {
|
|
114
|
+
armed = true;
|
|
115
|
+
render();
|
|
116
|
+
}
|
|
117
|
+
} else if (event.key !== 'Shift') disarm();
|
|
118
|
+
};
|
|
119
|
+
const onInput = () => {
|
|
120
|
+
if (input.dataset.dsInvalid) setFieldError(input, null);
|
|
121
|
+
disarm();
|
|
122
|
+
};
|
|
123
|
+
const onPaste = (event) => {
|
|
124
|
+
const text = event.clipboardData?.getData('text') ?? '';
|
|
125
|
+
if (!/[,;\n]/.test(text)) return;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
if (addText(text)) input.value = '';
|
|
128
|
+
};
|
|
129
|
+
const onBlur = () => {
|
|
130
|
+
disarm();
|
|
131
|
+
if (input.value.trim() && addText(input.value)) input.value = '';
|
|
132
|
+
};
|
|
133
|
+
const onClick = (event) => {
|
|
134
|
+
const remove = event.target.closest('[data-remove]');
|
|
135
|
+
if (remove) {
|
|
136
|
+
removeAt(Number(remove.dataset.remove));
|
|
137
|
+
input.focus({ preventScroll: true });
|
|
138
|
+
} else if (event.target === field || event.target === list) input.focus({ preventScroll: true });
|
|
139
|
+
};
|
|
140
|
+
const onLocale = () => render();
|
|
141
|
+
|
|
142
|
+
input.addEventListener('keydown', onKey);
|
|
143
|
+
input.addEventListener('input', onInput);
|
|
144
|
+
input.addEventListener('paste', onPaste);
|
|
145
|
+
input.addEventListener('blur', onBlur);
|
|
146
|
+
field.addEventListener('click', onClick);
|
|
147
|
+
document.documentElement.addEventListener('ds:localechange', onLocale);
|
|
148
|
+
|
|
149
|
+
render();
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
get value() {
|
|
153
|
+
return [...values];
|
|
154
|
+
},
|
|
155
|
+
setValue(next) {
|
|
156
|
+
values = [...next];
|
|
157
|
+
armed = false;
|
|
158
|
+
setFieldError(input, null);
|
|
159
|
+
render();
|
|
160
|
+
},
|
|
161
|
+
add: addText,
|
|
162
|
+
remove(text) {
|
|
163
|
+
const index = values.indexOf(text);
|
|
164
|
+
if (index !== -1) removeAt(index);
|
|
165
|
+
},
|
|
166
|
+
destroy() {
|
|
167
|
+
list.remove();
|
|
168
|
+
live.remove();
|
|
169
|
+
input.removeEventListener('keydown', onKey);
|
|
170
|
+
input.removeEventListener('input', onInput);
|
|
171
|
+
input.removeEventListener('paste', onPaste);
|
|
172
|
+
input.removeEventListener('blur', onBlur);
|
|
173
|
+
field.removeEventListener('click', onClick);
|
|
174
|
+
document.documentElement.removeEventListener('ds:localechange', onLocale);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
package/js/theme.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Gerado por scripts/build-react.mjs. Não edite.
|
|
2
|
+
export declare const THEMES: Array<'light' | 'dark'>;
|
|
3
|
+
export declare function getThemePreference(): 'system' | 'light' | 'dark';
|
|
4
|
+
export declare function themeFor(preference: string): 'light' | 'dark';
|
|
5
|
+
export declare function resolvedTheme(): 'light' | 'dark';
|
|
6
|
+
export declare function toggleTheme(): void;
|
|
7
|
+
export declare function setTheme(preference: 'system' | 'light' | 'dark'): void;
|
|
8
|
+
export declare function mountThemeControls(scope?: ParentNode): () => void;
|
|
9
|
+
export declare function initTheme(): void;
|
package/js/theme.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tema: claro (light) ou escuro (dark). Até a pessoa escolher, segue o sistema (preferência 'system');
|
|
3
|
+
* a escolha fica salva em ds-theme. O <html data-theme> recebe sempre o tema resolvido: light ou dark.
|
|
4
|
+
*
|
|
5
|
+
* toggleTheme(); // troca entre claro e escuro e salva
|
|
6
|
+
* setTheme('system'); // volta a seguir o sistema
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const KEY = 'ds-theme';
|
|
10
|
+
// versão dos valores salvos: sem versão, 'light' era o tema pêssego e 'refugio' era o claro de hoje; o tema orange saiu na 0.14.4
|
|
11
|
+
const VERSION_KEY = 'ds-theme-v';
|
|
12
|
+
const VERSION = '3';
|
|
13
|
+
export const THEMES = ['light', 'dark'];
|
|
14
|
+
const PREFERENCES = ['system', ...THEMES];
|
|
15
|
+
const DEFAULT = 'system';
|
|
16
|
+
// no servidor (renderização no servidor) não há documento: o tema só é aplicado quando o navegador assume
|
|
17
|
+
const BROWSER = typeof document !== 'undefined';
|
|
18
|
+
const root = BROWSER ? document.documentElement : null;
|
|
19
|
+
const darkQuery = BROWSER && typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : null;
|
|
20
|
+
|
|
21
|
+
const read = (key) => {
|
|
22
|
+
try {
|
|
23
|
+
return localStorage.getItem(key);
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const write = (key, value) => {
|
|
29
|
+
try {
|
|
30
|
+
localStorage.setItem(key, value);
|
|
31
|
+
} catch {}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function getThemePreference() {
|
|
35
|
+
let saved = read(KEY);
|
|
36
|
+
const version = read(VERSION_KEY);
|
|
37
|
+
if (version !== VERSION) {
|
|
38
|
+
if (!version) saved = { refugio: 'light', light: null }[saved] ?? saved;
|
|
39
|
+
// quem usava um tema que não existe mais volta a seguir o sistema
|
|
40
|
+
write(KEY, PREFERENCES.includes(saved) ? saved : DEFAULT);
|
|
41
|
+
write(VERSION_KEY, VERSION);
|
|
42
|
+
}
|
|
43
|
+
return PREFERENCES.includes(saved) ? saved : DEFAULT;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Tema resolvido de uma preferência: "system" vira claro ou escuro, como o aparelho. */
|
|
47
|
+
export function themeFor(preference) {
|
|
48
|
+
if (preference === 'system') return darkQuery?.matches ? 'dark' : 'light';
|
|
49
|
+
return THEMES.includes(preference) ? preference : 'light';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function resolvedTheme() {
|
|
53
|
+
return themeFor(getThemePreference());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// tema pedido que ainda não foi aplicado (a transição aplica de forma assíncrona)
|
|
57
|
+
let pending = null;
|
|
58
|
+
|
|
59
|
+
function apply(next) {
|
|
60
|
+
if (!root || next === (pending ?? root.dataset.theme)) return;
|
|
61
|
+
pending = next;
|
|
62
|
+
const run = () => {
|
|
63
|
+
root.dataset.theme = next;
|
|
64
|
+
if (pending === next) pending = null;
|
|
65
|
+
};
|
|
66
|
+
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
67
|
+
if (document.startViewTransition && !reduced) {
|
|
68
|
+
// trocas rápidas cancelam a transição anterior — isso é esperado, não é erro
|
|
69
|
+
const transition = document.startViewTransition(run);
|
|
70
|
+
[transition.ready, transition.finished, transition.updateCallbackDone].forEach((p) => p?.catch(() => {}));
|
|
71
|
+
} else run();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function announce() {
|
|
75
|
+
root?.dispatchEvent(new CustomEvent('ds:themechange', { detail: { preference: getThemePreference(), resolved: resolvedTheme() } }));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Troca entre claro e escuro; a escolha fica salva e o tema deixa de seguir o sistema. */
|
|
79
|
+
export const toggleTheme = () => setTheme(resolvedTheme() === 'dark' ? 'light' : 'dark');
|
|
80
|
+
|
|
81
|
+
export function setTheme(preference) {
|
|
82
|
+
if (!PREFERENCES.includes(preference)) return;
|
|
83
|
+
write(KEY, preference);
|
|
84
|
+
write(VERSION_KEY, VERSION);
|
|
85
|
+
apply(resolvedTheme());
|
|
86
|
+
syncControls();
|
|
87
|
+
announce();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function syncControls() {
|
|
91
|
+
if (!BROWSER) return;
|
|
92
|
+
const dark = resolvedTheme() === 'dark';
|
|
93
|
+
document.querySelectorAll('[data-theme-toggle]').forEach((btn) => btn.setAttribute('aria-pressed', String(dark)));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Liga os botões [data-theme-toggle]: cada clique troca o tema (aria-pressed: o escuro está ligado). */
|
|
97
|
+
export function mountThemeControls(scope = document) {
|
|
98
|
+
const buttons = [...scope.querySelectorAll('[data-theme-toggle]')];
|
|
99
|
+
buttons.forEach((btn) => btn.addEventListener('click', toggleTheme));
|
|
100
|
+
syncControls();
|
|
101
|
+
return () => buttons.forEach((btn) => btn.removeEventListener('click', toggleTheme));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function initTheme() {
|
|
105
|
+
if (!root) return;
|
|
106
|
+
root.dataset.theme = resolvedTheme();
|
|
107
|
+
// enquanto a pessoa não escolher, acompanha a troca de claro/escuro do sistema
|
|
108
|
+
darkQuery?.addEventListener('change', () => {
|
|
109
|
+
if (getThemePreference() !== 'system') return;
|
|
110
|
+
apply(resolvedTheme());
|
|
111
|
+
syncControls();
|
|
112
|
+
announce();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seletor de horário — um campo de texto com uma lista de horários.
|
|
3
|
+
*
|
|
4
|
+
* <div class="ds-field"><input class="ds-field__input" id="inicio" name="inicio" type="text"></div>
|
|
5
|
+
*
|
|
6
|
+
* const picker = createTimePicker(document.querySelector('#inicio'), {
|
|
7
|
+
* value: '14:30', // HH:MM (24 h)
|
|
8
|
+
* step: 15, // minutos entre as opções da lista
|
|
9
|
+
* min: '08:00', max: '18:00',
|
|
10
|
+
* onChange: (value) => …,
|
|
11
|
+
* });
|
|
12
|
+
* picker.value; picker.setValue('09:00'); picker.destroy();
|
|
13
|
+
*
|
|
14
|
+
* O formulário recebe sempre HH:MM, num input oculto com o name do campo; a tela mostra o formato do idioma
|
|
15
|
+
* (14:30 ou 2:30 PM). Aceita digitar 1430, 14h30, 2:30 pm.
|
|
16
|
+
* Padrão ARIA: combobox com listbox. Teclado: ↓/↑ abrem e movem, Home/End (lista aberta), Enter escolhe, Esc fecha.
|
|
17
|
+
*/
|
|
18
|
+
import { icon } from '../icons/icons.js';
|
|
19
|
+
import { msg, locale } from './i18n.js';
|
|
20
|
+
import { placePanel, panelHost, inheritTheme, hiddenValue, setFieldError } from './field-support.js';
|
|
21
|
+
|
|
22
|
+
let uid = 0;
|
|
23
|
+
|
|
24
|
+
const toMinutes = (hhmm) => {
|
|
25
|
+
const [h, m] = hhmm.split(':').map(Number);
|
|
26
|
+
return h * 60 + m;
|
|
27
|
+
};
|
|
28
|
+
const toValue = (minutes) => `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`;
|
|
29
|
+
|
|
30
|
+
const format = (minutes) => new Intl.DateTimeFormat(locale(), { hour: '2-digit', minute: '2-digit' }).format(new Date(2026, 0, 1, Math.floor(minutes / 60), minutes % 60));
|
|
31
|
+
|
|
32
|
+
/** “1430”, “14h30”, “2:30 pm”, “9” → minutos do dia. null se não for um horário. */
|
|
33
|
+
function parse(text) {
|
|
34
|
+
const m = text
|
|
35
|
+
.trim()
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.replace(/\s+/g, '')
|
|
38
|
+
.match(/^(\d{1,2})(?:[:h.]?(\d{2}))?h?([ap])?\.?(?:m\.?)?$/);
|
|
39
|
+
if (!m) return null;
|
|
40
|
+
let h = Number(m[1]);
|
|
41
|
+
const min = Number(m[2] ?? 0);
|
|
42
|
+
if (min > 59) return null;
|
|
43
|
+
if (m[3]) {
|
|
44
|
+
if (h < 1 || h > 12) return null;
|
|
45
|
+
h = (h % 12) + (m[3] === 'p' ? 12 : 0);
|
|
46
|
+
}
|
|
47
|
+
return h > 23 ? null : h * 60 + min;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createTimePicker(input, options = {}) {
|
|
51
|
+
const o = { step: 15, ...options };
|
|
52
|
+
const id = `ds-timepicker-${++uid}`;
|
|
53
|
+
const min = o.min ? toMinutes(o.min) : 0;
|
|
54
|
+
const max = o.max ? toMinutes(o.max) : 24 * 60 - 1;
|
|
55
|
+
const field = input.closest('.ds-field');
|
|
56
|
+
const hidden = input.name ? hiddenValue(input) : null;
|
|
57
|
+
if (!input.id) input.id = id;
|
|
58
|
+
input.autocomplete = 'off';
|
|
59
|
+
input.setAttribute('role', 'combobox');
|
|
60
|
+
input.setAttribute('aria-autocomplete', 'none');
|
|
61
|
+
input.setAttribute('aria-expanded', 'false');
|
|
62
|
+
input.setAttribute('aria-controls', id);
|
|
63
|
+
|
|
64
|
+
let value = o.value ? toMinutes(o.value) : null;
|
|
65
|
+
let active = -1;
|
|
66
|
+
|
|
67
|
+
const times = [];
|
|
68
|
+
for (let t = min; t <= max; t += o.step) times.push(t);
|
|
69
|
+
|
|
70
|
+
const button = document.createElement('button');
|
|
71
|
+
button.type = 'button';
|
|
72
|
+
button.className = 'ds-icon-btn ds-icon-btn--sm ds-field__action';
|
|
73
|
+
button.tabIndex = -1;
|
|
74
|
+
button.innerHTML = icon('clock', { size: 18 });
|
|
75
|
+
button.disabled = input.disabled;
|
|
76
|
+
input.after(button);
|
|
77
|
+
|
|
78
|
+
const list = document.createElement('div');
|
|
79
|
+
list.className = 'ds-picker ds-picker--list';
|
|
80
|
+
list.id = id;
|
|
81
|
+
list.setAttribute('role', 'listbox');
|
|
82
|
+
|
|
83
|
+
const isOpen = () => list.hasAttribute('data-open');
|
|
84
|
+
const emit = () => {
|
|
85
|
+
o.onChange?.(value === null ? null : toValue(value));
|
|
86
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
function syncField() {
|
|
90
|
+
input.value = value === null ? '' : format(value);
|
|
91
|
+
if (hidden) hidden.value = value === null ? '' : toValue(value);
|
|
92
|
+
setFieldError(input, null);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function syncTexts() {
|
|
96
|
+
if (!o.placeholder) input.placeholder = '--:--';
|
|
97
|
+
button.setAttribute('aria-label', msg('time.open'));
|
|
98
|
+
list.setAttribute('aria-label', msg('time.list'));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function commitText() {
|
|
102
|
+
const text = input.value.trim();
|
|
103
|
+
if (!text) {
|
|
104
|
+
if (value !== null) {
|
|
105
|
+
value = null;
|
|
106
|
+
syncField();
|
|
107
|
+
emit();
|
|
108
|
+
} else setFieldError(input, null);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const minutes = parse(text);
|
|
112
|
+
const fail = (message) => {
|
|
113
|
+
if (hidden) hidden.value = '';
|
|
114
|
+
setFieldError(input, message);
|
|
115
|
+
};
|
|
116
|
+
if (minutes === null) return fail(msg('time.invalid', format(14 * 60 + 30)));
|
|
117
|
+
if (minutes < min) return fail(msg('time.min', format(min)));
|
|
118
|
+
if (minutes > max) return fail(msg('time.max', format(max)));
|
|
119
|
+
const changed = minutes !== value;
|
|
120
|
+
value = minutes;
|
|
121
|
+
syncField();
|
|
122
|
+
if (changed) emit();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function setActive(index) {
|
|
126
|
+
active = Math.max(0, Math.min(index, times.length - 1));
|
|
127
|
+
list.querySelectorAll('[role="option"]').forEach((el, i) => el.toggleAttribute('data-active', i === active));
|
|
128
|
+
const el = list.children[active];
|
|
129
|
+
if (!el) return;
|
|
130
|
+
input.setAttribute('aria-activedescendant', el.id);
|
|
131
|
+
// rola só a lista, nunca a página
|
|
132
|
+
if (el.offsetTop < list.scrollTop) list.scrollTop = el.offsetTop - 6;
|
|
133
|
+
else if (el.offsetTop + el.offsetHeight > list.scrollTop + list.clientHeight) list.scrollTop = el.offsetTop + el.offsetHeight - list.clientHeight + 6;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function open() {
|
|
137
|
+
if (isOpen() || input.disabled) return;
|
|
138
|
+
inheritTheme(list, input);
|
|
139
|
+
list.innerHTML = times
|
|
140
|
+
.map((t, i) => `<div class="ds-picker__option" role="option" id="${id}-${i}" data-index="${i}" aria-selected="${t === value}">${format(t)}${icon('check', { size: 16, className: 'ds-picker__check' })}</div>`)
|
|
141
|
+
.join('');
|
|
142
|
+
panelHost(input).append(list);
|
|
143
|
+
list.style.minWidth = `${Math.min(field.offsetWidth, 240)}px`;
|
|
144
|
+
placePanel(list, field);
|
|
145
|
+
list.setAttribute('data-open', '');
|
|
146
|
+
input.setAttribute('aria-expanded', 'true');
|
|
147
|
+
// abre no horário escolhido; sem ele, no primeiro horário depois do que foi digitado ou de agora
|
|
148
|
+
const typed = parse(input.value);
|
|
149
|
+
const now = new Date();
|
|
150
|
+
const seed = value ?? typed ?? now.getHours() * 60 + now.getMinutes();
|
|
151
|
+
const index = times.findIndex((t) => t >= seed);
|
|
152
|
+
setActive(index === -1 ? times.length - 1 : index);
|
|
153
|
+
const el = list.children[active];
|
|
154
|
+
if (el) list.scrollTop = el.offsetTop - (list.clientHeight - el.offsetHeight) / 2;
|
|
155
|
+
document.addEventListener('pointerdown', onOutside);
|
|
156
|
+
addEventListener('resize', onReposition);
|
|
157
|
+
document.addEventListener('scroll', onReposition, true);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function close() {
|
|
161
|
+
if (!isOpen()) return;
|
|
162
|
+
list.removeAttribute('data-open');
|
|
163
|
+
list.remove();
|
|
164
|
+
input.setAttribute('aria-expanded', 'false');
|
|
165
|
+
input.removeAttribute('aria-activedescendant');
|
|
166
|
+
active = -1;
|
|
167
|
+
document.removeEventListener('pointerdown', onOutside);
|
|
168
|
+
removeEventListener('resize', onReposition);
|
|
169
|
+
document.removeEventListener('scroll', onReposition, true);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const onOutside = (event) => {
|
|
173
|
+
if (!list.contains(event.target) && !field.contains(event.target)) close();
|
|
174
|
+
};
|
|
175
|
+
const onReposition = (event) => {
|
|
176
|
+
if (event?.target && list.contains(event.target)) return;
|
|
177
|
+
if (field.isConnected) placePanel(list, field);
|
|
178
|
+
else close();
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
function choose(index) {
|
|
182
|
+
const changed = times[index] !== value;
|
|
183
|
+
value = times[index];
|
|
184
|
+
syncField();
|
|
185
|
+
close();
|
|
186
|
+
if (changed) emit();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
list.addEventListener('pointerdown', (event) => event.preventDefault()); // o foco fica no campo
|
|
190
|
+
list.addEventListener('click', (event) => {
|
|
191
|
+
const option = event.target.closest('[role="option"]');
|
|
192
|
+
if (option) choose(Number(option.dataset.index));
|
|
193
|
+
});
|
|
194
|
+
list.addEventListener('pointermove', (event) => {
|
|
195
|
+
const option = event.target.closest('[role="option"]');
|
|
196
|
+
if (option && Number(option.dataset.index) !== active) {
|
|
197
|
+
active = Number(option.dataset.index);
|
|
198
|
+
list.querySelectorAll('[data-active]').forEach((el) => el.removeAttribute('data-active'));
|
|
199
|
+
option.setAttribute('data-active', '');
|
|
200
|
+
input.setAttribute('aria-activedescendant', option.id);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
const onKey = (event) => {
|
|
205
|
+
const page = Math.max(1, Math.round(60 / o.step));
|
|
206
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
if (!isOpen()) open();
|
|
209
|
+
else setActive(active + (event.key === 'ArrowDown' ? 1 : -1));
|
|
210
|
+
} else if (!isOpen()) {
|
|
211
|
+
if (event.key === 'Enter') commitText();
|
|
212
|
+
} else if (event.key === 'Enter') {
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
if (active >= 0) choose(active);
|
|
215
|
+
} else if (event.key === 'Escape') {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
event.stopPropagation();
|
|
218
|
+
close();
|
|
219
|
+
} else if (event.key === 'PageDown' || event.key === 'PageUp') {
|
|
220
|
+
event.preventDefault();
|
|
221
|
+
setActive(active + (event.key === 'PageDown' ? page : -page));
|
|
222
|
+
} else if (event.key === 'Home' || event.key === 'End') {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
setActive(event.key === 'Home' ? 0 : times.length - 1);
|
|
225
|
+
} else if (event.key === 'Tab') close();
|
|
226
|
+
};
|
|
227
|
+
const onInput = () => {
|
|
228
|
+
if (!isOpen()) return;
|
|
229
|
+
const typed = parse(input.value);
|
|
230
|
+
if (typed === null) return;
|
|
231
|
+
const index = times.findIndex((t) => t >= typed);
|
|
232
|
+
if (index !== -1) setActive(index);
|
|
233
|
+
};
|
|
234
|
+
const onBlur = () => {
|
|
235
|
+
close();
|
|
236
|
+
commitText();
|
|
237
|
+
};
|
|
238
|
+
const onButton = () => {
|
|
239
|
+
if (isOpen()) close();
|
|
240
|
+
else {
|
|
241
|
+
input.focus({ preventScroll: true });
|
|
242
|
+
open();
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const onLocale = () => {
|
|
246
|
+
syncTexts();
|
|
247
|
+
if (!input.dataset.dsInvalid) input.value = value === null ? '' : format(value);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
input.addEventListener('keydown', onKey);
|
|
251
|
+
input.addEventListener('input', onInput);
|
|
252
|
+
input.addEventListener('blur', onBlur);
|
|
253
|
+
button.addEventListener('pointerdown', (event) => event.preventDefault());
|
|
254
|
+
button.addEventListener('click', onButton);
|
|
255
|
+
document.documentElement.addEventListener('ds:localechange', onLocale);
|
|
256
|
+
|
|
257
|
+
syncTexts();
|
|
258
|
+
syncField();
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
get value() {
|
|
262
|
+
return value === null ? null : toValue(value);
|
|
263
|
+
},
|
|
264
|
+
setValue(next) {
|
|
265
|
+
value = next ? toMinutes(next) : null;
|
|
266
|
+
syncField();
|
|
267
|
+
},
|
|
268
|
+
open,
|
|
269
|
+
close,
|
|
270
|
+
destroy() {
|
|
271
|
+
close();
|
|
272
|
+
button.remove();
|
|
273
|
+
input.removeEventListener('keydown', onKey);
|
|
274
|
+
input.removeEventListener('input', onInput);
|
|
275
|
+
input.removeEventListener('blur', onBlur);
|
|
276
|
+
document.documentElement.removeEventListener('ds:localechange', onLocale);
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
package/js/toast.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Gerado por scripts/build-react.mjs. Não edite.
|
|
2
|
+
export type ToastPosition = 'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end';
|
|
3
|
+
export interface ToastOptions {
|
|
4
|
+
icon?: string;
|
|
5
|
+
tone?: 'neutral' | 'success' | 'warning' | 'danger' | 'info';
|
|
6
|
+
action?: { label: string; onClick: () => void };
|
|
7
|
+
duration?: number;
|
|
8
|
+
position?: ToastPosition;
|
|
9
|
+
}
|
|
10
|
+
export declare const TOAST_POSITIONS: ToastPosition[];
|
|
11
|
+
export declare function toast(message: string, options?: ToastOptions): { close(): void };
|
|
12
|
+
export declare function clearToasts(): void;
|
|
13
|
+
export declare function copyText(text: string, label?: string, options?: { echo?: boolean }): Promise<boolean>;
|
|
14
|
+
export declare function getToastPosition(): ToastPosition;
|
|
15
|
+
export declare function setToastPosition(position: ToastPosition): ToastPosition;
|
|
16
|
+
export declare function toastContent(message: string, options?: ToastOptions & { dismissible?: boolean }): string;
|
|
17
|
+
export declare function toastClasses(options?: { tone?: string }): string;
|