@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.
- 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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type FieldSize } from './Field.js';
|
|
2
|
+
interface TextControlBase {
|
|
3
|
+
/** name do valor no formulário (vai num input oculto, no formato de máquina). */
|
|
4
|
+
name?: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
size?: FieldSize;
|
|
10
|
+
'aria-describedby'?: string;
|
|
11
|
+
'aria-label'?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DateRange {
|
|
14
|
+
start: Date;
|
|
15
|
+
end: Date | null;
|
|
16
|
+
}
|
|
17
|
+
interface DatePickerBase extends TextControlBase {
|
|
18
|
+
/** Primeiro e último dia que dá para escolher (inclusive). */
|
|
19
|
+
min?: Date;
|
|
20
|
+
max?: Date;
|
|
21
|
+
/** Meses lado a lado no calendário. Padrão: 1 (no período, 2 quando cabe). */
|
|
22
|
+
months?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface SingleDatePickerProps extends DatePickerBase {
|
|
25
|
+
mode?: 'single';
|
|
26
|
+
value: Date | null;
|
|
27
|
+
onChange: (value: Date | null) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface RangeDatePickerProps extends DatePickerBase {
|
|
30
|
+
mode: 'range';
|
|
31
|
+
value: DateRange | null;
|
|
32
|
+
onChange: (value: DateRange | null) => void;
|
|
33
|
+
}
|
|
34
|
+
export type DatePickerProps = SingleDatePickerProps | RangeDatePickerProps;
|
|
35
|
+
/**
|
|
36
|
+
* Campo de data que também abre um calendário; dá para digitar no formato do idioma.
|
|
37
|
+
* O formulário recebe a data em ISO (2026-11-08, ou 2026-11-08/2026-11-15 no período).
|
|
38
|
+
* https://lumeui.dev/#/componentes/seletor-de-data
|
|
39
|
+
*/
|
|
40
|
+
export declare function DatePicker(props: DatePickerProps): import("react").JSX.Element;
|
|
41
|
+
export interface TimePickerProps extends TextControlBase {
|
|
42
|
+
/** HH:MM, em 24 h. */
|
|
43
|
+
value: string | null;
|
|
44
|
+
onChange: (value: string | null) => void;
|
|
45
|
+
/** Minutos entre as opções da lista. Padrão: 15. */
|
|
46
|
+
step?: number;
|
|
47
|
+
min?: string;
|
|
48
|
+
max?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Campo de horário com uma lista; aceita digitar 1430, 14h30 ou 2:30 pm. O formulário recebe HH:MM.
|
|
52
|
+
* https://lumeui.dev/#/componentes/seletor-de-horario
|
|
53
|
+
*/
|
|
54
|
+
export declare function TimePicker({ value, onChange, step, min, max, name, size, ...rest }: TimePickerProps): import("react").JSX.Element;
|
|
55
|
+
export interface NumberFieldProps extends TextControlBase {
|
|
56
|
+
value: number | null;
|
|
57
|
+
onChange: (value: number | null) => void;
|
|
58
|
+
min?: number;
|
|
59
|
+
max?: number;
|
|
60
|
+
/** Padrão: 1. */
|
|
61
|
+
step?: number;
|
|
62
|
+
/** Opções de Intl.NumberFormat: { style: 'currency', currency: 'BRL' }, { style: 'percent' }… */
|
|
63
|
+
format?: Intl.NumberFormatOptions;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Número com − e +, limites, passo e o formato do idioma. O formulário recebe o número puro (1234.5).
|
|
67
|
+
* https://lumeui.dev/#/componentes/campo-numerico
|
|
68
|
+
*/
|
|
69
|
+
export declare function NumberField({ value, onChange, min, max, step, format, name, size, ...rest }: NumberFieldProps): import("react").JSX.Element;
|
|
70
|
+
export interface TagFieldProps extends TextControlBase {
|
|
71
|
+
value: string[];
|
|
72
|
+
onChange: (value: string[]) => void;
|
|
73
|
+
/** No máximo N tags. */
|
|
74
|
+
max?: number;
|
|
75
|
+
/** Devolve a mensagem de erro, ou null quando a tag vale. */
|
|
76
|
+
validate?: (text: string) => string | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Vários valores livres num campo só: Enter ou vírgula criam a tag. O formulário recebe os valores separados por vírgula.
|
|
80
|
+
* https://lumeui.dev/#/componentes/campo-de-tags
|
|
81
|
+
*/
|
|
82
|
+
export declare function TagField({ value, onChange, max, validate, name, size, ...rest }: TagFieldProps): import("react").JSX.Element;
|
|
83
|
+
export {};
|
package/react/Pickers.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
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 { createDatePicker } from '../js/date-picker.js';
|
|
5
|
+
import { createTimePicker } from '../js/time-picker.js';
|
|
6
|
+
import { createNumberField } from '../js/number-field.js';
|
|
7
|
+
import { createTagField } from '../js/tag-field.js';
|
|
8
|
+
import { Input } from './Field.js';
|
|
9
|
+
import { useLatest, stableKey, defined } from './useController.js';
|
|
10
|
+
/** Liga um controlador do Lume a um <input> e mantém o valor do React e o do controlador iguais. */
|
|
11
|
+
function useControlled(create, value, onChange, deps) {
|
|
12
|
+
const input = useRef(null);
|
|
13
|
+
const api = useRef(null);
|
|
14
|
+
const emit = useLatest(onChange);
|
|
15
|
+
const latest = useLatest(value);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const c = create(input.current, (v) => emit.current?.(v));
|
|
18
|
+
c.setValue(latest.current);
|
|
19
|
+
api.current = c;
|
|
20
|
+
return () => {
|
|
21
|
+
c.destroy();
|
|
22
|
+
api.current = null;
|
|
23
|
+
};
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
+
}, deps);
|
|
26
|
+
const key = stableKey(value);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (api.current && stableKey(api.current.value) !== key)
|
|
29
|
+
api.current.setValue(value);
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
+
}, [key]);
|
|
32
|
+
return input;
|
|
33
|
+
}
|
|
34
|
+
const iso = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
35
|
+
/**
|
|
36
|
+
* Campo de data que também abre um calendário; dá para digitar no formato do idioma.
|
|
37
|
+
* O formulário recebe a data em ISO (2026-11-08, ou 2026-11-08/2026-11-15 no período).
|
|
38
|
+
* https://lumeui.dev/#/componentes/seletor-de-data
|
|
39
|
+
*/
|
|
40
|
+
export function DatePicker(props) {
|
|
41
|
+
const { mode = 'single', min, max, months, name, size, value, onChange, ...rest } = props;
|
|
42
|
+
const input = useControlled((el, emit) => createDatePicker(el, defined({ mode, min, max, months, placeholder: rest.placeholder, onChange: emit })), value, onChange, [mode, min?.getTime(), max?.getTime(), months, rest.placeholder]);
|
|
43
|
+
const hidden = !value ? '' : mode === 'range' ? (value.end ? `${iso(value.start)}/${iso(value.end)}` : '') : iso(value);
|
|
44
|
+
return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: input, size: size, autoComplete: "off", ...rest }), name && _jsx("input", { type: "hidden", name: name, value: hidden })] }));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Campo de horário com uma lista; aceita digitar 1430, 14h30 ou 2:30 pm. O formulário recebe HH:MM.
|
|
48
|
+
* https://lumeui.dev/#/componentes/seletor-de-horario
|
|
49
|
+
*/
|
|
50
|
+
export function TimePicker({ value, onChange, step, min, max, name, size, ...rest }) {
|
|
51
|
+
const input = useControlled((el, emit) => createTimePicker(el, defined({ step, min, max, placeholder: rest.placeholder, onChange: emit })), value, onChange, [step, min, max, rest.placeholder]);
|
|
52
|
+
return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: input, size: size, autoComplete: "off", ...rest }), name && _jsx("input", { type: "hidden", name: name, value: value ?? '' })] }));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Número com − e +, limites, passo e o formato do idioma. O formulário recebe o número puro (1234.5).
|
|
56
|
+
* https://lumeui.dev/#/componentes/campo-numerico
|
|
57
|
+
*/
|
|
58
|
+
export function NumberField({ value, onChange, min, max, step, format, name, size, ...rest }) {
|
|
59
|
+
const input = useControlled((el, emit) => createNumberField(el, defined({ min, max, step, format, onChange: emit })), value, onChange, [min, max, step, stableKey(format)]);
|
|
60
|
+
return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: input, size: size, className: "ds-number", ...rest }), name && _jsx("input", { type: "hidden", name: name, value: value ?? '' })] }));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Vários valores livres num campo só: Enter ou vírgula criam a tag. O formulário recebe os valores separados por vírgula.
|
|
64
|
+
* https://lumeui.dev/#/componentes/campo-de-tags
|
|
65
|
+
*/
|
|
66
|
+
export function TagField({ value, onChange, max, validate, name, size, ...rest }) {
|
|
67
|
+
const check = useLatest(validate);
|
|
68
|
+
const input = useControlled((el, emit) => createTagField(el, defined({ max, validate: check.current ? (t) => check.current(t) : undefined, onChange: emit })), value, onChange, [max, Boolean(validate)]);
|
|
69
|
+
return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: input, size: size, className: "ds-tags", ...rest }), name && _jsx("input", { type: "hidden", name: name, value: value.join(',') })] }));
|
|
70
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface RatingProps {
|
|
2
|
+
/** A pergunta, para o leitor de tela (“Como você avalia esta página?”). */
|
|
3
|
+
label: string;
|
|
4
|
+
/** Nome do campo: o formulário envia a nota (1 a max). */
|
|
5
|
+
name?: string;
|
|
6
|
+
/** A nota, de 0 (sem nota) a max. Com onChange, acompanha o estado. */
|
|
7
|
+
value?: number;
|
|
8
|
+
onChange?: (value: number) => void;
|
|
9
|
+
max?: number;
|
|
10
|
+
/** Clicar de novo na estrela marcada tira a nota. Padrão: sim. */
|
|
11
|
+
clearable?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
size?: 'sm' | 'md' | 'lg';
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Estrelas para dar nota; cada estrela é um rádio nativo.
|
|
19
|
+
* <Rating label="Sua nota" name="nota" value={nota} onChange={setNota} />
|
|
20
|
+
* https://lumeui.dev/#/componentes/avaliacao
|
|
21
|
+
*/
|
|
22
|
+
export declare function Rating({ label, name, value, onChange, max, clearable, disabled, required, size, className }: RatingProps): import("react").JSX.Element;
|
|
23
|
+
export interface RatingDisplayProps {
|
|
24
|
+
/** A média, com qualquer decimal (4.5 mostra meia estrela). */
|
|
25
|
+
value: number;
|
|
26
|
+
max?: number;
|
|
27
|
+
size?: 'sm' | 'md' | 'lg';
|
|
28
|
+
/** Mostra o número ao lado (“4,5”). */
|
|
29
|
+
text?: boolean;
|
|
30
|
+
/** Quantas notas, entre parênteses. */
|
|
31
|
+
count?: number;
|
|
32
|
+
/** Texto para o leitor de tela; padrão “Nota 4,5 de 5”. */
|
|
33
|
+
label?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Só mostra a nota: uma imagem com o texto da nota para o leitor de tela.
|
|
37
|
+
* <RatingDisplay value={4.5} text count={128} />
|
|
38
|
+
*/
|
|
39
|
+
export declare function RatingDisplay({ value, max, size, text, count, label }: RatingDisplayProps): import("react").JSX.Element;
|
package/react/Rating.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { createRating, ratingHtml } from '../js/rating.js';
|
|
5
|
+
import { useLatest, defined } from './useController.js';
|
|
6
|
+
import { useLocale } from './useLocale.js';
|
|
7
|
+
import { cx } from './cx.js';
|
|
8
|
+
/**
|
|
9
|
+
* Estrelas para dar nota; cada estrela é um rádio nativo.
|
|
10
|
+
* <Rating label="Sua nota" name="nota" value={nota} onChange={setNota} />
|
|
11
|
+
* https://lumeui.dev/#/componentes/avaliacao
|
|
12
|
+
*/
|
|
13
|
+
export function Rating({ label, name, value, onChange, max, clearable, disabled, required, size = 'md', className }) {
|
|
14
|
+
const root = useRef(null);
|
|
15
|
+
const api = useRef(null);
|
|
16
|
+
const change = useLatest(onChange);
|
|
17
|
+
const start = useLatest(value);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
const r = createRating(root.current, defined({ name, max, clearable, disabled, required, value: start.current, onChange: (v) => change.current?.(v) }));
|
|
20
|
+
api.current = r;
|
|
21
|
+
return () => {
|
|
22
|
+
r.destroy();
|
|
23
|
+
api.current = null;
|
|
24
|
+
};
|
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
|
+
}, [name, max, clearable, disabled, required]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (value !== undefined && api.current && api.current.value !== value)
|
|
29
|
+
api.current.setValue(value);
|
|
30
|
+
}, [value]);
|
|
31
|
+
return _jsx("div", { ref: root, className: cx('ds-rating', size !== 'md' && `ds-rating--${size}`, className), "aria-label": label });
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Só mostra a nota: uma imagem com o texto da nota para o leitor de tela.
|
|
35
|
+
* <RatingDisplay value={4.5} text count={128} />
|
|
36
|
+
*/
|
|
37
|
+
export function RatingDisplay({ value, max, size, text, count, label }) {
|
|
38
|
+
useLocale();
|
|
39
|
+
const html = ratingHtml(value, defined({ max, size: size === 'md' ? undefined : size, text, count, label }));
|
|
40
|
+
return _jsx("span", { style: { display: 'contents' }, dangerouslySetInnerHTML: { __html: html } });
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
type Size = number | `${number}px`;
|
|
3
|
+
export interface ResizablePanelsProps {
|
|
4
|
+
/** Os painéis: um ResizablePanel por parte. As divisórias entram sozinhas entre eles. */
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
/** Nome da área para o leitor de tela (“Editor”). */
|
|
7
|
+
label?: string;
|
|
8
|
+
/** Lado a lado (padrão) ou um sobre o outro. */
|
|
9
|
+
direction?: 'horizontal' | 'vertical';
|
|
10
|
+
/** Alça à vista na divisória. */
|
|
11
|
+
grip?: boolean;
|
|
12
|
+
/** Guarda o tamanho no navegador com este nome. */
|
|
13
|
+
storageKey?: string;
|
|
14
|
+
/** Quanto cada seta anda, em %. */
|
|
15
|
+
step?: number;
|
|
16
|
+
/** Tamanhos em %, no fim de cada arrasto ou tecla. */
|
|
17
|
+
onChange?: (sizes: number[]) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
/** A área precisa de altura (ou de um pai flex) para dividir: height: '100%' costuma bastar. */
|
|
20
|
+
style?: CSSProperties;
|
|
21
|
+
}
|
|
22
|
+
export interface ResizablePanelProps {
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
/** Tamanho inicial, em % (30) ou px ('240px'). */
|
|
25
|
+
size?: Size;
|
|
26
|
+
min?: Size;
|
|
27
|
+
max?: Size;
|
|
28
|
+
/** Pode fechar até zero: arrastando até o fim ou com Enter na divisória. */
|
|
29
|
+
collapsible?: boolean;
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Uma parte da área. Fora de ResizablePanels não faz nada. */
|
|
33
|
+
export declare function ResizablePanel({ children, size, min, max, collapsible, className }: ResizablePanelProps): import("react").JSX.Element;
|
|
34
|
+
/**
|
|
35
|
+
* Área dividida em partes que a pessoa ajusta arrastando a divisória, com teclado e tamanho salvo.
|
|
36
|
+
* <ResizablePanels label="Editor" storageKey="editor">
|
|
37
|
+
* <ResizablePanel size={30} min={20} collapsible>…</ResizablePanel>
|
|
38
|
+
* <ResizablePanel min="240px">…</ResizablePanel>
|
|
39
|
+
* </ResizablePanels>
|
|
40
|
+
* As divisórias são desenhadas aqui (o módulo usa as que encontra), para o React continuar dono da marcação.
|
|
41
|
+
* https://lumeui.dev/#/componentes/paineis-redimensionaveis
|
|
42
|
+
*/
|
|
43
|
+
export declare function ResizablePanels({ children, label, direction, grip, storageKey, step, onChange, className, style }: ResizablePanelsProps): import("react").JSX.Element;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Children, Fragment, useEffect, useRef } from 'react';
|
|
4
|
+
import { createResizable } from '../js/resizable.js';
|
|
5
|
+
import { useLatest, defined } from './useController.js';
|
|
6
|
+
import { cx } from './cx.js';
|
|
7
|
+
/** Uma parte da área. Fora de ResizablePanels não faz nada. */
|
|
8
|
+
export function ResizablePanel({ children, size, min, max, collapsible, className }) {
|
|
9
|
+
return (_jsx("div", { className: cx('ds-resizable__panel', className), "data-size": size, "data-min": min, "data-max": max, "data-collapsible": collapsible ? '' : undefined, children: children }));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Área dividida em partes que a pessoa ajusta arrastando a divisória, com teclado e tamanho salvo.
|
|
13
|
+
* <ResizablePanels label="Editor" storageKey="editor">
|
|
14
|
+
* <ResizablePanel size={30} min={20} collapsible>…</ResizablePanel>
|
|
15
|
+
* <ResizablePanel min="240px">…</ResizablePanel>
|
|
16
|
+
* </ResizablePanels>
|
|
17
|
+
* As divisórias são desenhadas aqui (o módulo usa as que encontra), para o React continuar dono da marcação.
|
|
18
|
+
* https://lumeui.dev/#/componentes/paineis-redimensionaveis
|
|
19
|
+
*/
|
|
20
|
+
export function ResizablePanels({ children, label, direction = 'horizontal', grip, storageKey, step, onChange, className, style }) {
|
|
21
|
+
const root = useRef(null);
|
|
22
|
+
const change = useLatest(onChange);
|
|
23
|
+
const panels = Children.toArray(children);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const r = createResizable(root.current, defined({ direction, storageKey, step, onChange: (sizes) => change.current?.(sizes) }));
|
|
26
|
+
return () => r.destroy();
|
|
27
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
+
}, [panels.length, direction, storageKey, step]);
|
|
29
|
+
return (_jsx("div", { ref: root, className: cx('ds-resizable', grip && 'ds-resizable--grip', className), "data-direction": direction, "aria-label": label, style: style, children: panels.map((panel, i) => (_jsxs(Fragment, { children: [i > 0 && (_jsx("div", { className: "ds-resizable__handle", children: _jsx("span", { className: "ds-resizable__grip", "aria-hidden": "true" }) })), panel] }, panel.key ?? i))) }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { IconName } from './Icon.js';
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SelectGroup {
|
|
8
|
+
group: string;
|
|
9
|
+
options: SelectOption[];
|
|
10
|
+
}
|
|
11
|
+
interface SelectBase {
|
|
12
|
+
/** As opções, soltas ou em grupos ({ group: 'Américas', options: […] }). */
|
|
13
|
+
options: Array<SelectOption | SelectGroup>;
|
|
14
|
+
/** Campo de busca no topo da lista, para listas longas. */
|
|
15
|
+
search?: boolean;
|
|
16
|
+
searchPlaceholder?: string;
|
|
17
|
+
/** Texto quando nada está escolhido. */
|
|
18
|
+
placeholder?: string;
|
|
19
|
+
/** Padrão: md. */
|
|
20
|
+
size?: 'sm' | 'md' | 'lg';
|
|
21
|
+
/** Ícone antes do valor. */
|
|
22
|
+
icon?: IconName;
|
|
23
|
+
name?: string;
|
|
24
|
+
id?: string;
|
|
25
|
+
required?: boolean;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
'aria-describedby'?: string;
|
|
28
|
+
'aria-invalid'?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface SingleSelectProps extends SelectBase {
|
|
31
|
+
multiple?: false;
|
|
32
|
+
value: string | null;
|
|
33
|
+
onChange: (value: string | null) => void;
|
|
34
|
+
}
|
|
35
|
+
export interface MultipleSelectProps extends SelectBase {
|
|
36
|
+
multiple: true;
|
|
37
|
+
value: string[];
|
|
38
|
+
onChange: (value: string[]) => void;
|
|
39
|
+
/** chips (padrão) mostra as escolhas; count mostra "3 selecionados". */
|
|
40
|
+
display?: 'chips' | 'count';
|
|
41
|
+
/** No máximo N escolhas. */
|
|
42
|
+
max?: number;
|
|
43
|
+
/** Rodapé com "todos" e "limpar". */
|
|
44
|
+
footer?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export type SelectProps = SingleSelectProps | MultipleSelectProps;
|
|
47
|
+
/**
|
|
48
|
+
* Escolher uma ou várias opções numa lista própria do Lume (não a do sistema), com busca e teclado.
|
|
49
|
+
* Por baixo continua um <select> real: envio do formulário, required e o Form funcionam.
|
|
50
|
+
* https://lumeui.dev/#/componentes/selecao
|
|
51
|
+
*/
|
|
52
|
+
export declare function Select(props: SelectProps): import("react").JSX.Element;
|
|
53
|
+
export {};
|
package/react/Select.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { createSelect } from '../js/select.js';
|
|
5
|
+
import { useFieldProps } from './Field.js';
|
|
6
|
+
import { useLatest, stableKey } from './useController.js';
|
|
7
|
+
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
|
8
|
+
const optionHtml = (o) => `<option value="${esc(o.value)}"${o.disabled ? ' disabled' : ''}>${esc(o.label)}</option>`;
|
|
9
|
+
/**
|
|
10
|
+
* Escolher uma ou várias opções numa lista própria do Lume (não a do sistema), com busca e teclado.
|
|
11
|
+
* Por baixo continua um <select> real: envio do formulário, required e o Form funcionam.
|
|
12
|
+
* https://lumeui.dev/#/componentes/selecao
|
|
13
|
+
*/
|
|
14
|
+
export function Select(props) {
|
|
15
|
+
const { options, search, searchPlaceholder, placeholder, size = 'md', icon, name, required, disabled } = props;
|
|
16
|
+
const multi = props.multiple === true;
|
|
17
|
+
const display = multi ? props.display : undefined;
|
|
18
|
+
const max = multi ? props.max : undefined;
|
|
19
|
+
const footer = multi ? props.footer : undefined;
|
|
20
|
+
const a11y = useFieldProps(props);
|
|
21
|
+
const host = useRef(null);
|
|
22
|
+
const api = useRef(null);
|
|
23
|
+
const onChange = useLatest(props.onChange);
|
|
24
|
+
const optionsKey = stableKey(options);
|
|
25
|
+
const fill = (el) => {
|
|
26
|
+
el.innerHTML =
|
|
27
|
+
(!multi ? `<option value="">${esc(placeholder ?? '')}</option>` : '') +
|
|
28
|
+
options.map((o) => ('group' in o ? `<optgroup label="${esc(o.group)}">${o.options.map(optionHtml).join('')}</optgroup>` : optionHtml(o))).join('');
|
|
29
|
+
const chosen = multi ? props.value : [props.value ?? ''];
|
|
30
|
+
for (const opt of el.options)
|
|
31
|
+
opt.selected = chosen.includes(opt.value);
|
|
32
|
+
};
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const el = document.createElement('select');
|
|
35
|
+
if (a11y.id)
|
|
36
|
+
el.id = a11y.id;
|
|
37
|
+
if (name)
|
|
38
|
+
el.name = name;
|
|
39
|
+
el.multiple = multi;
|
|
40
|
+
el.required = Boolean(required);
|
|
41
|
+
el.disabled = Boolean(disabled);
|
|
42
|
+
if (size !== 'md')
|
|
43
|
+
el.dataset.size = size;
|
|
44
|
+
if (icon)
|
|
45
|
+
el.dataset.icon = icon;
|
|
46
|
+
if (a11y['aria-describedby'])
|
|
47
|
+
el.setAttribute('aria-describedby', a11y['aria-describedby']);
|
|
48
|
+
if (a11y['aria-invalid'])
|
|
49
|
+
el.setAttribute('aria-invalid', 'true');
|
|
50
|
+
fill(el);
|
|
51
|
+
host.current.append(el);
|
|
52
|
+
const instance = createSelect(el, { search, searchPlaceholder, placeholder, display, max, footer });
|
|
53
|
+
api.current = instance;
|
|
54
|
+
const onNative = () => {
|
|
55
|
+
if (multi)
|
|
56
|
+
onChange.current([...el.selectedOptions].map((o) => o.value));
|
|
57
|
+
else
|
|
58
|
+
onChange.current(el.value || null);
|
|
59
|
+
};
|
|
60
|
+
el.addEventListener('change', onNative);
|
|
61
|
+
return () => {
|
|
62
|
+
el.removeEventListener('change', onNative);
|
|
63
|
+
instance.destroy();
|
|
64
|
+
el.remove();
|
|
65
|
+
api.current = null;
|
|
66
|
+
};
|
|
67
|
+
// recria quando muda algo que o Lume só lê ao montar
|
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
+
}, [multi, search, searchPlaceholder, placeholder, display, max, footer, size, icon, name, required, disabled, a11y.id, a11y['aria-describedby'], a11y['aria-invalid']]);
|
|
70
|
+
// opções e valor: atualiza no lugar
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!api.current)
|
|
73
|
+
return;
|
|
74
|
+
fill(api.current.select);
|
|
75
|
+
api.current.sync();
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
}, [optionsKey, stableKey(props.value)]);
|
|
78
|
+
return _jsx("div", { ref: host, style: { display: 'contents' } });
|
|
79
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
export interface SortableItem {
|
|
3
|
+
id: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SortableListProps<T extends SortableItem> extends Omit<HTMLAttributes<HTMLUListElement>, 'onChange' | 'children'> {
|
|
6
|
+
/** O nome da lista, dito pelo leitor de tela e nos anúncios. */
|
|
7
|
+
label: string;
|
|
8
|
+
items: T[];
|
|
9
|
+
/** A nova ordem, depois de soltar. */
|
|
10
|
+
onChange: (items: T[]) => void;
|
|
11
|
+
/** O conteúdo de cada item, ao lado da alça. Use <span className="ds-sortable__label"> para o nome. */
|
|
12
|
+
renderItem: (item: T) => ReactNode;
|
|
13
|
+
/** Padrão: true. Sem alça, o item inteiro arrasta e recebe o foco. */
|
|
14
|
+
handle?: boolean;
|
|
15
|
+
orientation?: 'vertical' | 'horizontal';
|
|
16
|
+
/** Linhas sem caixa, para dentro de um card. */
|
|
17
|
+
plain?: boolean;
|
|
18
|
+
itemClassName?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Lista arrastável: mudar a ordem com o mouse, o toque ou o teclado.
|
|
22
|
+
* <SortableList label="Ordem" items={itens} onChange={setItens} renderItem={(i) => <span className="ds-sortable__label">{i.nome}</span>} />
|
|
23
|
+
* https://lumeui.dev/#/componentes/lista-arrastavel
|
|
24
|
+
*/
|
|
25
|
+
export declare function SortableList<T extends SortableItem>({ label, items, onChange, renderItem, handle, orientation, plain, itemClassName, className, ...rest }: SortableListProps<T>): import("react").JSX.Element;
|
|
26
|
+
export interface KanbanColumn<T extends SortableItem> {
|
|
27
|
+
id: string;
|
|
28
|
+
title: string;
|
|
29
|
+
items: T[];
|
|
30
|
+
}
|
|
31
|
+
export interface KanbanProps<T extends SortableItem> extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'children'> {
|
|
32
|
+
/** O nome do quadro. */
|
|
33
|
+
label: string;
|
|
34
|
+
columns: KanbanColumn<T>[];
|
|
35
|
+
/** As colunas depois de soltar, com o cartão já no lugar novo. */
|
|
36
|
+
onChange: (columns: KanbanColumn<T>[], change: {
|
|
37
|
+
id: string;
|
|
38
|
+
from: string;
|
|
39
|
+
to: string;
|
|
40
|
+
index: number;
|
|
41
|
+
}) => void;
|
|
42
|
+
/** O conteúdo do cartão: use ds-kanban__card-title, __card-text e __card-meta. */
|
|
43
|
+
renderCard: (item: T) => ReactNode;
|
|
44
|
+
/** Padrão: false (o cartão inteiro arrasta). Com true, cada cartão ganha uma alça e o resto fica livre para links. */
|
|
45
|
+
handle?: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Kanban: colunas de cartões que passam de uma para outra.
|
|
49
|
+
* <Kanban label="Roadmap" columns={colunas} onChange={setColunas} renderCard={(c) => <p className="ds-kanban__card-title">{c.titulo}</p>} />
|
|
50
|
+
* https://lumeui.dev/#/componentes/kanban
|
|
51
|
+
*/
|
|
52
|
+
export declare function Kanban<T extends SortableItem>({ label, columns, onChange, renderCard, handle, className, ...rest }: KanbanProps<T>): import("react").JSX.Element;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useLayoutEffect, useRef } from 'react';
|
|
4
|
+
import { createSortable } from '../js/sortable.js';
|
|
5
|
+
import { msg } from '../js/i18n.js';
|
|
6
|
+
import { Icon } from './Icon.js';
|
|
7
|
+
import { useLatest } from './useController.js';
|
|
8
|
+
import { useLocale } from './useLocale.js';
|
|
9
|
+
import { cx } from './cx.js';
|
|
10
|
+
/* O módulo move o <li> no DOM; o React precisa ser o dono da ordem. Ao soltar, o item volta
|
|
11
|
+
para onde o React o deixou e a nova ordem chega pelo estado: as chaves fazem o resto. */
|
|
12
|
+
function putBack(detail) {
|
|
13
|
+
const others = [...detail.from.children].filter((el) => el !== detail.item && el.classList.contains('ds-sortable__item'));
|
|
14
|
+
detail.from.insertBefore(detail.item, others[detail.oldIndex] ?? null);
|
|
15
|
+
}
|
|
16
|
+
function move(list, from, to) {
|
|
17
|
+
const next = list.slice();
|
|
18
|
+
const [it] = next.splice(from, 1);
|
|
19
|
+
next.splice(to, 0, it);
|
|
20
|
+
return next;
|
|
21
|
+
}
|
|
22
|
+
/* devolve o foco à alça (ou ao item) depois que o React redesenha a lista */
|
|
23
|
+
function useRefocus(root) {
|
|
24
|
+
const pending = useRef(null);
|
|
25
|
+
useLayoutEffect(() => {
|
|
26
|
+
const p = pending.current;
|
|
27
|
+
if (!p || !root.current)
|
|
28
|
+
return;
|
|
29
|
+
pending.current = null;
|
|
30
|
+
const item = root.current.querySelector(`.ds-sortable__item[data-id="${CSS.escape(p.id)}"]`);
|
|
31
|
+
(p.handle ? item?.querySelector('.ds-sortable__handle') : item)?.focus();
|
|
32
|
+
});
|
|
33
|
+
return (detail) => {
|
|
34
|
+
const active = document.activeElement;
|
|
35
|
+
if (active && detail.item.contains(active))
|
|
36
|
+
pending.current = { id: detail.id ?? '', handle: active !== detail.item };
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Lista arrastável: mudar a ordem com o mouse, o toque ou o teclado.
|
|
41
|
+
* <SortableList label="Ordem" items={itens} onChange={setItens} renderItem={(i) => <span className="ds-sortable__label">{i.nome}</span>} />
|
|
42
|
+
* https://lumeui.dev/#/componentes/lista-arrastavel
|
|
43
|
+
*/
|
|
44
|
+
export function SortableList({ label, items, onChange, renderItem, handle = true, orientation = 'vertical', plain, itemClassName, className, ...rest }) {
|
|
45
|
+
useLocale();
|
|
46
|
+
const ref = useRef(null);
|
|
47
|
+
const latest = useLatest({ items, onChange });
|
|
48
|
+
const refocus = useRefocus(ref);
|
|
49
|
+
const sortable = useRef(null);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const el = ref.current;
|
|
52
|
+
sortable.current = createSortable(el, { orientation });
|
|
53
|
+
const onSort = (event) => {
|
|
54
|
+
const detail = event.detail;
|
|
55
|
+
refocus(detail);
|
|
56
|
+
putBack(detail);
|
|
57
|
+
const { items: now, onChange: change } = latest.current;
|
|
58
|
+
change(move(now, detail.oldIndex, detail.newIndex));
|
|
59
|
+
};
|
|
60
|
+
el.addEventListener('ds:sortchange', onSort);
|
|
61
|
+
return () => {
|
|
62
|
+
el.removeEventListener('ds:sortchange', onSort);
|
|
63
|
+
sortable.current?.destroy();
|
|
64
|
+
sortable.current = null;
|
|
65
|
+
};
|
|
66
|
+
}, [orientation]);
|
|
67
|
+
useEffect(() => sortable.current?.refresh());
|
|
68
|
+
return (_jsx("ul", { ref: ref, role: "list", "aria-label": label, "aria-orientation": orientation === 'horizontal' ? 'horizontal' : undefined, className: cx('ds-sortable', plain && 'ds-sortable--plain', className), ...rest, children: items.map((item) => (_jsxs("li", { className: cx('ds-sortable__item', itemClassName), "data-id": item.id, tabIndex: handle ? undefined : 0, children: [handle && (_jsx("button", { type: "button", className: "ds-sortable__handle", children: _jsx(Icon, { name: "grip-vertical", size: 16 }) })), renderItem(item)] }, item.id))) }));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Kanban: colunas de cartões que passam de uma para outra.
|
|
72
|
+
* <Kanban label="Roadmap" columns={colunas} onChange={setColunas} renderCard={(c) => <p className="ds-kanban__card-title">{c.titulo}</p>} />
|
|
73
|
+
* https://lumeui.dev/#/componentes/kanban
|
|
74
|
+
*/
|
|
75
|
+
export function Kanban({ label, columns, onChange, renderCard, handle = false, className, ...rest }) {
|
|
76
|
+
useLocale();
|
|
77
|
+
const ref = useRef(null);
|
|
78
|
+
const latest = useLatest({ columns, onChange });
|
|
79
|
+
const refocus = useRefocus(ref);
|
|
80
|
+
const sortables = useRef([]);
|
|
81
|
+
const ids = columns.map((c) => c.id).join('\u0000');
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const board = ref.current;
|
|
84
|
+
const group = Symbol('kanban');
|
|
85
|
+
sortables.current = [...board.querySelectorAll('.ds-kanban__list')].map((l) => createSortable(l, { group }));
|
|
86
|
+
const onSort = (event) => {
|
|
87
|
+
const detail = event.detail;
|
|
88
|
+
refocus(detail);
|
|
89
|
+
putBack(detail);
|
|
90
|
+
const from = detail.from.closest('.ds-kanban__column').dataset.id;
|
|
91
|
+
const to = detail.to.closest('.ds-kanban__column').dataset.id;
|
|
92
|
+
const { columns: now, onChange: change } = latest.current;
|
|
93
|
+
const card = now.find((c) => c.id === from).items[detail.oldIndex];
|
|
94
|
+
const next = now.map((c) => {
|
|
95
|
+
let list = c.items;
|
|
96
|
+
if (c.id === from)
|
|
97
|
+
list = list.filter((_, i) => i !== detail.oldIndex);
|
|
98
|
+
if (c.id === to)
|
|
99
|
+
list = [...list.slice(0, detail.newIndex), card, ...list.slice(detail.newIndex)];
|
|
100
|
+
return list === c.items ? c : { ...c, items: list };
|
|
101
|
+
});
|
|
102
|
+
change(next, { id: card.id, from, to, index: detail.newIndex });
|
|
103
|
+
};
|
|
104
|
+
board.addEventListener('ds:sortchange', onSort);
|
|
105
|
+
return () => {
|
|
106
|
+
board.removeEventListener('ds:sortchange', onSort);
|
|
107
|
+
sortables.current.forEach((s) => s.destroy());
|
|
108
|
+
sortables.current = [];
|
|
109
|
+
};
|
|
110
|
+
}, [ids]);
|
|
111
|
+
useEffect(() => sortables.current.forEach((s) => s.refresh()));
|
|
112
|
+
return (_jsx("div", { ref: ref, role: "group", "aria-label": label, className: cx('ds-kanban', className), ...rest, children: columns.map((column) => (_jsxs("section", { className: "ds-kanban__column", "data-id": column.id, children: [_jsxs("header", { className: "ds-kanban__header", children: [_jsx("h3", { className: "ds-kanban__title", children: column.title }), _jsx("span", { className: "ds-kanban__count", children: column.items.length })] }), _jsx("ul", { className: "ds-kanban__list", role: "list", "aria-label": column.title, "data-empty-text": msg('kanban.empty'), children: column.items.map((item) => (_jsx("li", { className: cx('ds-sortable__item ds-kanban__card', handle && 'ds-kanban__card--handle'), "data-id": item.id, tabIndex: handle ? undefined : 0, children: handle ? (_jsxs("div", { className: "ds-kanban__card-top", children: [_jsx("div", { className: "ds-kanban__card-body", children: renderCard(item) }), _jsx("button", { type: "button", className: "ds-sortable__handle", children: _jsx(Icon, { name: "grip-vertical", size: 16 }) })] })) : (renderCard(item)) }, item.id))) })] }, column.id))) }));
|
|
113
|
+
}
|