@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/react/Form.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type FormHTMLAttributes } from 'react';
|
|
2
|
+
export type FormData = Record<string, string | File | Array<string | File>>;
|
|
3
|
+
export interface FormError {
|
|
4
|
+
name: string;
|
|
5
|
+
label: string;
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
export interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, 'onSubmit' | 'onInvalid'> {
|
|
9
|
+
/** Chamado só quando tudo está válido, com os valores pelo name de cada campo. */
|
|
10
|
+
onSubmit?: (data: FormData, form: HTMLFormElement) => void;
|
|
11
|
+
/** Chamado quando o envio parou por erro. */
|
|
12
|
+
onInvalid?: (errors: FormError[]) => void;
|
|
13
|
+
/** Regras próprias por name (ou id): devolva a mensagem de erro, ou null quando vale. Grupos recebem a lista dos marcados. */
|
|
14
|
+
rules?: Record<string, (value: string | string[], field: HTMLElement, form: HTMLFormElement) => string | null | undefined>;
|
|
15
|
+
/** Mensagens próprias por name e regra: { nome: { required: 'Dê um nome ao projeto.' } }. */
|
|
16
|
+
messages?: Record<string, Partial<Record<'required' | 'email' | 'url' | 'number' | 'minlength' | 'maxlength' | 'min' | 'max' | 'pattern' | 'groupMin', string>>>;
|
|
17
|
+
/** Quando valida. blur (padrão): ao sair do campo; submit: só ao enviar. Campo com erro revalida enquanto a pessoa corrige. */
|
|
18
|
+
validateOn?: 'blur' | 'submit' | 'input';
|
|
19
|
+
/** Resumo dos erros no topo, que recebe o foco no envio. Padrão: sim. */
|
|
20
|
+
summary?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface FormHandle {
|
|
23
|
+
/** Valida tudo e mostra os erros; devolve true se está tudo certo. */
|
|
24
|
+
validate(): boolean;
|
|
25
|
+
/** Limpa valores nativos, erros e o resumo. Os valores que estão no estado do React, limpe você. */
|
|
26
|
+
reset(): void;
|
|
27
|
+
data(): FormData;
|
|
28
|
+
errors(): FormError[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Formulário com a validação do Lume: required, email, minlength, regras próprias, erro ligado a cada campo
|
|
32
|
+
* e resumo no topo. Use o required e os tipos nativos nos campos; o resto é com o Lume.
|
|
33
|
+
* Valide pelo Form ou passe error nos campos, não os dois no mesmo campo.
|
|
34
|
+
* https://lumeui.dev/#/padroes/formularios
|
|
35
|
+
*/
|
|
36
|
+
export declare const Form: import("react").ForwardRefExoticComponent<FormProps & import("react").RefAttributes<FormHandle>>;
|
package/react/Form.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
4
|
+
import { createForm } from '../js/form.js';
|
|
5
|
+
import { useLatest } from './useController.js';
|
|
6
|
+
/**
|
|
7
|
+
* Formulário com a validação do Lume: required, email, minlength, regras próprias, erro ligado a cada campo
|
|
8
|
+
* e resumo no topo. Use o required e os tipos nativos nos campos; o resto é com o Lume.
|
|
9
|
+
* Valide pelo Form ou passe error nos campos, não os dois no mesmo campo.
|
|
10
|
+
* https://lumeui.dev/#/padroes/formularios
|
|
11
|
+
*/
|
|
12
|
+
export const Form = forwardRef(function Form({ onSubmit, onInvalid, rules, messages, validateOn, summary, children, ...rest }, ref) {
|
|
13
|
+
const form = useRef(null);
|
|
14
|
+
const api = useRef(null);
|
|
15
|
+
const submit = useLatest(onSubmit);
|
|
16
|
+
const invalid = useLatest(onInvalid);
|
|
17
|
+
const ruleFns = useLatest(rules);
|
|
18
|
+
const texts = useLatest(messages);
|
|
19
|
+
const ruleNames = Object.keys(rules ?? {}).join(',');
|
|
20
|
+
useImperativeHandle(ref, () => ({
|
|
21
|
+
validate: () => api.current?.validate() ?? false,
|
|
22
|
+
reset: () => api.current?.reset(),
|
|
23
|
+
data: () => api.current?.data() ?? {},
|
|
24
|
+
errors: () => api.current?.errors() ?? [],
|
|
25
|
+
}));
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const proxied = Object.fromEntries(ruleNames.split(',').filter(Boolean).map((name) => [name, (value, el, f) => ruleFns.current?.[name]?.(value, el, f) ?? null]));
|
|
28
|
+
const c = createForm(form.current, {
|
|
29
|
+
...(validateOn && { validateOn }),
|
|
30
|
+
...(summary !== undefined && { summary }),
|
|
31
|
+
rules: proxied,
|
|
32
|
+
// as mensagens são lidas na hora de validar: um objeto que sempre olha a versão mais nova
|
|
33
|
+
messages: new Proxy({}, { get: (_t, name) => texts.current?.[name] }),
|
|
34
|
+
onSubmit: (data, el) => submit.current?.(data, el),
|
|
35
|
+
onInvalid: (errors) => invalid.current?.(errors),
|
|
36
|
+
});
|
|
37
|
+
api.current = c;
|
|
38
|
+
return () => {
|
|
39
|
+
c.destroy();
|
|
40
|
+
api.current = null;
|
|
41
|
+
};
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
}, [validateOn, summary, ruleNames]);
|
|
44
|
+
return (_jsx("form", { ref: form, ...rest, children: children }));
|
|
45
|
+
});
|
package/react/Icon.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SVGAttributes } from 'react';
|
|
2
|
+
import type { IconName } from './icon-names.js';
|
|
3
|
+
export type { IconName };
|
|
4
|
+
export interface IconProps extends Omit<SVGAttributes<SVGSVGElement>, 'name'> {
|
|
5
|
+
/** Um dos 154 ícones do Lume. */
|
|
6
|
+
name: IconName;
|
|
7
|
+
/** Tamanho em px. Padrão: 20. Abaixo de 16 px o traço engrossa para 1,75. */
|
|
8
|
+
size?: number;
|
|
9
|
+
/** Texto para leitores de tela. Sem ele, o ícone é decorativo (aria-hidden). */
|
|
10
|
+
label?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Ícone do Lume. Herda a cor do texto. */
|
|
13
|
+
export declare function Icon({ name, size, label, className, ...rest }: IconProps): import("react").JSX.Element;
|
package/react/Icon.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { icons } from '../icons/icons.js';
|
|
4
|
+
import { cx } from './cx.js';
|
|
5
|
+
/** Ícone do Lume. Herda a cor do texto. */
|
|
6
|
+
export function Icon({ name, size = 20, label, className, ...rest }) {
|
|
7
|
+
return (_jsx("svg", { className: cx('ds-icon', className), width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: size <= 16 ? 1.75 : 1.5, strokeLinecap: "round", strokeLinejoin: "round", focusable: "false", role: label ? 'img' : undefined, "aria-label": label, "aria-hidden": label ? undefined : true, dangerouslySetInnerHTML: { __html: icons[name]?.body ?? '' }, ...rest }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import { type IconName } from './Icon.js';
|
|
3
|
+
export interface IconButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'children'> {
|
|
4
|
+
/** O ícone do botão. */
|
|
5
|
+
icon: IconName;
|
|
6
|
+
/** O nome da ação para leitores de tela ("Fechar", "Editar"). Obrigatório: o botão não tem texto. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Padrão: md (36 px). */
|
|
9
|
+
size?: 'sm' | 'md' | 'lg';
|
|
10
|
+
/** Padrão: sem fundo. subtle tem fundo leve; outline, contorno; muted, ícone apagado. */
|
|
11
|
+
look?: 'plain' | 'subtle' | 'outline' | 'muted';
|
|
12
|
+
/** Redondo. */
|
|
13
|
+
round?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Botão só com ícone, sem fundo até o hover.
|
|
17
|
+
* https://lumeui.dev/#/componentes/botao
|
|
18
|
+
*/
|
|
19
|
+
export declare const IconButton: import("react").ForwardRefExoticComponent<IconButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { Icon } from './Icon.js';
|
|
5
|
+
import { cx } from './cx.js';
|
|
6
|
+
/**
|
|
7
|
+
* Botão só com ícone, sem fundo até o hover.
|
|
8
|
+
* https://lumeui.dev/#/componentes/botao
|
|
9
|
+
*/
|
|
10
|
+
export const IconButton = forwardRef(function IconButton({ icon, label, size = 'md', look = 'plain', round, className, type = 'button', ...rest }, ref) {
|
|
11
|
+
return (_jsx("button", { ref: ref, type: type, "aria-label": label, className: cx('ds-icon-btn', size !== 'md' && `ds-icon-btn--${size}`, look !== 'plain' && `ds-icon-btn--${look}`, round && 'ds-icon-btn--round', className), ...rest, children: _jsx(Icon, { name: icon, size: size === 'sm' ? 16 : 20 }) }));
|
|
12
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type HTMLAttributes } from 'react';
|
|
2
|
+
import { openImageViewer, type ViewerImage } from '../js/image-viewer.js';
|
|
3
|
+
export { openImageViewer, type ViewerImage };
|
|
4
|
+
export interface GalleryImage extends ViewerImage {
|
|
5
|
+
/** A miniatura que fica na página. Sem ela, a própria imagem grande. */
|
|
6
|
+
thumb?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ImageGalleryProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
9
|
+
images: GalleryImage[];
|
|
10
|
+
/** Chamado com o índice da imagem a cada troca dentro do visualizador. */
|
|
11
|
+
onChange?: (index: number) => void;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Miniaturas que abrem o visualizador de imagem, com zoom, arrastar e a galeria inteira.
|
|
16
|
+
* <ImageGallery className="grade" images={[{ src: 'inicio.jpg', thumb: 'inicio-mini.jpg', alt: 'A página inicial do Lume', caption: 'Início' }]} />
|
|
17
|
+
* Para abrir de outro lugar: openImageViewer(imagens, { index: 1 }).
|
|
18
|
+
* https://lumeui.dev/#/componentes/visualizador-de-imagem
|
|
19
|
+
*/
|
|
20
|
+
export declare function ImageGallery({ images, onChange, onClose, className, ...rest }: ImageGalleryProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { openImageViewer } from '../js/image-viewer.js';
|
|
5
|
+
export { openImageViewer };
|
|
6
|
+
/**
|
|
7
|
+
* Miniaturas que abrem o visualizador de imagem, com zoom, arrastar e a galeria inteira.
|
|
8
|
+
* <ImageGallery className="grade" images={[{ src: 'inicio.jpg', thumb: 'inicio-mini.jpg', alt: 'A página inicial do Lume', caption: 'Início' }]} />
|
|
9
|
+
* Para abrir de outro lugar: openImageViewer(imagens, { index: 1 }).
|
|
10
|
+
* https://lumeui.dev/#/componentes/visualizador-de-imagem
|
|
11
|
+
*/
|
|
12
|
+
export function ImageGallery({ images, onChange, onClose, className, ...rest }) {
|
|
13
|
+
const viewer = useRef(null);
|
|
14
|
+
useEffect(() => () => viewer.current?.close(), []);
|
|
15
|
+
const open = (event, index) => {
|
|
16
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey || event.button)
|
|
17
|
+
return;
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
viewer.current = openImageViewer(images.map(({ thumb: _thumb, ...image }) => image), { index, onChange, onClose: () => { viewer.current = null; onClose?.(); } });
|
|
20
|
+
};
|
|
21
|
+
return (_jsx("div", { className: className, ...rest, children: images.map((image, i) => (_jsx("a", { className: "ds-viewer-thumb", href: image.src, "data-caption": image.caption, onClick: (event) => open(event, i), children: _jsx("img", { src: image.thumb ?? image.src, alt: image.alt ?? '', loading: "lazy" }) }, image.src + i))) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import { type IconName } from './Icon.js';
|
|
3
|
+
export interface InlineActionProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
4
|
+
/** Ícone antes do texto. */
|
|
5
|
+
icon?: IconName;
|
|
6
|
+
/** Mostra o + depois do texto, para ações que adicionam algo ("Na cena +"). */
|
|
7
|
+
plus?: boolean;
|
|
8
|
+
/** Texto mais forte, para a ação principal de um grupo. */
|
|
9
|
+
strong?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Ação mínima dentro do texto ou de um painel: "Adicionar nota +".
|
|
13
|
+
* https://lumeui.dev/#/componentes/acao-inline
|
|
14
|
+
*/
|
|
15
|
+
export declare const InlineAction: import("react").ForwardRefExoticComponent<InlineActionProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { Icon } from './Icon.js';
|
|
5
|
+
import { cx } from './cx.js';
|
|
6
|
+
/**
|
|
7
|
+
* Ação mínima dentro do texto ou de um painel: "Adicionar nota +".
|
|
8
|
+
* https://lumeui.dev/#/componentes/acao-inline
|
|
9
|
+
*/
|
|
10
|
+
export const InlineAction = forwardRef(function InlineAction({ icon, plus, strong, className, type = 'button', children, ...rest }, ref) {
|
|
11
|
+
return (_jsxs("button", { ref: ref, type: type, className: cx('ds-inline-action', strong && 'ds-inline-action--strong', className), ...rest, children: [icon && _jsx(Icon, { name: icon, size: 16 }), children, plus && _jsx(Icon, { name: "plus", size: 14, className: "ds-inline-action__plus" })] }));
|
|
12
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode, type RefObject } from 'react';
|
|
2
|
+
import { type IconName } from './Icon.js';
|
|
3
|
+
import type { ButtonVariant } from './Button.js';
|
|
4
|
+
import type { MenuOption } from './Navigation.js';
|
|
5
|
+
export interface DialogAction {
|
|
6
|
+
label: string;
|
|
7
|
+
/** O valor que onClose recebe quando a pessoa escolhe esta ação. */
|
|
8
|
+
value: string;
|
|
9
|
+
variant?: ButtonVariant;
|
|
10
|
+
icon?: IconName;
|
|
11
|
+
/** Recebe o foco ao abrir. */
|
|
12
|
+
autofocus?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface DialogBase {
|
|
15
|
+
/** Aberto ou fechado: o estado é seu. */
|
|
16
|
+
open: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Chamado quando o diálogo fecha por dentro: uma ação (com o value dela), o ×, Esc ou clique fora (undefined).
|
|
19
|
+
* Ponha open em false aqui.
|
|
20
|
+
*/
|
|
21
|
+
onClose: (value?: string) => void;
|
|
22
|
+
title: ReactNode;
|
|
23
|
+
eyebrow?: ReactNode;
|
|
24
|
+
/** O conteúdo. */
|
|
25
|
+
children?: ReactNode;
|
|
26
|
+
/** Botões do rodapé, do menos ao mais importante; fecham com o valor deles. */
|
|
27
|
+
actions?: DialogAction[];
|
|
28
|
+
/** Rodapé próprio, no lugar de actions. Um botão com data-ds-modal-close="valor" fecha com esse valor. */
|
|
29
|
+
footer?: ReactNode;
|
|
30
|
+
/** Padrão: true. Sem ele, só as ações fecham (sem ×, Esc nem clique fora). */
|
|
31
|
+
dismissible?: boolean;
|
|
32
|
+
className?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ModalProps extends DialogBase {
|
|
35
|
+
/** sm 400 · md 520 (padrão) · lg 720. */
|
|
36
|
+
size?: 'sm' | 'md' | 'lg';
|
|
37
|
+
/** danger: para ações que destroem; já traz o ícone de alerta. */
|
|
38
|
+
tone?: 'danger';
|
|
39
|
+
/** Ícone ao lado do título. */
|
|
40
|
+
icon?: IconName;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Decisão ou tarefa curta que interrompe o fluxo, sobre <dialog>: foco preso, Esc, clique fora e o foco volta ao gatilho.
|
|
44
|
+
* <Modal open={aberto} onClose={(v) => { setAberto(false); if (v === 'publicar') publicar(); }}
|
|
45
|
+
* title="Publicar alterações?" actions={[{ label: 'Cancelar', value: 'cancel' }, { label: 'Publicar', value: 'publicar', variant: 'primary' }]} />
|
|
46
|
+
* https://lumeui.dev/#/componentes/modal
|
|
47
|
+
*/
|
|
48
|
+
export declare function Modal({ size, tone, icon, className, ...rest }: ModalProps): import("react").JSX.Element;
|
|
49
|
+
export interface DrawerProps extends DialogBase {
|
|
50
|
+
/** Padrão: right. */
|
|
51
|
+
side?: 'right' | 'left' | 'bottom';
|
|
52
|
+
/** sm 360 · md 480 (padrão) · lg 640. */
|
|
53
|
+
size?: 'sm' | 'md' | 'lg';
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Detalhes ou uma tarefa sem sair da página: um Modal que entra pela borda.
|
|
57
|
+
* https://lumeui.dev/#/componentes/gaveta-lateral
|
|
58
|
+
*/
|
|
59
|
+
export declare function Drawer({ side, size, className, ...rest }: DrawerProps): import("react").JSX.Element;
|
|
60
|
+
export interface PopoverProps {
|
|
61
|
+
/** O botão que abre (useRef no gatilho). */
|
|
62
|
+
triggerRef: RefObject<HTMLElement | null>;
|
|
63
|
+
/** O conteúdo, em React. */
|
|
64
|
+
children: ReactNode;
|
|
65
|
+
/** Dá nome ao painel e mostra o ×. */
|
|
66
|
+
title?: string;
|
|
67
|
+
/** Nome para leitores de tela, quando não há título. */
|
|
68
|
+
label?: string;
|
|
69
|
+
placement?: 'bottom' | 'top' | 'right' | 'left';
|
|
70
|
+
align?: 'start' | 'center' | 'end';
|
|
71
|
+
onOpenChange?: (open: boolean) => void;
|
|
72
|
+
className?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Conteúdo livre preso ao gatilho, sem bloquear a tela. Abre ao clicar; Esc e clique fora fecham.
|
|
76
|
+
* https://lumeui.dev/#/componentes/popover
|
|
77
|
+
*/
|
|
78
|
+
export declare function Popover({ triggerRef, children, title, label, placement, align, onOpenChange, className }: PopoverProps): import("react").ReactPortal | null;
|
|
79
|
+
export interface ContextMenuProps {
|
|
80
|
+
/** A área que tem o menu (useRef). */
|
|
81
|
+
targetRef: RefObject<HTMLElement | null>;
|
|
82
|
+
/** Só nestes elementos dentro da área ('[data-arquivo]'); sem ele, vale a área inteira. */
|
|
83
|
+
selector?: string;
|
|
84
|
+
/** Lista fixa, ou função que recebe o item clicado. */
|
|
85
|
+
options: MenuOption[] | ((target: HTMLElement) => MenuOption[]);
|
|
86
|
+
onSelect: (value: string, target: HTMLElement) => void;
|
|
87
|
+
/** Nome para leitores de tela. */
|
|
88
|
+
label?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Ações de um item com o botão direito, Shift+F10 ou toque longo. Ofereça as mesmas ações em outro lugar.
|
|
92
|
+
* https://lumeui.dev/#/componentes/menu-de-contexto
|
|
93
|
+
*/
|
|
94
|
+
export declare function ContextMenu({ targetRef, selector, options, onSelect, label }: ContextMenuProps): null;
|
|
95
|
+
export interface TooltipProps {
|
|
96
|
+
/** O texto da dica: curto, sem formatação. */
|
|
97
|
+
content: string;
|
|
98
|
+
placement?: 'top' | 'right' | 'bottom' | 'left';
|
|
99
|
+
/** Atalho mostrado ao lado ("⌘B"). */
|
|
100
|
+
kbd?: string;
|
|
101
|
+
/** Um elemento só, que recebe hover e foco (um botão). */
|
|
102
|
+
children: ReactElement<Record<string, unknown>>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Dica curta em hover e foco. Num botão só de ícone, repita o texto no aria-label.
|
|
106
|
+
* https://lumeui.dev/#/componentes/tooltip
|
|
107
|
+
*/
|
|
108
|
+
export declare function Tooltip({ content, placement, kbd, children }: TooltipProps): ReactElement<Record<string, unknown>, string | import("react").JSXElementConstructor<any>>;
|
|
109
|
+
/** Liga os tooltips de data-ds-tooltip na página inteira (o Tooltip já chama sozinho). */
|
|
110
|
+
export declare function useTooltips(): void;
|
|
111
|
+
/** Estado aberto/fechado com as funções prontas, para Modal e Drawer: const m = useDisclosure(); <Modal open={m.open} onClose={m.close} />. */
|
|
112
|
+
export declare function useDisclosure(initial?: boolean): {
|
|
113
|
+
open: boolean;
|
|
114
|
+
show: () => void;
|
|
115
|
+
close: () => void;
|
|
116
|
+
toggle: () => void;
|
|
117
|
+
};
|
|
118
|
+
export {};
|
package/react/Layers.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cloneElement, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { enhanceModal } from '../js/modal.js';
|
|
6
|
+
import { createPopover } from '../js/popover.js';
|
|
7
|
+
import { createContextMenu } from '../js/context-menu.js';
|
|
8
|
+
import { initTooltips } from '../js/tooltip.js';
|
|
9
|
+
import { msg } from '../js/i18n.js';
|
|
10
|
+
import { Icon } from './Icon.js';
|
|
11
|
+
import { useLocale } from './useLocale.js';
|
|
12
|
+
import { useLatest, stableKey, defined, useSafeId } from './useController.js';
|
|
13
|
+
import { cx } from './cx.js';
|
|
14
|
+
function DialogShell({ open, onClose, title, eyebrow, children, actions = [], footer, dismissible = true, className, lead, }) {
|
|
15
|
+
useLocale();
|
|
16
|
+
const id = useSafeId('dlg');
|
|
17
|
+
const dialog = useRef(null);
|
|
18
|
+
const api = useRef(null);
|
|
19
|
+
const closed = useLatest(onClose);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const c = enhanceModal(dialog.current, { dismissible, onClose: (v) => closed.current(v) });
|
|
22
|
+
api.current = c;
|
|
23
|
+
return () => {
|
|
24
|
+
c.destroy();
|
|
25
|
+
api.current = null;
|
|
26
|
+
};
|
|
27
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
+
}, [dismissible]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!api.current)
|
|
31
|
+
return;
|
|
32
|
+
if (open && !api.current.isOpen)
|
|
33
|
+
api.current.open();
|
|
34
|
+
if (!open && api.current.isOpen)
|
|
35
|
+
api.current.close();
|
|
36
|
+
}, [open, dismissible]);
|
|
37
|
+
return (_jsxs("dialog", { ref: dialog, className: className, "aria-labelledby": `${id}-title`, "aria-describedby": children ? `${id}-body` : undefined, children: [_jsxs("header", { className: "ds-modal__header", children: [lead && _jsx("span", { className: "ds-modal__icon", children: _jsx(Icon, { name: lead, size: 20 }) }), _jsxs("div", { className: "ds-modal__heading", children: [eyebrow && _jsx("p", { className: "ds-modal__eyebrow", children: eyebrow }), _jsx("h2", { className: "ds-modal__title", id: `${id}-title`, children: title })] }), dismissible && (_jsx("button", { type: "button", className: "ds-icon-btn ds-icon-btn--muted ds-modal__close", "data-ds-modal-close": "", "aria-label": msg('common.close'), children: _jsx(Icon, { name: "x", size: 20 }) }))] }), children && _jsx("div", { className: "ds-modal__body", id: `${id}-body`, children: children }), footer ? (_jsx("footer", { className: "ds-modal__footer", children: footer })) : actions.length > 0 ? (_jsx("footer", { className: "ds-modal__footer", children: actions.map((a) => (_jsxs("button", { type: "button", className: `ds-btn ds-btn--${a.variant ?? 'secondary'}`, "data-ds-modal-close": a.value, "data-ds-autofocus": a.autofocus ? '' : undefined, children: [a.icon && _jsx(Icon, { name: a.icon, size: 18 }), a.label] }, a.value))) })) : null] }));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Decisão ou tarefa curta que interrompe o fluxo, sobre <dialog>: foco preso, Esc, clique fora e o foco volta ao gatilho.
|
|
41
|
+
* <Modal open={aberto} onClose={(v) => { setAberto(false); if (v === 'publicar') publicar(); }}
|
|
42
|
+
* title="Publicar alterações?" actions={[{ label: 'Cancelar', value: 'cancel' }, { label: 'Publicar', value: 'publicar', variant: 'primary' }]} />
|
|
43
|
+
* https://lumeui.dev/#/componentes/modal
|
|
44
|
+
*/
|
|
45
|
+
export function Modal({ size = 'md', tone, icon, className, ...rest }) {
|
|
46
|
+
return (_jsx(DialogShell, { ...rest, lead: icon ?? (tone === 'danger' ? 'alert-triangle' : null), className: cx('ds-modal', size !== 'md' && `ds-modal--${size}`, tone && `ds-modal--${tone}`, className) }));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Detalhes ou uma tarefa sem sair da página: um Modal que entra pela borda.
|
|
50
|
+
* https://lumeui.dev/#/componentes/gaveta-lateral
|
|
51
|
+
*/
|
|
52
|
+
export function Drawer({ side = 'right', size = 'md', className, ...rest }) {
|
|
53
|
+
return _jsx(DialogShell, { ...rest, className: cx('ds-modal', 'ds-drawer', `ds-drawer--${side}`, size !== 'md' && `ds-drawer--${size}`, className) });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Conteúdo livre preso ao gatilho, sem bloquear a tela. Abre ao clicar; Esc e clique fora fecham.
|
|
57
|
+
* https://lumeui.dev/#/componentes/popover
|
|
58
|
+
*/
|
|
59
|
+
export function Popover({ triggerRef, children, title, label, placement, align, onOpenChange, className }) {
|
|
60
|
+
const locale = useLocale();
|
|
61
|
+
const host = useMemo(() => (typeof document === 'undefined' ? null : document.createElement('div')), []);
|
|
62
|
+
const change = useLatest(onOpenChange);
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!triggerRef.current || !host)
|
|
65
|
+
return;
|
|
66
|
+
const c = createPopover(triggerRef.current, defined({
|
|
67
|
+
title, label, placement, align, className, content: host,
|
|
68
|
+
onOpen: () => change.current?.(true),
|
|
69
|
+
onClose: () => change.current?.(false),
|
|
70
|
+
}));
|
|
71
|
+
return () => c.destroy();
|
|
72
|
+
}, [triggerRef, host, title, label, placement, align, className, locale]);
|
|
73
|
+
return host ? createPortal(children, host) : null;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Ações de um item com o botão direito, Shift+F10 ou toque longo. Ofereça as mesmas ações em outro lugar.
|
|
77
|
+
* https://lumeui.dev/#/componentes/menu-de-contexto
|
|
78
|
+
*/
|
|
79
|
+
export function ContextMenu({ targetRef, selector, options, onSelect, label }) {
|
|
80
|
+
const select = useLatest(onSelect);
|
|
81
|
+
const list = useLatest(options);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!targetRef.current)
|
|
84
|
+
return;
|
|
85
|
+
const c = createContextMenu(targetRef.current, defined({
|
|
86
|
+
selector, label,
|
|
87
|
+
options: (target) => (typeof list.current === 'function' ? list.current(target) : list.current),
|
|
88
|
+
onSelect: (v, t) => select.current(v, t),
|
|
89
|
+
}));
|
|
90
|
+
return () => c.destroy();
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
|
+
}, [targetRef, selector, label, typeof options === 'function' ? 'fn' : stableKey(options)]);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Dica curta em hover e foco. Num botão só de ícone, repita o texto no aria-label.
|
|
97
|
+
* https://lumeui.dev/#/componentes/tooltip
|
|
98
|
+
*/
|
|
99
|
+
export function Tooltip({ content, placement, kbd, children }) {
|
|
100
|
+
useEffect(() => initTooltips(), []);
|
|
101
|
+
return cloneElement(children, {
|
|
102
|
+
'data-ds-tooltip': content,
|
|
103
|
+
'data-ds-tooltip-placement': placement,
|
|
104
|
+
'data-ds-tooltip-kbd': kbd,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** Liga os tooltips de data-ds-tooltip na página inteira (o Tooltip já chama sozinho). */
|
|
108
|
+
export function useTooltips() {
|
|
109
|
+
useEffect(() => initTooltips(), []);
|
|
110
|
+
}
|
|
111
|
+
/** Estado aberto/fechado com as funções prontas, para Modal e Drawer: const m = useDisclosure(); <Modal open={m.open} onClose={m.close} />. */
|
|
112
|
+
export function useDisclosure(initial = false) {
|
|
113
|
+
const [open, setOpen] = useState(initial);
|
|
114
|
+
return useMemo(() => ({ open, show: () => setOpen(true), close: () => setOpen(false), toggle: () => setOpen((o) => !o) }), [open]);
|
|
115
|
+
}
|
package/react/Link.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AnchorHTMLAttributes, type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
3
|
+
/** inline (padrão): sublinhado, no meio do texto. standalone: solto, no fim de um card ou lista, com seta. */
|
|
4
|
+
variant?: 'inline' | 'standalone';
|
|
5
|
+
/** Apagado, para rodapés e metadados. */
|
|
6
|
+
muted?: boolean;
|
|
7
|
+
/** Sai do site: abre em nova aba, com o ícone de link externo e o aviso para o leitor de tela. */
|
|
8
|
+
external?: boolean;
|
|
9
|
+
/** Sem destino: fica apagado e não navega. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Link do Lume. Para ir a algum lugar; para fazer algo, use Button.
|
|
15
|
+
* <Link href="/cores">cores</Link> · <Link variant="standalone" href="/novidades">Ver todas as versões</Link>
|
|
16
|
+
* https://lumeui.dev/#/componentes/link
|
|
17
|
+
*/
|
|
18
|
+
export declare function Link({ variant, muted, external, disabled, href, className, children, ...rest }: LinkProps): import("react").JSX.Element;
|
|
19
|
+
export interface DividerProps extends HTMLAttributes<HTMLElement> {
|
|
20
|
+
/** Na vertical, entre itens de uma linha (o contêiner precisa ser flex). */
|
|
21
|
+
vertical?: boolean;
|
|
22
|
+
/** Texto no meio da linha (“ou”), ou no começo com labelPosition="start". */
|
|
23
|
+
label?: ReactNode;
|
|
24
|
+
labelPosition?: 'center' | 'start';
|
|
25
|
+
/** Some nas pontas, como o divisor da sidebar. */
|
|
26
|
+
fade?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Linha fina entre blocos. Sem margem: o espaço vem do gap de quem o contém.
|
|
30
|
+
* https://lumeui.dev/#/componentes/divisor
|
|
31
|
+
*/
|
|
32
|
+
export declare function Divider({ vertical, label, labelPosition, fade, className, ...rest }: DividerProps): import("react").JSX.Element;
|
package/react/Link.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Icon } from './Icon.js';
|
|
4
|
+
import { msg } from '../js/i18n.js';
|
|
5
|
+
import { useLocale } from './useLocale.js';
|
|
6
|
+
import { cx } from './cx.js';
|
|
7
|
+
/**
|
|
8
|
+
* Link do Lume. Para ir a algum lugar; para fazer algo, use Button.
|
|
9
|
+
* <Link href="/cores">cores</Link> · <Link variant="standalone" href="/novidades">Ver todas as versões</Link>
|
|
10
|
+
* https://lumeui.dev/#/componentes/link
|
|
11
|
+
*/
|
|
12
|
+
export function Link({ variant = 'inline', muted, external, disabled, href, className, children, ...rest }) {
|
|
13
|
+
useLocale();
|
|
14
|
+
return (_jsxs("a", { className: cx('ds-link', variant === 'standalone' && 'ds-link--standalone', muted && 'ds-link--muted', className), href: disabled ? undefined : href, "aria-disabled": disabled || undefined, ...(external && !disabled ? { target: '_blank', rel: 'noopener noreferrer' } : {}), ...rest, children: [children, external ? (_jsxs(_Fragment, { children: [_jsx(Icon, { name: "external-link", size: 16, className: "ds-link__icon" }), _jsx("span", { className: "ds-visually-hidden", children: msg('link.external') })] })) : (variant === 'standalone' && _jsx(Icon, { name: "arrow-right", size: 16, className: "ds-link__icon", "data-arrow": "" }))] }));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Linha fina entre blocos. Sem margem: o espaço vem do gap de quem o contém.
|
|
18
|
+
* https://lumeui.dev/#/componentes/divisor
|
|
19
|
+
*/
|
|
20
|
+
export function Divider({ vertical, label, labelPosition = 'center', fade, className, ...rest }) {
|
|
21
|
+
if (label != null)
|
|
22
|
+
return (_jsx("div", { className: cx('ds-divider', 'ds-divider--label', labelPosition === 'start' && 'ds-divider--start', className), ...rest, children: _jsx("span", { children: label }) }));
|
|
23
|
+
if (vertical)
|
|
24
|
+
return _jsx("span", { className: cx('ds-divider', 'ds-divider--vertical', className), role: "separator", "aria-orientation": "vertical", ...rest });
|
|
25
|
+
return _jsx("hr", { className: cx('ds-divider', fade && 'ds-divider--fade', className), ...rest });
|
|
26
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface ProgressProps extends Omit<HTMLAttributes<HTMLProgressElement>, 'children'> {
|
|
3
|
+
/** De 0 a max. Sem valor, a barra fica indeterminada (em movimento). */
|
|
4
|
+
value?: number;
|
|
5
|
+
/** Padrão: 100. */
|
|
6
|
+
max?: number;
|
|
7
|
+
/** Tom do resultado: success no fim, danger no erro, warning perto do limite. */
|
|
8
|
+
tone?: 'brand' | 'success' | 'warning' | 'danger';
|
|
9
|
+
/** Mais grossa (8 px). */
|
|
10
|
+
large?: boolean;
|
|
11
|
+
/** O que está carregando. Com rótulo, mostra a linha de cima com o nome e a porcentagem. */
|
|
12
|
+
label?: ReactNode;
|
|
13
|
+
/** Mostra a porcentagem ao lado do rótulo. Padrão: sim, quando há valor. */
|
|
14
|
+
showValue?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Barra de progresso. Com label, vira o campo completo (nome em cima, porcentagem à direita).
|
|
18
|
+
* https://lumeui.dev/#/componentes/barra-de-progresso
|
|
19
|
+
*/
|
|
20
|
+
export declare function Progress({ value, max, tone, large, label, showValue, className, ...rest }: ProgressProps): import("react").JSX.Element;
|
|
21
|
+
export interface ProgressRingProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
22
|
+
/** De 0 a max. Sem valor, o arco gira: indeterminado. */
|
|
23
|
+
value?: number;
|
|
24
|
+
/** Padrão: 100. */
|
|
25
|
+
max?: number;
|
|
26
|
+
/** sm (20 px, sem número) · md (56, padrão) · lg (80). */
|
|
27
|
+
size?: 'sm' | 'md' | 'lg';
|
|
28
|
+
/** Tom do resultado, como na barra. */
|
|
29
|
+
tone?: 'brand' | 'success' | 'warning' | 'danger';
|
|
30
|
+
/** O que está progredindo, para o leitor de tela. Padrão: "Progresso", no idioma do Lume. */
|
|
31
|
+
label?: string;
|
|
32
|
+
/** Mostra a porcentagem no meio (md e lg). Padrão: sim. */
|
|
33
|
+
showValue?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Progresso circular: o anel da barra, para quando a barra não cabe.
|
|
37
|
+
* https://lumeui.dev/#/componentes/progresso-circular
|
|
38
|
+
*/
|
|
39
|
+
export declare function ProgressRing({ value, max, size, tone, label, showValue, className, style, ...rest }: ProgressRingProps): import("react").JSX.Element;
|
|
40
|
+
export interface SpinnerProps extends HTMLAttributes<HTMLSpanElement> {
|
|
41
|
+
/** Padrão: md (24 px). sm (16) dentro de botões. */
|
|
42
|
+
size?: 'sm' | 'md' | 'lg';
|
|
43
|
+
/** O que está carregando, para leitores de tela. Padrão: "Carregando", no idioma do Lume. */
|
|
44
|
+
label?: string;
|
|
45
|
+
/** Dentro de algo que já se anuncia (um botão com aria-busy): esconde do leitor de tela. */
|
|
46
|
+
decorative?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Indicador de espera curta. Para conteúdo que vai aparecer no lugar, prefira o Skeleton.
|
|
50
|
+
* https://lumeui.dev/#/componentes/spinner
|
|
51
|
+
*/
|
|
52
|
+
export declare function Spinner({ size, label, decorative, className, ...rest }: SpinnerProps): import("react").JSX.Element;
|
|
53
|
+
export interface SkeletonProps extends HTMLAttributes<HTMLSpanElement> {
|
|
54
|
+
/** block (padrão): um bloco de 64 px de altura; text: uma linha de texto; circle: avatar. */
|
|
55
|
+
shape?: 'block' | 'text' | 'circle';
|
|
56
|
+
/** Largura ("60%", "120px"). Padrão: a largura toda. */
|
|
57
|
+
width?: string;
|
|
58
|
+
/** Altura de um bloco ("120px"). */
|
|
59
|
+
height?: string;
|
|
60
|
+
/** Diâmetro de um círculo ("32px"). Padrão: 40 px. */
|
|
61
|
+
size?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Forma apagada no lugar do conteúdo que está chegando. Ponha o grupo dentro de algo com aria-busy="true".
|
|
65
|
+
* https://lumeui.dev/#/componentes/skeleton
|
|
66
|
+
*/
|
|
67
|
+
export declare function Skeleton({ shape, width, height, size, className, style, ...rest }: SkeletonProps): import("react").JSX.Element;
|
package/react/Loading.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { formatNumber, msg } from '../js/i18n.js';
|
|
4
|
+
import { useLocale } from './useLocale.js';
|
|
5
|
+
import { useSafeId } from './useController.js';
|
|
6
|
+
import { cx } from './cx.js';
|
|
7
|
+
/**
|
|
8
|
+
* Barra de progresso. Com label, vira o campo completo (nome em cima, porcentagem à direita).
|
|
9
|
+
* https://lumeui.dev/#/componentes/barra-de-progresso
|
|
10
|
+
*/
|
|
11
|
+
export function Progress({ value, max = 100, tone = 'brand', large, label, showValue = true, className, ...rest }) {
|
|
12
|
+
const id = useSafeId('pg');
|
|
13
|
+
const bar = (_jsx("progress", { className: cx('ds-progress', tone !== 'brand' && `ds-progress--${tone}`, large && 'ds-progress--lg', !label && className), value: value, max: max, "aria-labelledby": label ? id : undefined, ...rest }));
|
|
14
|
+
if (!label)
|
|
15
|
+
return bar;
|
|
16
|
+
return (_jsxs("div", { className: cx('ds-progress-field', className), children: [_jsxs("div", { className: "ds-progress-field__head", children: [_jsx("span", { id: id, children: label }), showValue && value !== undefined && (_jsx("span", { className: "ds-progress-field__value", children: formatNumber(value / max, { style: 'percent' }) }))] }), bar] }));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Progresso circular: o anel da barra, para quando a barra não cabe.
|
|
20
|
+
* https://lumeui.dev/#/componentes/progresso-circular
|
|
21
|
+
*/
|
|
22
|
+
export function ProgressRing({ value, max = 100, size = 'md', tone = 'brand', label, showValue = true, className, style, ...rest }) {
|
|
23
|
+
useLocale();
|
|
24
|
+
const on = value !== undefined && value !== null;
|
|
25
|
+
const v = on ? Math.max(0, Math.min(max, value)) : 0;
|
|
26
|
+
return (_jsxs("div", { className: cx('ds-progress-ring', size !== 'md' && `ds-progress-ring--${size}`, tone !== 'brand' && `ds-progress-ring--${tone}`, className), role: "progressbar", "aria-label": label ?? msg('progress.label'), ...(on ? { 'aria-valuemin': 0, 'aria-valuemax': max, 'aria-valuenow': v } : {}), style: { ...(on ? { '--ds-progress-value': (v / max) * 100 } : {}), ...style }, ...rest, children: [_jsxs("svg", { viewBox: "0 0 40 40", "aria-hidden": "true", focusable: "false", children: [_jsx("circle", { className: "ds-progress-ring__track", cx: "20", cy: "20", r: "18" }), _jsx("circle", { className: "ds-progress-ring__bar", cx: "20", cy: "20", r: "18", pathLength: 100 })] }), on && showValue && size !== 'sm' && (_jsx("span", { className: "ds-progress-ring__value", "aria-hidden": "true", children: formatNumber(v / max, { style: 'percent', maximumFractionDigits: 0 }) }))] }));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Indicador de espera curta. Para conteúdo que vai aparecer no lugar, prefira o Skeleton.
|
|
30
|
+
* https://lumeui.dev/#/componentes/spinner
|
|
31
|
+
*/
|
|
32
|
+
export function Spinner({ size = 'md', label, decorative, className, ...rest }) {
|
|
33
|
+
useLocale();
|
|
34
|
+
return (_jsx("span", { className: cx('ds-spinner', size !== 'md' && `ds-spinner--${size}`, className), ...(decorative ? { 'aria-hidden': true } : { role: 'status', 'aria-label': label ?? msg('common.loading') }), ...rest }));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Forma apagada no lugar do conteúdo que está chegando. Ponha o grupo dentro de algo com aria-busy="true".
|
|
38
|
+
* https://lumeui.dev/#/componentes/skeleton
|
|
39
|
+
*/
|
|
40
|
+
export function Skeleton({ shape = 'block', width, height, size, className, style, ...rest }) {
|
|
41
|
+
const vars = {};
|
|
42
|
+
if (width)
|
|
43
|
+
vars['--w'] = width;
|
|
44
|
+
if (height)
|
|
45
|
+
vars['--h'] = height;
|
|
46
|
+
if (size)
|
|
47
|
+
vars['--s'] = size;
|
|
48
|
+
return (_jsx("span", { "aria-hidden": "true", className: cx('ds-skeleton', shape !== 'block' && `ds-skeleton--${shape}`, className), style: { ...vars, ...style }, ...rest }));
|
|
49
|
+
}
|