@joniguerini/lume 1.10.0 → 1.11.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/README.md +3 -3
- package/components/button.css +49 -0
- package/components/form.css +65 -0
- package/js/command-palette.js +6 -2
- package/js/currency-field.d.ts +4 -0
- package/js/currency-field.js +130 -0
- package/js/messages.js +12 -0
- package/js/password-field.d.ts +2 -0
- package/js/password-field.js +68 -0
- package/js/search-field.d.ts +2 -0
- package/js/search-field.js +115 -0
- package/lume.css +115 -1
- package/lume.d.ts +3 -0
- package/lume.js +3 -0
- package/package.json +2 -2
- package/react/Button.d.ts +26 -0
- package/react/Button.js +14 -1
- package/react/EmptyState.d.ts +25 -0
- package/react/EmptyState.js +11 -0
- package/react/Field.d.ts +59 -1
- package/react/Field.js +92 -3
- package/react/index.d.ts +3 -2
- package/react/index.js +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Lume Design System
|
|
2
2
|
|
|
3
|
-
Tokens, typography, 154 custom icons,
|
|
3
|
+
Tokens, typography, 154 custom icons, 66 components, charts, and screen patterns, in light and dark themes. Native HTML, CSS, and JavaScript, with no dependencies, plus React components. Works with any framework, or none.
|
|
4
4
|
|
|
5
5
|
Documentation: https://lumeui.dev · in English, Portuguese, and Spanish.
|
|
6
6
|
|
|
@@ -45,9 +45,9 @@ The files become yours: edit them as you like.
|
|
|
45
45
|
## Or load it from the web
|
|
46
46
|
|
|
47
47
|
```html
|
|
48
|
-
<link rel="stylesheet" href="https://lumeui.dev/v/1.
|
|
48
|
+
<link rel="stylesheet" href="https://lumeui.dev/v/1.11/lume.css">
|
|
49
49
|
<script type="module">
|
|
50
|
-
import { initTheme } from 'https://lumeui.dev/v/1.
|
|
50
|
+
import { initTheme } from 'https://lumeui.dev/v/1.11/lume.js';
|
|
51
51
|
initTheme();
|
|
52
52
|
</script>
|
|
53
53
|
```
|
package/components/button.css
CHANGED
|
@@ -140,6 +140,55 @@
|
|
|
140
140
|
width: 100%;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/*
|
|
144
|
+
* Botão dividido — a ação principal e, colada nela, a seta que abre as alternativas (createMenu).
|
|
145
|
+
* <div class="ds-split-button">
|
|
146
|
+
* <button type="button" class="ds-btn ds-btn--primary">Novo atendimento</button>
|
|
147
|
+
* <button type="button" class="ds-btn ds-btn--primary ds-split-button__menu" aria-label="Mais opções"><ds-icon name="chevron-down"></ds-icon></button>
|
|
148
|
+
* </div>
|
|
149
|
+
* Os dois botões levam a mesma variante e o mesmo tamanho. Um fio na cor do fundo separa os dois.
|
|
150
|
+
*/
|
|
151
|
+
.ds-split-button {
|
|
152
|
+
display: inline-flex;
|
|
153
|
+
isolation: isolate;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.ds-split-button > .ds-btn:first-child {
|
|
157
|
+
border-start-end-radius: 0;
|
|
158
|
+
border-end-end-radius: 0;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.ds-split-button > .ds-split-button__menu {
|
|
162
|
+
width: var(--_h);
|
|
163
|
+
padding-inline: 0;
|
|
164
|
+
margin-inline-start: -1px;
|
|
165
|
+
border-start-start-radius: 0;
|
|
166
|
+
border-end-start-radius: 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* nas variantes com fundo, o fio entre os dois é a cor da superfície; nas de contorno, o próprio contorno */
|
|
170
|
+
.ds-split-button > .ds-split-button__menu:is(.ds-btn--primary, .ds-btn--danger, .ds-btn--subtle) {
|
|
171
|
+
margin-inline-start: 1px;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.ds-split-button > .ds-btn:is(:hover, :focus-visible, [data-state="hover"], [data-state="focus"]) {
|
|
175
|
+
z-index: 1;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.ds-split-button > .ds-split-button__menu .ds-icon {
|
|
179
|
+
transition: transform var(--ds-duration-base) var(--ds-easing-emphasized);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.ds-split-button > .ds-split-button__menu[aria-expanded="true"] .ds-icon {
|
|
183
|
+
transform: rotate(180deg);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@media (prefers-reduced-motion: reduce) {
|
|
187
|
+
.ds-split-button > .ds-split-button__menu .ds-icon {
|
|
188
|
+
transition: none;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
143
192
|
/* ───────── Botão de ícone ───────── */
|
|
144
193
|
|
|
145
194
|
.ds-icon-btn {
|
package/components/form.css
CHANGED
|
@@ -457,6 +457,71 @@
|
|
|
457
457
|
margin-inline-start: calc(-1 * var(--ds-space-150) + 2px);
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
+
/* símbolo depois do valor (moeda em espanhol: "12,50 €") */
|
|
461
|
+
.ds-field__input + .ds-field__affix {
|
|
462
|
+
margin-inline-start: calc(-1 * var(--ds-space-150) + 2px);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/*
|
|
466
|
+
* Campo de dinheiro (ds/js/currency-field.js): o valor alinha à direita, como numa coluna de valores,
|
|
467
|
+
* e os algarismos têm a mesma largura.
|
|
468
|
+
*/
|
|
469
|
+
.ds-currency .ds-field__input {
|
|
470
|
+
font-variant-numeric: tabular-nums;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/*
|
|
474
|
+
* Campo de busca (ds/js/search-field.js): a lupa, o × quando há texto e a tecla de atalho quando está vazio.
|
|
475
|
+
* O × nativo do type="search" sai: o do Lume tem nome e o mesmo desenho dos outros campos.
|
|
476
|
+
*/
|
|
477
|
+
.ds-search .ds-field__input::-webkit-search-cancel-button,
|
|
478
|
+
.ds-search .ds-field__input::-webkit-search-decoration {
|
|
479
|
+
appearance: none;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.ds-search__kbd {
|
|
483
|
+
flex: none;
|
|
484
|
+
margin-inline-end: calc(-1 * var(--ds-space-050));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/*
|
|
488
|
+
* Grupo de campos — um rótulo, uma dica e um erro para vários controles ("Quando": data e dois horários).
|
|
489
|
+
* <div class="ds-form-field ds-field-group" role="group" aria-labelledby="quando-label" aria-describedby="quando-hint">
|
|
490
|
+
* <span class="ds-form-field__label" id="quando-label">Quando</span>
|
|
491
|
+
* <div class="ds-field-group__controls">…controles, cada um com o próprio aria-label…</div>
|
|
492
|
+
* <div class="ds-form-field__footer"><p class="ds-form-field__hint" id="quando-hint">Dica</p></div>
|
|
493
|
+
* </div>
|
|
494
|
+
*/
|
|
495
|
+
.ds-field-group__controls {
|
|
496
|
+
display: flex;
|
|
497
|
+
flex-wrap: wrap;
|
|
498
|
+
align-items: center;
|
|
499
|
+
gap: var(--ds-space-100);
|
|
500
|
+
min-width: 0;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/* o primeiro controle ocupa o dobro dos outros (a data e os horários); todos quebram a linha quando falta espaço.
|
|
504
|
+
Sem min-width: 0, o input largo por natureza empurraria os vizinhos para a linha de baixo. */
|
|
505
|
+
.ds-field-group__controls > * {
|
|
506
|
+
flex: 1 1 120px;
|
|
507
|
+
min-width: 0;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
.ds-field-group__controls > :first-child {
|
|
511
|
+
flex: 2 1 160px;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/* com --even, todos dividem a linha por igual (nome e sobrenome) */
|
|
515
|
+
.ds-field-group--even .ds-field-group__controls > * {
|
|
516
|
+
flex: 1 1 0;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.ds-field-group__controls > .ds-field-group__sep {
|
|
520
|
+
flex: none;
|
|
521
|
+
color: var(--ds-color-fg-subtle);
|
|
522
|
+
font: var(--ds-text-body-sm);
|
|
523
|
+
}
|
|
524
|
+
|
|
460
525
|
@media (max-width: 639.98px) {
|
|
461
526
|
.ds-form__row,
|
|
462
527
|
.ds-form__row--3 {
|
package/js/command-palette.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Paleta de comandos (⌘K / Ctrl K / "/").
|
|
2
|
+
* Paleta de comandos (⌘K / Ctrl K / "/"). Se a página tem um Campo de busca com o atalho "/", a tecla fica com ele.
|
|
3
3
|
*
|
|
4
4
|
* const palette = createCommandPalette({
|
|
5
5
|
* items: () => [{ id, label, group, icon, keywords?, description?, hint?, perform }],
|
|
@@ -202,11 +202,15 @@ export function createCommandPalette({ items = [], placeholder, label, hotkeys =
|
|
|
202
202
|
returnFocus = null;
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
+
// um Campo de busca da página com shortcut: '/' (aria-keyshortcuts) fica com a tecla; ⌘K continua abrindo a paleta
|
|
206
|
+
const pageSearchOwnsSlash = () =>
|
|
207
|
+
[...document.querySelectorAll('[aria-keyshortcuts="/"]')].some((el) => !el.disabled && el.getClientRects().length > 0);
|
|
208
|
+
|
|
205
209
|
const onKey = (event) => {
|
|
206
210
|
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k' && !event.defaultPrevented) {
|
|
207
211
|
event.preventDefault();
|
|
208
212
|
dialog.open ? close() : open();
|
|
209
|
-
} else if (event.key === '/' && !dialog.open && !isTyping(event.target)) {
|
|
213
|
+
} else if (event.key === '/' && !dialog.open && !isTyping(event.target) && !pageSearchOwnsSlash()) {
|
|
210
214
|
event.preventDefault();
|
|
211
215
|
open();
|
|
212
216
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Gerado por scripts/build-react.mjs. Não edite.
|
|
2
|
+
export declare function currencyParts(currency?: string): { symbol: string; after: boolean; digits: number };
|
|
3
|
+
export declare function parseMoney(text: string): number | null;
|
|
4
|
+
export declare function createCurrencyField(input: HTMLInputElement, options?: { currency?: string; value?: number | null; min?: number; max?: number; onChange?: (value: number | null) => void }): { el: HTMLInputElement; value: number | null; setValue(value: number | null): void; destroy(): void };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Campo de dinheiro — digita-se livre ("1290", "1.290,5") e, ao sair do campo, o valor volta formatado
|
|
3
|
+
* no idioma atual, com o símbolo da moeda fixo no campo.
|
|
4
|
+
*
|
|
5
|
+
* <div class="ds-field"><input class="ds-field__input" id="valor" name="valor" type="text"></div>
|
|
6
|
+
*
|
|
7
|
+
* const valor = createCurrencyField(document.querySelector('#valor'), {
|
|
8
|
+
* currency: 'BRL', // código ISO 4217 (padrão: BRL)
|
|
9
|
+
* value: 1290.5, // número ou null
|
|
10
|
+
* min: 0, max: 100000, // opcionais: ao sair do campo, o valor volta para dentro deles
|
|
11
|
+
* onChange: (value) => …, // quando o valor se firma (ao sair do campo ou com Enter)
|
|
12
|
+
* });
|
|
13
|
+
* valor.value; valor.setValue(80); valor.destroy();
|
|
14
|
+
*
|
|
15
|
+
* O formulário recebe o número puro (1290.5), num input oculto com o name do campo. O símbolo e as casas
|
|
16
|
+
* decimais vêm do Intl: R$ e duas casas no real, ¥ e nenhuma no iene; em espanhol, o € vai depois do valor.
|
|
17
|
+
* Texto que não é número volta ao último valor válido.
|
|
18
|
+
*/
|
|
19
|
+
import { numberFormat } from './i18n.js';
|
|
20
|
+
import { hiddenValue } from './field-support.js';
|
|
21
|
+
|
|
22
|
+
/** Símbolo, lado do símbolo e casas decimais da moeda no idioma atual. */
|
|
23
|
+
export function currencyParts(currency = 'BRL') {
|
|
24
|
+
const f = numberFormat({ style: 'currency', currency, currencyDisplay: 'narrowSymbol' });
|
|
25
|
+
const parts = f.formatToParts(1);
|
|
26
|
+
const symbol = parts.find((p) => p.type === 'currency')?.value ?? currency;
|
|
27
|
+
const after = parts.findIndex((p) => p.type === 'currency') > parts.findIndex((p) => p.type === 'integer');
|
|
28
|
+
return { symbol, after, digits: f.resolvedOptions().maximumFractionDigits };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** "1.290,50" (pt-BR), "1,290.50" (en) ou "R$ 12" → número, conforme os separadores do idioma; null se não for número. */
|
|
32
|
+
export function parseMoney(text) {
|
|
33
|
+
// um milhão: o espanhol não separa o milhar em números de quatro dígitos
|
|
34
|
+
const parts = numberFormat({ minimumFractionDigits: 1 }).formatToParts(1234567.5);
|
|
35
|
+
const group = parts.find((p) => p.type === 'group')?.value ?? '';
|
|
36
|
+
const decimal = parts.find((p) => p.type === 'decimal')?.value ?? '.';
|
|
37
|
+
// o separador de milhar do pt-BR e do es é o ponto; o espaço fino do Intl também vale
|
|
38
|
+
let clean = String(text).trim().replace(/\s/g, '');
|
|
39
|
+
const g = group.replace(/\s/g, '');
|
|
40
|
+
// "12.5" num idioma de vírgula: um separador só, com uma ou duas casas no fim, é o decimal
|
|
41
|
+
const tail = g && !clean.includes(decimal) && clean.split(g).length === 2 && new RegExp(`\\${g}\\d{1,2}$`).test(clean);
|
|
42
|
+
if (tail) clean = clean.replace(g, decimal);
|
|
43
|
+
else if (g) clean = clean.split(g).join('');
|
|
44
|
+
clean = clean.replace(decimal, '.').replace(/[^\d.-]/g, '');
|
|
45
|
+
if (!clean || clean === '-' || (clean.match(/\./g) ?? []).length > 1) return null;
|
|
46
|
+
const n = Number(clean);
|
|
47
|
+
return Number.isNaN(n) ? null : n;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createCurrencyField(input, options = {}) {
|
|
51
|
+
const o = { currency: 'BRL', ...options };
|
|
52
|
+
const field = input.closest('.ds-field');
|
|
53
|
+
field?.classList.add('ds-currency');
|
|
54
|
+
const hidden = input.name ? hiddenValue(input) : null;
|
|
55
|
+
input.inputMode = 'decimal';
|
|
56
|
+
input.autocomplete = 'off';
|
|
57
|
+
|
|
58
|
+
const affix = document.createElement('span');
|
|
59
|
+
affix.className = 'ds-field__affix';
|
|
60
|
+
affix.setAttribute('aria-hidden', 'true');
|
|
61
|
+
|
|
62
|
+
let value = o.value ?? null;
|
|
63
|
+
let parts = currencyParts(o.currency);
|
|
64
|
+
const round = (n) => Number(n.toFixed(parts.digits));
|
|
65
|
+
const clamp = (n) => Math.min(o.max ?? Infinity, Math.max(o.min ?? -Infinity, n));
|
|
66
|
+
const format = (n) => numberFormat({ minimumFractionDigits: parts.digits, maximumFractionDigits: parts.digits }).format(n);
|
|
67
|
+
|
|
68
|
+
function placeAffix() {
|
|
69
|
+
affix.textContent = parts.symbol;
|
|
70
|
+
if (parts.after) input.after(affix);
|
|
71
|
+
else input.before(affix);
|
|
72
|
+
field?.classList.toggle('ds-currency--after', parts.after);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function sync() {
|
|
76
|
+
input.value = value === null ? '' : format(value);
|
|
77
|
+
if (hidden) hidden.value = value === null ? '' : String(value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function set(next) {
|
|
81
|
+
const changed = next !== value;
|
|
82
|
+
value = next;
|
|
83
|
+
sync();
|
|
84
|
+
if (changed) {
|
|
85
|
+
o.onChange?.(value);
|
|
86
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const commit = () => {
|
|
91
|
+
const text = input.value.trim();
|
|
92
|
+
if (!text) return set(null);
|
|
93
|
+
const n = parseMoney(text);
|
|
94
|
+
if (n === null) return sync(); // não é número: volta ao último valor
|
|
95
|
+
set(clamp(round(n)));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const onKey = (event) => {
|
|
99
|
+
if (event.key === 'Enter') commit();
|
|
100
|
+
};
|
|
101
|
+
const onLocale = () => {
|
|
102
|
+
parts = currencyParts(o.currency);
|
|
103
|
+
placeAffix();
|
|
104
|
+
sync();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
input.addEventListener('blur', commit);
|
|
108
|
+
input.addEventListener('keydown', onKey);
|
|
109
|
+
document.documentElement.addEventListener('ds:localechange', onLocale);
|
|
110
|
+
placeAffix();
|
|
111
|
+
sync();
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
el: input,
|
|
115
|
+
get value() {
|
|
116
|
+
return value;
|
|
117
|
+
},
|
|
118
|
+
setValue(next) {
|
|
119
|
+
value = next === null || next === undefined ? null : clamp(round(Number(next)));
|
|
120
|
+
sync();
|
|
121
|
+
},
|
|
122
|
+
destroy() {
|
|
123
|
+
input.removeEventListener('blur', commit);
|
|
124
|
+
input.removeEventListener('keydown', onKey);
|
|
125
|
+
document.documentElement.removeEventListener('ds:localechange', onLocale);
|
|
126
|
+
affix.remove();
|
|
127
|
+
field?.classList.remove('ds-currency', 'ds-currency--after');
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
package/js/messages.js
CHANGED
|
@@ -138,6 +138,10 @@ export const MESSAGES = {
|
|
|
138
138
|
|
|
139
139
|
'number.increase': 'Aumentar',
|
|
140
140
|
'number.decrease': 'Diminuir',
|
|
141
|
+
'password.show': 'Mostrar senha',
|
|
142
|
+
'search.clear': 'Limpar busca',
|
|
143
|
+
'search.shortcut': (key) => `Atalho: ${key}`,
|
|
144
|
+
'split.more': 'Mais opções',
|
|
141
145
|
'slider.min': 'Mínimo',
|
|
142
146
|
'slider.max': 'Máximo',
|
|
143
147
|
|
|
@@ -437,6 +441,10 @@ export const MESSAGES = {
|
|
|
437
441
|
|
|
438
442
|
'number.increase': 'Increase',
|
|
439
443
|
'number.decrease': 'Decrease',
|
|
444
|
+
'password.show': 'Show password',
|
|
445
|
+
'search.clear': 'Clear search',
|
|
446
|
+
'search.shortcut': (key) => `Shortcut: ${key}`,
|
|
447
|
+
'split.more': 'More options',
|
|
440
448
|
'slider.min': 'Minimum',
|
|
441
449
|
'slider.max': 'Maximum',
|
|
442
450
|
|
|
@@ -736,6 +744,10 @@ export const MESSAGES = {
|
|
|
736
744
|
|
|
737
745
|
'number.increase': 'Aumentar',
|
|
738
746
|
'number.decrease': 'Disminuir',
|
|
747
|
+
'password.show': 'Mostrar contraseña',
|
|
748
|
+
'search.clear': 'Borrar búsqueda',
|
|
749
|
+
'search.shortcut': (key) => `Atajo: ${key}`,
|
|
750
|
+
'split.more': 'Más opciones',
|
|
739
751
|
'slider.min': 'Mínimo',
|
|
740
752
|
'slider.max': 'Máximo',
|
|
741
753
|
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Gerado por scripts/build-react.mjs. Não edite.
|
|
2
|
+
export declare function createPasswordField(input: HTMLInputElement, options?: { onToggle?: (visible: boolean) => void }): { el: HTMLInputElement; visible: boolean; show(): void; hide(): void; toggle(): void; destroy(): void };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Campo de senha — o botão de mostrar e esconder dentro do campo, sem tirar o foco de quem digita.
|
|
3
|
+
*
|
|
4
|
+
* <div class="ds-field"><input class="ds-field__input" id="senha" name="senha" type="password" autocomplete="current-password"></div>
|
|
5
|
+
*
|
|
6
|
+
* const senha = createPasswordField(document.querySelector('#senha'));
|
|
7
|
+
* senha.visible; senha.show(); senha.hide(); senha.toggle(); senha.destroy();
|
|
8
|
+
*
|
|
9
|
+
* O botão é um .ds-field__action com aria-pressed: o nome ("Mostrar senha") não muda, e o estado diz se
|
|
10
|
+
* a senha está à vista. Ao enviar o formulário, a senha volta a ficar escondida (o navegador não oferece
|
|
11
|
+
* para salvar um campo de texto comum).
|
|
12
|
+
*/
|
|
13
|
+
import { icon } from '../icons/icons.js';
|
|
14
|
+
import { msg } from './i18n.js';
|
|
15
|
+
|
|
16
|
+
export function createPasswordField(input, { onToggle } = {}) {
|
|
17
|
+
const button = document.createElement('button');
|
|
18
|
+
button.type = 'button';
|
|
19
|
+
button.className = 'ds-icon-btn ds-icon-btn--sm ds-icon-btn--muted ds-field__action';
|
|
20
|
+
input.after(button);
|
|
21
|
+
let visible = false;
|
|
22
|
+
|
|
23
|
+
function sync() {
|
|
24
|
+
input.type = visible ? 'text' : 'password';
|
|
25
|
+
button.setAttribute('aria-pressed', String(visible));
|
|
26
|
+
button.setAttribute('aria-label', msg('password.show'));
|
|
27
|
+
button.innerHTML = icon(visible ? 'eye-off' : 'eye', { size: 16 });
|
|
28
|
+
button.disabled = input.disabled;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function set(next) {
|
|
32
|
+
if (next === visible) return;
|
|
33
|
+
visible = next;
|
|
34
|
+
sync();
|
|
35
|
+
onToggle?.(visible);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// o clique no botão não tira o foco do campo (o cursor fica onde estava)
|
|
39
|
+
const onDown = (event) => event.preventDefault();
|
|
40
|
+
const onClick = () => set(!visible);
|
|
41
|
+
const form = input.form;
|
|
42
|
+
const onSubmit = () => set(false);
|
|
43
|
+
const onLocale = () => sync();
|
|
44
|
+
|
|
45
|
+
button.addEventListener('pointerdown', onDown);
|
|
46
|
+
button.addEventListener('click', onClick);
|
|
47
|
+
form?.addEventListener('submit', onSubmit);
|
|
48
|
+
document.documentElement.addEventListener('ds:localechange', onLocale);
|
|
49
|
+
sync();
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
el: input,
|
|
53
|
+
get visible() {
|
|
54
|
+
return visible;
|
|
55
|
+
},
|
|
56
|
+
show: () => set(true),
|
|
57
|
+
hide: () => set(false),
|
|
58
|
+
toggle: () => set(!visible),
|
|
59
|
+
destroy() {
|
|
60
|
+
button.removeEventListener('pointerdown', onDown);
|
|
61
|
+
button.removeEventListener('click', onClick);
|
|
62
|
+
form?.removeEventListener('submit', onSubmit);
|
|
63
|
+
document.documentElement.removeEventListener('ds:localechange', onLocale);
|
|
64
|
+
button.remove();
|
|
65
|
+
input.type = 'password';
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Gerado por scripts/build-react.mjs. Não edite.
|
|
2
|
+
export declare function createSearchField(input: HTMLInputElement, options?: { shortcut?: string; onChange?: (value: string) => void }): { el: HTMLInputElement; value: string; setValue(value: string): void; clear(): void; focus(): void; destroy(): void };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Campo de busca — a lupa, o × para limpar quando há texto, Esc que limpa e, se quiser, uma tecla que
|
|
3
|
+
* leva o foco ao campo de qualquer lugar da página (a tecla aparece no campo enquanto ele está vazio).
|
|
4
|
+
*
|
|
5
|
+
* <div class="ds-field ds-search">
|
|
6
|
+
* <ds-icon name="search" size="18"></ds-icon>
|
|
7
|
+
* <input class="ds-field__input" id="busca" type="search" aria-label="Buscar clientes" placeholder="Buscar">
|
|
8
|
+
* </div>
|
|
9
|
+
*
|
|
10
|
+
* const busca = createSearchField(document.querySelector('#busca'), {
|
|
11
|
+
* shortcut: '/', // opcional: uma tecla sem modificador
|
|
12
|
+
* onChange: (value) => …, // a cada letra e ao limpar
|
|
13
|
+
* });
|
|
14
|
+
* busca.value; busca.setValue('ana'); busca.clear(); busca.focus(); busca.destroy();
|
|
15
|
+
*
|
|
16
|
+
* A tecla não dispara enquanto a pessoa digita em outro campo. Esc limpa só quando há texto; com o campo
|
|
17
|
+
* vazio, o Esc segue adiante (fecha o painel em volta, por exemplo).
|
|
18
|
+
*/
|
|
19
|
+
import { icon } from '../icons/icons.js';
|
|
20
|
+
import { msg } from './i18n.js';
|
|
21
|
+
|
|
22
|
+
const typing = (target) =>
|
|
23
|
+
target instanceof HTMLElement && (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName));
|
|
24
|
+
|
|
25
|
+
export function createSearchField(input, { shortcut, onChange } = {}) {
|
|
26
|
+
const field = input.closest('.ds-field');
|
|
27
|
+
field?.classList.add('ds-search');
|
|
28
|
+
|
|
29
|
+
const clearBtn = document.createElement('button');
|
|
30
|
+
clearBtn.type = 'button';
|
|
31
|
+
clearBtn.className = 'ds-icon-btn ds-icon-btn--sm ds-icon-btn--muted ds-field__action';
|
|
32
|
+
clearBtn.innerHTML = icon('x', { size: 16 });
|
|
33
|
+
input.after(clearBtn);
|
|
34
|
+
|
|
35
|
+
let kbd = null;
|
|
36
|
+
if (shortcut) {
|
|
37
|
+
kbd = document.createElement('kbd');
|
|
38
|
+
kbd.className = 'ds-kbd ds-search__kbd';
|
|
39
|
+
kbd.textContent = shortcut;
|
|
40
|
+
kbd.setAttribute('aria-hidden', 'true');
|
|
41
|
+
clearBtn.after(kbd);
|
|
42
|
+
input.setAttribute('aria-keyshortcuts', shortcut);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function sync() {
|
|
46
|
+
const empty = !input.value;
|
|
47
|
+
clearBtn.hidden = empty || input.disabled;
|
|
48
|
+
if (kbd) kbd.hidden = !empty;
|
|
49
|
+
clearBtn.setAttribute('aria-label', msg('search.clear'));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function emit() {
|
|
53
|
+
sync();
|
|
54
|
+
onChange?.(input.value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// limpar avisa como se a pessoa tivesse apagado: o evento input chega a quem escuta o campo (e ao onChange)
|
|
58
|
+
function clear() {
|
|
59
|
+
if (!input.value) return;
|
|
60
|
+
input.value = '';
|
|
61
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const onInput = () => emit();
|
|
65
|
+
const onKey = (event) => {
|
|
66
|
+
if (event.key === 'Escape' && input.value) {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
event.stopPropagation();
|
|
69
|
+
clear();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const onClear = () => {
|
|
73
|
+
clear();
|
|
74
|
+
input.focus();
|
|
75
|
+
};
|
|
76
|
+
const onDocKey = (event) => {
|
|
77
|
+
if (event.key !== shortcut || event.metaKey || event.ctrlKey || event.altKey || event.defaultPrevented || typing(event.target)) return;
|
|
78
|
+
if (input.disabled || !input.isConnected || input.getClientRects().length === 0) return;
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
input.focus();
|
|
81
|
+
input.select();
|
|
82
|
+
};
|
|
83
|
+
const onLocale = () => sync();
|
|
84
|
+
|
|
85
|
+
input.addEventListener('input', onInput);
|
|
86
|
+
input.addEventListener('keydown', onKey);
|
|
87
|
+
clearBtn.addEventListener('click', onClear);
|
|
88
|
+
if (shortcut) document.addEventListener('keydown', onDocKey);
|
|
89
|
+
document.documentElement.addEventListener('ds:localechange', onLocale);
|
|
90
|
+
sync();
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
el: input,
|
|
94
|
+
get value() {
|
|
95
|
+
return input.value;
|
|
96
|
+
},
|
|
97
|
+
setValue(next) {
|
|
98
|
+
input.value = next ?? '';
|
|
99
|
+
sync();
|
|
100
|
+
},
|
|
101
|
+
clear,
|
|
102
|
+
focus: () => input.focus(),
|
|
103
|
+
destroy() {
|
|
104
|
+
input.removeEventListener('input', onInput);
|
|
105
|
+
input.removeEventListener('keydown', onKey);
|
|
106
|
+
clearBtn.removeEventListener('click', onClear);
|
|
107
|
+
document.removeEventListener('keydown', onDocKey);
|
|
108
|
+
document.documentElement.removeEventListener('ds:localechange', onLocale);
|
|
109
|
+
input.removeAttribute('aria-keyshortcuts');
|
|
110
|
+
clearBtn.remove();
|
|
111
|
+
kbd?.remove();
|
|
112
|
+
field?.classList.remove('ds-search');
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
package/lume.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Lume Design System 1.
|
|
1
|
+
/* Lume Design System 1.11.0 · MIT · https://lumeui.dev */
|
|
2
2
|
/* Lume Design System — ponto de entrada CSS */
|
|
3
3
|
/*
|
|
4
4
|
* Fontes do Lume, servidas daqui (sem Google Fonts nem CDN): a mesma letra em qualquer aparelho e rede.
|
|
@@ -1344,6 +1344,55 @@ ds-icon {
|
|
|
1344
1344
|
width: 100%;
|
|
1345
1345
|
}
|
|
1346
1346
|
|
|
1347
|
+
/*
|
|
1348
|
+
* Botão dividido — a ação principal e, colada nela, a seta que abre as alternativas (createMenu).
|
|
1349
|
+
* <div class="ds-split-button">
|
|
1350
|
+
* <button type="button" class="ds-btn ds-btn--primary">Novo atendimento</button>
|
|
1351
|
+
* <button type="button" class="ds-btn ds-btn--primary ds-split-button__menu" aria-label="Mais opções"><ds-icon name="chevron-down"></ds-icon></button>
|
|
1352
|
+
* </div>
|
|
1353
|
+
* Os dois botões levam a mesma variante e o mesmo tamanho. Um fio na cor do fundo separa os dois.
|
|
1354
|
+
*/
|
|
1355
|
+
.ds-split-button {
|
|
1356
|
+
display: inline-flex;
|
|
1357
|
+
isolation: isolate;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
.ds-split-button > .ds-btn:first-child {
|
|
1361
|
+
border-start-end-radius: 0;
|
|
1362
|
+
border-end-end-radius: 0;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
.ds-split-button > .ds-split-button__menu {
|
|
1366
|
+
width: var(--_h);
|
|
1367
|
+
padding-inline: 0;
|
|
1368
|
+
margin-inline-start: -1px;
|
|
1369
|
+
border-start-start-radius: 0;
|
|
1370
|
+
border-end-start-radius: 0;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
/* nas variantes com fundo, o fio entre os dois é a cor da superfície; nas de contorno, o próprio contorno */
|
|
1374
|
+
.ds-split-button > .ds-split-button__menu:is(.ds-btn--primary, .ds-btn--danger, .ds-btn--subtle) {
|
|
1375
|
+
margin-inline-start: 1px;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
.ds-split-button > .ds-btn:is(:hover, :focus-visible, [data-state="hover"], [data-state="focus"]) {
|
|
1379
|
+
z-index: 1;
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
.ds-split-button > .ds-split-button__menu .ds-icon {
|
|
1383
|
+
transition: transform var(--ds-duration-base) var(--ds-easing-emphasized);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
.ds-split-button > .ds-split-button__menu[aria-expanded="true"] .ds-icon {
|
|
1387
|
+
transform: rotate(180deg);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1391
|
+
.ds-split-button > .ds-split-button__menu .ds-icon {
|
|
1392
|
+
transition: none;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1347
1396
|
/* ───────── Botão de ícone ───────── */
|
|
1348
1397
|
|
|
1349
1398
|
.ds-icon-btn {
|
|
@@ -2176,6 +2225,71 @@ ds-icon {
|
|
|
2176
2225
|
margin-inline-start: calc(-1 * var(--ds-space-150) + 2px);
|
|
2177
2226
|
}
|
|
2178
2227
|
|
|
2228
|
+
/* símbolo depois do valor (moeda em espanhol: "12,50 €") */
|
|
2229
|
+
.ds-field__input + .ds-field__affix {
|
|
2230
|
+
margin-inline-start: calc(-1 * var(--ds-space-150) + 2px);
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
/*
|
|
2234
|
+
* Campo de dinheiro (ds/js/currency-field.js): o valor alinha à direita, como numa coluna de valores,
|
|
2235
|
+
* e os algarismos têm a mesma largura.
|
|
2236
|
+
*/
|
|
2237
|
+
.ds-currency .ds-field__input {
|
|
2238
|
+
font-variant-numeric: tabular-nums;
|
|
2239
|
+
}
|
|
2240
|
+
|
|
2241
|
+
/*
|
|
2242
|
+
* Campo de busca (ds/js/search-field.js): a lupa, o × quando há texto e a tecla de atalho quando está vazio.
|
|
2243
|
+
* O × nativo do type="search" sai: o do Lume tem nome e o mesmo desenho dos outros campos.
|
|
2244
|
+
*/
|
|
2245
|
+
.ds-search .ds-field__input::-webkit-search-cancel-button,
|
|
2246
|
+
.ds-search .ds-field__input::-webkit-search-decoration {
|
|
2247
|
+
appearance: none;
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
.ds-search__kbd {
|
|
2251
|
+
flex: none;
|
|
2252
|
+
margin-inline-end: calc(-1 * var(--ds-space-050));
|
|
2253
|
+
}
|
|
2254
|
+
|
|
2255
|
+
/*
|
|
2256
|
+
* Grupo de campos — um rótulo, uma dica e um erro para vários controles ("Quando": data e dois horários).
|
|
2257
|
+
* <div class="ds-form-field ds-field-group" role="group" aria-labelledby="quando-label" aria-describedby="quando-hint">
|
|
2258
|
+
* <span class="ds-form-field__label" id="quando-label">Quando</span>
|
|
2259
|
+
* <div class="ds-field-group__controls">…controles, cada um com o próprio aria-label…</div>
|
|
2260
|
+
* <div class="ds-form-field__footer"><p class="ds-form-field__hint" id="quando-hint">Dica</p></div>
|
|
2261
|
+
* </div>
|
|
2262
|
+
*/
|
|
2263
|
+
.ds-field-group__controls {
|
|
2264
|
+
display: flex;
|
|
2265
|
+
flex-wrap: wrap;
|
|
2266
|
+
align-items: center;
|
|
2267
|
+
gap: var(--ds-space-100);
|
|
2268
|
+
min-width: 0;
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
/* o primeiro controle ocupa o dobro dos outros (a data e os horários); todos quebram a linha quando falta espaço.
|
|
2272
|
+
Sem min-width: 0, o input largo por natureza empurraria os vizinhos para a linha de baixo. */
|
|
2273
|
+
.ds-field-group__controls > * {
|
|
2274
|
+
flex: 1 1 120px;
|
|
2275
|
+
min-width: 0;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
.ds-field-group__controls > :first-child {
|
|
2279
|
+
flex: 2 1 160px;
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
/* com --even, todos dividem a linha por igual (nome e sobrenome) */
|
|
2283
|
+
.ds-field-group--even .ds-field-group__controls > * {
|
|
2284
|
+
flex: 1 1 0;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
.ds-field-group__controls > .ds-field-group__sep {
|
|
2288
|
+
flex: none;
|
|
2289
|
+
color: var(--ds-color-fg-subtle);
|
|
2290
|
+
font: var(--ds-text-body-sm);
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2179
2293
|
@media (max-width: 639.98px) {
|
|
2180
2294
|
.ds-form__row,
|
|
2181
2295
|
.ds-form__row--3 {
|
package/lume.d.ts
CHANGED
|
@@ -69,6 +69,9 @@ export declare const openModal: any;
|
|
|
69
69
|
export declare const confirmModal: any;
|
|
70
70
|
export declare const modalHtml: any;
|
|
71
71
|
export declare const createNumberField: any;
|
|
72
|
+
export declare const createCurrencyField: any;
|
|
73
|
+
export declare const createPasswordField: any;
|
|
74
|
+
export declare const createSearchField: any;
|
|
72
75
|
export declare const createOtpField: any;
|
|
73
76
|
export declare const createPagination: any;
|
|
74
77
|
export declare const createPopover: any;
|
package/lume.js
CHANGED
|
@@ -49,6 +49,9 @@ export {
|
|
|
49
49
|
export { createMenu } from './js/menu.js';
|
|
50
50
|
export { createModal, openModal, confirmModal, modalHtml } from './js/modal.js';
|
|
51
51
|
export { createNumberField } from './js/number-field.js';
|
|
52
|
+
export { createCurrencyField } from './js/currency-field.js';
|
|
53
|
+
export { createPasswordField } from './js/password-field.js';
|
|
54
|
+
export { createSearchField } from './js/search-field.js';
|
|
52
55
|
export { createOtpField } from './js/otp-field.js';
|
|
53
56
|
export { createPagination } from './js/pagination.js';
|
|
54
57
|
export { createPopover } from './js/popover.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joniguerini/lume",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Lume Design System: tokens, 154 icons,
|
|
3
|
+
"version": "1.11.0",
|
|
4
|
+
"description": "Lume Design System: tokens, 154 icons, 66 components, charts and screen patterns in native HTML, CSS and JavaScript, with no dependencies. React components included.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lume.js",
|
|
7
7
|
"types": "./lume.d.ts",
|
package/react/Button.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AnchorHTMLAttributes, type ButtonHTMLAttributes } from 'react';
|
|
2
2
|
import { type IconName } from './Icon.js';
|
|
3
|
+
import { type MenuOption } from './Navigation.js';
|
|
3
4
|
export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'subtle' | 'danger';
|
|
4
5
|
export type ButtonSize = 'sm' | 'md' | 'lg';
|
|
5
6
|
interface ButtonLook {
|
|
@@ -32,4 +33,29 @@ export interface ButtonLinkProps extends ButtonLook, AnchorHTMLAttributes<HTMLAn
|
|
|
32
33
|
}
|
|
33
34
|
/** O mesmo visual do Botão, para navegar: vira um link (<a>), com o teclado e o leitor de tela de um link. */
|
|
34
35
|
export declare const ButtonLink: import("react").ForwardRefExoticComponent<ButtonLinkProps & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
36
|
+
export interface SplitButtonProps {
|
|
37
|
+
/** O rótulo da ação principal, com verbo ("Novo atendimento"). */
|
|
38
|
+
label: string;
|
|
39
|
+
icon?: IconName;
|
|
40
|
+
/** A ação principal. */
|
|
41
|
+
onClick: () => void;
|
|
42
|
+
/** As alternativas, no menu da seta (modo ação: separador e tone: 'danger' valem). */
|
|
43
|
+
options: MenuOption[];
|
|
44
|
+
/** Chamado com o value da alternativa escolhida. */
|
|
45
|
+
onSelect: (value: string) => void;
|
|
46
|
+
/** Nome da seta e do menu para o leitor de tela. Padrão: "Mais opções". */
|
|
47
|
+
menuLabel?: string;
|
|
48
|
+
/** Padrão: primary. Ghost não entra: sem contorno, as duas metades não se leem como uma peça. */
|
|
49
|
+
variant?: Exclude<ButtonVariant, 'ghost'>;
|
|
50
|
+
size?: ButtonSize;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
/** A ação principal está em andamento: o spinner entra nela e a seta fica indisponível. */
|
|
53
|
+
busy?: boolean;
|
|
54
|
+
className?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A ação principal e, colada nela, a seta com as alternativas ("Novo atendimento ▾").
|
|
58
|
+
* https://lumeui.dev/#/componentes/botao-dividido
|
|
59
|
+
*/
|
|
60
|
+
export declare function SplitButton({ label, icon, onClick, options, onSelect, menuLabel, variant, size, disabled, busy, className, }: SplitButtonProps): import("react").JSX.Element;
|
|
35
61
|
export {};
|
package/react/Button.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { forwardRef } from 'react';
|
|
3
|
+
import { forwardRef, useRef } from 'react';
|
|
4
4
|
import { Icon } from './Icon.js';
|
|
5
|
+
import { Menu } from './Navigation.js';
|
|
6
|
+
import { msg } from '../js/i18n.js';
|
|
7
|
+
import { useLocale } from './useLocale.js';
|
|
5
8
|
import { cx } from './cx.js';
|
|
6
9
|
const classes = ({ variant = 'secondary', size = 'md', pill, block }, className) => cx('ds-btn', `ds-btn--${variant}`, size !== 'md' && `ds-btn--${size}`, pill && 'ds-btn--pill', block && 'ds-btn--block', className);
|
|
7
10
|
/**
|
|
@@ -22,3 +25,13 @@ export const Button = forwardRef(function Button({ variant, size, icon, iconEnd,
|
|
|
22
25
|
export const ButtonLink = forwardRef(function ButtonLink({ variant, size, icon, iconEnd, pill, block, className, children, ...rest }, ref) {
|
|
23
26
|
return (_jsxs("a", { ref: ref, className: classes({ variant, size, pill, block }, className), ...rest, children: [icon && _jsx(Icon, { name: icon }), children, iconEnd && _jsx(Icon, { name: iconEnd })] }));
|
|
24
27
|
});
|
|
28
|
+
/**
|
|
29
|
+
* A ação principal e, colada nela, a seta com as alternativas ("Novo atendimento ▾").
|
|
30
|
+
* https://lumeui.dev/#/componentes/botao-dividido
|
|
31
|
+
*/
|
|
32
|
+
export function SplitButton({ label, icon, onClick, options, onSelect, menuLabel, variant = 'primary', size = 'md', disabled, busy, className, }) {
|
|
33
|
+
useLocale();
|
|
34
|
+
const arrow = useRef(null);
|
|
35
|
+
const name = menuLabel ?? msg('split.more');
|
|
36
|
+
return (_jsxs("div", { className: cx('ds-split-button', className), children: [_jsx(Button, { variant: variant, size: size, icon: icon, disabled: disabled, busy: busy, onClick: onClick, children: label }), _jsx("button", { ref: arrow, type: "button", className: classes({ variant, size }, 'ds-split-button__menu'), "aria-label": name, disabled: disabled || busy, children: _jsx(Icon, { name: "chevron-down", size: size === 'sm' ? 16 : 18 }) }), _jsx(Menu, { triggerRef: arrow, options: options, mode: "action", label: name, hideLabel: true, onChange: onSelect })] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
import { type IconName } from './Icon.js';
|
|
3
|
+
export interface EmptyStateProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
4
|
+
/** O ícone do assunto. Padrão: inbox. */
|
|
5
|
+
icon?: IconName;
|
|
6
|
+
/** Diz o que falta, sem culpa: "Nenhum cliente ainda". */
|
|
7
|
+
title: ReactNode;
|
|
8
|
+
/** Por que está vazio ou o que acontece depois. */
|
|
9
|
+
description?: ReactNode;
|
|
10
|
+
/** O próximo passo: um botão principal e, se precisar, um secundário. */
|
|
11
|
+
actions?: ReactNode;
|
|
12
|
+
/** Linha pequena no fim (código do erro, hora). */
|
|
13
|
+
meta?: ReactNode;
|
|
14
|
+
/** danger para erro, warning para atenção (offline), muted para ícone neutro, loading para o ícone girando. */
|
|
15
|
+
tone?: 'danger' | 'warning' | 'muted' | 'loading';
|
|
16
|
+
/** page (padrão) para a página ou a lista inteira; compact dentro de um painel; inline numa linha de tabela. */
|
|
17
|
+
size?: 'page' | 'compact' | 'inline';
|
|
18
|
+
/** Sem contorno nem fundo, quando já está dentro de um cartão. */
|
|
19
|
+
plain?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Estado vazio: o que falta, por quê e o próximo passo. Anunciado sem interromper (role="status").
|
|
23
|
+
* https://lumeui.dev/#/componentes/estado-vazio
|
|
24
|
+
*/
|
|
25
|
+
export declare function EmptyState({ icon, title, description, actions, meta, tone, size, plain, className, role, ...rest }: EmptyStateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Icon } from './Icon.js';
|
|
4
|
+
import { cx } from './cx.js';
|
|
5
|
+
/**
|
|
6
|
+
* Estado vazio: o que falta, por quê e o próximo passo. Anunciado sem interromper (role="status").
|
|
7
|
+
* https://lumeui.dev/#/componentes/estado-vazio
|
|
8
|
+
*/
|
|
9
|
+
export function EmptyState({ icon = 'inbox', title, description, actions, meta, tone, size = 'page', plain, className, role = 'status', ...rest }) {
|
|
10
|
+
return (_jsxs("div", { className: cx('ds-empty', size !== 'page' && `ds-empty--${size}`, plain && 'ds-empty--plain', tone && `ds-empty--${tone}`, className), role: role, ...rest, children: [_jsx("span", { className: "ds-empty__icon", children: _jsx(Icon, { name: icon }) }), _jsx("p", { className: "ds-empty__title", children: title }), description && _jsx("p", { className: "ds-empty__description", children: description }), actions && _jsx("div", { className: "ds-empty__actions", children: actions }), meta && _jsx("p", { className: "ds-empty__meta", children: meta })] }));
|
|
11
|
+
}
|
package/react/Field.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { type InputHTMLAttributes, type ReactNode, type TextareaHTMLAttributes }
|
|
|
2
2
|
import { type IconName } from './Icon.js';
|
|
3
3
|
export type FieldSize = 'sm' | 'md' | 'lg';
|
|
4
4
|
interface FieldContextValue {
|
|
5
|
-
id:
|
|
5
|
+
/** Sem id dentro de um FieldGroup: cada controle do grupo leva o próprio. */
|
|
6
|
+
id?: string;
|
|
6
7
|
describedBy?: string;
|
|
7
8
|
invalid: boolean;
|
|
8
9
|
}
|
|
@@ -87,4 +88,61 @@ export interface TextFieldProps extends Omit<InputProps, 'children'> {
|
|
|
87
88
|
* https://lumeui.dev/#/componentes/campo-de-texto
|
|
88
89
|
*/
|
|
89
90
|
export declare const TextField: import("react").ForwardRefExoticComponent<TextFieldProps & import("react").RefAttributes<HTMLInputElement & HTMLTextAreaElement>>;
|
|
91
|
+
export interface FieldGroupProps {
|
|
92
|
+
/** O nome do grupo ("Quando"). Cada controle de dentro leva o próprio aria-label ("Data", "Início"). */
|
|
93
|
+
label: ReactNode;
|
|
94
|
+
/** Uma linha logo abaixo. Some quando há erro. */
|
|
95
|
+
hint?: ReactNode;
|
|
96
|
+
/** A mensagem de erro do grupo. Liga aria-invalid nos controles de dentro. */
|
|
97
|
+
error?: ReactNode;
|
|
98
|
+
optional?: boolean;
|
|
99
|
+
/** Os controles dividem a linha por igual (nome e sobrenome). Padrão: o primeiro ocupa o dobro dos outros. */
|
|
100
|
+
even?: boolean;
|
|
101
|
+
/** Base dos ids do rótulo e da mensagem. Padrão: um gerado. */
|
|
102
|
+
id?: string;
|
|
103
|
+
className?: string;
|
|
104
|
+
children: ReactNode;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Um rótulo, uma dica e um erro para vários controles lado a lado (data e dois horários).
|
|
108
|
+
* O grupo tem role="group" e o nome do rótulo; cada controle mantém o próprio id e lê a dica e o erro sozinho.
|
|
109
|
+
* https://lumeui.dev/#/componentes/grupo-de-campos
|
|
110
|
+
*/
|
|
111
|
+
export declare function FieldGroup({ label, hint, error, optional, even, id, className, children }: FieldGroupProps): import("react").JSX.Element;
|
|
112
|
+
export interface PasswordFieldProps extends Omit<InputProps, 'type' | 'action' | 'affix'> {
|
|
113
|
+
/** Padrão: current-password. Em criar conta e trocar senha, use new-password. */
|
|
114
|
+
autoComplete?: 'current-password' | 'new-password';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Senha com o botão de mostrar e esconder dentro do campo (aria-pressed; o foco fica no campo).
|
|
118
|
+
* https://lumeui.dev/#/componentes/campo-de-senha
|
|
119
|
+
*/
|
|
120
|
+
export declare const PasswordField: import("react").ForwardRefExoticComponent<PasswordFieldProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
121
|
+
export interface SearchFieldProps extends Omit<InputProps, 'type' | 'value' | 'onChange' | 'action' | 'icon'> {
|
|
122
|
+
value: string;
|
|
123
|
+
onChange: (value: string) => void;
|
|
124
|
+
/** Uma tecla sem modificador que leva o foco ao campo de qualquer lugar ("/"). Aparece no campo vazio. */
|
|
125
|
+
shortcut?: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Busca: a lupa, o × quando há texto, Esc que limpa e o atalho opcional. Dê um aria-label ("Buscar clientes")
|
|
129
|
+
* ou ponha dentro de um Field.
|
|
130
|
+
* https://lumeui.dev/#/componentes/campo-de-busca
|
|
131
|
+
*/
|
|
132
|
+
export declare const SearchField: import("react").ForwardRefExoticComponent<SearchFieldProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
133
|
+
export interface CurrencyFieldProps extends Omit<InputProps, 'value' | 'onChange' | 'affix' | 'type' | 'inputMode' | 'defaultValue'> {
|
|
134
|
+
value: number | null;
|
|
135
|
+
/** Quando o valor se firma: ao sair do campo ou com Enter. */
|
|
136
|
+
onChange: (value: number | null) => void;
|
|
137
|
+
/** Código ISO 4217. Padrão: BRL. */
|
|
138
|
+
currency?: string;
|
|
139
|
+
min?: number;
|
|
140
|
+
max?: number;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Dinheiro: digita-se livre e, ao sair do campo, o valor volta formatado no idioma, com o símbolo fixo.
|
|
144
|
+
* O formulário recebe o número puro (1290.5) pelo name.
|
|
145
|
+
* https://lumeui.dev/#/componentes/campo-de-dinheiro
|
|
146
|
+
*/
|
|
147
|
+
export declare const CurrencyField: import("react").ForwardRefExoticComponent<CurrencyFieldProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
90
148
|
export {};
|
package/react/Field.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, forwardRef, useContext, useState, } from 'react';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState, } from 'react';
|
|
4
4
|
import { Icon } from './Icon.js';
|
|
5
|
+
import { Kbd } from './Content.js';
|
|
5
6
|
import { msg } from '../js/i18n.js';
|
|
7
|
+
import { createCurrencyField } from '../js/currency-field.js';
|
|
6
8
|
import { useLocale } from './useLocale.js';
|
|
7
|
-
import { useSafeId } from './useController.js';
|
|
9
|
+
import { useSafeId, useLatest, defined } from './useController.js';
|
|
8
10
|
import { cx } from './cx.js';
|
|
9
11
|
const FieldContext = createContext(null);
|
|
10
12
|
/** O id, a descrição (dica ou erro) e o estado de erro do Field em volta. Para controles próprios dentro de um Field. */
|
|
@@ -63,3 +65,90 @@ export const TextField = forwardRef(function TextField({ label, hint, error, opt
|
|
|
63
65
|
const { size, icon, affix, action, type, ...common } = rest;
|
|
64
66
|
return (_jsx(Field, { label: label, hint: hint, error: error, optional: optional, count: count, id: id, className: className, children: multiline ? (_jsx(Textarea, { ref: ref, rows: rows, maxLength: maxLength, onChange: change, ...common })) : (_jsx(Input, { ref: ref, size: size, icon: icon, affix: affix, type: type, maxLength: maxLength, onChange: change, action: action ?? (onClear && length > 0 ? _jsx(FieldAction, { icon: "x", label: msg('form.clear'), onClick: onClear }) : undefined), ...common })) }));
|
|
65
67
|
});
|
|
68
|
+
/**
|
|
69
|
+
* Um rótulo, uma dica e um erro para vários controles lado a lado (data e dois horários).
|
|
70
|
+
* O grupo tem role="group" e o nome do rótulo; cada controle mantém o próprio id e lê a dica e o erro sozinho.
|
|
71
|
+
* https://lumeui.dev/#/componentes/grupo-de-campos
|
|
72
|
+
*/
|
|
73
|
+
export function FieldGroup({ label, hint, error, optional, even, id, className, children }) {
|
|
74
|
+
useLocale();
|
|
75
|
+
const auto = useSafeId('fg');
|
|
76
|
+
const groupId = id ?? auto;
|
|
77
|
+
const invalid = Boolean(error);
|
|
78
|
+
const describedBy = invalid ? `${groupId}-error` : hint ? `${groupId}-hint` : undefined;
|
|
79
|
+
return (_jsx(FieldContext.Provider, { value: { id: undefined, describedBy, invalid }, children: _jsxs("div", { className: cx('ds-form-field ds-field-group', even && 'ds-field-group--even', className), role: "group", "aria-labelledby": `${groupId}-label`, children: [_jsxs("span", { className: "ds-form-field__label", id: `${groupId}-label`, children: [label, optional && _jsx("span", { className: "ds-form-field__optional", children: msg('form.optional') })] }), _jsx("div", { className: "ds-field-group__controls", children: children }), (invalid || hint) && (_jsx("div", { className: "ds-form-field__footer", children: invalid ? (_jsxs("p", { className: "ds-form-field__error", id: `${groupId}-error`, children: [_jsx(Icon, { name: "alert-circle", size: 16 }), _jsx("span", { children: error })] })) : (_jsx("p", { className: "ds-form-field__hint", id: `${groupId}-hint`, children: hint })) }))] }) }));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Senha com o botão de mostrar e esconder dentro do campo (aria-pressed; o foco fica no campo).
|
|
83
|
+
* https://lumeui.dev/#/componentes/campo-de-senha
|
|
84
|
+
*/
|
|
85
|
+
export const PasswordField = forwardRef(function PasswordField({ autoComplete = 'current-password', disabled, ...rest }, ref) {
|
|
86
|
+
useLocale();
|
|
87
|
+
const [visible, setVisible] = useState(false);
|
|
88
|
+
return (_jsx(Input, { ref: ref, ...rest, disabled: disabled, type: visible ? 'text' : 'password', autoComplete: autoComplete, action: _jsx("button", { type: "button", className: "ds-icon-btn ds-icon-btn--sm ds-icon-btn--muted ds-field__action", "aria-label": msg('password.show'), "aria-pressed": visible, disabled: disabled, onPointerDown: (event) => event.preventDefault(), onClick: () => setVisible((v) => !v), children: _jsx(Icon, { name: visible ? 'eye-off' : 'eye', size: 16 }) }) }));
|
|
89
|
+
});
|
|
90
|
+
const typing = (target) => target instanceof HTMLElement && (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName));
|
|
91
|
+
/**
|
|
92
|
+
* Busca: a lupa, o × quando há texto, Esc que limpa e o atalho opcional. Dê um aria-label ("Buscar clientes")
|
|
93
|
+
* ou ponha dentro de um Field.
|
|
94
|
+
* https://lumeui.dev/#/componentes/campo-de-busca
|
|
95
|
+
*/
|
|
96
|
+
export const SearchField = forwardRef(function SearchField({ value, onChange, shortcut, onKeyDown, disabled, className, placeholder, ...rest }, ref) {
|
|
97
|
+
useLocale();
|
|
98
|
+
const input = useRef(null);
|
|
99
|
+
useImperativeHandle(ref, () => input.current, []);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (!shortcut)
|
|
102
|
+
return;
|
|
103
|
+
const onKey = (event) => {
|
|
104
|
+
if (event.key !== shortcut || event.metaKey || event.ctrlKey || event.altKey || event.defaultPrevented || typing(event.target))
|
|
105
|
+
return;
|
|
106
|
+
const el = input.current;
|
|
107
|
+
if (!el || el.disabled || el.getClientRects().length === 0)
|
|
108
|
+
return;
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
el.focus();
|
|
111
|
+
el.select();
|
|
112
|
+
};
|
|
113
|
+
document.addEventListener('keydown', onKey);
|
|
114
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
115
|
+
}, [shortcut]);
|
|
116
|
+
const clear = () => {
|
|
117
|
+
onChange('');
|
|
118
|
+
input.current?.focus();
|
|
119
|
+
};
|
|
120
|
+
return (_jsx(Input, { ref: input, ...rest, type: "search", icon: "search", className: cx('ds-search', className), placeholder: placeholder ?? msg('common.search'), disabled: disabled, value: value, "aria-keyshortcuts": shortcut, onChange: (event) => onChange(event.target.value), onKeyDown: (event) => {
|
|
121
|
+
if (event.key === 'Escape' && value) {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
event.stopPropagation();
|
|
124
|
+
onChange('');
|
|
125
|
+
}
|
|
126
|
+
onKeyDown?.(event);
|
|
127
|
+
}, action: value && !disabled ? (_jsx(FieldAction, { icon: "x", label: msg('search.clear'), onClick: clear })) : shortcut ? (_jsx(Kbd, { className: "ds-search__kbd", "aria-hidden": "true", children: shortcut })) : undefined }));
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* Dinheiro: digita-se livre e, ao sair do campo, o valor volta formatado no idioma, com o símbolo fixo.
|
|
131
|
+
* O formulário recebe o número puro (1290.5) pelo name.
|
|
132
|
+
* https://lumeui.dev/#/componentes/campo-de-dinheiro
|
|
133
|
+
*/
|
|
134
|
+
export const CurrencyField = forwardRef(function CurrencyField({ value, onChange, currency = 'BRL', min, max, name, ...rest }, ref) {
|
|
135
|
+
const input = useRef(null);
|
|
136
|
+
useImperativeHandle(ref, () => input.current, []);
|
|
137
|
+
const api = useRef(null);
|
|
138
|
+
const emit = useLatest(onChange);
|
|
139
|
+
const latest = useLatest(value);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const c = createCurrencyField(input.current, defined({ currency, min, max, value: latest.current, onChange: (v) => emit.current(v) }));
|
|
142
|
+
api.current = c;
|
|
143
|
+
return () => {
|
|
144
|
+
c.destroy();
|
|
145
|
+
api.current = null;
|
|
146
|
+
};
|
|
147
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
148
|
+
}, [currency, min, max]);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (api.current && api.current.value !== value)
|
|
151
|
+
api.current.setValue(value);
|
|
152
|
+
}, [value]);
|
|
153
|
+
return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: input, ...rest }), name && _jsx("input", { type: "hidden", name: name, value: value ?? '' })] }));
|
|
154
|
+
});
|
package/react/index.d.ts
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
export { cx } from './cx.js';
|
|
7
7
|
export { useLocale } from './useLocale.js';
|
|
8
8
|
export { Icon, type IconName, type IconProps } from './Icon.js';
|
|
9
|
-
export { Button, ButtonLink, type ButtonProps, type ButtonLinkProps, type ButtonVariant, type ButtonSize } from './Button.js';
|
|
9
|
+
export { Button, ButtonLink, SplitButton, type ButtonProps, type ButtonLinkProps, type ButtonVariant, type ButtonSize, type SplitButtonProps } from './Button.js';
|
|
10
10
|
export { IconButton, type IconButtonProps } from './IconButton.js';
|
|
11
11
|
export { InlineAction, type InlineActionProps } from './InlineAction.js';
|
|
12
12
|
export { Link, Divider, type LinkProps, type DividerProps } from './Link.js';
|
|
13
13
|
export { Chip, RemovableChip, ChipGroup, type ChipProps, type RemovableChipProps, type ChipGroupProps } from './Chip.js';
|
|
14
14
|
export { Badge, type BadgeProps, type Tone } from './Badge.js';
|
|
15
15
|
export { Alert, type AlertProps, type AlertTone } from './Alert.js';
|
|
16
|
+
export { EmptyState, type EmptyStateProps } from './EmptyState.js';
|
|
16
17
|
export { Banner, NotificationCenter, type BannerProps, type BannerTone, type NotificationCenterProps, type NotificationItem } from './Notices.js';
|
|
17
18
|
export { ImageGallery, openImageViewer, type ImageGalleryProps, type GalleryImage, type ViewerImage } from './ImageViewer.js';
|
|
18
19
|
export { SortableList, Kanban, type SortableListProps, type SortableItem, type KanbanProps, type KanbanColumn } from './Sortable.js';
|
|
@@ -21,7 +22,7 @@ export { Progress, ProgressRing, Spinner, Skeleton, type ProgressProps, type Pro
|
|
|
21
22
|
export { Card, CardLink, Panel, PanelSpacer, PanelMeta, Section, type CardProps, type CardLinkProps, type PanelProps, type SectionProps } from './Panel.js';
|
|
22
23
|
export { Avatar, AvatarGroup, avatarTone, initials, type AvatarProps, type AvatarGroupProps, type AvatarTone, type AvatarStatus, type AvatarSize } from './Avatar.js';
|
|
23
24
|
export { Kbd, DescriptionList, Timeline, Breadcrumb, type KbdProps, type DescriptionListProps, type TimelineProps, type TimelineItem, type BreadcrumbProps, type BreadcrumbItem, } from './Content.js';
|
|
24
|
-
export { Field, Input, Textarea, TextField, FieldAction, useField, type FieldProps, type InputProps, type TextareaProps, type TextFieldProps, type FieldActionProps, type FieldSize } from './Field.js';
|
|
25
|
+
export { Field, Input, Textarea, TextField, FieldAction, FieldGroup, PasswordField, SearchField, CurrencyField, useField, type FieldProps, type InputProps, type TextareaProps, type TextFieldProps, type FieldActionProps, type FieldSize, type FieldGroupProps, type PasswordFieldProps, type SearchFieldProps, type CurrencyFieldProps, } from './Field.js';
|
|
25
26
|
export { Select, type SelectProps, type SelectOption, type SelectGroup } from './Select.js';
|
|
26
27
|
export { Checkbox, Radio, Switch, ChoiceGroup, RadioGroup, CheckboxGroup, type CheckboxProps, type RadioProps, type SwitchProps, type ChoiceGroupProps, type RadioGroupProps, type CheckboxGroupProps, type ChoiceOption, } from './Choice.js';
|
|
27
28
|
export { DatePicker, TimePicker, NumberField, TagField, type DatePickerProps, type DateRange, type TimePickerProps, type NumberFieldProps, type TagFieldProps, } from './Pickers.js';
|
package/react/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { cx } from './cx.js';
|
|
|
8
8
|
export { useLocale } from './useLocale.js';
|
|
9
9
|
export { Icon } from './Icon.js';
|
|
10
10
|
// Ações
|
|
11
|
-
export { Button, ButtonLink } from './Button.js';
|
|
11
|
+
export { Button, ButtonLink, SplitButton } from './Button.js';
|
|
12
12
|
export { IconButton } from './IconButton.js';
|
|
13
13
|
export { InlineAction } from './InlineAction.js';
|
|
14
14
|
export { Link, Divider } from './Link.js';
|
|
@@ -16,6 +16,7 @@ export { Chip, RemovableChip, ChipGroup } from './Chip.js';
|
|
|
16
16
|
// Feedback e carregamento
|
|
17
17
|
export { Badge } from './Badge.js';
|
|
18
18
|
export { Alert } from './Alert.js';
|
|
19
|
+
export { EmptyState } from './EmptyState.js';
|
|
19
20
|
export { Banner, NotificationCenter } from './Notices.js';
|
|
20
21
|
export { ImageGallery, openImageViewer } from './ImageViewer.js';
|
|
21
22
|
export { SortableList, Kanban } from './Sortable.js';
|
|
@@ -26,7 +27,7 @@ export { Card, CardLink, Panel, PanelSpacer, PanelMeta, Section } from './Panel.
|
|
|
26
27
|
export { Avatar, AvatarGroup, avatarTone, initials } from './Avatar.js';
|
|
27
28
|
export { Kbd, DescriptionList, Timeline, Breadcrumb, } from './Content.js';
|
|
28
29
|
// Formulários
|
|
29
|
-
export { Field, Input, Textarea, TextField, FieldAction, useField } from './Field.js';
|
|
30
|
+
export { Field, Input, Textarea, TextField, FieldAction, FieldGroup, PasswordField, SearchField, CurrencyField, useField, } from './Field.js';
|
|
30
31
|
export { Select } from './Select.js';
|
|
31
32
|
export { Checkbox, Radio, Switch, ChoiceGroup, RadioGroup, CheckboxGroup, } from './Choice.js';
|
|
32
33
|
export { DatePicker, TimePicker, NumberField, TagField, } from './Pickers.js';
|