@arshad-shah/cynosure 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -8
- package/dist/components/Accordion/Accordion.d.ts +14 -0
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/Announcer/Announcer.d.ts +1 -0
- package/dist/components/Announcer/Announcer.js.map +1 -1
- package/dist/components/AppShell/AppShell.d.ts +22 -1
- package/dist/components/AppShell/AppShell.js +95 -83
- package/dist/components/AppShell/AppShell.js.map +1 -1
- package/dist/components/AppShell/index.d.ts +1 -1
- package/dist/components/AspectRatio/AspectRatio.d.ts +29 -0
- package/dist/components/AspectRatio/AspectRatio.js +21 -0
- package/dist/components/AspectRatio/AspectRatio.js.map +1 -0
- package/dist/components/AspectRatio/index.d.ts +1 -0
- package/dist/components/Avatar/Avatar.d.ts +96 -0
- package/dist/components/Avatar/Avatar.js +90 -0
- package/dist/components/Avatar/Avatar.js.map +1 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +55 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js +85 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js.map +1 -0
- package/dist/components/Breadcrumbs/index.d.ts +1 -0
- package/dist/components/Button/Button.d.ts +13 -2
- package/dist/components/Button/Button.js +28 -26
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/Calendar/Calendar.d.ts +65 -7
- package/dist/components/Calendar/Calendar.js +207 -95
- package/dist/components/Calendar/Calendar.js.map +1 -1
- package/dist/components/Calendar/dates.d.ts +4 -0
- package/dist/components/Calendar/dates.js +41 -27
- package/dist/components/Calendar/dates.js.map +1 -1
- package/dist/components/Calendar/index.d.ts +1 -1
- package/dist/components/Card/Card.d.ts +27 -0
- package/dist/components/Card/Card.js +48 -36
- package/dist/components/Card/Card.js.map +1 -1
- package/dist/components/Card/index.d.ts +1 -1
- package/dist/components/Checkbox/Checkbox.d.ts +8 -1
- package/dist/components/Checkbox/Checkbox.js +7 -6
- package/dist/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/components/Checkbox/ChoiceRow.d.ts +17 -1
- package/dist/components/Checkbox/ChoiceRow.js +19 -18
- package/dist/components/Checkbox/ChoiceRow.js.map +1 -1
- package/dist/components/Checklist/Checklist.d.ts +65 -0
- package/dist/components/Checklist/Checklist.js +163 -0
- package/dist/components/Checklist/Checklist.js.map +1 -0
- package/dist/components/Checklist/index.d.ts +1 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +5 -0
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/ColorField/ColorField.d.ts +12 -0
- package/dist/components/ColorField/ColorField.js +19 -19
- package/dist/components/ColorField/ColorField.js.map +1 -1
- package/dist/components/ColorSwatches/ColorSwatches.d.ts +5 -0
- package/dist/components/ColorSwatches/ColorSwatches.js +6 -6
- package/dist/components/ColorSwatches/ColorSwatches.js.map +1 -1
- package/dist/components/Combobox/Combobox.d.ts +20 -1
- package/dist/components/Combobox/Combobox.js +38 -34
- package/dist/components/Combobox/Combobox.js.map +1 -1
- package/dist/components/CommandPalette/CommandPalette.d.ts +9 -0
- package/dist/components/CommandPalette/CommandPalette.js +10 -10
- package/dist/components/CommandPalette/CommandPalette.js.map +1 -1
- package/dist/components/CompareSlider/CompareSlider.d.ts +4 -0
- package/dist/components/CompareSlider/CompareSlider.js +4 -4
- package/dist/components/CompareSlider/CompareSlider.js.map +1 -1
- package/dist/components/Container/Container.d.ts +44 -0
- package/dist/components/Container/Container.js +24 -0
- package/dist/components/Container/Container.js.map +1 -0
- package/dist/components/Container/index.d.ts +1 -0
- package/dist/components/ContextMenu/ContextMenu.d.ts +11 -0
- package/dist/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/components/CopyButton/CopyButton.d.ts +8 -0
- package/dist/components/CopyButton/CopyButton.js.map +1 -1
- package/dist/components/DateField/DateField.d.ts +17 -0
- package/dist/components/DateField/DateField.js +6 -6
- package/dist/components/DateField/DateField.js.map +1 -1
- package/dist/components/DescriptionList/DescriptionList.d.ts +3 -0
- package/dist/components/DescriptionList/DescriptionList.js.map +1 -1
- package/dist/components/Dialog/Dialog.d.ts +16 -2
- package/dist/components/Dialog/Dialog.js +82 -70
- package/dist/components/Dialog/Dialog.js.map +1 -1
- package/dist/components/Disclosure/Disclosure.d.ts +7 -0
- package/dist/components/Disclosure/Disclosure.js.map +1 -1
- package/dist/components/Divider/Divider.d.ts +59 -0
- package/dist/components/Divider/Divider.js +32 -0
- package/dist/components/Divider/Divider.js.map +1 -0
- package/dist/components/Divider/index.d.ts +1 -0
- package/dist/components/DocumentViewport/DocumentViewport.d.ts +8 -0
- package/dist/components/DocumentViewport/DocumentViewport.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.d.ts +3 -0
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/Field/Field.d.ts +6 -0
- package/dist/components/Field/Field.js.map +1 -1
- package/dist/components/FileDrop/FileDrop.d.ts +8 -0
- package/dist/components/FileDrop/FileDrop.js.map +1 -1
- package/dist/components/FloatingToolbar/FloatingToolbar.d.ts +4 -0
- package/dist/components/FloatingToolbar/FloatingToolbar.js +4 -4
- package/dist/components/FloatingToolbar/FloatingToolbar.js.map +1 -1
- package/dist/components/Grid/Grid.d.ts +33 -7
- package/dist/components/Grid/Grid.js +46 -25
- package/dist/components/Grid/Grid.js.map +1 -1
- package/dist/components/Grid/index.d.ts +1 -1
- package/dist/components/Heading/Heading.d.ts +57 -0
- package/dist/components/Heading/Heading.js +33 -0
- package/dist/components/Heading/Heading.js.map +1 -0
- package/dist/components/Heading/index.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.d.ts +1 -0
- package/dist/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/components/IconButton/IconButton.d.ts +1 -0
- package/dist/components/IconButton/IconButton.js.map +1 -1
- package/dist/components/Image/Image.d.ts +62 -0
- package/dist/components/Image/Image.js +75 -0
- package/dist/components/Image/Image.js.map +1 -0
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/components/Inline/Inline.d.ts +7 -3
- package/dist/components/Inline/Inline.js +19 -13
- package/dist/components/Inline/Inline.js.map +1 -1
- package/dist/components/Kbd/Kbd.d.ts +2 -0
- package/dist/components/Kbd/Kbd.js.map +1 -1
- package/dist/components/KeyValueEditor/KeyValueEditor.d.ts +7 -0
- package/dist/components/KeyValueEditor/KeyValueEditor.js +8 -8
- package/dist/components/KeyValueEditor/KeyValueEditor.js.map +1 -1
- package/dist/components/Link/Link.d.ts +7 -0
- package/dist/components/Link/Link.js.map +1 -1
- package/dist/components/LoadingDots/LoadingDots.d.ts +2 -0
- package/dist/components/LoadingDots/LoadingDots.js.map +1 -1
- package/dist/components/Menu/Menu.d.ts +13 -1
- package/dist/components/Menu/Menu.js +37 -35
- package/dist/components/Menu/Menu.js.map +1 -1
- package/dist/components/Notice/Notice.d.ts +5 -0
- package/dist/components/Notice/Notice.js.map +1 -1
- package/dist/components/NumberField/NumberField.d.ts +17 -0
- package/dist/components/NumberField/NumberField.js +8 -8
- package/dist/components/NumberField/NumberField.js.map +1 -1
- package/dist/components/PageHeader/PageHeader.d.ts +61 -0
- package/dist/components/PageHeader/PageHeader.js +63 -0
- package/dist/components/PageHeader/PageHeader.js.map +1 -0
- package/dist/components/PageHeader/index.d.ts +1 -0
- package/dist/components/Pagination/Pagination.d.ts +77 -0
- package/dist/components/Pagination/Pagination.js +120 -0
- package/dist/components/Pagination/Pagination.js.map +1 -0
- package/dist/components/Pagination/index.d.ts +1 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.d.ts +4 -0
- package/dist/components/PanZoomCanvas/PanZoomCanvas.js.map +1 -1
- package/dist/components/Popover/Popover.d.ts +10 -0
- package/dist/components/Popover/Popover.js.map +1 -1
- package/dist/components/ProgressBar/ProgressBar.d.ts +5 -0
- package/dist/components/ProgressBar/ProgressBar.js.map +1 -1
- package/dist/components/ProgressOverlay/ProgressOverlay.d.ts +3 -0
- package/dist/components/ProgressOverlay/ProgressOverlay.js.map +1 -1
- package/dist/components/Prose/Prose.d.ts +1 -0
- package/dist/components/Prose/Prose.js.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +13 -0
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +9 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +35 -27
- package/dist/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/components/Select/Select.d.ts +18 -1
- package/dist/components/Select/Select.js +97 -88
- package/dist/components/Select/Select.js.map +1 -1
- package/dist/components/Select/index.d.ts +1 -0
- package/dist/components/SelectionFrame/SelectionFrame.d.ts +6 -0
- package/dist/components/SelectionFrame/SelectionFrame.js.map +1 -1
- package/dist/components/SideNav/SideNav.d.ts +37 -1
- package/dist/components/SideNav/SideNav.js +100 -73
- package/dist/components/SideNav/SideNav.js.map +1 -1
- package/dist/components/SideNav/index.d.ts +1 -1
- package/dist/components/SignaturePad/SignaturePad.d.ts +3 -0
- package/dist/components/SignaturePad/SignaturePad.js.map +1 -1
- package/dist/components/Skeleton/Skeleton.d.ts +1 -0
- package/dist/components/Skeleton/Skeleton.js.map +1 -1
- package/dist/components/Slider/Slider.d.ts +11 -0
- package/dist/components/Slider/Slider.js +6 -6
- package/dist/components/Slider/Slider.js.map +1 -1
- package/dist/components/SortableList/SortableList.d.ts +6 -0
- package/dist/components/SortableList/SortableList.js.map +1 -1
- package/dist/components/SplitPane/SplitPane.d.ts +5 -0
- package/dist/components/SplitPane/SplitPane.js +4 -4
- package/dist/components/SplitPane/SplitPane.js.map +1 -1
- package/dist/components/Stack/Stack.d.ts +7 -3
- package/dist/components/Stack/Stack.js +18 -12
- package/dist/components/Stack/Stack.js.map +1 -1
- package/dist/components/Stack/index.d.ts +1 -0
- package/dist/components/Stack/space.d.ts +18 -0
- package/dist/components/Stack/space.js +12 -0
- package/dist/components/Stack/space.js.map +1 -0
- package/dist/components/Steps/Steps.d.ts +4 -0
- package/dist/components/Steps/Steps.js.map +1 -1
- package/dist/components/Table/Table.d.ts +12 -0
- package/dist/components/Table/Table.js.map +1 -1
- package/dist/components/Tabs/Tabs.d.ts +14 -0
- package/dist/components/Tabs/Tabs.js +4 -4
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/TagInput/TagInput.d.ts +18 -0
- package/dist/components/TagInput/TagInput.js +5 -5
- package/dist/components/TagInput/TagInput.js.map +1 -1
- package/dist/components/Text/Text.d.ts +72 -0
- package/dist/components/Text/Text.js +30 -0
- package/dist/components/Text/Text.js.map +1 -0
- package/dist/components/Text/index.d.ts +1 -0
- package/dist/components/TextArea/TextArea.d.ts +10 -0
- package/dist/components/TextArea/TextArea.js +4 -4
- package/dist/components/TextArea/TextArea.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +13 -0
- package/dist/components/TextField/TextField.js +4 -4
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/components/ThemeToggle/ThemeToggle.d.ts +4 -0
- package/dist/components/ThemeToggle/ThemeToggle.js.map +1 -1
- package/dist/components/TimeField/TimeField.d.ts +62 -8
- package/dist/components/TimeField/TimeField.js +308 -72
- package/dist/components/TimeField/TimeField.js.map +1 -1
- package/dist/components/Toast/Toast.d.ts +25 -1
- package/dist/components/Toast/Toast.js +134 -125
- package/dist/components/Toast/Toast.js.map +1 -1
- package/dist/components/Toast/index.d.ts +1 -1
- package/dist/components/Toolbar/Toolbar.d.ts +3 -0
- package/dist/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/components/Tree/Tree.d.ts +8 -0
- package/dist/components/Tree/Tree.js.map +1 -1
- package/dist/components/VirtualList/VirtualList.d.ts +8 -0
- package/dist/components/VirtualList/VirtualList.js +4 -4
- package/dist/components/VirtualList/VirtualList.js.map +1 -1
- package/dist/components/ZoomControls/ZoomControls.d.ts +4 -0
- package/dist/components/ZoomControls/ZoomControls.js.map +1 -1
- package/dist/foundations/ChoiceBase/ChoiceBase.d.ts +1 -0
- package/dist/foundations/ChoiceBase/ChoiceBase.js.map +1 -1
- package/dist/foundations/HiddenValue/HiddenValue.d.ts +3 -0
- package/dist/foundations/HiddenValue/HiddenValue.js.map +1 -1
- package/dist/foundations/Icon/Icon.d.ts +3 -0
- package/dist/foundations/Icon/Icon.js.map +1 -1
- package/dist/foundations/image-outcome.d.ts +15 -0
- package/dist/foundations/image-outcome.js +39 -0
- package/dist/foundations/image-outcome.js.map +1 -0
- package/dist/foundations/option-icon.d.ts +26 -0
- package/dist/foundations/option-icon.js +16 -0
- package/dist/foundations/option-icon.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +476 -474
- package/dist/icons/keywords.d.ts +249 -0
- package/dist/icons/keywords.js +1728 -0
- package/dist/icons/keywords.js.map +1 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.js +240 -213
- package/dist/styles/app-shell.css +1 -1
- package/dist/styles/aspect-ratio.css +1 -0
- package/dist/styles/avatar.css +1 -0
- package/dist/styles/breadcrumbs.css +1 -0
- package/dist/styles/calendar.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/checklist.css +1 -0
- package/dist/styles/container.css +1 -0
- package/dist/styles/divider.css +1 -0
- package/dist/styles/generated-css.d.ts +1 -1
- package/dist/styles/generated-css.js +1 -1
- package/dist/styles/generated-css.js.map +1 -1
- package/dist/styles/grid.css +1 -1
- package/dist/styles/heading.css +1 -0
- package/dist/styles/image.css +1 -0
- package/dist/styles/menu.css +1 -1
- package/dist/styles/page-header.css +1 -0
- package/dist/styles/pagination.css +1 -0
- package/dist/styles/segmented-control.css +1 -1
- package/dist/styles/side-nav.css +1 -1
- package/dist/styles/stack.css +1 -1
- package/dist/styles/text.css +1 -0
- package/dist/styles/time-field.css +1 -1
- package/dist/styles/toast.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme/CynosureTheme.d.ts +4 -0
- package/dist/theme/CynosureTheme.js.map +1 -1
- package/dist/tokens/to-css.js +12 -12
- package/dist/tokens/to-css.js.map +1 -1
- package/package.json +4 -3
|
@@ -33,15 +33,21 @@ export interface SortableListLabels {
|
|
|
33
33
|
export interface SortableListProps {
|
|
34
34
|
/** Accessible name of the list. */
|
|
35
35
|
label: string;
|
|
36
|
+
/** Controlled items, in order: `{ id, label, content? }`. */
|
|
36
37
|
items?: SortableItem[] | undefined;
|
|
38
|
+
/** Starting items when uncontrolled. */
|
|
37
39
|
defaultItems?: SortableItem[];
|
|
38
40
|
/** Called with the items in their new order after a move is dropped. */
|
|
39
41
|
onReorder?: ((items: SortableItem[]) => void) | undefined;
|
|
42
|
+
/** Disables the handles, so nothing can be moved. */
|
|
40
43
|
disabled?: boolean;
|
|
41
44
|
/** `list` (rows, default) or `grid` (tiles that wrap: file grids, page thumbnails). */
|
|
42
45
|
layout?: "list" | "grid";
|
|
46
|
+
/** Text size of the rows. Default "md". */
|
|
43
47
|
size?: Size;
|
|
48
|
+
/** Replace the built-in English text: the handle name, the instructions and the announcements. */
|
|
44
49
|
labels?: Partial<SortableListLabels>;
|
|
50
|
+
/** Added to the root element, for layout. */
|
|
45
51
|
className?: string;
|
|
46
52
|
/** Layout only. Restyle through --cy-sortable-list-* tokens. */
|
|
47
53
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortableList.js","names":["sortable","useControllableState","useClientLayoutEffect","isRtl","IconButton","vt","grip","useId","useRef","useState","jsx","jsxs","DEFAULT_LABELS","label","p","n","moveItem","list","from","to","next","item","SortableList","items","defaultItems","onReorder","disabled","layout","size","labels","className","style","text","id","committed","setCommitted","preview","setPreviewState","moving","setMovingState","previewRef","movingRef","setPreview","setMoving","said","setSaid","shown","total","handleOf","itemId","start","drop","i","at","changed","cancel","columns","tiles","top","t","shift","delta","onKeyDown","event","active","across","row","move","latest","el","sorted","itemOf","node","bound","reduced","base","now","words","cancelled"],"sources":["../../../src/components/SortableList/SortableList.tsx"],"sourcesContent":["import { sortable } from \"@arshad-shah/detent\";\nimport { type CSSProperties, type KeyboardEvent, type ReactNode, useId, useRef, useState } from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { isRtl } from \"../../foundations/dir.js\";\nimport { grip } from \"../../icons/grip.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\n\nexport interface SortableListTokens {\n /** Background of a row. */\n itemBackground: string;\n /** Corner radius of a row. */\n radius: string;\n /** Smallest tile width in the grid layout. */\n tileMin: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n sortableList: SortableListTokens;\n }\n}\n\nexport interface SortableItem {\n id: string;\n /** Plain text: used in announcements and the handle's name. Shown when there is no `content`. */\n label: string;\n /** What the row shows, if more than the label. */\n content?: ReactNode;\n}\n\nexport interface SortableListLabels {\n /** Handle name. Default: \"Move Docs\". */\n handle: (label: string) => string;\n /** Read with every handle. */\n instructions: string;\n pickedUp: (label: string, position: number, total: number) => string;\n moved: (label: string, position: number, total: number) => string;\n dropped: (label: string, position: number, total: number) => string;\n cancelled: (label: string) => string;\n}\n\nexport interface SortableListProps {\n /** Accessible name of the list. */\n label: string;\n items?: SortableItem[] | undefined;\n defaultItems?: SortableItem[];\n /** Called with the items in their new order after a move is dropped. */\n onReorder?: ((items: SortableItem[]) => void) | undefined;\n disabled?: boolean;\n /** `list` (rows, default) or `grid` (tiles that wrap: file grids, page thumbnails). */\n layout?: \"list\" | \"grid\";\n size?: Size;\n labels?: Partial<SortableListLabels>;\n className?: string;\n /** Layout only. Restyle through --cy-sortable-list-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: SortableListLabels = {\n handle: (label) => `Move ${label}`,\n instructions: \"Press Space to pick up, the arrow keys to move, Space to drop, Escape to cancel.\",\n pickedUp: (label, p, n) => `${label} picked up. Position ${p} of ${n}.`,\n moved: (label, p, n) => `${label} moved to position ${p} of ${n}.`,\n dropped: (label, p, n) => `${label} dropped at position ${p} of ${n}.`,\n cancelled: (label) => `Move cancelled. ${label} is back where it was.`,\n};\n\nconst moveItem = <T,>(list: T[], from: number, to: number) => {\n const next = [...list];\n const [item] = next.splice(from, 1);\n next.splice(to, 0, item as T);\n return next;\n};\n\n/**\n * A list people put in order: drag a row by its handle (mouse, pen or touch), or focus the handle, press Space and\n * move it with the arrow keys. Every step is announced.\n */\nexport function SortableList({\n label,\n items,\n defaultItems = [],\n onReorder,\n disabled = false,\n layout = \"list\",\n size = \"md\",\n labels,\n className,\n style,\n}: SortableListProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const [committed, setCommitted] = useControllableState(items, defaultItems, onReorder);\n /**\n * While moving: the order being previewed, and the row being moved. Kept in refs too, so events that arrive before\n * React re-renders (a fast drag's move and release) always see the latest values.\n */\n type Moving = { id: string; by: \"keyboard\" | \"pointer\" };\n const [preview, setPreviewState] = useState<SortableItem[] | null>(null);\n const [moving, setMovingState] = useState<Moving | null>(null);\n const previewRef = useRef<SortableItem[] | null>(null);\n const movingRef = useRef<Moving | null>(null);\n const setPreview = (next: SortableItem[] | null) => {\n previewRef.current = next;\n setPreviewState(next);\n };\n const setMoving = (next: Moving | null) => {\n movingRef.current = next;\n setMovingState(next);\n };\n const [said, setSaid] = useState(\"\");\n const list = useRef<HTMLUListElement>(null);\n const shown = preview ?? committed;\n const total = shown.length;\n\n const handleOf = (itemId: string) =>\n list.current?.querySelector<HTMLButtonElement>(\n `[data-id=\"${CSS.escape(itemId)}\"] .cy-sortable-list-handle`,\n );\n\n const start = (item: SortableItem) => {\n setPreview(committed);\n setMoving({ id: item.id, by: \"keyboard\" });\n setSaid(text.pickedUp(item.label, committed.indexOf(item) + 1, committed.length));\n };\n // drop, cancel and shift run only while a row is moving (their callers check), so the refs are set.\n const drop = () => {\n const moving = movingRef.current as Moving;\n const preview = previewRef.current as SortableItem[];\n const item = preview.find((i) => i.id === moving.id) as SortableItem;\n const at = preview.indexOf(item);\n const changed = preview.some((i, n) => i.id !== committed[n]?.id);\n setSaid(text.dropped(item.label, at + 1, preview.length));\n if (changed) {\n setCommitted(preview);\n }\n setPreview(null);\n setMoving(null);\n };\n const cancel = () => {\n const moving = movingRef.current as Moving;\n const item = committed.find((i) => i.id === moving.id) as SortableItem;\n setSaid(text.cancelled(item.label));\n setPreview(null);\n setMoving(null);\n };\n /** Tiles in one row of the grid, measured from the layout (1 for a list). */\n const columns = () => {\n const tiles = [...(list.current as HTMLUListElement).children] as HTMLElement[];\n const top = tiles[0]?.offsetTop;\n const n = tiles.findIndex((t) => t.offsetTop !== top);\n return n < 0 ? tiles.length : n;\n };\n const shift = (delta: number) => {\n const moving = movingRef.current as Moving;\n const preview = previewRef.current as SortableItem[];\n const from = preview.findIndex((i) => i.id === moving.id);\n const to = Math.min(Math.max(from + delta, 0), preview.length - 1);\n if (to === from) return;\n setPreview(moveItem(preview, from, to));\n setSaid(text.moved((preview[from] as SortableItem).label, to + 1, preview.length));\n // The moved row's handle keeps focus as it changes place.\n requestAnimationFrame(() => handleOf(moving.id)?.focus());\n };\n\n // A disabled handle cannot be focused, so it never gets key presses.\n const onKeyDown = (item: SortableItem) => (event: KeyboardEvent<HTMLButtonElement>) => {\n const moving = movingRef.current;\n const active = moving?.id === item.id && moving.by === \"keyboard\";\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n if (active) drop();\n else if (!moving) start(item);\n return;\n }\n if (!active) return;\n // In a grid, Left and Right move one place (following the reading direction) and Up and Down a whole row.\n const across = isRtl(event.currentTarget) ? -1 : 1;\n const row = layout === \"grid\" ? columns() : 1;\n const moves: Record<string, () => void> = {\n ArrowUp: () => shift(-row),\n ArrowDown: () => shift(row),\n ...(layout === \"grid\" ? { ArrowLeft: () => shift(-across), ArrowRight: () => shift(across) } : {}),\n Home: () => shift(-total),\n End: () => shift(total),\n Escape: cancel,\n Tab: drop,\n };\n const move = moves[event.key];\n if (!move) return;\n if (event.key !== \"Tab\") event.preventDefault();\n move();\n };\n\n // Pointer, touch and pen dragging come from detent (one input path, FLIP animation, auto-scroll). Its own keyboard\n // mode stays off: Cynosure's keyboard mode above has labelled, overridable announcements inside the app.\n const latest = useRef({ committed, text, disabled });\n latest.current = { committed, text, disabled };\n useClientLayoutEffect(() => {\n const el = list.current as HTMLUListElement;\n let sorted = false;\n const itemOf = (node: HTMLElement) =>\n latest.current.committed.find((i) => i.id === node.dataset.id) as SortableItem;\n const bound = sortable(el, {\n handle: \".cy-sortable-list-handle\",\n direction: layout === \"grid\" ? \"grid\" : \"y\",\n keyboard: false,\n // The grip is a dedicated handle that never scrolls the page, so touch needs no press-and-hold.\n delay: 0,\n get animation() {\n const reduced = globalThis.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches;\n const base = Number.parseFloat(getComputedStyle(el).getPropertyValue(\"--cy-motion-slow\"));\n return reduced ? 0 : Number.isFinite(base) ? base : 180;\n },\n get disabled() {\n return latest.current.disabled;\n },\n onStart: (node, from) => {\n if (movingRef.current) return false;\n const item = itemOf(node);\n sorted = false;\n setMoving({ id: item.id, by: \"pointer\" });\n setSaid(latest.current.text.pickedUp(item.label, from.index + 1, latest.current.committed.length));\n },\n onSort: ({ item: node, from, to }) => {\n sorted = true;\n // Put the node back where React rendered it, then let React apply the new order: React stays the DOM's owner.\n node.remove();\n el.insertBefore(node, el.children[from.index] ?? null);\n const { committed: now, text: words } = latest.current;\n const next = moveItem(now, from.index, to.index);\n setSaid(words.dropped((now[from.index] as SortableItem).label, to.index + 1, next.length));\n setCommitted(next);\n },\n onEnd: (node, cancelled) => {\n const item = itemOf(node);\n setMoving(null);\n if (cancelled) setSaid(latest.current.text.cancelled(item.label));\n else if (!sorted) {\n const at = latest.current.committed.indexOf(item);\n setSaid(latest.current.text.dropped(item.label, at + 1, latest.current.committed.length));\n }\n },\n });\n return () => bound.destroy();\n }, [layout]);\n\n return (\n <div\n className={className ? `cy-sortable-list ${className}` : \"cy-sortable-list\"}\n data-size={size}\n data-layout={layout}\n style={style}\n >\n <ul ref={list} className=\"cy-sortable-list-items cy-reset\" aria-label={label}>\n {shown.map((item) => (\n <li\n key={item.id}\n data-id={item.id}\n className=\"cy-sortable-list-item cy-reset\"\n data-moving={moving?.id === item.id ? \"\" : undefined}\n >\n <IconButton\n icon={grip}\n label={text.handle(item.label)}\n variant=\"ghost\"\n tone=\"neutral\"\n size=\"sm\"\n disabled={disabled}\n className=\"cy-sortable-list-handle\"\n aria-describedby={`${id}-how`}\n aria-pressed={moving?.id === item.id}\n tooltipPlacement=\"start\"\n onKeyDown={onKeyDown(item)}\n />\n <div className=\"cy-sortable-list-content cy-reset\">{item.content ?? item.label}</div>\n </li>\n ))}\n </ul>\n <span id={`${id}-how`} className=\"cy-sortable-list-hidden cy-reset\">\n {text.instructions}\n </span>\n <span className=\"cy-sortable-list-hidden cy-reset\" role=\"status\">\n {said}\n </span>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AA4DA,IAAMY,KAAqC;AAAA,EACzC,QAAA,CAASC,MAAU,QAAQA,CAAA;AAAA,EAC3B,cAAc;AAAA,EACd,UAAA,CAAWA,GAAOC,GAAGC,MAAM,GAAGF,CAAA,wBAA6BC,CAAA,OAAQC,CAAA;AAAA,EACnE,OAAA,CAAQF,GAAOC,GAAGC,MAAM,GAAGF,CAAA,sBAA2BC,CAAA,OAAQC,CAAA;AAAA,EAC9D,SAAA,CAAUF,GAAOC,GAAGC,MAAM,GAAGF,CAAA,wBAA6BC,CAAA,OAAQC,CAAA;AAAA,EAClE,WAAA,CAAYF,MAAU,mBAAmBA,CAAA;AAC3C,GAEMG,IAAA,CAAgBC,GAAWC,GAAcC,MAAe;AAC5D,QAAMC,IA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,YAClC,kBAAiB;AAAA,YACjB,WAAWyC,EAAUzC,CAAI;AAAA,UAC1B,CAAA,GACD,gBAAAX,EAAC,OAAD;AAAA,YAAK,WAAU;AAAA,YAAqC,UAAAW,EAAK,WAAWA,EAAK;AAAA,UAAW,CAAA,CAClF;AAAA,QAnBG,GAAAA,EAAK,EAmBR,CACL;AAAA,MACC,CAAA;AAAA,MACJ,gBAAAX,EAAC,QAAD;AAAA,QAAM,IAAI,GAAGuB,CAAA;AAAA,QAAU,WAAU;AAAA,QAC9B,UAAAD,EAAK;AAAA,MACF,CAAA;AAAA,MACN,gBAAAtB,EAAC,QAAD;AAAA,QAAM,WAAU;AAAA,QAAmC,MAAK;AAAA,QACrD,UAAAkC;AAAA,MACG,CAAA;AAAA,IACH;AAAA,E;AAET"}
|
|
1
|
+
{"version":3,"file":"SortableList.js","names":["sortable","useControllableState","useClientLayoutEffect","isRtl","IconButton","vt","grip","useId","useRef","useState","jsx","jsxs","DEFAULT_LABELS","label","p","n","moveItem","list","from","to","next","item","SortableList","items","defaultItems","onReorder","disabled","layout","size","labels","className","style","text","id","committed","setCommitted","preview","setPreviewState","moving","setMovingState","previewRef","movingRef","setPreview","setMoving","said","setSaid","shown","total","handleOf","itemId","start","drop","i","at","changed","cancel","columns","tiles","top","t","shift","delta","onKeyDown","event","active","across","row","move","latest","el","sorted","itemOf","node","bound","reduced","base","now","words","cancelled"],"sources":["../../../src/components/SortableList/SortableList.tsx"],"sourcesContent":["import { sortable } from \"@arshad-shah/detent\";\nimport { type CSSProperties, type KeyboardEvent, type ReactNode, useId, useRef, useState } from \"react\";\nimport { useClientLayoutEffect } from \"../../foundations/client-layout-effect.js\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { isRtl } from \"../../foundations/dir.js\";\nimport { grip } from \"../../icons/grip.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { IconButton } from \"../IconButton/IconButton.js\";\n\nexport interface SortableListTokens {\n /** Background of a row. */\n itemBackground: string;\n /** Corner radius of a row. */\n radius: string;\n /** Smallest tile width in the grid layout. */\n tileMin: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n sortableList: SortableListTokens;\n }\n}\n\nexport interface SortableItem {\n id: string;\n /** Plain text: used in announcements and the handle's name. Shown when there is no `content`. */\n label: string;\n /** What the row shows, if more than the label. */\n content?: ReactNode;\n}\n\nexport interface SortableListLabels {\n /** Handle name. Default: \"Move Docs\". */\n handle: (label: string) => string;\n /** Read with every handle. */\n instructions: string;\n pickedUp: (label: string, position: number, total: number) => string;\n moved: (label: string, position: number, total: number) => string;\n dropped: (label: string, position: number, total: number) => string;\n cancelled: (label: string) => string;\n}\n\nexport interface SortableListProps {\n /** Accessible name of the list. */\n label: string;\n /** Controlled items, in order: `{ id, label, content? }`. */\n items?: SortableItem[] | undefined;\n /** Starting items when uncontrolled. */\n defaultItems?: SortableItem[];\n /** Called with the items in their new order after a move is dropped. */\n onReorder?: ((items: SortableItem[]) => void) | undefined;\n /** Disables the handles, so nothing can be moved. */\n disabled?: boolean;\n /** `list` (rows, default) or `grid` (tiles that wrap: file grids, page thumbnails). */\n layout?: \"list\" | \"grid\";\n /** Text size of the rows. Default \"md\". */\n size?: Size;\n /** Replace the built-in English text: the handle name, the instructions and the announcements. */\n labels?: Partial<SortableListLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-sortable-list-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: SortableListLabels = {\n handle: (label) => `Move ${label}`,\n instructions: \"Press Space to pick up, the arrow keys to move, Space to drop, Escape to cancel.\",\n pickedUp: (label, p, n) => `${label} picked up. Position ${p} of ${n}.`,\n moved: (label, p, n) => `${label} moved to position ${p} of ${n}.`,\n dropped: (label, p, n) => `${label} dropped at position ${p} of ${n}.`,\n cancelled: (label) => `Move cancelled. ${label} is back where it was.`,\n};\n\nconst moveItem = <T,>(list: T[], from: number, to: number) => {\n const next = [...list];\n const [item] = next.splice(from, 1);\n next.splice(to, 0, item as T);\n return next;\n};\n\n/**\n * A list people put in order: drag a row by its handle (mouse, pen or touch), or focus the handle, press Space and\n * move it with the arrow keys. Every step is announced.\n */\nexport function SortableList({\n label,\n items,\n defaultItems = [],\n onReorder,\n disabled = false,\n layout = \"list\",\n size = \"md\",\n labels,\n className,\n style,\n}: SortableListProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const [committed, setCommitted] = useControllableState(items, defaultItems, onReorder);\n /**\n * While moving: the order being previewed, and the row being moved. Kept in refs too, so events that arrive before\n * React re-renders (a fast drag's move and release) always see the latest values.\n */\n type Moving = { id: string; by: \"keyboard\" | \"pointer\" };\n const [preview, setPreviewState] = useState<SortableItem[] | null>(null);\n const [moving, setMovingState] = useState<Moving | null>(null);\n const previewRef = useRef<SortableItem[] | null>(null);\n const movingRef = useRef<Moving | null>(null);\n const setPreview = (next: SortableItem[] | null) => {\n previewRef.current = next;\n setPreviewState(next);\n };\n const setMoving = (next: Moving | null) => {\n movingRef.current = next;\n setMovingState(next);\n };\n const [said, setSaid] = useState(\"\");\n const list = useRef<HTMLUListElement>(null);\n const shown = preview ?? committed;\n const total = shown.length;\n\n const handleOf = (itemId: string) =>\n list.current?.querySelector<HTMLButtonElement>(\n `[data-id=\"${CSS.escape(itemId)}\"] .cy-sortable-list-handle`,\n );\n\n const start = (item: SortableItem) => {\n setPreview(committed);\n setMoving({ id: item.id, by: \"keyboard\" });\n setSaid(text.pickedUp(item.label, committed.indexOf(item) + 1, committed.length));\n };\n // drop, cancel and shift run only while a row is moving (their callers check), so the refs are set.\n const drop = () => {\n const moving = movingRef.current as Moving;\n const preview = previewRef.current as SortableItem[];\n const item = preview.find((i) => i.id === moving.id) as SortableItem;\n const at = preview.indexOf(item);\n const changed = preview.some((i, n) => i.id !== committed[n]?.id);\n setSaid(text.dropped(item.label, at + 1, preview.length));\n if (changed) {\n setCommitted(preview);\n }\n setPreview(null);\n setMoving(null);\n };\n const cancel = () => {\n const moving = movingRef.current as Moving;\n const item = committed.find((i) => i.id === moving.id) as SortableItem;\n setSaid(text.cancelled(item.label));\n setPreview(null);\n setMoving(null);\n };\n /** Tiles in one row of the grid, measured from the layout (1 for a list). */\n const columns = () => {\n const tiles = [...(list.current as HTMLUListElement).children] as HTMLElement[];\n const top = tiles[0]?.offsetTop;\n const n = tiles.findIndex((t) => t.offsetTop !== top);\n return n < 0 ? tiles.length : n;\n };\n const shift = (delta: number) => {\n const moving = movingRef.current as Moving;\n const preview = previewRef.current as SortableItem[];\n const from = preview.findIndex((i) => i.id === moving.id);\n const to = Math.min(Math.max(from + delta, 0), preview.length - 1);\n if (to === from) return;\n setPreview(moveItem(preview, from, to));\n setSaid(text.moved((preview[from] as SortableItem).label, to + 1, preview.length));\n // The moved row's handle keeps focus as it changes place.\n requestAnimationFrame(() => handleOf(moving.id)?.focus());\n };\n\n // A disabled handle cannot be focused, so it never gets key presses.\n const onKeyDown = (item: SortableItem) => (event: KeyboardEvent<HTMLButtonElement>) => {\n const moving = movingRef.current;\n const active = moving?.id === item.id && moving.by === \"keyboard\";\n if (event.key === \" \" || event.key === \"Enter\") {\n event.preventDefault();\n if (active) drop();\n else if (!moving) start(item);\n return;\n }\n if (!active) return;\n // In a grid, Left and Right move one place (following the reading direction) and Up and Down a whole row.\n const across = isRtl(event.currentTarget) ? -1 : 1;\n const row = layout === \"grid\" ? columns() : 1;\n const moves: Record<string, () => void> = {\n ArrowUp: () => shift(-row),\n ArrowDown: () => shift(row),\n ...(layout === \"grid\" ? { ArrowLeft: () => shift(-across), ArrowRight: () => shift(across) } : {}),\n Home: () => shift(-total),\n End: () => shift(total),\n Escape: cancel,\n Tab: drop,\n };\n const move = moves[event.key];\n if (!move) return;\n if (event.key !== \"Tab\") event.preventDefault();\n move();\n };\n\n // Pointer, touch and pen dragging come from detent (one input path, FLIP animation, auto-scroll). Its own keyboard\n // mode stays off: Cynosure's keyboard mode above has labelled, overridable announcements inside the app.\n const latest = useRef({ committed, text, disabled });\n latest.current = { committed, text, disabled };\n useClientLayoutEffect(() => {\n const el = list.current as HTMLUListElement;\n let sorted = false;\n const itemOf = (node: HTMLElement) =>\n latest.current.committed.find((i) => i.id === node.dataset.id) as SortableItem;\n const bound = sortable(el, {\n handle: \".cy-sortable-list-handle\",\n direction: layout === \"grid\" ? \"grid\" : \"y\",\n keyboard: false,\n // The grip is a dedicated handle that never scrolls the page, so touch needs no press-and-hold.\n delay: 0,\n get animation() {\n const reduced = globalThis.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches;\n const base = Number.parseFloat(getComputedStyle(el).getPropertyValue(\"--cy-motion-slow\"));\n return reduced ? 0 : Number.isFinite(base) ? base : 180;\n },\n get disabled() {\n return latest.current.disabled;\n },\n onStart: (node, from) => {\n if (movingRef.current) return false;\n const item = itemOf(node);\n sorted = false;\n setMoving({ id: item.id, by: \"pointer\" });\n setSaid(latest.current.text.pickedUp(item.label, from.index + 1, latest.current.committed.length));\n },\n onSort: ({ item: node, from, to }) => {\n sorted = true;\n // Put the node back where React rendered it, then let React apply the new order: React stays the DOM's owner.\n node.remove();\n el.insertBefore(node, el.children[from.index] ?? null);\n const { committed: now, text: words } = latest.current;\n const next = moveItem(now, from.index, to.index);\n setSaid(words.dropped((now[from.index] as SortableItem).label, to.index + 1, next.length));\n setCommitted(next);\n },\n onEnd: (node, cancelled) => {\n const item = itemOf(node);\n setMoving(null);\n if (cancelled) setSaid(latest.current.text.cancelled(item.label));\n else if (!sorted) {\n const at = latest.current.committed.indexOf(item);\n setSaid(latest.current.text.dropped(item.label, at + 1, latest.current.committed.length));\n }\n },\n });\n return () => bound.destroy();\n }, [layout]);\n\n return (\n <div\n className={className ? `cy-sortable-list ${className}` : \"cy-sortable-list\"}\n data-size={size}\n data-layout={layout}\n style={style}\n >\n <ul ref={list} className=\"cy-sortable-list-items cy-reset\" aria-label={label}>\n {shown.map((item) => (\n <li\n key={item.id}\n data-id={item.id}\n className=\"cy-sortable-list-item cy-reset\"\n data-moving={moving?.id === item.id ? \"\" : undefined}\n >\n <IconButton\n icon={grip}\n label={text.handle(item.label)}\n variant=\"ghost\"\n tone=\"neutral\"\n size=\"sm\"\n disabled={disabled}\n className=\"cy-sortable-list-handle\"\n aria-describedby={`${id}-how`}\n aria-pressed={moving?.id === item.id}\n tooltipPlacement=\"start\"\n onKeyDown={onKeyDown(item)}\n />\n <div className=\"cy-sortable-list-content cy-reset\">{item.content ?? item.label}</div>\n </li>\n ))}\n </ul>\n <span id={`${id}-how`} className=\"cy-sortable-list-hidden cy-reset\">\n {text.instructions}\n </span>\n <span className=\"cy-sortable-list-hidden cy-reset\" role=\"status\">\n {said}\n </span>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAkEA,IAAMY,KAAqC;AAAA,EACzC,QAAA,CAASC,MAAU,QAAQA,CAAA;AAAA,EAC3B,cAAc;AAAA,EACd,UAAA,CAAWA,GAAOC,GAAGC,MAAM,GAAGF,CAAA,wBAA6BC,CAAA,OAAQC,CAAA;AAAA,EACnE,OAAA,CAAQF,GAAOC,GAAGC,MAAM,GAAGF,CAAA,sBAA2BC,CAAA,OAAQC,CAAA;AAAA,EAC9D,SAAA,CAAUF,GAAOC,GAAGC,MAAM,GAAGF,CAAA,wBAA6BC,CAAA,OAAQC,CAAA;AAAA,EAClE,WAAA,CAAYF,MAAU,mBAAmBA,CAAA;AAC3C,GAEMG,IAAA,CAAgBC,GAAWC,GAAcC,MAAe;AAC5D,QAAMC,IAAO,CAAC,GAAGH,CAAI,GACf,CAACI,CAAA,IAAQD,EAAK,OAAOF,GAAM,CAAC;AAClC,SAAAE,EAAK,OAAOD,GAAI,GAAGE,CAAS,GACrBD;AACT;AAMA,SAAgBE,GAAa,EAC3B,OAAAT,GACA,OAAAU,GACA,cAAAC,IAAe,CAAC,GAChB,WAAAC,GACA,UAAAC,IAAW,IACX,QAAAC,IAAS,QACT,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACoB;AACpB,QAAMC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UAAAD,EAAK;AAAA,MACF,CAAA;AAAA,MACN,gBAAAtB,EAAC,QAAD;AAAA,QAAM,WAAU;AAAA,QAAmC,MAAK;AAAA,QACrD,UAAAkC;AAAA,MACG,CAAA;AAAA,IACH;AAAA,E;AAET"}
|
|
@@ -13,6 +13,7 @@ declare module "../../tokens/schema.js" {
|
|
|
13
13
|
export interface SplitPaneProps {
|
|
14
14
|
/** The first pane (left, or right in right-to-left text; top when vertical). Its size is what the divider sets. */
|
|
15
15
|
start: ReactNode;
|
|
16
|
+
/** The second pane (right, or left in right-to-left text; bottom when vertical). */
|
|
16
17
|
end: ReactNode;
|
|
17
18
|
/** Accessible name of the divider, e.g. "Resize the file list". */
|
|
18
19
|
label: string;
|
|
@@ -25,15 +26,19 @@ export interface SplitPaneProps {
|
|
|
25
26
|
unit?: "percent" | "px";
|
|
26
27
|
/** Size of the start pane, in `unit`. */
|
|
27
28
|
size?: number | undefined;
|
|
29
|
+
/** Starting size of the start pane when uncontrolled, in `unit`. Default 50 percent, or 240 pixels. */
|
|
28
30
|
defaultSize?: number | undefined;
|
|
31
|
+
/** Called with the new size as the divider moves. */
|
|
29
32
|
onSizeChange?: ((size: number) => void) | undefined;
|
|
30
33
|
/** Limits for the start pane, in `unit`. Defaults: 10 and 90 percent, or 120 and 600 pixels. */
|
|
31
34
|
min?: number;
|
|
35
|
+
/** Largest size of the start pane, in `unit`. Default 90 percent, or 600 pixels. */
|
|
32
36
|
max?: number;
|
|
33
37
|
/** Arrow keys move by this much, in `unit`. Default 5 percent, or 16 pixels. */
|
|
34
38
|
step?: number;
|
|
35
39
|
/** Enter collapses the start pane to 0 and restores it. */
|
|
36
40
|
collapsible?: boolean;
|
|
41
|
+
/** Added to the root element, for layout. */
|
|
37
42
|
className?: string;
|
|
38
43
|
/** Layout only. Restyle through --cy-split-pane-* tokens. */
|
|
39
44
|
style?: CSSProperties;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { useControllableState as F } from "../../foundations/controllable.js";
|
|
3
3
|
import { isRtl as D } from "../../foundations/dir.js";
|
|
4
4
|
import { clamp as T } from "../../foundations/math.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { stepKey as q } from "../../foundations/keys.js";
|
|
6
|
+
import { useDrag as G } from "../../foundations/drag.js";
|
|
7
7
|
import { useId as H, useRef as c, useState as J } from "react";
|
|
8
8
|
import { jsx as f, jsxs as L } from "react/jsx-runtime";
|
|
9
9
|
var O = (l) => Math.round(l * 10) / 10;
|
|
@@ -15,7 +15,7 @@ function tt({ start: l, end: M, label: b, orientation: v = "horizontal", unit: z
|
|
|
15
15
|
const e = p.current.getBoundingClientRect(), a = !s && D(p.current), o = s ? t.y - e.top : a ? e.right - t.x : t.x - e.left;
|
|
16
16
|
i(n ? o : ((s ? o / e.height : o / e.width) || 0) * 100);
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
G(m, {
|
|
19
19
|
onStart: () => {
|
|
20
20
|
S.current = r, m.current?.focus({ preventScroll: !0 }), h(!0);
|
|
21
21
|
},
|
|
@@ -25,7 +25,7 @@ function tt({ start: l, end: M, label: b, orientation: v = "horizontal", unit: z
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
const B = (t) => {
|
|
28
|
-
const e =
|
|
28
|
+
const e = q(t, {
|
|
29
29
|
value: r,
|
|
30
30
|
min: u,
|
|
31
31
|
max: d,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SplitPane.js","names":["useControllableState","isRtl","clamp","
|
|
1
|
+
{"version":3,"file":"SplitPane.js","names":["useControllableState","isRtl","clamp","stepKey","useDrag","useId","useRef","useState","jsx","jsxs","round","n","SplitPane","start","end","label","orientation","unit","size","defaultSize","onSizeChange","minProp","maxProp","stepProp","collapsible","className","style","px","min","max","step","id","root","dragging","setDragging","restore","divider","dragFrom","initial","current","setCurrent","vertical","set","next","allowCollapse","value","fromPoint","point","box","rtl","offset","_","cancelled","onKeyDown","event","target","moves","move"],"sources":["../../../src/components/SplitPane/SplitPane.tsx"],"sourcesContent":["import { type CSSProperties, type KeyboardEvent, type ReactNode, useId, useRef, useState } from \"react\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { isRtl } from \"../../foundations/dir.js\";\nimport { useDrag } from \"../../foundations/drag.js\";\nimport { stepKey } from \"../../foundations/keys.js\";\nimport { clamp } from \"../../foundations/math.js\";\n\nexport interface SplitPaneTokens {\n /** Thickness of the visible divider line. */\n dividerSize: string;\n /** Divider colour (the accent shows while dragging or focused). */\n divider: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n splitPane: SplitPaneTokens;\n }\n}\n\nexport interface SplitPaneProps {\n /** The first pane (left, or right in right-to-left text; top when vertical). Its size is what the divider sets. */\n start: ReactNode;\n /** The second pane (right, or left in right-to-left text; bottom when vertical). */\n end: ReactNode;\n /** Accessible name of the divider, e.g. \"Resize the file list\". */\n label: string;\n /** `horizontal`: panes side by side. `vertical`: stacked. */\n orientation?: \"horizontal\" | \"vertical\";\n /**\n * `percent` (default): sizes are percent of the whole. `px`: the start pane has a fixed width (or height) in pixels,\n * such as a sidebar that keeps its size as the window grows.\n */\n unit?: \"percent\" | \"px\";\n /** Size of the start pane, in `unit`. */\n size?: number | undefined;\n /** Starting size of the start pane when uncontrolled, in `unit`. Default 50 percent, or 240 pixels. */\n defaultSize?: number | undefined;\n /** Called with the new size as the divider moves. */\n onSizeChange?: ((size: number) => void) | undefined;\n /** Limits for the start pane, in `unit`. Defaults: 10 and 90 percent, or 120 and 600 pixels. */\n min?: number;\n /** Largest size of the start pane, in `unit`. Default 90 percent, or 600 pixels. */\n max?: number;\n /** Arrow keys move by this much, in `unit`. Default 5 percent, or 16 pixels. */\n step?: number;\n /** Enter collapses the start pane to 0 and restores it. */\n collapsible?: boolean;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-split-pane-* tokens. */\n style?: CSSProperties;\n}\n\nconst round = (n: number) => Math.round(n * 10) / 10;\n\n/**\n * Two panes with a divider people can move: drag it (mouse, pen or touch), or focus it and use the arrow keys. An APG\n * window splitter: the divider is a focusable separator whose value is the start pane's size in percent.\n */\nexport function SplitPane({\n start,\n end,\n label,\n orientation = \"horizontal\",\n unit = \"percent\",\n size,\n defaultSize,\n onSizeChange,\n min: minProp,\n max: maxProp,\n step: stepProp,\n collapsible = false,\n className,\n style,\n}: SplitPaneProps) {\n const px = unit === \"px\";\n const min = minProp ?? (px ? 120 : 10);\n const max = maxProp ?? (px ? 600 : 90);\n const step = stepProp ?? (px ? 16 : 5);\n const id = useId();\n const root = useRef<HTMLDivElement>(null);\n const [dragging, setDragging] = useState(false);\n const restore = useRef<number | null>(null);\n const divider = useRef<HTMLDivElement>(null);\n const dragFrom = useRef(0);\n const initial = defaultSize ?? (px ? 240 : 50);\n const [current, setCurrent] = useControllableState(size, initial, onSizeChange);\n const vertical = orientation === \"vertical\";\n\n const set = (next: number, allowCollapse = false) => {\n const value = round(allowCollapse && next === 0 ? 0 : clamp(next, min, max));\n if (value !== current) setCurrent(value);\n };\n\n const fromPoint = (point: { x: number; y: number }) => {\n const box = (root.current as HTMLDivElement).getBoundingClientRect();\n const rtl = !vertical && isRtl(root.current as HTMLDivElement);\n const offset = vertical ? point.y - box.top : rtl ? box.right - point.x : point.x - box.left;\n set(px ? offset : ((vertical ? offset / box.height : offset / box.width) || 0) * 100);\n };\n // Dragging the divider through detent; Escape puts it back where the drag began.\n useDrag(divider, {\n onStart: () => {\n dragFrom.current = current;\n divider.current?.focus({ preventScroll: true });\n setDragging(true);\n },\n onMove: ({ point }) => fromPoint(point),\n onEnd: (_, cancelled) => {\n if (cancelled) set(dragFrom.current, true);\n setDragging(false);\n },\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLElement>) => {\n const target = stepKey(event, {\n value: current,\n min,\n max,\n step,\n axis: vertical ? \"y\" : \"x\",\n rtl: isRtl(event.currentTarget),\n downAdds: true,\n });\n const moves: Record<string, () => void> = {};\n if (target !== undefined) moves[event.key] = () => set(target);\n if (collapsible)\n moves.Enter = () => {\n if (current === 0) set(restore.current ?? initial);\n else {\n restore.current = current;\n set(0, true);\n }\n };\n const move = moves[event.key];\n if (!move) return;\n event.preventDefault();\n move();\n };\n\n return (\n <div\n ref={root}\n className={className ? `cy-split-pane ${className}` : \"cy-split-pane\"}\n data-orientation={orientation}\n data-dragging={dragging ? \"\" : undefined}\n style={{ \"--_size\": px ? `${current}px` : `${current}%`, ...style } as CSSProperties}\n >\n <div\n id={`${id}-start`}\n className=\"cy-split-pane-pane cy-reset\"\n data-pane=\"start\"\n data-collapsed={current === 0 ? \"\" : undefined}\n >\n {start}\n </div>\n {/* biome-ignore lint/a11y/useSemanticElements: an APG window splitter is a focusable separator; <hr> cannot take focus or a value */}\n <div\n role=\"separator\"\n tabIndex={0}\n aria-label={label}\n aria-controls={`${id}-start`}\n aria-orientation={vertical ? \"horizontal\" : \"vertical\"}\n aria-valuenow={current}\n aria-valuemin={collapsible ? 0 : min}\n aria-valuemax={max}\n aria-valuetext={px ? `${Math.round(current)} pixels` : `${Math.round(current)}%`}\n ref={divider}\n className=\"cy-split-pane-divider cy-reset\"\n onKeyDown={onKeyDown}\n />\n <div className=\"cy-split-pane-pane cy-reset\" data-pane=\"end\">\n {end}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;AAsDA,IAAMU,IAAA,CAASC,MAAc,KAAK,MAAMA,IAAI,EAAE,IAAI;AAMlD,SAAgBC,GAAU,EACxB,OAAAC,GACA,KAAAC,GACA,OAAAC,GACA,aAAAC,IAAc,cACd,MAAAC,IAAO,WACP,MAAAC,GACA,aAAAC,GACA,cAAAC,GACA,KAAKC,GACL,KAAKC,GACL,MAAMC,GACN,aAAAC,IAAc,IACd,WAAAC,GACA,OAAAC,EAAA,GACiB;AACjB,QAAMC,IAAKV,MAAS,MACdW,IAAMP,MAAYM,IAAK,MAAM,KAC7BE,IAAMP,MAAYK,IAAK,MAAM,KAC7BG,IAAOP,MAAaI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AeC;AAAA,QACf,kBAAgBF,IAAK,GAAG,KAAK,MAAMY,CAAO,CAAA,YAAa,GAAG,KAAK,MAAMA,CAAO,CAAA;AAAA,QAC5E,KAAKH;AAAA,QACL,WAAU;AAAA,QACC,WAAAiB;AAAA,MACZ,CAAA;AAAA,MACD,gBAAA7C,EAAC,OAAD;AAAA,QAAK,WAAU;AAAA,QAA8B,aAAU;AAAA,QACpD,UAAAM;AAAA,MACE,CAAA;AAAA,IACF;AAAA,E;AAET"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
export interface StackProps {
|
|
2
|
+
import { type PaddingProps, type Space } from "./space.js";
|
|
3
|
+
export interface StackProps extends PaddingProps {
|
|
4
4
|
/** Space token between children. */
|
|
5
5
|
gap?: Space;
|
|
6
|
+
/** How children line up across the stack (horizontally). */
|
|
6
7
|
align?: "start" | "center" | "end" | "stretch";
|
|
8
|
+
/** How children are spread along the stack (vertically); `between` pushes them apart. */
|
|
7
9
|
justify?: "start" | "center" | "end" | "between";
|
|
8
10
|
/** Neutral layout element to render (never an interactive one). */
|
|
9
11
|
as?: "div" | "section" | "ul" | "ol" | "nav" | "aside" | "header" | "footer" | "span";
|
|
12
|
+
/** Added to the root element, for layout. */
|
|
10
13
|
className?: string;
|
|
11
14
|
/** Layout only. */
|
|
12
15
|
style?: CSSProperties;
|
|
16
|
+
/** The items to stack. */
|
|
13
17
|
children?: ReactNode;
|
|
18
|
+
/** Passed to the root element, for tests. */
|
|
14
19
|
"data-testid"?: string;
|
|
15
20
|
}
|
|
16
21
|
/** Vertical layout with token gaps. */
|
|
17
22
|
export declare const Stack: import("react").ForwardRefExoticComponent<StackProps & import("react").RefAttributes<HTMLElement>>;
|
|
18
|
-
export {};
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { paddingVars as n, space as u } from "./space.js";
|
|
3
|
+
import { forwardRef as g } from "react";
|
|
4
|
+
import { jsx as k } from "react/jsx-runtime";
|
|
5
|
+
var x = g(function({ gap: t = "4", padding: r, paddingInline: i, paddingBlock: o, align: c, justify: e, as: f = "div", className: a, style: p, children: s, ...d }, m) {
|
|
6
|
+
return /* @__PURE__ */ k(f, {
|
|
7
|
+
ref: m,
|
|
8
|
+
...d,
|
|
8
9
|
className: `cy-stack${a ? ` ${a}` : ""}`,
|
|
9
|
-
"data-align":
|
|
10
|
-
"data-justify":
|
|
10
|
+
"data-align": c,
|
|
11
|
+
"data-justify": e,
|
|
11
12
|
style: {
|
|
12
|
-
"--_gap":
|
|
13
|
-
...
|
|
13
|
+
"--_gap": u(t),
|
|
14
|
+
...n({
|
|
15
|
+
padding: r,
|
|
16
|
+
paddingInline: i,
|
|
17
|
+
paddingBlock: o
|
|
18
|
+
}),
|
|
19
|
+
...p
|
|
14
20
|
},
|
|
15
|
-
children:
|
|
21
|
+
children: s
|
|
16
22
|
});
|
|
17
23
|
});
|
|
18
24
|
export {
|
|
19
|
-
|
|
25
|
+
x as Stack
|
|
20
26
|
};
|
|
21
27
|
|
|
22
28
|
//# sourceMappingURL=Stack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stack.js","names":["Tag","forwardRef","jsx","Stack","gap","align","justify","as","className","style","children","rest","ref"],"sources":["../../../src/components/Stack/Stack.tsx"],"sourcesContent":["import { type CSSProperties, type ElementType, forwardRef, type ReactNode } from \"react\";\
|
|
1
|
+
{"version":3,"file":"Stack.js","names":["Tag","paddingVars","space","forwardRef","jsx","Stack","gap","padding","paddingInline","paddingBlock","align","justify","as","className","style","children","rest","ref"],"sources":["../../../src/components/Stack/Stack.tsx"],"sourcesContent":["import { type CSSProperties, type ElementType, forwardRef, type ReactNode } from \"react\";\nimport { type PaddingProps, paddingVars, type Space, space } from \"./space.js\";\n\nexport interface StackProps extends PaddingProps {\n /** Space token between children. */\n gap?: Space;\n /** How children line up across the stack (horizontally). */\n align?: \"start\" | \"center\" | \"end\" | \"stretch\";\n /** How children are spread along the stack (vertically); `between` pushes them apart. */\n justify?: \"start\" | \"center\" | \"end\" | \"between\";\n\n /** Neutral layout element to render (never an interactive one). */\n as?: \"div\" | \"section\" | \"ul\" | \"ol\" | \"nav\" | \"aside\" | \"header\" | \"footer\" | \"span\";\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. */\n style?: CSSProperties;\n /** The items to stack. */\n children?: ReactNode;\n /** Passed to the root element, for tests. */\n \"data-testid\"?: string;\n}\n\n/** Vertical layout with token gaps. */\nexport const Stack = forwardRef<HTMLElement, StackProps>(function Stack(\n {\n gap = \"4\",\n padding,\n paddingInline,\n paddingBlock,\n align,\n justify,\n as = \"div\",\n className,\n style,\n children,\n ...rest\n },\n ref,\n) {\n const Tag = as as ElementType;\n return (\n <Tag\n ref={ref}\n {...rest}\n className={`cy-stack${className ? ` ${className}` : \"\"}`}\n data-align={align}\n data-justify={justify}\n style={\n {\n \"--_gap\": space(gap),\n ...paddingVars({ padding, paddingInline, paddingBlock }),\n ...style,\n } as CSSProperties\n }\n >\n {children}\n </Tag>\n );\n});\n"],"mappings":";;;;AAwBA,IAAaK,IAAQF,EAAoC,SACvD,EACE,KAAAG,IAAM,KACN,SAAAC,GACA,eAAAC,GACA,cAAAC,GACA,OAAAC,GACA,SAAAC,GACA,IAAAC,IAAK,OACL,WAAAC,GACA,OAAAC,GACA,UAAAC,GACA,GAAGC,EAAA,GAELC,GACA;AAEA,SACE,gBAAAb,EAACJ,GAAD;AAAA,IACO,KAAAiB;AAAA,IACL,GAAID;AAAA,IACJ,WAAW,WAAWH,IAAY,IAAIA,CAAA,KAAc,EAAA;AAAA,IACpD,cAAYH;AAAA,IACZ,gBAAcC;AAAA,IACd,OACE;AAAA,MACE,UAAUT,EAAMI,CAAG;AAAA,MACnB,GAAGL,EAAY;AAAA,QAAE,SAAAM;AAAA,QAAS,eAAAC;AAAA,QAAe,cAAAC;AAAA,MAAa,CAAC;AAAA,MACvD,GAAGK;AAAA,IACL;AAAA,IAGD,UAAAC;AAAA,EACE,CAAA;AAET,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** A step of the theme's space scale (`--cy-space-0` … `--cy-space-10`). */
|
|
2
|
+
export type Space = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10";
|
|
3
|
+
/** The padding props shared by the layout primitives (Stack, Inline, Grid). */
|
|
4
|
+
export interface PaddingProps {
|
|
5
|
+
/** Space token of padding on all four sides of the box. Default: none. */
|
|
6
|
+
padding?: Space | undefined;
|
|
7
|
+
/** Space token of padding at the inline start and end (left and right in English). Wins over `padding`. */
|
|
8
|
+
paddingInline?: Space | undefined;
|
|
9
|
+
/** Space token of padding at the block start and end (top and bottom in English). Wins over `padding`. */
|
|
10
|
+
paddingBlock?: Space | undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The space token a key stands for, as a CSS value. */
|
|
13
|
+
export declare const space: (key: Space) => string;
|
|
14
|
+
/**
|
|
15
|
+
* The private custom properties the layout CSS reads its padding from, for the sides that are set. Sides that are
|
|
16
|
+
* not set are left out: the stylesheet resets them to zero on every root, so a nested layout never inherits them.
|
|
17
|
+
*/
|
|
18
|
+
export declare function paddingVars({ padding, paddingInline, paddingBlock }: PaddingProps): Record<string, string>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var s = (r) => `var(--cy-space-${r})`;
|
|
3
|
+
function t({ padding: r, paddingInline: c = r, paddingBlock: e = r }) {
|
|
4
|
+
const a = {};
|
|
5
|
+
return c && (a["--_pad-inline"] = s(c)), e && (a["--_pad-block"] = s(e)), a;
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
t as paddingVars,
|
|
9
|
+
s as space
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=space.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space.js","names":["space","key","paddingVars","padding","paddingInline","paddingBlock","vars"],"sources":["../../../src/components/Stack/space.ts"],"sourcesContent":["/** A step of the theme's space scale (`--cy-space-0` … `--cy-space-10`). */\nexport type Space = \"0\" | \"1\" | \"2\" | \"3\" | \"4\" | \"5\" | \"6\" | \"7\" | \"8\" | \"9\" | \"10\";\n\n/** The padding props shared by the layout primitives (Stack, Inline, Grid). */\nexport interface PaddingProps {\n /** Space token of padding on all four sides of the box. Default: none. */\n padding?: Space | undefined;\n /** Space token of padding at the inline start and end (left and right in English). Wins over `padding`. */\n paddingInline?: Space | undefined;\n /** Space token of padding at the block start and end (top and bottom in English). Wins over `padding`. */\n paddingBlock?: Space | undefined;\n}\n\n/** The space token a key stands for, as a CSS value. */\nexport const space = (key: Space) => `var(--cy-space-${key})`;\n\n/**\n * The private custom properties the layout CSS reads its padding from, for the sides that are set. Sides that are\n * not set are left out: the stylesheet resets them to zero on every root, so a nested layout never inherits them.\n */\nexport function paddingVars({ padding, paddingInline = padding, paddingBlock = padding }: PaddingProps) {\n const vars: Record<string, string> = {};\n if (paddingInline) vars[\"--_pad-inline\"] = space(paddingInline);\n if (paddingBlock) vars[\"--_pad-block\"] = space(paddingBlock);\n return vars;\n}\n"],"mappings":";AAcA,IAAaA,IAAA,CAASC,MAAe,kBAAkBA,CAAA;AAMvD,SAAgBC,EAAY,EAAE,SAAAC,GAAS,eAAAC,IAAgBD,GAAS,cAAAE,IAAeF,EAAA,GAAyB;AACtG,QAAMG,IAA+B,CAAC;AACtC,SAAIF,MAAeE,EAAK,eAAA,IAAmBN,EAAMI,CAAa,IAC1DC,MAAcC,EAAK,cAAA,IAAkBN,EAAMK,CAAY,IACpDC;AACT"}
|
|
@@ -34,15 +34,19 @@ export interface StepsLabels {
|
|
|
34
34
|
error: string;
|
|
35
35
|
}
|
|
36
36
|
export interface StepsProps {
|
|
37
|
+
/** The steps, in order. */
|
|
37
38
|
steps: StepItem[];
|
|
38
39
|
/** `id` of the step the person is on. Steps before it are complete, steps after it upcoming. */
|
|
39
40
|
current: string;
|
|
41
|
+
/** Lays the steps out in a row or in a column. Default "horizontal". */
|
|
40
42
|
orientation?: "horizontal" | "vertical";
|
|
41
43
|
/** Makes steps buttons that go to that step. Leave it out for a read-only progress display. */
|
|
42
44
|
onStepSelect?: (id: string) => void;
|
|
43
45
|
/** Text size of labels and markers. */
|
|
44
46
|
size?: Size;
|
|
47
|
+
/** Replace the built-in English text: the list's name and the status read after each step. */
|
|
45
48
|
labels?: Partial<StepsLabels>;
|
|
49
|
+
/** Added to the root element, for layout. */
|
|
46
50
|
className?: string;
|
|
47
51
|
/** Layout only. Restyle through --cy-steps-* tokens. */
|
|
48
52
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Steps.js","names":["_Fragment","ButtonBase","Icon","check","alert","Fragment","jsx","jsxs","DEFAULT_LABELS","Steps","steps","current","orientation","onStepSelect","size","labels","className","style","text","at","s","step","i","status","isCurrent","content"],"sources":["../../../src/components/Steps/Steps.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from \"react\";\nimport { ButtonBase } from \"../../foundations/ButtonBase/ButtonBase.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { alert } from \"../../icons/alert.js\";\nimport { check } from \"../../icons/check.js\";\nimport type { Size } from \"../../tokens/schema.js\";\n\nexport interface StepsTokens {\n /** Diameter of the numbered marker. */\n markerSize: string;\n /** Thickness of the line between steps. */\n lineWidth: string;\n /** Space between steps. */\n gap: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n steps: StepsTokens;\n }\n}\n\nexport type StepStatus = \"complete\" | \"current\" | \"upcoming\" | \"error\";\n\nexport interface StepItem {\n id: string;\n label: ReactNode;\n /** A second line under the label. */\n description?: ReactNode;\n /** Overrides the status worked out from `current`: mark a step `error`, or `complete` out of order. */\n status?: \"complete\" | \"error\" | undefined;\n /** With `onStepSelect`: this step cannot be chosen. */\n disabled?: boolean;\n}\n\nexport interface StepsLabels {\n /** Accessible name of the list. Default: \"Progress\". */\n list: string;\n /** Read after each step's label. Defaults: \"completed\", \"current step\", \"not started\", \"has a problem\". */\n complete: string;\n current: string;\n upcoming: string;\n error: string;\n}\n\nexport interface StepsProps {\n steps: StepItem[];\n /** `id` of the step the person is on. Steps before it are complete, steps after it upcoming. */\n current: string;\n orientation?: \"horizontal\" | \"vertical\";\n /** Makes steps buttons that go to that step. Leave it out for a read-only progress display. */\n onStepSelect?: (id: string) => void;\n /** Text size of labels and markers. */\n size?: Size;\n labels?: Partial<StepsLabels>;\n className?: string;\n /** Layout only. Restyle through --cy-steps-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: StepsLabels = {\n list: \"Progress\",\n complete: \"completed\",\n current: \"current step\",\n upcoming: \"not started\",\n error: \"has a problem\",\n};\n\n/** Progress through an ordered flow (a setup wizard, a checkout): numbered steps with the current one marked. */\nexport function Steps({\n steps,\n current,\n orientation = \"horizontal\",\n onStepSelect,\n size = \"md\",\n labels,\n className,\n style,\n}: StepsProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const at = steps.findIndex((s) => s.id === current);\n return (\n <ol\n className={className ? `cy-steps ${className}` : \"cy-steps\"}\n aria-label={text.list}\n data-orientation={orientation}\n data-size={size}\n style={style}\n >\n {steps.map((step, i) => {\n const status: StepStatus =\n step.status ?? (i === at ? \"current\" : at >= 0 && i < at ? \"complete\" : \"upcoming\");\n const isCurrent = i === at;\n const content = (\n <>\n <span className=\"cy-steps-marker cy-reset\" aria-hidden=\"true\">\n {status === \"complete\" ? (\n <Icon icon={check} size=\"sm\" />\n ) : status === \"error\" ? (\n <Icon icon={alert} size=\"sm\" />\n ) : (\n i + 1\n )}\n </span>\n <span className=\"cy-steps-text cy-reset\">\n <span className=\"cy-steps-label cy-reset\">{step.label}</span>\n {step.description != null && (\n <span className=\"cy-steps-description cy-reset\">{step.description}</span>\n )}\n <span className=\"cy-steps-hidden\">{`, ${text[status]}`}</span>\n </span>\n </>\n );\n return (\n <li key={step.id} className=\"cy-steps-item cy-reset\" data-status={status}>\n {onStepSelect ? (\n <ButtonBase\n className=\"cy-steps-step cy-reset\"\n aria-current={isCurrent ? \"step\" : undefined}\n aria-disabled={step.disabled || undefined}\n onClick={() => {\n if (!step.disabled && !isCurrent) onStepSelect(step.id);\n }}\n >\n {content}\n </ButtonBase>\n ) : (\n <span className=\"cy-steps-step cy-reset\" aria-current={isCurrent ? \"step\" : undefined}>\n {content}\n </span>\n )}\n {i < steps.length - 1 && <span className=\"cy-steps-line cy-reset\" aria-hidden=\"true\" />}\n </li>\n );\n })}\n </ol>\n );\n}\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"Steps.js","names":["_Fragment","ButtonBase","Icon","check","alert","Fragment","jsx","jsxs","DEFAULT_LABELS","Steps","steps","current","orientation","onStepSelect","size","labels","className","style","text","at","s","step","i","status","isCurrent","content"],"sources":["../../../src/components/Steps/Steps.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from \"react\";\nimport { ButtonBase } from \"../../foundations/ButtonBase/ButtonBase.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { alert } from \"../../icons/alert.js\";\nimport { check } from \"../../icons/check.js\";\nimport type { Size } from \"../../tokens/schema.js\";\n\nexport interface StepsTokens {\n /** Diameter of the numbered marker. */\n markerSize: string;\n /** Thickness of the line between steps. */\n lineWidth: string;\n /** Space between steps. */\n gap: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n steps: StepsTokens;\n }\n}\n\nexport type StepStatus = \"complete\" | \"current\" | \"upcoming\" | \"error\";\n\nexport interface StepItem {\n id: string;\n label: ReactNode;\n /** A second line under the label. */\n description?: ReactNode;\n /** Overrides the status worked out from `current`: mark a step `error`, or `complete` out of order. */\n status?: \"complete\" | \"error\" | undefined;\n /** With `onStepSelect`: this step cannot be chosen. */\n disabled?: boolean;\n}\n\nexport interface StepsLabels {\n /** Accessible name of the list. Default: \"Progress\". */\n list: string;\n /** Read after each step's label. Defaults: \"completed\", \"current step\", \"not started\", \"has a problem\". */\n complete: string;\n current: string;\n upcoming: string;\n error: string;\n}\n\nexport interface StepsProps {\n /** The steps, in order. */\n steps: StepItem[];\n /** `id` of the step the person is on. Steps before it are complete, steps after it upcoming. */\n current: string;\n /** Lays the steps out in a row or in a column. Default \"horizontal\". */\n orientation?: \"horizontal\" | \"vertical\";\n /** Makes steps buttons that go to that step. Leave it out for a read-only progress display. */\n onStepSelect?: (id: string) => void;\n /** Text size of labels and markers. */\n size?: Size;\n /** Replace the built-in English text: the list's name and the status read after each step. */\n labels?: Partial<StepsLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-steps-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: StepsLabels = {\n list: \"Progress\",\n complete: \"completed\",\n current: \"current step\",\n upcoming: \"not started\",\n error: \"has a problem\",\n};\n\n/** Progress through an ordered flow (a setup wizard, a checkout): numbered steps with the current one marked. */\nexport function Steps({\n steps,\n current,\n orientation = \"horizontal\",\n onStepSelect,\n size = \"md\",\n labels,\n className,\n style,\n}: StepsProps) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const at = steps.findIndex((s) => s.id === current);\n return (\n <ol\n className={className ? `cy-steps ${className}` : \"cy-steps\"}\n aria-label={text.list}\n data-orientation={orientation}\n data-size={size}\n style={style}\n >\n {steps.map((step, i) => {\n const status: StepStatus =\n step.status ?? (i === at ? \"current\" : at >= 0 && i < at ? \"complete\" : \"upcoming\");\n const isCurrent = i === at;\n const content = (\n <>\n <span className=\"cy-steps-marker cy-reset\" aria-hidden=\"true\">\n {status === \"complete\" ? (\n <Icon icon={check} size=\"sm\" />\n ) : status === \"error\" ? (\n <Icon icon={alert} size=\"sm\" />\n ) : (\n i + 1\n )}\n </span>\n <span className=\"cy-steps-text cy-reset\">\n <span className=\"cy-steps-label cy-reset\">{step.label}</span>\n {step.description != null && (\n <span className=\"cy-steps-description cy-reset\">{step.description}</span>\n )}\n <span className=\"cy-steps-hidden\">{`, ${text[status]}`}</span>\n </span>\n </>\n );\n return (\n <li key={step.id} className=\"cy-steps-item cy-reset\" data-status={status}>\n {onStepSelect ? (\n <ButtonBase\n className=\"cy-steps-step cy-reset\"\n aria-current={isCurrent ? \"step\" : undefined}\n aria-disabled={step.disabled || undefined}\n onClick={() => {\n if (!step.disabled && !isCurrent) onStepSelect(step.id);\n }}\n >\n {content}\n </ButtonBase>\n ) : (\n <span className=\"cy-steps-step cy-reset\" aria-current={isCurrent ? \"step\" : undefined}>\n {content}\n </span>\n )}\n {i < steps.length - 1 && <span className=\"cy-steps-line cy-reset\" aria-hidden=\"true\" />}\n </li>\n );\n })}\n </ol>\n );\n}\n"],"mappings":";;;;;;AAgEA,IAAMQ,IAA8B;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,UAAU;AAAA,EACV,OAAO;AACT;AAGA,SAAgBC,EAAM,EACpB,OAAAC,GACA,SAAAC,GACA,aAAAC,IAAc,cACd,cAAAC,GACA,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACa;AACb,QAAMC,IAAO;AAAA,IAAE,GAAGV;AAAA,IAAgB,GAAGO;AAAA,EAAO,GACtCI,IAAKT,EAAM,UAAA,CAAWU,MAAMA,EAAE,OAAOT,CAAO;AAClD,SACE,gBAAAL,EAAC,MAAD;AAAA,IACE,WAAWU,IAAY,YAAYA,CAAA,KAAc;AAAA,IACjD,cAAYE,EAAK;AAAA,IACjB,oBAAkBN;AAAA,IAClB,aAAWE;AAAA,IACJ,OAAAG;AAAA,IAEN,UAAAP,EAAM,IAAA,CAAKW,GAAMC,MAAM;AACtB,YAAMC,IACJF,EAAK,WAAWC,MAAMH,IAAK,YAAYA,KAAM,KAAKG,IAAIH,IAAK,aAAa,aACpEK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ACzE,UAAAC;AAAA,QACG,CAAA,GAEPH,IAAIZ,EAAM,SAAS,KAAK,gBAAAJ,EAAC,QAAD;AAAA,UAAM,WAAU;AAAA,UAAyB,eAAY;AAAA,QAAQ,CAAA,CACpF;AAAA,MAlBK,GAAAe,EAAK,EAkBV;AAAA,IAER,CAAC;AAAA,EACC,CAAA;AAER"}
|
|
@@ -44,25 +44,37 @@ export interface TableLabels {
|
|
|
44
44
|
export interface TableProps<Row> {
|
|
45
45
|
/** The table's caption: its accessible name, shown above it unless `captionHidden`. */
|
|
46
46
|
caption: ReactNode;
|
|
47
|
+
/** Hides the caption visually; it still names the table. */
|
|
47
48
|
captionHidden?: boolean;
|
|
49
|
+
/** The columns, in display order. */
|
|
48
50
|
columns: TableColumn<Row>[];
|
|
51
|
+
/** The data, one entry per row. */
|
|
49
52
|
rows: Row[];
|
|
50
53
|
/** A stable id per row (for selection and React keys). */
|
|
51
54
|
getRowId: (row: Row) => string;
|
|
55
|
+
/** The current sort (controlled); `null` is unsorted. */
|
|
52
56
|
sort?: TableSort | null | undefined;
|
|
57
|
+
/** Starting sort when uncontrolled; unsorted when left out. */
|
|
53
58
|
defaultSort?: TableSort | null;
|
|
59
|
+
/** Called when a sortable header is pressed, with the new sort, or `null` when it goes back to unsorted. */
|
|
54
60
|
onSortChange?: ((sort: TableSort | null) => void) | undefined;
|
|
55
61
|
/** You sort the rows (e.g. on a server); the table only shows and reports the sort. */
|
|
56
62
|
manualSort?: boolean;
|
|
57
63
|
/** Adds a checkbox per row and a select-all in the header. */
|
|
58
64
|
selectable?: boolean;
|
|
65
|
+
/** Ids of the selected rows (controlled). */
|
|
59
66
|
selected?: string[] | undefined;
|
|
67
|
+
/** Ids of the rows selected at the start when uncontrolled. */
|
|
60
68
|
defaultSelected?: string[];
|
|
69
|
+
/** Called when a row's checkbox or select-all changes, with the selected ids in row order. */
|
|
61
70
|
onSelectionChange?: ((ids: string[]) => void) | undefined;
|
|
62
71
|
/** The header stays visible while the body scrolls inside the table. */
|
|
63
72
|
stickyHeader?: boolean;
|
|
73
|
+
/** Cell padding and text size. Default "md". */
|
|
64
74
|
size?: Size;
|
|
75
|
+
/** Replace the built-in English text: the checkbox names and the empty message. */
|
|
65
76
|
labels?: Partial<TableLabels>;
|
|
77
|
+
/** Added to the root element, for layout. */
|
|
66
78
|
className?: string;
|
|
67
79
|
/** Layout only. Restyle through --cy-table-* tokens. */
|
|
68
80
|
style?: CSSProperties;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","names":["useControllableState","ButtonBase","Icon","Checkbox","arrowDown","arrowUp","chevronsUpDown","useId","useMemo","jsx","jsxs","DEFAULT_LABELS","name","collator","cellValue","row","key","compare","b","Table","caption","captionHidden","columns","rows","getRowId","sort","defaultSort","onSortChange","manualSort","selectable","selected","defaultSelected","onSelectionChange","stickyHeader","size","labels","className","style","text","id","currentSort","setSort","chosenIds","setChosen","chosen","headerColumn","c","shown","column","get","sign","a","x","y","xEmpty","yEmpty","cycle","setSelected","next","ids","rowId","allIds","chosenCount","rowName","v","sortIcon","on","sorted","isChosen","content"],"sources":["../../../src/components/Table/Table.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useId, useMemo } from \"react\";\nimport { ButtonBase } from \"../../foundations/ButtonBase/ButtonBase.js\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { arrowDown } from \"../../icons/arrow-down.js\";\nimport { arrowUp } from \"../../icons/arrow-up.js\";\nimport { chevronsUpDown } from \"../../icons/chevrons-up-down.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Checkbox } from \"../Checkbox/Checkbox.js\";\n\nexport interface TableTokens {\n /** Background of the header row. */\n headerBackground: string;\n /** Background of selected rows. */\n selectedBackground: string;\n /** Tallest the table gets before its body scrolls (with `stickyHeader`). */\n maxHeight: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n table: TableTokens;\n }\n}\n\nexport type SortDirection = \"ascending\" | \"descending\";\nexport interface TableSort {\n key: string;\n direction: SortDirection;\n}\n\nexport interface TableColumn<Row> {\n key: string;\n header: ReactNode;\n /** What the cell shows. Default: `row[key]`. */\n cell?: (row: Row) => ReactNode;\n /** Header becomes a sort button. */\n sortable?: boolean;\n /** What sorting compares. Default: `row[key]` (numbers as numbers, text in the locale's order). */\n sortValue?: (row: Row) => string | number | null | undefined;\n /** `end` for numbers. */\n align?: \"start\" | \"end\";\n /** Any CSS width for the column. */\n width?: string;\n /** This column's cells name their rows (screen readers announce it with each cell). Default: the first column. */\n rowHeader?: boolean;\n}\n\nexport interface TableLabels {\n /** Name of a row's checkbox. Default: \"Select row\" plus the row header's text when it is a string. */\n selectRow: (rowName: string) => string;\n selectAll: string;\n /** Shown when there are no rows. */\n empty: ReactNode;\n}\n\nexport interface TableProps<Row> {\n /** The table's caption: its accessible name, shown above it unless `captionHidden`. */\n caption: ReactNode;\n captionHidden?: boolean;\n columns: TableColumn<Row>[];\n rows: Row[];\n /** A stable id per row (for selection and React keys). */\n getRowId: (row: Row) => string;\n sort?: TableSort | null | undefined;\n defaultSort?: TableSort | null;\n onSortChange?: ((sort: TableSort | null) => void) | undefined;\n /** You sort the rows (e.g. on a server); the table only shows and reports the sort. */\n manualSort?: boolean;\n /** Adds a checkbox per row and a select-all in the header. */\n selectable?: boolean;\n selected?: string[] | undefined;\n defaultSelected?: string[];\n onSelectionChange?: ((ids: string[]) => void) | undefined;\n /** The header stays visible while the body scrolls inside the table. */\n stickyHeader?: boolean;\n size?: Size;\n labels?: Partial<TableLabels>;\n className?: string;\n /** Layout only. Restyle through --cy-table-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: TableLabels = {\n selectRow: (name) => (name ? `Select ${name}` : \"Select row\"),\n selectAll: \"Select all rows\",\n empty: \"Nothing to show\",\n};\n\nconst collator = new Intl.Collator(undefined, { numeric: true, sensitivity: \"base\" });\nconst cellValue = <Row,>(row: Row, key: string) => (row as Record<string, unknown>)[key];\n\nfunction compare(a: unknown, b: unknown) {\n // Empty values sort last in either direction (handled by the caller).\n if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n return collator.compare(String(a), String(b));\n}\n\n/**\n * Rows of data with headers: sortable columns, optional row selection, and a sticky header. A semantic `<table>`, so\n * screen readers announce headers with every cell.\n */\nexport function Table<Row>({\n caption,\n captionHidden = false,\n columns,\n rows,\n getRowId,\n sort,\n defaultSort = null,\n onSortChange,\n manualSort = false,\n selectable = false,\n selected,\n defaultSelected = [],\n onSelectionChange,\n stickyHeader = false,\n size = \"md\",\n labels,\n className,\n style,\n}: TableProps<Row>) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const [currentSort, setSort] = useControllableState<TableSort | null>(sort, defaultSort, onSortChange);\n const [chosenIds, setChosen] = useControllableState(selected, defaultSelected, onSelectionChange);\n const chosen = new Set(chosenIds);\n const headerColumn = columns.find((c) => c.rowHeader) ?? columns[0];\n\n const shown = useMemo(() => {\n if (manualSort || !currentSort) return rows;\n const column = columns.find((c) => c.key === currentSort.key);\n if (!column) return rows;\n const get = (row: Row) => (column.sortValue ? column.sortValue(row) : cellValue(row, column.key));\n const sign = currentSort.direction === \"ascending\" ? 1 : -1;\n return [...rows].sort((a, b) => {\n const x = get(a);\n const y = get(b);\n const xEmpty = x === null || x === undefined || x === \"\";\n const yEmpty = y === null || y === undefined || y === \"\";\n if (xEmpty || yEmpty) return xEmpty === yEmpty ? 0 : xEmpty ? 1 : -1;\n return compare(x, y) * sign;\n });\n }, [rows, columns, currentSort, manualSort]);\n\n // Ascending, then descending, then unsorted.\n const cycle = (key: string) => {\n if (currentSort?.key !== key) setSort({ key, direction: \"ascending\" });\n else if (currentSort.direction === \"ascending\") setSort({ key, direction: \"descending\" });\n else setSort(null);\n };\n const setSelected = (next: Set<string>) => {\n const ids = rows.map(getRowId).filter((rowId) => next.has(rowId));\n setChosen(ids);\n };\n\n const allIds = rows.map(getRowId);\n const chosenCount = allIds.filter((rowId) => chosen.has(rowId)).length;\n const rowName = (row: Row) => {\n const v = headerColumn?.cell ? headerColumn.cell(row) : cellValue(row, headerColumn?.key ?? \"\");\n return typeof v === \"string\" || typeof v === \"number\" ? String(v) : \"\";\n };\n const sortIcon = (key: string) =>\n currentSort?.key !== key ? chevronsUpDown : currentSort.direction === \"ascending\" ? arrowUp : arrowDown;\n\n return (\n <div\n className={className ? `cy-table ${className}` : \"cy-table\"}\n data-size={size}\n data-sticky={stickyHeader ? \"\" : undefined}\n style={style}\n >\n {/* With a sticky header the table scrolls inside this region, which must be reachable by keyboard. */}\n <div\n className=\"cy-table-scroll cy-reset\"\n {...(stickyHeader ? { tabIndex: 0, role: \"region\", \"aria-labelledby\": `${id}-caption` } : {})}\n >\n <table className=\"cy-table-table cy-reset\">\n <caption\n id={`${id}-caption`}\n className=\"cy-table-caption cy-reset\"\n data-hidden={captionHidden ? \"\" : undefined}\n >\n {caption}\n </caption>\n <thead className=\"cy-reset\">\n <tr className=\"cy-reset\">\n {selectable && (\n <th scope=\"col\" className=\"cy-table-th cy-table-select cy-reset\">\n <Checkbox\n label={<span className=\"cy-table-hidden\">{text.selectAll}</span>}\n checked={allIds.length > 0 && chosenCount === allIds.length}\n indeterminate={chosenCount > 0 && chosenCount < allIds.length}\n disabled={allIds.length === 0}\n onChange={(on) => setSelected(on ? new Set(allIds) : new Set())}\n />\n </th>\n )}\n {columns.map((column) => {\n const sorted = currentSort?.key === column.key ? currentSort.direction : undefined;\n return (\n <th\n key={column.key}\n scope=\"col\"\n className=\"cy-table-th cy-reset\"\n data-align={column.align}\n aria-sort={column.sortable ? (sorted ?? \"none\") : undefined}\n style={column.width ? { inlineSize: column.width } : undefined}\n >\n {column.sortable ? (\n <ButtonBase className=\"cy-table-sort cy-reset\" onClick={() => cycle(column.key)}>\n <span className=\"cy-reset\">{column.header}</span>\n <Icon icon={sortIcon(column.key)} size=\"sm\" className=\"cy-table-sort-icon\" />\n </ButtonBase>\n ) : (\n column.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody className=\"cy-reset\">\n {shown.length === 0 ? (\n <tr className=\"cy-reset\">\n <td\n className=\"cy-table-td cy-table-empty cy-reset\"\n colSpan={columns.length + (selectable ? 1 : 0)}\n >\n {text.empty}\n </td>\n </tr>\n ) : (\n shown.map((row) => {\n const rowId = getRowId(row);\n const isChosen = chosen.has(rowId);\n return (\n <tr key={rowId} className=\"cy-table-row cy-reset\" data-selected={isChosen ? \"\" : undefined}>\n {selectable && (\n <td className=\"cy-table-td cy-table-select cy-reset\">\n <Checkbox\n label={<span className=\"cy-table-hidden\">{text.selectRow(rowName(row))}</span>}\n checked={isChosen}\n onChange={(on) => {\n const next = new Set(chosen);\n if (on) next.add(rowId);\n else next.delete(rowId);\n setSelected(next);\n }}\n />\n </td>\n )}\n {columns.map((column) => {\n const content = column.cell\n ? column.cell(row)\n : (cellValue(row, column.key) as ReactNode);\n return column === headerColumn ? (\n <th\n key={column.key}\n scope=\"row\"\n className=\"cy-table-td cy-table-rowheader cy-reset\"\n data-align={column.align}\n >\n {content}\n </th>\n ) : (\n <td key={column.key} className=\"cy-table-td cy-reset\" data-align={column.align}>\n {content}\n </td>\n );\n })}\n </tr>\n );\n })\n )}\n </tbody>\n </table>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAmFA,IAAMW,KAA8B;AAAA,EAClC,WAAA,CAAYC,MAAUA,IAAO,UAAUA,CAAA,KAAS;AAAA,EAChD,WAAW;AAAA,EACX,OAAO;AACT,GAEMC,KAAW,IAAI,KAAK,SAAS,QAAW;AAAA,EAAE,SAAS;AAAA,EAAM,aAAa;AAAO,CAAC,GAC9EC,IAAA,CAAmBC,GAAUC,MAAiBD,EAAgCC,CAAA;AAEpF,SAASC,GAAQ,GAAYC,GAAY;AAEvC,SAAI,OAAO,KAAM,YAAY,OAAOA,KAAM,WAAiB,IAAIA,IACxDL,GAAS,QAAQ,OAAO,CAAC,GAAG,OAAOK,CAAC,CAA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AAA,CAAWF,MAAO;AAChB,4BAAMR,IAAO,IAAI,IAAId,CAAM;AAC3B,sBAAIsB,IAAIR,EAAK,IAAIE,CAAK,IACjBF,EAAK,OAAOE,CAAK,GACtBH,EAAYC,CAAI;AAAA,oBAClB;AAAA,kBACD,CAAA;AAAA,gBACC,CAAA,GAELpC,EAAQ,IAAA,CAAK0B,MAAW;AACvB,wBAAMqB,IAAUrB,EAAO,OACnBA,EAAO,KAAKjC,CAAG,IACdD,EAAUC,GAAKiC,EAAO,GAAG;AAC9B,yBAAOA,MAAWH,IAChB,gBAAApC,EAAC,MAAD;AAAA,oBAEE,OAAM;AAAA,oBACN,WAAU;AAAA,oBACV,cAAYuC,EAAO;AAAA,oBAElB,UAAAqB;AAAA,kBACC,GANGrB,EAAO,GAMV,IAEJ,gBAAAvC,EAAC,MAAD;AAAA,oBAAqB,WAAU;AAAA,oBAAuB,cAAYuC,EAAO;AAAA,oBACtE,UAAAqB;AAAA,kBACC,GAFKrB,EAAO,GAEZ;AAAA,gBAER,CAAC,CACC;AAAA,cAlCK,GAAAY,CAkCL;AAAA,YAER,CAAC;AAAA,UAEE,CAAA;AAAA,QACF;AAAA,M;A,IACJ,CAAA;AAAA,EACF,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"Table.js","names":["useControllableState","ButtonBase","Icon","Checkbox","arrowDown","arrowUp","chevronsUpDown","useId","useMemo","jsx","jsxs","DEFAULT_LABELS","name","collator","cellValue","row","key","compare","b","Table","caption","captionHidden","columns","rows","getRowId","sort","defaultSort","onSortChange","manualSort","selectable","selected","defaultSelected","onSelectionChange","stickyHeader","size","labels","className","style","text","id","currentSort","setSort","chosenIds","setChosen","chosen","headerColumn","c","shown","column","get","sign","a","x","y","xEmpty","yEmpty","cycle","setSelected","next","ids","rowId","allIds","chosenCount","rowName","v","sortIcon","on","sorted","isChosen","content"],"sources":["../../../src/components/Table/Table.tsx"],"sourcesContent":["import { type CSSProperties, type ReactNode, useId, useMemo } from \"react\";\nimport { ButtonBase } from \"../../foundations/ButtonBase/ButtonBase.js\";\nimport { useControllableState } from \"../../foundations/controllable.js\";\nimport { Icon } from \"../../foundations/Icon/Icon.js\";\nimport { arrowDown } from \"../../icons/arrow-down.js\";\nimport { arrowUp } from \"../../icons/arrow-up.js\";\nimport { chevronsUpDown } from \"../../icons/chevrons-up-down.js\";\nimport type { Size } from \"../../tokens/schema.js\";\nimport { Checkbox } from \"../Checkbox/Checkbox.js\";\n\nexport interface TableTokens {\n /** Background of the header row. */\n headerBackground: string;\n /** Background of selected rows. */\n selectedBackground: string;\n /** Tallest the table gets before its body scrolls (with `stickyHeader`). */\n maxHeight: string;\n}\n\ndeclare module \"../../tokens/schema.js\" {\n interface ComponentTokens {\n table: TableTokens;\n }\n}\n\nexport type SortDirection = \"ascending\" | \"descending\";\nexport interface TableSort {\n key: string;\n direction: SortDirection;\n}\n\nexport interface TableColumn<Row> {\n key: string;\n header: ReactNode;\n /** What the cell shows. Default: `row[key]`. */\n cell?: (row: Row) => ReactNode;\n /** Header becomes a sort button. */\n sortable?: boolean;\n /** What sorting compares. Default: `row[key]` (numbers as numbers, text in the locale's order). */\n sortValue?: (row: Row) => string | number | null | undefined;\n /** `end` for numbers. */\n align?: \"start\" | \"end\";\n /** Any CSS width for the column. */\n width?: string;\n /** This column's cells name their rows (screen readers announce it with each cell). Default: the first column. */\n rowHeader?: boolean;\n}\n\nexport interface TableLabels {\n /** Name of a row's checkbox. Default: \"Select row\" plus the row header's text when it is a string. */\n selectRow: (rowName: string) => string;\n selectAll: string;\n /** Shown when there are no rows. */\n empty: ReactNode;\n}\n\nexport interface TableProps<Row> {\n /** The table's caption: its accessible name, shown above it unless `captionHidden`. */\n caption: ReactNode;\n /** Hides the caption visually; it still names the table. */\n captionHidden?: boolean;\n /** The columns, in display order. */\n columns: TableColumn<Row>[];\n /** The data, one entry per row. */\n rows: Row[];\n /** A stable id per row (for selection and React keys). */\n getRowId: (row: Row) => string;\n /** The current sort (controlled); `null` is unsorted. */\n sort?: TableSort | null | undefined;\n /** Starting sort when uncontrolled; unsorted when left out. */\n defaultSort?: TableSort | null;\n /** Called when a sortable header is pressed, with the new sort, or `null` when it goes back to unsorted. */\n onSortChange?: ((sort: TableSort | null) => void) | undefined;\n /** You sort the rows (e.g. on a server); the table only shows and reports the sort. */\n manualSort?: boolean;\n /** Adds a checkbox per row and a select-all in the header. */\n selectable?: boolean;\n /** Ids of the selected rows (controlled). */\n selected?: string[] | undefined;\n /** Ids of the rows selected at the start when uncontrolled. */\n defaultSelected?: string[];\n /** Called when a row's checkbox or select-all changes, with the selected ids in row order. */\n onSelectionChange?: ((ids: string[]) => void) | undefined;\n /** The header stays visible while the body scrolls inside the table. */\n stickyHeader?: boolean;\n /** Cell padding and text size. Default \"md\". */\n size?: Size;\n /** Replace the built-in English text: the checkbox names and the empty message. */\n labels?: Partial<TableLabels>;\n /** Added to the root element, for layout. */\n className?: string;\n /** Layout only. Restyle through --cy-table-* tokens. */\n style?: CSSProperties;\n}\n\nconst DEFAULT_LABELS: TableLabels = {\n selectRow: (name) => (name ? `Select ${name}` : \"Select row\"),\n selectAll: \"Select all rows\",\n empty: \"Nothing to show\",\n};\n\nconst collator = new Intl.Collator(undefined, { numeric: true, sensitivity: \"base\" });\nconst cellValue = <Row,>(row: Row, key: string) => (row as Record<string, unknown>)[key];\n\nfunction compare(a: unknown, b: unknown) {\n // Empty values sort last in either direction (handled by the caller).\n if (typeof a === \"number\" && typeof b === \"number\") return a - b;\n return collator.compare(String(a), String(b));\n}\n\n/**\n * Rows of data with headers: sortable columns, optional row selection, and a sticky header. A semantic `<table>`, so\n * screen readers announce headers with every cell.\n */\nexport function Table<Row>({\n caption,\n captionHidden = false,\n columns,\n rows,\n getRowId,\n sort,\n defaultSort = null,\n onSortChange,\n manualSort = false,\n selectable = false,\n selected,\n defaultSelected = [],\n onSelectionChange,\n stickyHeader = false,\n size = \"md\",\n labels,\n className,\n style,\n}: TableProps<Row>) {\n const text = { ...DEFAULT_LABELS, ...labels };\n const id = useId();\n const [currentSort, setSort] = useControllableState<TableSort | null>(sort, defaultSort, onSortChange);\n const [chosenIds, setChosen] = useControllableState(selected, defaultSelected, onSelectionChange);\n const chosen = new Set(chosenIds);\n const headerColumn = columns.find((c) => c.rowHeader) ?? columns[0];\n\n const shown = useMemo(() => {\n if (manualSort || !currentSort) return rows;\n const column = columns.find((c) => c.key === currentSort.key);\n if (!column) return rows;\n const get = (row: Row) => (column.sortValue ? column.sortValue(row) : cellValue(row, column.key));\n const sign = currentSort.direction === \"ascending\" ? 1 : -1;\n return [...rows].sort((a, b) => {\n const x = get(a);\n const y = get(b);\n const xEmpty = x === null || x === undefined || x === \"\";\n const yEmpty = y === null || y === undefined || y === \"\";\n if (xEmpty || yEmpty) return xEmpty === yEmpty ? 0 : xEmpty ? 1 : -1;\n return compare(x, y) * sign;\n });\n }, [rows, columns, currentSort, manualSort]);\n\n // Ascending, then descending, then unsorted.\n const cycle = (key: string) => {\n if (currentSort?.key !== key) setSort({ key, direction: \"ascending\" });\n else if (currentSort.direction === \"ascending\") setSort({ key, direction: \"descending\" });\n else setSort(null);\n };\n const setSelected = (next: Set<string>) => {\n const ids = rows.map(getRowId).filter((rowId) => next.has(rowId));\n setChosen(ids);\n };\n\n const allIds = rows.map(getRowId);\n const chosenCount = allIds.filter((rowId) => chosen.has(rowId)).length;\n const rowName = (row: Row) => {\n const v = headerColumn?.cell ? headerColumn.cell(row) : cellValue(row, headerColumn?.key ?? \"\");\n return typeof v === \"string\" || typeof v === \"number\" ? String(v) : \"\";\n };\n const sortIcon = (key: string) =>\n currentSort?.key !== key ? chevronsUpDown : currentSort.direction === \"ascending\" ? arrowUp : arrowDown;\n\n return (\n <div\n className={className ? `cy-table ${className}` : \"cy-table\"}\n data-size={size}\n data-sticky={stickyHeader ? \"\" : undefined}\n style={style}\n >\n {/* With a sticky header the table scrolls inside this region, which must be reachable by keyboard. */}\n <div\n className=\"cy-table-scroll cy-reset\"\n {...(stickyHeader ? { tabIndex: 0, role: \"region\", \"aria-labelledby\": `${id}-caption` } : {})}\n >\n <table className=\"cy-table-table cy-reset\">\n <caption\n id={`${id}-caption`}\n className=\"cy-table-caption cy-reset\"\n data-hidden={captionHidden ? \"\" : undefined}\n >\n {caption}\n </caption>\n <thead className=\"cy-reset\">\n <tr className=\"cy-reset\">\n {selectable && (\n <th scope=\"col\" className=\"cy-table-th cy-table-select cy-reset\">\n <Checkbox\n label={<span className=\"cy-table-hidden\">{text.selectAll}</span>}\n checked={allIds.length > 0 && chosenCount === allIds.length}\n indeterminate={chosenCount > 0 && chosenCount < allIds.length}\n disabled={allIds.length === 0}\n onChange={(on) => setSelected(on ? new Set(allIds) : new Set())}\n />\n </th>\n )}\n {columns.map((column) => {\n const sorted = currentSort?.key === column.key ? currentSort.direction : undefined;\n return (\n <th\n key={column.key}\n scope=\"col\"\n className=\"cy-table-th cy-reset\"\n data-align={column.align}\n aria-sort={column.sortable ? (sorted ?? \"none\") : undefined}\n style={column.width ? { inlineSize: column.width } : undefined}\n >\n {column.sortable ? (\n <ButtonBase className=\"cy-table-sort cy-reset\" onClick={() => cycle(column.key)}>\n <span className=\"cy-reset\">{column.header}</span>\n <Icon icon={sortIcon(column.key)} size=\"sm\" className=\"cy-table-sort-icon\" />\n </ButtonBase>\n ) : (\n column.header\n )}\n </th>\n );\n })}\n </tr>\n </thead>\n <tbody className=\"cy-reset\">\n {shown.length === 0 ? (\n <tr className=\"cy-reset\">\n <td\n className=\"cy-table-td cy-table-empty cy-reset\"\n colSpan={columns.length + (selectable ? 1 : 0)}\n >\n {text.empty}\n </td>\n </tr>\n ) : (\n shown.map((row) => {\n const rowId = getRowId(row);\n const isChosen = chosen.has(rowId);\n return (\n <tr key={rowId} className=\"cy-table-row cy-reset\" data-selected={isChosen ? \"\" : undefined}>\n {selectable && (\n <td className=\"cy-table-td cy-table-select cy-reset\">\n <Checkbox\n label={<span className=\"cy-table-hidden\">{text.selectRow(rowName(row))}</span>}\n checked={isChosen}\n onChange={(on) => {\n const next = new Set(chosen);\n if (on) next.add(rowId);\n else next.delete(rowId);\n setSelected(next);\n }}\n />\n </td>\n )}\n {columns.map((column) => {\n const content = column.cell\n ? column.cell(row)\n : (cellValue(row, column.key) as ReactNode);\n return column === headerColumn ? (\n <th\n key={column.key}\n scope=\"row\"\n className=\"cy-table-td cy-table-rowheader cy-reset\"\n data-align={column.align}\n >\n {content}\n </th>\n ) : (\n <td key={column.key} className=\"cy-table-td cy-reset\" data-align={column.align}>\n {content}\n </td>\n );\n })}\n </tr>\n );\n })\n )}\n </tbody>\n </table>\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AA+FA,IAAMW,KAA8B;AAAA,EAClC,WAAA,CAAYC,MAAUA,IAAO,UAAUA,CAAA,KAAS;AAAA,EAChD,WAAW;AAAA,EACX,OAAO;AACT,GAEMC,KAAW,IAAI,KAAK,SAAS,QAAW;AAAA,EAAE,SAAS;AAAA,EAAM,aAAa;AAAO,CAAC,GAC9EC,IAAA,CAAmBC,GAAUC,MAAiBD,EAAgCC,CAAA;AAEpF,SAASC,GAAQ,GAAYC,GAAY;AAEvC,SAAI,OAAO,KAAM,YAAY,OAAOA,KAAM,WAAiB,IAAIA,IACxDL,GAAS,QAAQ,OAAO,CAAC,GAAG,OAAOK,CAAC,CAAC;AAC9C;AAMA,SAAgBC,GAAW,EACzB,SAAAC,GACA,eAAAC,IAAgB,IAChB,SAAAC,GACA,MAAAC,GACA,UAAAC,GACA,MAAAC,GACA,aAAAC,IAAc,MACd,cAAAC,GACA,YAAAC,IAAa,IACb,YAAAC,IAAa,IACb,UAAAC,GACA,iBAAAC,IAAkB,CAAC,GACnB,mBAAAC,GACA,cAAAC,IAAe,IACf,MAAAC,IAAO,MACP,QAAAC,GACA,WAAAC,GACA,OAAAC,EAAA,GACkB;AAClB,QAAMC,IAAO;AAAA,IAAE,GAAG3B;AAAA,IAAgB,GAAGwB;AAAA,EAAO,GACtCI,IAAKhC,EAAM,GACX,CAACiC,GAAaC,CAAA,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