@joniguerini/lume 0.0.0-stage → 1.9.1

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.
Files changed (226) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +62 -2
  3. package/base.css +165 -0
  4. package/bin/lumeui.mjs +163 -0
  5. package/components/alert.css +156 -0
  6. package/components/banner.css +98 -0
  7. package/components/button.css +291 -0
  8. package/components/calendar.css +532 -0
  9. package/components/carousel.css +175 -0
  10. package/components/chart.css +813 -0
  11. package/components/chat.css +670 -0
  12. package/components/checkbox.css +212 -0
  13. package/components/chip.css +224 -0
  14. package/components/code.css +36 -0
  15. package/components/color-picker.css +192 -0
  16. package/components/command.css +148 -0
  17. package/components/content.css +211 -0
  18. package/components/editor.css +174 -0
  19. package/components/feedback.css +320 -0
  20. package/components/filters.css +103 -0
  21. package/components/form.css +455 -0
  22. package/components/image-viewer.css +237 -0
  23. package/components/layers.css +138 -0
  24. package/components/link.css +87 -0
  25. package/components/loading.css +260 -0
  26. package/components/menu.css +180 -0
  27. package/components/modal.css +209 -0
  28. package/components/navigation.css +507 -0
  29. package/components/notifications.css +186 -0
  30. package/components/number-field.css +52 -0
  31. package/components/otp.css +119 -0
  32. package/components/panel.css +208 -0
  33. package/components/picker.css +207 -0
  34. package/components/rating.css +143 -0
  35. package/components/resizable.css +173 -0
  36. package/components/scrollbar.css +110 -0
  37. package/components/select.css +477 -0
  38. package/components/shell.css +837 -0
  39. package/components/slider.css +189 -0
  40. package/components/sortable.css +287 -0
  41. package/components/surfaces.css +182 -0
  42. package/components/switch.css +115 -0
  43. package/components/table.css +228 -0
  44. package/components/tabs.css +190 -0
  45. package/components/tags.css +83 -0
  46. package/components/toast.css +164 -0
  47. package/components/toolbar.css +80 -0
  48. package/components/upload.css +181 -0
  49. package/ds.css +48 -0
  50. package/fonts/Geist-LICENSE.txt +92 -0
  51. package/fonts/Geist-Variable.woff2 +0 -0
  52. package/fonts/GeistSerif-Regular.woff2 +0 -0
  53. package/fonts/JetBrainsMono-LICENSE.txt +93 -0
  54. package/fonts/JetBrainsMono-Variable.woff2 +0 -0
  55. package/fonts.css +29 -0
  56. package/icons/icons.d.ts +5 -0
  57. package/icons/icons.js +266 -0
  58. package/js/back-to-top.d.ts +2 -0
  59. package/js/back-to-top.js +62 -0
  60. package/js/banner.js +87 -0
  61. package/js/calendar.d.ts +3 -0
  62. package/js/calendar.js +472 -0
  63. package/js/carousel.d.ts +2 -0
  64. package/js/carousel.js +258 -0
  65. package/js/charts/bar.js +361 -0
  66. package/js/charts/core.js +604 -0
  67. package/js/charts/donut.js +206 -0
  68. package/js/charts/figures.js +97 -0
  69. package/js/charts/heatmap.js +410 -0
  70. package/js/charts/line.js +268 -0
  71. package/js/charts/scatter.js +211 -0
  72. package/js/charts.d.ts +12 -0
  73. package/js/charts.js +27 -0
  74. package/js/code-block.d.ts +3 -0
  75. package/js/code-block.js +32 -0
  76. package/js/color-picker.d.ts +4 -0
  77. package/js/color-picker.js +448 -0
  78. package/js/command-palette.js +233 -0
  79. package/js/composer.js +573 -0
  80. package/js/context-menu.d.ts +2 -0
  81. package/js/context-menu.js +154 -0
  82. package/js/date-picker.d.ts +2 -0
  83. package/js/date-picker.js +430 -0
  84. package/js/drawer.js +48 -0
  85. package/js/editor.d.ts +5 -0
  86. package/js/editor.js +615 -0
  87. package/js/field-support.js +77 -0
  88. package/js/file-upload.d.ts +2 -0
  89. package/js/file-upload.js +230 -0
  90. package/js/filters.js +266 -0
  91. package/js/form.d.ts +2 -0
  92. package/js/form.js +409 -0
  93. package/js/i18n.d.ts +14 -0
  94. package/js/i18n.js +83 -0
  95. package/js/image-viewer.d.ts +4 -0
  96. package/js/image-viewer.js +275 -0
  97. package/js/menu.d.ts +4 -0
  98. package/js/menu.js +237 -0
  99. package/js/messages.js +908 -0
  100. package/js/modal.d.ts +7 -0
  101. package/js/modal.js +183 -0
  102. package/js/notifications.d.ts +4 -0
  103. package/js/notifications.js +204 -0
  104. package/js/number-field.d.ts +2 -0
  105. package/js/number-field.js +175 -0
  106. package/js/otp-field.d.ts +2 -0
  107. package/js/otp-field.js +107 -0
  108. package/js/pagination.d.ts +3 -0
  109. package/js/pagination.js +143 -0
  110. package/js/popover.d.ts +2 -0
  111. package/js/popover.js +155 -0
  112. package/js/progress-ring.js +48 -0
  113. package/js/rating.d.ts +3 -0
  114. package/js/rating.js +130 -0
  115. package/js/resizable.d.ts +2 -0
  116. package/js/resizable.js +311 -0
  117. package/js/scrollbar.d.ts +2 -0
  118. package/js/scrollbar.js +273 -0
  119. package/js/segmented.js +60 -0
  120. package/js/select.d.ts +3 -0
  121. package/js/select.js +784 -0
  122. package/js/shell.d.ts +6 -0
  123. package/js/shell.js +373 -0
  124. package/js/slider.d.ts +2 -0
  125. package/js/slider.js +89 -0
  126. package/js/sortable.d.ts +5 -0
  127. package/js/sortable.js +463 -0
  128. package/js/stepper.d.ts +2 -0
  129. package/js/stepper.js +72 -0
  130. package/js/tabs.js +99 -0
  131. package/js/tag-field.d.ts +2 -0
  132. package/js/tag-field.js +177 -0
  133. package/js/theme.d.ts +9 -0
  134. package/js/theme.js +114 -0
  135. package/js/time-picker.d.ts +2 -0
  136. package/js/time-picker.js +279 -0
  137. package/js/toast.d.ts +17 -0
  138. package/js/toast.js +171 -0
  139. package/js/toolbar.d.ts +2 -0
  140. package/js/toolbar.js +107 -0
  141. package/js/tooltip.d.ts +2 -0
  142. package/js/tooltip.js +208 -0
  143. package/js/tree.d.ts +2 -0
  144. package/js/tree.js +168 -0
  145. package/lume.css +11574 -0
  146. package/lume.d.ts +104 -0
  147. package/lume.js +67 -0
  148. package/package.json +66 -4
  149. package/react/Alert.d.ts +24 -0
  150. package/react/Alert.js +21 -0
  151. package/react/AppShell.d.ts +67 -0
  152. package/react/AppShell.js +94 -0
  153. package/react/Avatar.d.ts +39 -0
  154. package/react/Avatar.js +40 -0
  155. package/react/Badge.d.ts +17 -0
  156. package/react/Badge.js +10 -0
  157. package/react/Button.d.ts +32 -0
  158. package/react/Button.js +17 -0
  159. package/react/Calendar.d.ts +48 -0
  160. package/react/Calendar.js +67 -0
  161. package/react/Carousel.d.ts +30 -0
  162. package/react/Carousel.js +38 -0
  163. package/react/Charts.d.ts +186 -0
  164. package/react/Charts.js +58 -0
  165. package/react/Chip.d.ts +34 -0
  166. package/react/Chip.js +26 -0
  167. package/react/Choice.d.ts +72 -0
  168. package/react/Choice.js +51 -0
  169. package/react/ColorPicker.d.ts +43 -0
  170. package/react/ColorPicker.js +73 -0
  171. package/react/Content.d.ts +58 -0
  172. package/react/Content.js +42 -0
  173. package/react/Controls.d.ts +97 -0
  174. package/react/Controls.js +118 -0
  175. package/react/Editor.d.ts +28 -0
  176. package/react/Editor.js +57 -0
  177. package/react/Field.d.ts +90 -0
  178. package/react/Field.js +65 -0
  179. package/react/Form.d.ts +36 -0
  180. package/react/Form.js +45 -0
  181. package/react/Icon.d.ts +13 -0
  182. package/react/Icon.js +8 -0
  183. package/react/IconButton.d.ts +19 -0
  184. package/react/IconButton.js +12 -0
  185. package/react/ImageViewer.d.ts +20 -0
  186. package/react/ImageViewer.js +22 -0
  187. package/react/InlineAction.d.ts +15 -0
  188. package/react/InlineAction.js +12 -0
  189. package/react/Layers.d.ts +118 -0
  190. package/react/Layers.js +115 -0
  191. package/react/Link.d.ts +32 -0
  192. package/react/Link.js +26 -0
  193. package/react/Loading.d.ts +67 -0
  194. package/react/Loading.js +49 -0
  195. package/react/Navigation.d.ts +181 -0
  196. package/react/Navigation.js +197 -0
  197. package/react/Notices.d.ts +43 -0
  198. package/react/Notices.js +89 -0
  199. package/react/Panel.d.ts +57 -0
  200. package/react/Panel.js +33 -0
  201. package/react/Pickers.d.ts +83 -0
  202. package/react/Pickers.js +70 -0
  203. package/react/Rating.d.ts +39 -0
  204. package/react/Rating.js +41 -0
  205. package/react/Resizable.d.ts +44 -0
  206. package/react/Resizable.js +30 -0
  207. package/react/Select.d.ts +53 -0
  208. package/react/Select.js +79 -0
  209. package/react/Sortable.d.ts +52 -0
  210. package/react/Sortable.js +113 -0
  211. package/react/Table.d.ts +60 -0
  212. package/react/Table.js +34 -0
  213. package/react/Toolbar.d.ts +45 -0
  214. package/react/Toolbar.js +45 -0
  215. package/react/cx.d.ts +2 -0
  216. package/react/cx.js +5 -0
  217. package/react/icon-names.d.ts +1 -0
  218. package/react/icon-names.js +2 -0
  219. package/react/index.d.ts +42 -0
  220. package/react/index.js +52 -0
  221. package/react/useController.d.ts +8 -0
  222. package/react/useController.js +16 -0
  223. package/react/useLocale.d.ts +5 -0
  224. package/react/useLocale.js +15 -0
  225. package/tokens.css +739 -0
  226. package/tokens.js +4911 -0
@@ -0,0 +1,73 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useRef } from 'react';
4
+ import { createColorPicker, createColorField } from '../js/color-picker.js';
5
+ import { Input } from './Field.js';
6
+ import { useLatest, stableKey, defined } from './useController.js';
7
+ import { cx } from './cx.js';
8
+ /**
9
+ * Seletor de cor solto: área de saturação e brilho, matiz, hexadecimal e amostras.
10
+ * <ColorPicker value={cor} onChange={setCor} swatches={['#c97b63', '#3b82f6']} />
11
+ * https://lumeui.dev/#/componentes/seletor-de-cor
12
+ */
13
+ export function ColorPicker({ value, onChange, onCommit, swatches, className }) {
14
+ const root = useRef(null);
15
+ const api = useRef(null);
16
+ const change = useLatest(onChange);
17
+ const commit = useLatest(onCommit);
18
+ const latest = useLatest(value);
19
+ useEffect(() => {
20
+ let last = latest.current?.toLowerCase();
21
+ const live = (h) => {
22
+ if (h === last)
23
+ return;
24
+ last = h;
25
+ change.current(h);
26
+ };
27
+ const c = createColorPicker(root.current, defined({
28
+ value: latest.current,
29
+ swatches,
30
+ onInput: live,
31
+ onChange: (h) => {
32
+ live(h);
33
+ commit.current?.(h);
34
+ },
35
+ }));
36
+ api.current = c;
37
+ return () => {
38
+ c.destroy();
39
+ api.current = null;
40
+ };
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
42
+ }, [stableKey(swatches)]);
43
+ useEffect(() => {
44
+ if (api.current && api.current.value !== value?.toLowerCase())
45
+ api.current.setValue(value);
46
+ }, [value]);
47
+ return _jsx("div", { ref: root, className: cx('ds-color-picker', className) });
48
+ }
49
+ /**
50
+ * Campo de cor: a amostra no começo abre o seletor num painel, e o hexadecimal dá para digitar.
51
+ * <ColorField id="marca" value={cor} onChange={setCor} swatches={paleta} />
52
+ * https://lumeui.dev/#/componentes/seletor-de-cor
53
+ */
54
+ export function ColorField({ value, onChange, swatches, name, size, ...rest }) {
55
+ const input = useRef(null);
56
+ const api = useRef(null);
57
+ const change = useLatest(onChange);
58
+ const latest = useLatest(value);
59
+ useEffect(() => {
60
+ const c = createColorField(input.current, defined({ value: latest.current ?? undefined, swatches, placeholder: rest.placeholder, onChange: (h) => change.current(h) }));
61
+ api.current = c;
62
+ return () => {
63
+ c.destroy();
64
+ api.current = null;
65
+ };
66
+ // eslint-disable-next-line react-hooks/exhaustive-deps
67
+ }, [stableKey(swatches), rest.placeholder]);
68
+ useEffect(() => {
69
+ if (api.current && api.current.value !== (value?.toLowerCase() ?? null))
70
+ api.current.setValue(value);
71
+ }, [value]);
72
+ return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: input, size: size, autoComplete: "off", spellCheck: false, ...rest }), name && _jsx("input", { type: "hidden", name: name, value: value ?? '' })] }));
73
+ }
@@ -0,0 +1,58 @@
1
+ import { type HTMLAttributes, type ReactNode } from 'react';
2
+ import { type IconName } from './Icon.js';
3
+ export interface KbdProps extends HTMLAttributes<HTMLElement> {
4
+ /** Uma tecla ("Esc"), ou várias para uma combinação (["⌘", "K"]): cada uma vira uma etiqueta. */
5
+ keys?: string | string[];
6
+ }
7
+ /**
8
+ * Tecla de um atalho. O atalho é só um atalho: o caminho normal continua existindo.
9
+ * https://lumeui.dev/#/componentes/tecla
10
+ */
11
+ export declare function Kbd({ keys, className, children, ...rest }: KbdProps): import("react").JSX.Element;
12
+ export interface DescriptionListProps extends HTMLAttributes<HTMLDListElement> {
13
+ /** Os pares rótulo e valor, na ordem. */
14
+ items: Array<[label: ReactNode, value: ReactNode]>;
15
+ /** lines: com divisórias, para listas longas; stacked: rótulo em cima, para resumos. */
16
+ variant?: 'default' | 'lines' | 'stacked';
17
+ }
18
+ /**
19
+ * Pares de rótulo e valor: os dados de um pedido, de uma conta.
20
+ * https://lumeui.dev/#/componentes/lista-de-definicoes
21
+ */
22
+ export declare function DescriptionList({ items, variant, className, ...rest }: DescriptionListProps): import("react").JSX.Element;
23
+ export interface TimelineItem {
24
+ /** O que aconteceu. */
25
+ title: ReactNode;
26
+ /** Detalhe curto. */
27
+ text?: ReactNode;
28
+ /** Quando: texto para mostrar e, de preferência, a data em ISO em dateTime. */
29
+ time?: ReactNode;
30
+ dateTime?: string;
31
+ /** Tom do marcador. Padrão: neutro. */
32
+ tone?: 'neutral' | 'brand' | 'success' | 'warning' | 'danger';
33
+ /** Ícone do marcador. Sem ícone, um ponto. */
34
+ icon?: IconName;
35
+ }
36
+ export interface TimelineProps extends HTMLAttributes<HTMLOListElement> {
37
+ items: TimelineItem[];
38
+ }
39
+ /**
40
+ * O que aconteceu, em ordem: histórico de um pedido, de um documento.
41
+ * https://lumeui.dev/#/componentes/linha-do-tempo
42
+ */
43
+ export declare function Timeline({ items, className, ...rest }: TimelineProps): import("react").JSX.Element;
44
+ export interface BreadcrumbItem {
45
+ label: ReactNode;
46
+ /** Endereço. O último item é a página atual e não leva link. */
47
+ href?: string;
48
+ }
49
+ export interface BreadcrumbProps extends HTMLAttributes<HTMLElement> {
50
+ items: BreadcrumbItem[];
51
+ /** Troca o link padrão (<a>) pelo do seu roteador: renderLink={(item) => <Link to={item.href}>{item.label}</Link>}. */
52
+ renderLink?: (item: BreadcrumbItem) => ReactNode;
53
+ }
54
+ /**
55
+ * Onde a pessoa está, do geral para o específico.
56
+ * https://lumeui.dev/#/componentes/breadcrumb
57
+ */
58
+ export declare function Breadcrumb({ items, renderLink, className, ...rest }: BreadcrumbProps): import("react").JSX.Element;
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { Fragment } from 'react';
4
+ import { Icon } from './Icon.js';
5
+ import { msg } from '../js/i18n.js';
6
+ import { useLocale } from './useLocale.js';
7
+ import { cx } from './cx.js';
8
+ /**
9
+ * Tecla de um atalho. O atalho é só um atalho: o caminho normal continua existindo.
10
+ * https://lumeui.dev/#/componentes/tecla
11
+ */
12
+ export function Kbd({ keys, className, children, ...rest }) {
13
+ if (Array.isArray(keys)) {
14
+ return (_jsx(_Fragment, { children: keys.map((k, i) => (_jsxs(Fragment, { children: [i > 0 && ' ', _jsx("kbd", { className: cx('ds-kbd', className), ...rest, children: k })] }, i))) }));
15
+ }
16
+ return _jsx("kbd", { className: cx('ds-kbd', className), ...rest, children: keys ?? children });
17
+ }
18
+ /**
19
+ * Pares de rótulo e valor: os dados de um pedido, de uma conta.
20
+ * https://lumeui.dev/#/componentes/lista-de-definicoes
21
+ */
22
+ export function DescriptionList({ items, variant = 'default', className, ...rest }) {
23
+ return (_jsx("dl", { className: cx('ds-dl', variant !== 'default' && `ds-dl--${variant}`, className), ...rest, children: items.map(([label, value], i) => (_jsxs("div", { className: "ds-dl__row", children: [_jsx("dt", { children: label }), _jsx("dd", { children: value })] }, i))) }));
24
+ }
25
+ /**
26
+ * O que aconteceu, em ordem: histórico de um pedido, de um documento.
27
+ * https://lumeui.dev/#/componentes/linha-do-tempo
28
+ */
29
+ export function Timeline({ items, className, ...rest }) {
30
+ return (_jsx("ol", { className: cx('ds-timeline', className), ...rest, children: items.map((item, i) => (_jsxs("li", { className: "ds-timeline__item", "data-tone": item.tone && item.tone !== 'neutral' ? item.tone : undefined, children: [_jsx("span", { className: "ds-timeline__marker", children: item.icon && _jsx(Icon, { name: item.icon, size: 14 }) }), _jsxs("div", { className: "ds-timeline__content", children: [_jsx("p", { className: "ds-timeline__title", children: item.title }), item.text && _jsx("p", { className: "ds-timeline__text", children: item.text }), item.time && _jsx("time", { className: "ds-timeline__time", dateTime: item.dateTime, children: item.time })] })] }, i))) }));
31
+ }
32
+ /**
33
+ * Onde a pessoa está, do geral para o específico.
34
+ * https://lumeui.dev/#/componentes/breadcrumb
35
+ */
36
+ export function Breadcrumb({ items, renderLink, className, ...rest }) {
37
+ useLocale();
38
+ return (_jsx("nav", { className: cx('ds-breadcrumb', className), "aria-label": msg('common.breadcrumb'), ...rest, children: _jsx("ol", { children: items.map((item, i) => {
39
+ const last = i === items.length - 1;
40
+ return (_jsxs("li", { children: [i > 0 && _jsx(Icon, { name: "chevron-right", size: 14 }), last ? (_jsx("span", { "aria-current": "page", children: item.label })) : renderLink ? (renderLink(item)) : (_jsx("a", { href: item.href, children: item.label }))] }, i));
41
+ }) }) }));
42
+ }
@@ -0,0 +1,97 @@
1
+ import { type ReactNode } from 'react';
2
+ interface SliderBase {
3
+ /** O rótulo, à esquerda; o valor aparece à direita. */
4
+ label: ReactNode;
5
+ min?: number;
6
+ max?: number;
7
+ step?: number;
8
+ /** Texto do valor e do leitor de tela: (v) => `${v}%`. */
9
+ format?: (value: number) => string;
10
+ /** Marcas abaixo do trilho. */
11
+ marks?: Array<{
12
+ value: number;
13
+ label?: string;
14
+ }>;
15
+ name?: string;
16
+ disabled?: boolean;
17
+ className?: string;
18
+ }
19
+ export interface SingleSliderProps extends SliderBase {
20
+ value: number;
21
+ /** A cada movimento. */
22
+ onChange: (value: number) => void;
23
+ /** Ao soltar: bom para salvar ou buscar. */
24
+ onCommit?: (value: number) => void;
25
+ }
26
+ export interface RangeSliderProps extends SliderBase {
27
+ value: [number, number];
28
+ onChange: (value: [number, number]) => void;
29
+ onCommit?: (value: [number, number]) => void;
30
+ }
31
+ export type SliderProps = SingleSliderProps | RangeSliderProps;
32
+ /**
33
+ * Um valor, ou uma faixa, num trilho. Por baixo, o <input type="range"> nativo cuida do teclado e do leitor de tela.
34
+ * https://lumeui.dev/#/componentes/slider
35
+ */
36
+ export declare function Slider(props: SliderProps): import("react").JSX.Element;
37
+ export interface FileUploadProps {
38
+ /** Tipos aceitos: ['image/*', '.pdf']. */
39
+ accept?: string[];
40
+ /** Tamanho máximo por arquivo, em bytes. */
41
+ maxSize?: number;
42
+ maxFiles?: number;
43
+ multiple?: boolean;
44
+ /** Mais uma linha de orientação, junto dos limites. */
45
+ hint?: string;
46
+ /**
47
+ * Envia cada arquivo assim que entra na lista; devolva uma promessa. Uma falha vira erro naquela linha, com "Tentar de novo".
48
+ * Sem upload, os arquivos seguem com o formulário (name).
49
+ */
50
+ upload?: (file: File, ctx: {
51
+ onProgress: (fraction: number) => void;
52
+ signal: AbortSignal;
53
+ }) => Promise<unknown>;
54
+ /** Os arquivos aceitos, a cada mudança. */
55
+ onChange?: (files: File[]) => void;
56
+ name?: string;
57
+ id?: string;
58
+ disabled?: boolean;
59
+ required?: boolean;
60
+ className?: string;
61
+ }
62
+ export interface FileUploadHandle {
63
+ readonly files: File[];
64
+ clear(): void;
65
+ }
66
+ /**
67
+ * Arrastar ou escolher arquivos, com progresso e erro por arquivo. A área inteira é o <input type="file"> nativo.
68
+ * https://lumeui.dev/#/componentes/upload
69
+ */
70
+ export declare const FileUpload: import("react").ForwardRefExoticComponent<FileUploadProps & import("react").RefAttributes<FileUploadHandle>>;
71
+ export interface OtpFieldProps {
72
+ /** Casas. Padrão: 6. */
73
+ length?: number;
74
+ /** Separa em grupos de N (3 = "123 456"). */
75
+ group?: number;
76
+ /** Aceita letras também. */
77
+ alphanumeric?: boolean;
78
+ value?: string;
79
+ /** A cada dígito. */
80
+ onChange?: (value: string) => void;
81
+ /** Quando a última casa é preenchida: hora de verificar. */
82
+ onComplete?: (code: string) => void;
83
+ /** Código recusado: casas em vermelho e aria-invalid. */
84
+ error?: boolean;
85
+ name?: string;
86
+ id?: string;
87
+ disabled?: boolean;
88
+ /** Nome para leitores de tela, quando não há Field com rótulo. */
89
+ 'aria-label'?: string;
90
+ className?: string;
91
+ }
92
+ /**
93
+ * Um dígito por casa, para login em duas etapas. Por baixo é um input só, com autocomplete="one-time-code".
94
+ * https://lumeui.dev/#/componentes/codigo-de-verificacao
95
+ */
96
+ export declare function OtpField({ length, group, alphanumeric, value, onChange, onComplete, error, name, disabled, className, ...rest }: OtpFieldProps): import("react").JSX.Element;
97
+ export {};
@@ -0,0 +1,118 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
4
+ import { createSlider } from '../js/slider.js';
5
+ import { createFileUpload } from '../js/file-upload.js';
6
+ import { createOtpField } from '../js/otp-field.js';
7
+ import { msg } from '../js/i18n.js';
8
+ import { useFieldProps } from './Field.js';
9
+ import { useLocale } from './useLocale.js';
10
+ import { useLatest, stableKey, defined, useSafeId } from './useController.js';
11
+ import { cx } from './cx.js';
12
+ /**
13
+ * Um valor, ou uma faixa, num trilho. Por baixo, o <input type="range"> nativo cuida do teclado e do leitor de tela.
14
+ * https://lumeui.dev/#/componentes/slider
15
+ */
16
+ export function Slider(props) {
17
+ useLocale();
18
+ const { label, min = 0, max = 100, step = 1, format, marks, name, disabled, className, value } = props;
19
+ const range = Array.isArray(value);
20
+ const id = useSafeId('s');
21
+ const root = useRef(null);
22
+ const api = useRef(null);
23
+ const change = useLatest(props.onChange);
24
+ const commit = useLatest(props.onCommit);
25
+ const fmt = useLatest(format);
26
+ const latest = useLatest(value);
27
+ useEffect(() => {
28
+ const c = createSlider(root.current, defined({
29
+ format: (v) => (fmt.current ? fmt.current(v) : String(v)),
30
+ marks,
31
+ onInput: (v) => change.current(v),
32
+ onChange: (v) => commit.current?.(v),
33
+ }));
34
+ c.setValue(latest.current);
35
+ api.current = c;
36
+ return () => {
37
+ c.destroy();
38
+ api.current = null;
39
+ };
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ }, [range, min, max, step, stableKey(marks)]);
42
+ const key = stableKey(value);
43
+ useEffect(() => {
44
+ if (api.current && stableKey(api.current.value) !== key)
45
+ api.current.setValue(value);
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, [key]);
48
+ const common = { className: 'ds-slider__input', type: 'range', min, max, step, disabled };
49
+ return (_jsxs("div", { className: cx('ds-form-field', className), children: [_jsxs("div", { className: "ds-slider__head", children: [range ? _jsx("span", { className: "ds-form-field__label", id: `${id}-label`, children: label }) : _jsx("label", { className: "ds-form-field__label", htmlFor: id, children: label }), _jsx("output", { className: "ds-slider__value", htmlFor: id })] }), range ? (_jsxs("div", { ref: root, className: "ds-slider", role: "group", "aria-labelledby": `${id}-label`, children: [_jsx("input", { ...common, defaultValue: value[0], "aria-label": msg('slider.min'), name: name ? `${name}-min` : undefined }), _jsx("input", { ...common, defaultValue: value[1], "aria-label": msg('slider.max'), name: name ? `${name}-max` : undefined })] })) : (_jsx("div", { ref: root, className: "ds-slider", children: _jsx("input", { ...common, id: id, defaultValue: value, name: name }) }))] }));
50
+ }
51
+ /**
52
+ * Arrastar ou escolher arquivos, com progresso e erro por arquivo. A área inteira é o <input type="file"> nativo.
53
+ * https://lumeui.dev/#/componentes/upload
54
+ */
55
+ export const FileUpload = forwardRef(function FileUpload({ accept, maxSize, maxFiles, multiple, hint, upload, onChange, name, disabled, required, className, ...rest }, ref) {
56
+ const a11y = useFieldProps(rest);
57
+ const root = useRef(null);
58
+ const api = useRef(null);
59
+ const change = useLatest(onChange);
60
+ const send = useLatest(upload);
61
+ useImperativeHandle(ref, () => ({
62
+ get files() {
63
+ return api.current?.files ?? [];
64
+ },
65
+ clear: () => api.current?.clear(),
66
+ }));
67
+ useEffect(() => {
68
+ const c = createFileUpload(root.current, defined({
69
+ accept,
70
+ maxSize,
71
+ maxFiles,
72
+ hint,
73
+ upload: send.current ? (file, ctx) => send.current(file, ctx) : undefined,
74
+ onChange: (files) => change.current?.(files),
75
+ }));
76
+ api.current = c;
77
+ return () => {
78
+ c.destroy();
79
+ api.current = null;
80
+ };
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, [stableKey(accept), maxSize, maxFiles, hint, multiple, Boolean(upload)]);
83
+ return (_jsx("div", { ref: root, className: cx('ds-upload', className), children: _jsx("input", { className: "ds-upload__input", type: "file", id: a11y.id, name: name, multiple: multiple, disabled: disabled, required: required, "aria-invalid": a11y['aria-invalid'] }) }));
84
+ });
85
+ /**
86
+ * Um dígito por casa, para login em duas etapas. Por baixo é um input só, com autocomplete="one-time-code".
87
+ * https://lumeui.dev/#/componentes/codigo-de-verificacao
88
+ */
89
+ export function OtpField({ length = 6, group, alphanumeric, value, onChange, onComplete, error, name, disabled, className, ...rest }) {
90
+ const a11y = useFieldProps(rest);
91
+ const root = useRef(null);
92
+ const api = useRef(null);
93
+ const done = useLatest(onComplete);
94
+ const change = useLatest(onChange);
95
+ useEffect(() => {
96
+ const c = createOtpField(root.current, defined({ length, group, alphanumeric, onComplete: (code) => done.current?.(code) }));
97
+ api.current = c;
98
+ const input = root.current.querySelector('input');
99
+ const onInput = () => change.current?.(input.value);
100
+ input.addEventListener('input', onInput);
101
+ if (value)
102
+ c.setValue(value);
103
+ return () => {
104
+ input.removeEventListener('input', onInput);
105
+ c.destroy();
106
+ api.current = null;
107
+ };
108
+ // eslint-disable-next-line react-hooks/exhaustive-deps
109
+ }, [length, group, alphanumeric]);
110
+ useEffect(() => {
111
+ if (api.current && value !== undefined && api.current.value !== value)
112
+ api.current.setValue(value);
113
+ }, [value]);
114
+ useEffect(() => {
115
+ api.current?.setError(Boolean(error));
116
+ }, [error]);
117
+ return (_jsx("div", { ref: root, className: cx('ds-otp', className), children: _jsx("input", { className: "ds-otp__input", id: a11y.id, name: name, disabled: disabled, "aria-label": rest['aria-label'], "aria-describedby": a11y['aria-describedby'] }) }));
118
+ }
@@ -0,0 +1,28 @@
1
+ import { type HTMLAttributes } from 'react';
2
+ import { type EditorTool } from '../js/editor.js';
3
+ export type { EditorTool };
4
+ export interface RichTextEditorProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {
5
+ /** O nome do campo para o leitor de tela (ou use labelledBy com o id de um rótulo). */
6
+ label?: string;
7
+ labelledBy?: string;
8
+ /** HTML inicial. Para controlar, use value + onChange. */
9
+ defaultValue?: string;
10
+ value?: string;
11
+ /** O HTML limpo a cada mudança ("" quando vazio). */
12
+ onChange?: (html: string) => void;
13
+ /** Grupos da barra, na ordem. Padrão: todos. */
14
+ tools?: EditorTool[];
15
+ placeholder?: string;
16
+ /** Envia o HTML num campo oculto com este nome. */
17
+ name?: string;
18
+ disabled?: boolean;
19
+ /** Sem contorno, para quando o editor é a própria página. */
20
+ borderless?: boolean;
21
+ }
22
+ /**
23
+ * Editor de texto rico: títulos, listas, citações, negrito, itálico e links, com a barra do Lume.
24
+ * <RichTextEditor label="Nota da versão" value={html} onChange={setHtml} tools={['marks', 'link']} />
25
+ * O editor é dono do próprio DOM (contenteditable): o React só monta a caixa e conversa pelo HTML.
26
+ * https://lumeui.dev/#/componentes/editor-de-texto-rico
27
+ */
28
+ export declare function RichTextEditor({ label, labelledBy, defaultValue, value, onChange, tools, placeholder, name, disabled, borderless, className, ...rest }: RichTextEditorProps): import("react").JSX.Element;
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useEffect, useRef, useState } from 'react';
4
+ import { createEditor } from '../js/editor.js';
5
+ import { useLatest, defined, stableKey } from './useController.js';
6
+ import { useLocale } from './useLocale.js';
7
+ import { cx } from './cx.js';
8
+ /**
9
+ * Editor de texto rico: títulos, listas, citações, negrito, itálico e links, com a barra do Lume.
10
+ * <RichTextEditor label="Nota da versão" value={html} onChange={setHtml} tools={['marks', 'link']} />
11
+ * O editor é dono do próprio DOM (contenteditable): o React só monta a caixa e conversa pelo HTML.
12
+ * https://lumeui.dev/#/componentes/editor-de-texto-rico
13
+ */
14
+ export function RichTextEditor({ label, labelledBy, defaultValue, value, onChange, tools, placeholder, name, disabled, borderless, className, ...rest }) {
15
+ useLocale();
16
+ const host = useRef(null);
17
+ const editor = useRef(null);
18
+ const current = useRef(value ?? defaultValue ?? '');
19
+ const [html, setHtml] = useState(current.current);
20
+ const latest = useLatest({ onChange });
21
+ useEffect(() => {
22
+ const root = document.createElement('div');
23
+ root.className = cx('ds-editor', borderless && 'ds-editor--borderless', className);
24
+ const content = document.createElement('div');
25
+ content.className = 'ds-editor__content';
26
+ if (label)
27
+ content.setAttribute('aria-label', label);
28
+ if (labelledBy)
29
+ content.setAttribute('aria-labelledby', labelledBy);
30
+ root.append(content);
31
+ host.current.append(root);
32
+ const ed = createEditor(root, defined({
33
+ tools,
34
+ placeholder,
35
+ value: current.current,
36
+ onChange: (next) => {
37
+ current.current = next;
38
+ setHtml(next);
39
+ latest.current.onChange?.(next);
40
+ },
41
+ }));
42
+ editor.current = ed;
43
+ return () => {
44
+ ed.destroy();
45
+ root.remove();
46
+ editor.current = null;
47
+ };
48
+ }, [stableKey(tools), placeholder, label, labelledBy, borderless, className]);
49
+ useEffect(() => {
50
+ if (value !== undefined && editor.current && value !== editor.current.value) {
51
+ current.current = value;
52
+ editor.current.setValue(value);
53
+ }
54
+ }, [value]);
55
+ useEffect(() => editor.current?.setDisabled(!!disabled), [disabled, stableKey(tools), borderless, className]);
56
+ return (_jsx("div", { ref: host, style: { display: 'contents' }, ...rest, children: name && _jsx("input", { type: "hidden", name: name, value: html }) }));
57
+ }
@@ -0,0 +1,90 @@
1
+ import { type InputHTMLAttributes, type ReactNode, type TextareaHTMLAttributes } from 'react';
2
+ import { type IconName } from './Icon.js';
3
+ export type FieldSize = 'sm' | 'md' | 'lg';
4
+ interface FieldContextValue {
5
+ id: string;
6
+ describedBy?: string;
7
+ invalid: boolean;
8
+ }
9
+ /** 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. */
10
+ export declare function useField(): FieldContextValue | null;
11
+ export interface FieldProps {
12
+ /** Sempre visível, acima do controle. */
13
+ label: ReactNode;
14
+ /** Uma linha logo abaixo, com o formato ou o motivo. Some quando há erro. */
15
+ hint?: ReactNode;
16
+ /** A mensagem de erro, dizendo como resolver. Liga aria-invalid no controle. */
17
+ error?: ReactNode;
18
+ /** Marca o campo como opcional (o obrigatório não leva marca). */
19
+ optional?: boolean;
20
+ /** Contador "atual/máximo", para campos com limite. */
21
+ count?: {
22
+ value: number;
23
+ max: number;
24
+ };
25
+ /** id do controle. Padrão: um gerado. */
26
+ id?: string;
27
+ className?: string;
28
+ /** O controle: Input, Textarea, Select, DatePicker… Eles leem o id e a descrição sozinhos. */
29
+ children: ReactNode;
30
+ }
31
+ /**
32
+ * Rótulo, controle, dica, erro e contador, ligados para leitores de tela.
33
+ * https://lumeui.dev/#/componentes/campo-de-texto
34
+ */
35
+ export declare function Field({ label, hint, error, optional, count, id, className, children }: FieldProps): import("react").JSX.Element;
36
+ /** Junta os atributos de acessibilidade do Field com os que vieram por props. */
37
+ export declare function useFieldProps(props: {
38
+ id?: string;
39
+ 'aria-describedby'?: string;
40
+ 'aria-invalid'?: unknown;
41
+ }): {
42
+ id: string | undefined;
43
+ 'aria-describedby': string | undefined;
44
+ 'aria-invalid': boolean | undefined;
45
+ };
46
+ export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'size'> {
47
+ /** Padrão: md (40 px). Use o mesmo tamanho dos botões ao lado. */
48
+ size?: FieldSize;
49
+ /** Ícone à esquerda, só quando ajuda a reconhecer o dado (busca, e-mail). */
50
+ icon?: IconName;
51
+ /** Texto fixo antes do valor ("https://", "R$"). */
52
+ affix?: ReactNode;
53
+ /** Botão dentro do campo, à direita (use FieldAction). */
54
+ action?: ReactNode;
55
+ }
56
+ /** O campo de texto. Dentro de um Field, pega o id, a dica e o erro sozinho. */
57
+ export declare const Input: import("react").ForwardRefExoticComponent<InputProps & import("react").RefAttributes<HTMLInputElement>>;
58
+ export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
59
+ }
60
+ /** Texto de mais de uma frase. Cresce na vertical. */
61
+ export declare const Textarea: import("react").ForwardRefExoticComponent<TextareaProps & import("react").RefAttributes<HTMLTextAreaElement>>;
62
+ export interface FieldActionProps {
63
+ icon: IconName;
64
+ /** O nome da ação ("Limpar", "Mostrar a senha"). */
65
+ label: string;
66
+ onClick: () => void;
67
+ /** Para ações que ligam e desligam (mostrar a senha). */
68
+ pressed?: boolean;
69
+ }
70
+ /** Botão de ícone dentro do campo: limpar, mostrar a senha. */
71
+ export declare function FieldAction({ icon, label, onClick, pressed }: FieldActionProps): import("react").JSX.Element;
72
+ export interface TextFieldProps extends Omit<InputProps, 'children'> {
73
+ label: ReactNode;
74
+ hint?: ReactNode;
75
+ error?: ReactNode;
76
+ optional?: boolean;
77
+ /** Mostra o contador "atual/máximo". Pede maxLength. */
78
+ showCount?: boolean;
79
+ /** Linhas: vira um Textarea. */
80
+ multiline?: boolean;
81
+ rows?: number;
82
+ /** Mostra o × para limpar quando há texto; chamado ao clicar. */
83
+ onClear?: () => void;
84
+ }
85
+ /**
86
+ * Atalho para o caso comum: Field + Input (ou Textarea, com multiline).
87
+ * https://lumeui.dev/#/componentes/campo-de-texto
88
+ */
89
+ export declare const TextField: import("react").ForwardRefExoticComponent<TextFieldProps & import("react").RefAttributes<HTMLInputElement & HTMLTextAreaElement>>;
90
+ export {};
package/react/Field.js ADDED
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { createContext, forwardRef, useContext, useState, } from 'react';
4
+ import { Icon } from './Icon.js';
5
+ import { msg } from '../js/i18n.js';
6
+ import { useLocale } from './useLocale.js';
7
+ import { useSafeId } from './useController.js';
8
+ import { cx } from './cx.js';
9
+ const FieldContext = createContext(null);
10
+ /** 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. */
11
+ export function useField() {
12
+ return useContext(FieldContext);
13
+ }
14
+ /**
15
+ * Rótulo, controle, dica, erro e contador, ligados para leitores de tela.
16
+ * https://lumeui.dev/#/componentes/campo-de-texto
17
+ */
18
+ export function Field({ label, hint, error, optional, count, id, className, children }) {
19
+ useLocale();
20
+ const auto = useSafeId('f');
21
+ const fieldId = id ?? auto;
22
+ const invalid = Boolean(error);
23
+ const describedBy = invalid ? `${fieldId}-error` : hint ? `${fieldId}-hint` : undefined;
24
+ return (_jsx(FieldContext.Provider, { value: { id: fieldId, describedBy, invalid }, children: _jsxs("div", { className: cx('ds-form-field', className), children: [_jsxs("label", { className: "ds-form-field__label", htmlFor: fieldId, children: [label, optional && _jsx("span", { className: "ds-form-field__optional", children: msg('form.optional') })] }), children, (invalid || hint || count) && (_jsxs("div", { className: "ds-form-field__footer", children: [invalid && (_jsxs("p", { className: "ds-form-field__error", id: `${fieldId}-error`, children: [_jsx(Icon, { name: "alert-circle", size: 16 }), _jsx("span", { children: error })] })), !invalid && hint && _jsx("p", { className: "ds-form-field__hint", id: `${fieldId}-hint`, children: hint }), count && (_jsxs("span", { className: "ds-form-field__counter", "data-over": count.value > count.max ? '' : undefined, children: [count.value, "/", count.max] }))] }))] }) }));
25
+ }
26
+ /** Junta os atributos de acessibilidade do Field com os que vieram por props. */
27
+ export function useFieldProps(props) {
28
+ const field = useField();
29
+ return {
30
+ id: props.id ?? field?.id,
31
+ 'aria-describedby': cx(field?.describedBy, props['aria-describedby']) || undefined,
32
+ 'aria-invalid': props['aria-invalid'] ?? (field?.invalid ? true : undefined),
33
+ };
34
+ }
35
+ /** O campo de texto. Dentro de um Field, pega o id, a dica e o erro sozinho. */
36
+ export const Input = forwardRef(function Input({ size = 'md', icon, affix, action, className, type = 'text', ...rest }, ref) {
37
+ const a11y = useFieldProps(rest);
38
+ return (_jsxs("div", { className: cx('ds-field', size !== 'md' && `ds-field--${size}`, className), children: [icon && _jsx(Icon, { name: icon, size: size === 'sm' ? 16 : 18 }), affix && _jsx("span", { className: "ds-field__affix", "aria-hidden": "true", children: affix }), _jsx("input", { ref: ref, type: type, className: "ds-field__input", ...rest, ...a11y }), action] }));
39
+ });
40
+ /** Texto de mais de uma frase. Cresce na vertical. */
41
+ export const Textarea = forwardRef(function Textarea({ className, rows = 4, ...rest }, ref) {
42
+ const a11y = useFieldProps(rest);
43
+ return (_jsx("div", { className: cx('ds-field', 'ds-field--multiline', className), children: _jsx("textarea", { ref: ref, rows: rows, className: "ds-field__input", ...rest, ...a11y }) }));
44
+ });
45
+ /** Botão de ícone dentro do campo: limpar, mostrar a senha. */
46
+ export function FieldAction({ icon, label, onClick, pressed }) {
47
+ return (_jsx("button", { type: "button", className: "ds-icon-btn ds-icon-btn--sm ds-icon-btn--muted ds-field__action", "aria-label": label, "aria-pressed": pressed, onClick: onClick, children: _jsx(Icon, { name: icon, size: 16 }) }));
48
+ }
49
+ /**
50
+ * Atalho para o caso comum: Field + Input (ou Textarea, com multiline).
51
+ * https://lumeui.dev/#/componentes/campo-de-texto
52
+ */
53
+ export const TextField = forwardRef(function TextField({ label, hint, error, optional, showCount, multiline, rows, onClear, id, className, onChange, maxLength, ...rest }, ref) {
54
+ useLocale();
55
+ const initial = String(rest.value ?? rest.defaultValue ?? '').length;
56
+ const [typed, setTyped] = useState(initial);
57
+ const length = rest.value !== undefined ? String(rest.value).length : typed;
58
+ const change = (event) => {
59
+ setTyped(event.target.value.length);
60
+ onChange?.(event);
61
+ };
62
+ const count = showCount && maxLength ? { value: length, max: maxLength } : undefined;
63
+ const { size, icon, affix, action, type, ...common } = rest;
64
+ 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
+ });