@joniguerini/lume 1.9.2 → 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 +92 -0
- package/components/loading.css +8 -1
- package/components/menu.css +13 -0
- package/components/shell.css +25 -0
- package/components/toast.css +36 -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/menu.js +8 -3
- 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/js/shell.js +7 -3
- package/js/toast.d.ts +3 -1
- package/js/toast.js +7 -3
- package/lume.css +224 -2
- package/lume.d.ts +3 -0
- package/lume.js +3 -0
- package/package.json +2 -2
- package/react/Alert.d.ts +3 -2
- package/react/Alert.js +4 -3
- package/react/AppShell.d.ts +2 -0
- package/react/Button.d.ts +30 -1
- package/react/Button.js +23 -3
- package/react/Charts.d.ts +4 -0
- 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/Navigation.d.ts +13 -3
- package/react/Navigation.js +6 -6
- 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
|
@@ -232,6 +232,8 @@
|
|
|
232
232
|
|
|
233
233
|
.ds-segmented__item {
|
|
234
234
|
display: inline-grid;
|
|
235
|
+
grid-auto-flow: column;
|
|
236
|
+
gap: var(--ds-space-075);
|
|
235
237
|
place-items: center;
|
|
236
238
|
min-width: 28px;
|
|
237
239
|
height: var(--ds-size-control-xs);
|
|
@@ -245,6 +247,31 @@
|
|
|
245
247
|
box-shadow var(--ds-duration-base) var(--ds-easing-standard);
|
|
246
248
|
}
|
|
247
249
|
|
|
250
|
+
/* Tamanhos pela altura total (trilho + item): sm 32 · md 36 (padrão) · lg 40, que alinha com campos e botões médios */
|
|
251
|
+
.ds-segmented--sm .ds-segmented__item {
|
|
252
|
+
min-width: 24px;
|
|
253
|
+
height: calc(var(--ds-size-control-sm) - 8px);
|
|
254
|
+
padding-inline: var(--ds-space-075);
|
|
255
|
+
font: var(--ds-text-label-sm);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.ds-segmented--lg .ds-segmented__item {
|
|
259
|
+
min-width: 32px;
|
|
260
|
+
height: calc(var(--ds-size-control-md) - 8px);
|
|
261
|
+
padding-inline: var(--ds-space-150);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* Largura toda: as opções dividem o espaço por igual */
|
|
265
|
+
.ds-segmented--fill {
|
|
266
|
+
display: flex;
|
|
267
|
+
width: 100%;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.ds-segmented--fill .ds-segmented__item {
|
|
271
|
+
flex: 1;
|
|
272
|
+
min-width: 0;
|
|
273
|
+
}
|
|
274
|
+
|
|
248
275
|
.ds-segmented__item:hover,
|
|
249
276
|
.ds-segmented__item[data-state="hover"] {
|
|
250
277
|
color: var(--ds-color-fg-default);
|
|
@@ -430,6 +457,71 @@
|
|
|
430
457
|
margin-inline-start: calc(-1 * var(--ds-space-150) + 2px);
|
|
431
458
|
}
|
|
432
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
|
+
|
|
433
525
|
@media (max-width: 639.98px) {
|
|
434
526
|
.ds-form__row,
|
|
435
527
|
.ds-form__row--3 {
|
package/components/loading.css
CHANGED
|
@@ -190,12 +190,19 @@
|
|
|
190
190
|
to { transform: rotate(1turn); }
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
/*
|
|
193
|
+
/*
|
|
194
|
+
* Botão ocupado: <button class="ds-btn" aria-busy="true" aria-disabled="true"><span class="ds-spinner ds-spinner--sm"></span>Salvando</button>
|
|
195
|
+
* Fica indisponível (sem segundo clique) mas não esmaece: o spinner já diz que está trabalhando.
|
|
196
|
+
*/
|
|
194
197
|
.ds-btn[aria-busy="true"] {
|
|
195
198
|
cursor: progress;
|
|
196
199
|
pointer-events: none;
|
|
197
200
|
}
|
|
198
201
|
|
|
202
|
+
.ds-btn[aria-busy="true"][aria-disabled="true"] {
|
|
203
|
+
opacity: 1;
|
|
204
|
+
}
|
|
205
|
+
|
|
199
206
|
/*
|
|
200
207
|
* Skeleton — a forma do conteúdo antes de ele chegar: formas lisas que pulsam devagar, sem brilho.
|
|
201
208
|
* <div aria-busy="true" aria-label="Carregando"><div class="ds-skeleton ds-skeleton--text" style="--w:60%"></div></div>
|
package/components/menu.css
CHANGED
|
@@ -142,6 +142,19 @@
|
|
|
142
142
|
background: var(--ds-color-border-subtle);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
/* meta: texto curto à direita (uma contagem); com a marca do modo radio, fica antes dela */
|
|
146
|
+
.ds-menu__meta {
|
|
147
|
+
margin-inline-start: auto;
|
|
148
|
+
padding-inline-start: var(--ds-space-200);
|
|
149
|
+
color: var(--ds-color-fg-subtle);
|
|
150
|
+
font: var(--ds-text-caption);
|
|
151
|
+
font-variant-numeric: tabular-nums;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.ds-menu__meta + .ds-menu__check {
|
|
155
|
+
margin-inline-start: var(--ds-space-100);
|
|
156
|
+
}
|
|
157
|
+
|
|
145
158
|
.ds-menu__shortcut {
|
|
146
159
|
margin-inline-start: auto;
|
|
147
160
|
padding-inline-start: var(--ds-space-200);
|
package/components/shell.css
CHANGED
|
@@ -202,6 +202,19 @@
|
|
|
202
202
|
transition: opacity var(--ds-duration-base) var(--ds-easing-standard);
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/* contagem à direita do rótulo: número apagado, sem pílula (o rótulo continua mandando) */
|
|
206
|
+
.ds-nav-item__count {
|
|
207
|
+
flex: none;
|
|
208
|
+
color: var(--ds-color-fg-subtle);
|
|
209
|
+
font: var(--ds-text-caption);
|
|
210
|
+
font-variant-numeric: tabular-nums;
|
|
211
|
+
transition: opacity var(--ds-duration-base) var(--ds-easing-standard);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.ds-nav-item[aria-current="page"] .ds-nav-item__count {
|
|
215
|
+
color: var(--ds-color-fg-muted);
|
|
216
|
+
}
|
|
217
|
+
|
|
205
218
|
.ds-nav-item > .ds-dot {
|
|
206
219
|
margin-inline-end: 4px;
|
|
207
220
|
transition: translate var(--_dur) var(--_ease);
|
|
@@ -532,6 +545,12 @@ button.ds-account {
|
|
|
532
545
|
color: var(--ds-color-fg-default);
|
|
533
546
|
}
|
|
534
547
|
|
|
548
|
+
.ds-navbar__count {
|
|
549
|
+
color: var(--ds-color-fg-subtle);
|
|
550
|
+
font: var(--ds-text-caption);
|
|
551
|
+
font-variant-numeric: tabular-nums;
|
|
552
|
+
}
|
|
553
|
+
|
|
535
554
|
.ds-navbar__item > .ds-dot {
|
|
536
555
|
margin-inline-start: 2px;
|
|
537
556
|
}
|
|
@@ -689,6 +708,7 @@ button.ds-account {
|
|
|
689
708
|
.ds-sidebar-search .ds-field__placeholder,
|
|
690
709
|
.ds-sidebar-search__kbd,
|
|
691
710
|
.ds-nav-item__label,
|
|
711
|
+
.ds-nav-item__count,
|
|
692
712
|
.ds-nav-group__label,
|
|
693
713
|
.ds-nav-group__toggle,
|
|
694
714
|
.ds-account__text,
|
|
@@ -719,6 +739,11 @@ button.ds-account {
|
|
|
719
739
|
visibility: visible;
|
|
720
740
|
}
|
|
721
741
|
|
|
742
|
+
/* recolhida: a contagem sai do fluxo, para o ícone não sair do lugar */
|
|
743
|
+
.ds-shell[data-sidebar="collapsed"] > .ds-sidebar .ds-nav-item__count {
|
|
744
|
+
position: absolute;
|
|
745
|
+
}
|
|
746
|
+
|
|
722
747
|
.ds-shell[data-sidebar="collapsed"] > .ds-sidebar .ds-nav-item > .ds-dot {
|
|
723
748
|
position: absolute;
|
|
724
749
|
top: 9px;
|
package/components/toast.css
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Toast — aviso curto e passageiro (ds/js/toast.js)
|
|
3
3
|
* tons: --success --warning --danger --info (neutro é o padrão)
|
|
4
4
|
* partes: __icon, __message, __action (opcional), __close (quando dura até fechar)
|
|
5
|
+
* com descrição (--stacked): __message guarda __title e __description, em duas linhas
|
|
5
6
|
* regiões: .ds-toast-region--{top|bottom}-{start|center|end}, uma por posição
|
|
6
7
|
* recuos ajustáveis: --ds-toast-offset-top (abaixo da topbar), --ds-toast-offset-bottom, --ds-toast-offset-inline
|
|
7
8
|
*/
|
|
@@ -105,6 +106,41 @@
|
|
|
105
106
|
white-space: nowrap;
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
/* Título e descrição: duas linhas, o ícone e os botões alinham com o título */
|
|
110
|
+
.ds-toast--stacked {
|
|
111
|
+
align-items: flex-start;
|
|
112
|
+
min-width: min(280px, 100%);
|
|
113
|
+
padding-block: var(--ds-space-150);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.ds-toast--stacked .ds-toast__message {
|
|
117
|
+
display: grid;
|
|
118
|
+
gap: 2px;
|
|
119
|
+
white-space: normal;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.ds-toast__title {
|
|
123
|
+
overflow: hidden;
|
|
124
|
+
text-overflow: ellipsis;
|
|
125
|
+
white-space: nowrap;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.ds-toast__description {
|
|
129
|
+
font: var(--ds-text-body-sm);
|
|
130
|
+
letter-spacing: var(--ds-text-body-sm-tracking);
|
|
131
|
+
opacity: 0.72;
|
|
132
|
+
overflow-wrap: anywhere;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* a primeira linha tem 20 px: ícone, ação e fechar descem para o meio dela */
|
|
136
|
+
.ds-toast--stacked .ds-toast__icon {
|
|
137
|
+
min-height: 20px;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.ds-toast--stacked :is(.ds-toast__action, .ds-toast__close) {
|
|
141
|
+
margin-block: -4px;
|
|
142
|
+
}
|
|
143
|
+
|
|
108
144
|
.ds-toast code {
|
|
109
145
|
font: var(--ds-text-code-sm);
|
|
110
146
|
}
|
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/menu.js
CHANGED
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
* });
|
|
22
22
|
*
|
|
23
23
|
* Itens especiais: { type: 'separator' }, { type: 'group', label } e { …, disabled: true }.
|
|
24
|
+
* meta: texto curto à direita do item, como uma contagem ({ value, label, meta: '37' }).
|
|
25
|
+
*
|
|
26
|
+
* label vira o título pequeno no topo e o nome do menu. Com hideLabel: true, o título some e o nome
|
|
27
|
+
* fica só para o leitor de tela (menus de ações de uma linha, que não precisam de título visível).
|
|
24
28
|
*
|
|
25
29
|
* Colunas — listas longas viram uma grade em vez de rolar: maxRows é o máximo de itens por coluna;
|
|
26
30
|
* passando disso, os itens seguem para a coluna do lado, equilibrados (16 itens com maxRows 5 → 4 × 4).
|
|
@@ -64,11 +68,12 @@ export function menuContent({ label, options = [], value, mode = 'radio', rows =
|
|
|
64
68
|
: o.shortcut
|
|
65
69
|
? `<span class="ds-menu__shortcut">${escape(o.shortcut)}</span>`
|
|
66
70
|
: '';
|
|
71
|
+
const meta = o.meta !== undefined && o.meta !== null && o.meta !== '' ? `<span class="ds-menu__meta">${escape(o.meta)}</span>` : '';
|
|
67
72
|
const cls = `ds-menu__item${o.tone === 'danger' ? ' ds-menu__item--danger' : ''}`;
|
|
68
73
|
const state = radio ? ` aria-checked="${o.value === value}"` : '';
|
|
69
74
|
const disabled = o.disabled ? ' aria-disabled="true"' : '';
|
|
70
75
|
return `<button type="button" class="${cls}" role="${radio ? 'menuitemradio' : 'menuitem'}" tabindex="-1"${state}${disabled} data-value="${escape(o.value)}">
|
|
71
|
-
${lead}<span class="ds-menu__text">${escape(o.label)}</span>${trail}
|
|
76
|
+
${lead}<span class="ds-menu__text">${escape(o.label)}</span>${meta}${trail}
|
|
72
77
|
</button>`;
|
|
73
78
|
})
|
|
74
79
|
.join('');
|
|
@@ -90,7 +95,7 @@ export function menuContent({ label, options = [], value, mode = 'radio', rows =
|
|
|
90
95
|
);
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
export function createMenu(trigger, { label, options = [], value, onChange, mode = 'radio', maxRows = 0, sectionColumns = false } = {}) {
|
|
98
|
+
export function createMenu(trigger, { label, hideLabel = false, options = [], value, onChange, mode = 'radio', maxRows = 0, sectionColumns = false } = {}) {
|
|
94
99
|
const id = `ds-menu-${++uid}`;
|
|
95
100
|
const menu = document.createElement('div');
|
|
96
101
|
menu.className = 'ds-menu';
|
|
@@ -110,7 +115,7 @@ export function createMenu(trigger, { label, options = [], value, onChange, mode
|
|
|
110
115
|
const items = () => [...menu.querySelectorAll('.ds-menu__item:not([aria-disabled="true"])')];
|
|
111
116
|
|
|
112
117
|
function render() {
|
|
113
|
-
menu.innerHTML = menuContent({ label, options, value: current, mode, rows, sectionColumns });
|
|
118
|
+
menu.innerHTML = menuContent({ label: hideLabel ? undefined : label, options, value: current, mode, rows, sectionColumns });
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
function position() {
|
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 };
|