@calcifer-design/ui 0.4.0 → 0.5.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/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
- package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
- package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
- package/dist/components/CardList/CardList.d.ts +30 -0
- package/dist/components/CardList/CardList.js +35 -0
- package/dist/components/CardList/CardList.module.js +7 -0
- package/dist/components/CardList/CardList_module.css +20 -0
- package/dist/components/DatePicker/Calendar.d.ts +19 -0
- package/dist/components/DatePicker/Calendar.js +207 -0
- package/dist/components/DatePicker/DatePicker.d.ts +72 -0
- package/dist/components/DatePicker/DatePicker.js +116 -0
- package/dist/components/DatePicker/DatePicker.module.js +14 -0
- package/dist/components/DatePicker/DatePicker_module.css +112 -0
- package/dist/components/DatePicker/calendarDate.d.ts +46 -0
- package/dist/components/DatePicker/calendarDate.js +117 -0
- package/dist/components/Descriptions/Descriptions.d.ts +25 -0
- package/dist/components/Descriptions/Descriptions.js +44 -0
- package/dist/components/Descriptions/Descriptions.module.js +8 -0
- package/dist/components/Descriptions/Descriptions_module.css +47 -0
- package/dist/components/Field/Field.d.ts +1 -1
- package/dist/components/Field/Field.js +7 -1
- package/dist/components/Field/PickerField.d.ts +41 -0
- package/dist/components/Field/PickerField.js +115 -0
- package/dist/components/Field/PickerField.module.js +8 -0
- package/dist/components/Field/PickerField_module.css +36 -0
- package/dist/components/FilterBar/FilterBar.d.ts +55 -0
- package/dist/components/FilterBar/FilterBar.js +138 -0
- package/dist/components/FilterBar/FilterBar.module.js +13 -0
- package/dist/components/FilterBar/FilterBar_module.css +98 -0
- package/dist/components/Form/Form.d.ts +48 -0
- package/dist/components/Form/Form.js +38 -0
- package/dist/components/Form/Form.module.js +5 -0
- package/dist/components/Form/FormContext.d.ts +15 -0
- package/dist/components/Form/FormContext.js +20 -0
- package/dist/components/Form/Form_module.css +6 -0
- package/dist/components/PageShell/PageShell.d.ts +27 -0
- package/dist/components/PageShell/PageShell.js +35 -0
- package/dist/components/PageShell/PageShell.module.js +9 -0
- package/dist/components/PageShell/PageShell_module.css +56 -0
- package/dist/components/Segmented/Segmented.d.ts +49 -0
- package/dist/components/Segmented/Segmented.js +55 -0
- package/dist/components/Segmented/Segmented.module.js +7 -0
- package/dist/components/Segmented/Segmented_module.css +75 -0
- package/dist/components/Steps/Steps.d.ts +30 -0
- package/dist/components/Steps/Steps.js +63 -0
- package/dist/components/Steps/Steps.module.js +10 -0
- package/dist/components/Steps/Steps_module.css +126 -0
- package/dist/components/TextArea/TextArea.d.ts +16 -0
- package/dist/components/TextArea/TextArea.js +28 -0
- package/dist/components/TextArea/TextArea.module.js +5 -0
- package/dist/components/TextArea/TextArea_module.css +12 -0
- package/dist/components/TimePicker/TimePicker.d.ts +19 -0
- package/dist/components/TimePicker/TimePicker.js +17 -0
- package/dist/components/Timeline/Timeline.d.ts +39 -0
- package/dist/components/Timeline/Timeline.js +109 -0
- package/dist/components/Timeline/Timeline.module.js +12 -0
- package/dist/components/Timeline/Timeline_module.css +99 -0
- package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
- package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
- package/dist/components/Toolbar/Toolbar.d.ts +46 -0
- package/dist/components/Toolbar/Toolbar.js +43 -0
- package/dist/components/Toolbar/Toolbar.module.js +7 -0
- package/dist/components/Toolbar/Toolbar_module.css +26 -0
- package/dist/components/Tree/Tree.d.ts +81 -0
- package/dist/components/Tree/Tree.js +232 -0
- package/dist/components/Tree/Tree.module.js +12 -0
- package/dist/components/Tree/Tree_module.css +124 -0
- package/dist/components/Tree/treeIndex.d.ts +23 -0
- package/dist/components/Tree/treeIndex.js +33 -0
- package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
- package/dist/components/TreeSelect/TreeSelect.js +117 -0
- package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
- package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
- package/dist/components/Upload/Upload.d.ts +66 -0
- package/dist/components/Upload/Upload.js +287 -0
- package/dist/components/Upload/Upload.module.js +12 -0
- package/dist/components/Upload/Upload_module.css +96 -0
- package/dist/components/ViewField/ViewField.d.ts +26 -0
- package/dist/components/ViewField/ViewField.js +29 -0
- package/dist/components/ViewField/ViewField.module.js +6 -0
- package/dist/components/ViewField/ViewField_module.css +17 -0
- package/dist/hooks/useFormReset.d.ts +10 -0
- package/dist/hooks/useFormReset.js +34 -0
- package/dist/icons/CalendarIcon.d.ts +2 -0
- package/dist/icons/CalendarIcon.js +26 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +17 -0
- package/dist/styles/pair.module.js +6 -0
- package/dist/styles/pair_module.css +18 -0
- package/package.json +2 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
.list-idznt {
|
|
2
|
+
flex-direction: column;
|
|
3
|
+
margin: 0;
|
|
4
|
+
padding: 0;
|
|
5
|
+
list-style: none;
|
|
6
|
+
display: flex;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.item-qvxp0 {
|
|
10
|
+
--timeline-marker-size: .75rem;
|
|
11
|
+
--timeline-color: var(--color-neutral);
|
|
12
|
+
--timeline-tint: var(--color-surface-2);
|
|
13
|
+
--timeline-line: var(--color-border-strong);
|
|
14
|
+
gap: var(--space-3);
|
|
15
|
+
min-width: 0;
|
|
16
|
+
padding-block-end: var(--space-4);
|
|
17
|
+
display: flex;
|
|
18
|
+
position: relative;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.item-qvxp0[data-tone="accent"] {
|
|
22
|
+
--timeline-color: var(--color-accent);
|
|
23
|
+
--timeline-tint: var(--color-accent-soft);
|
|
24
|
+
--timeline-line: var(--color-border-accent);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.item-qvxp0[data-tone="success"] {
|
|
28
|
+
--timeline-color: var(--color-success);
|
|
29
|
+
--timeline-tint: color-mix(in srgb, var(--color-success) 14%, transparent);
|
|
30
|
+
--timeline-line: color-mix(in srgb, var(--color-success) 35%, transparent);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.item-qvxp0[data-tone="danger"] {
|
|
34
|
+
--timeline-color: var(--color-danger);
|
|
35
|
+
--timeline-tint: var(--color-danger-surface);
|
|
36
|
+
--timeline-line: var(--color-danger-border);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.item-qvxp0:last-child {
|
|
40
|
+
padding-block-end: 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.item-qvxp0:not(:last-child):before {
|
|
44
|
+
content: "";
|
|
45
|
+
inset-block: calc(var(--space-1) + var(--timeline-marker-size)) 0;
|
|
46
|
+
border-inline-start: 1px solid var(--color-border-strong);
|
|
47
|
+
position: absolute;
|
|
48
|
+
inset-inline-start: calc(var(--timeline-marker-size) / 2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.marker-bb9HI {
|
|
52
|
+
width: var(--timeline-marker-size);
|
|
53
|
+
height: var(--timeline-marker-size);
|
|
54
|
+
border: 1px solid var(--timeline-color);
|
|
55
|
+
border-radius: var(--radius-full);
|
|
56
|
+
background: var(--timeline-color);
|
|
57
|
+
flex: none;
|
|
58
|
+
margin-block-start: var(--space-1);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.body-Ebp5l {
|
|
62
|
+
gap: var(--space-1);
|
|
63
|
+
overflow-wrap: anywhere;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
min-width: 0;
|
|
66
|
+
display: flex;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.title-ppcg_ {
|
|
70
|
+
color: var(--color-text);
|
|
71
|
+
font-size: var(--text-sm);
|
|
72
|
+
font-weight: 500;
|
|
73
|
+
line-height: var(--leading-snug);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.meta-Qkwq4 {
|
|
77
|
+
align-items: center;
|
|
78
|
+
gap: var(--space-2);
|
|
79
|
+
color: var(--color-text-muted);
|
|
80
|
+
font-size: var(--text-xs);
|
|
81
|
+
line-height: var(--leading-snug);
|
|
82
|
+
flex-wrap: wrap;
|
|
83
|
+
display: flex;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.tone-AP_HF {
|
|
87
|
+
padding-inline: var(--space-2);
|
|
88
|
+
border: 1px solid var(--timeline-line);
|
|
89
|
+
border-radius: var(--radius-full);
|
|
90
|
+
background: var(--timeline-tint);
|
|
91
|
+
color: var(--color-text);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.description-lVcj_ {
|
|
95
|
+
color: var(--color-text-muted);
|
|
96
|
+
font-size: var(--text-sm);
|
|
97
|
+
line-height: var(--leading-prose);
|
|
98
|
+
}
|
|
99
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a control sits in a `Toolbar`, which then owns the one tab stop. Private to the library:
|
|
3
|
+
* `src/index.ts` does not export it, and `Segmented` reads it to leave that stop alone. Its own
|
|
4
|
+
* file so that reading it does not pull `Toolbar` and `Button` into `Segmented`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const InsideToolbarContext: import("react").Context<boolean>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Toolbar as BaseToolbar } from '@base-ui/react/toolbar';
|
|
2
|
+
import type { ComponentPropsWithoutRef, CSSProperties, ReactElement, ReactNode } from 'react';
|
|
3
|
+
export interface ToolbarProps {
|
|
4
|
+
/** Names the toolbar. Required: a toolbar has no visible name to fall back on. */
|
|
5
|
+
'aria-label': string;
|
|
6
|
+
/** Which arrow keys move focus: left and right when `horizontal`, up and down when `vertical`. */
|
|
7
|
+
orientation?: 'horizontal' | 'vertical';
|
|
8
|
+
/** `ToolbarButton`, `ToolbarGroup`, `ToolbarSeparator` and `Segmented`. */
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A row or a column of controls that is one tab stop, whose arrow keys move focus and loop at the
|
|
13
|
+
* ends. Base UI's `Toolbar.Root` does not turn on Home and End and has no public prop to; the
|
|
14
|
+
* WAI-ARIA toolbar pattern lists them as optional.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Toolbar({ 'aria-label': ariaLabel, orientation, children, }: ToolbarProps): import("react").JSX.Element;
|
|
17
|
+
export interface ToolbarButtonProps extends Omit<ComponentPropsWithoutRef<typeof BaseToolbar.Button>, 'className' | 'style' | 'render' | 'focusableWhenDisabled' | 'nativeButton'> {
|
|
18
|
+
/** A `Button` or `IconButton` to wear. With none it wears a small secondary `Button`. */
|
|
19
|
+
render?: ReactElement;
|
|
20
|
+
/** Shows a busy state on the `Button` or `IconButton` it wears, and blocks activation. */
|
|
21
|
+
loading?: boolean;
|
|
22
|
+
className?: string;
|
|
23
|
+
style?: CSSProperties;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A button in the toolbar's roving focus. `render` picks its look: `<Button variant="ghost" />`
|
|
27
|
+
* or `<IconButton label="Approve">{icon}</IconButton>`. Base UI's part draws nothing of its own,
|
|
28
|
+
* so with no `render` it wears a small secondary `Button` rather than go unstyled.
|
|
29
|
+
*
|
|
30
|
+
* `disabled` and `loading` go here, not on the element in `render`. Here, Base UI keeps the button
|
|
31
|
+
* focusable and says so with `aria-disabled`. On a `Button` in `render`, `disabled` comes out
|
|
32
|
+
* natively disabled, out of the arrow keys' reach, and with a contradictory `aria-disabled="false"`;
|
|
33
|
+
* `loading` comes out dimmed and inert, with that same `aria-disabled="false"`. Measured.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ToolbarButton({ render, disabled, loading, ...rest }: ToolbarButtonProps): import("react").JSX.Element;
|
|
36
|
+
export interface ToolbarGroupProps {
|
|
37
|
+
/** Names the group for assistive technology. */
|
|
38
|
+
'aria-label'?: string;
|
|
39
|
+
/** Disables every `ToolbarButton` inside it. */
|
|
40
|
+
disabled?: boolean;
|
|
41
|
+
children: ReactNode;
|
|
42
|
+
}
|
|
43
|
+
/** Groups related controls. It adds no tab stop: arrow keys pass straight through it. */
|
|
44
|
+
export declare function ToolbarGroup({ 'aria-label': ariaLabel, disabled, children }: ToolbarGroupProps): import("react").JSX.Element;
|
|
45
|
+
/** A rule between controls, drawn across the toolbar's own direction. */
|
|
46
|
+
export declare function ToolbarSeparator(): import("react").JSX.Element;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Toolbar } from "@base-ui/react/toolbar";
|
|
3
|
+
import { Button } from "../Button/Button.js";
|
|
4
|
+
import { InsideToolbarContext } from "./InsideToolbarContext.js";
|
|
5
|
+
import Toolbar_module from "./Toolbar.module.js";
|
|
6
|
+
function Toolbar_Toolbar({ 'aria-label': ariaLabel, orientation = 'horizontal', children }) {
|
|
7
|
+
return /*#__PURE__*/ jsx(InsideToolbarContext.Provider, {
|
|
8
|
+
value: true,
|
|
9
|
+
children: /*#__PURE__*/ jsx(Toolbar.Root, {
|
|
10
|
+
className: Toolbar_module.root,
|
|
11
|
+
"aria-label": ariaLabel,
|
|
12
|
+
orientation: orientation,
|
|
13
|
+
children: children
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function ToolbarButton({ render = /*#__PURE__*/ jsx(Button, {
|
|
18
|
+
variant: "secondary",
|
|
19
|
+
size: "sm"
|
|
20
|
+
}), disabled, loading, ...rest }) {
|
|
21
|
+
return /*#__PURE__*/ jsx(Toolbar.Button, {
|
|
22
|
+
render: render,
|
|
23
|
+
disabled: disabled || loading,
|
|
24
|
+
...loading ? {
|
|
25
|
+
loading
|
|
26
|
+
} : null,
|
|
27
|
+
...rest
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function ToolbarGroup({ 'aria-label': ariaLabel, disabled, children }) {
|
|
31
|
+
return /*#__PURE__*/ jsx(Toolbar.Group, {
|
|
32
|
+
className: Toolbar_module.group,
|
|
33
|
+
"aria-label": ariaLabel,
|
|
34
|
+
disabled: disabled,
|
|
35
|
+
children: children
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function ToolbarSeparator() {
|
|
39
|
+
return /*#__PURE__*/ jsx(Toolbar.Separator, {
|
|
40
|
+
className: Toolbar_module.separator
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export { ToolbarButton, ToolbarGroup, ToolbarSeparator, Toolbar_Toolbar as Toolbar };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.root-TasA5, .group-gw9JG {
|
|
2
|
+
align-items: center;
|
|
3
|
+
gap: var(--space-2);
|
|
4
|
+
flex-wrap: wrap;
|
|
5
|
+
display: flex;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.root-TasA5[data-orientation="vertical"], .group-gw9JG[data-orientation="vertical"] {
|
|
9
|
+
flex-direction: column;
|
|
10
|
+
align-items: stretch;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.separator-pZlgb {
|
|
14
|
+
background: var(--color-border-strong);
|
|
15
|
+
flex: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.separator-pZlgb[data-orientation="vertical"] {
|
|
19
|
+
align-self: stretch;
|
|
20
|
+
width: 1px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.separator-pZlgb[data-orientation="horizontal"] {
|
|
24
|
+
height: 1px;
|
|
25
|
+
}
|
|
26
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface TreeItem {
|
|
3
|
+
/**
|
|
4
|
+
* Identifies the item across renders, and unique in the whole tree, not only among its siblings.
|
|
5
|
+
* A repeated id is left out, with everything under it: the first one in reading order stays.
|
|
6
|
+
*/
|
|
7
|
+
id: string;
|
|
8
|
+
/** The visible text, the accessible name and what type-ahead matches. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** Sits before the label. Decorative: it stays out of the accessible name. */
|
|
11
|
+
icon?: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* Focusable and read out, as the WAI-ARIA pattern asks, but inert: it cannot be selected and does
|
|
14
|
+
* not open or close. It says nothing about what it holds, which an app can still open for it.
|
|
15
|
+
*/
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
children?: TreeItem[];
|
|
18
|
+
}
|
|
19
|
+
export type TreeSelectionMode = 'none' | 'single' | 'multiple';
|
|
20
|
+
interface TreeBaseProps {
|
|
21
|
+
/**
|
|
22
|
+
* Static data. A new array of the same ids changes nothing but what is drawn. With none, nothing
|
|
23
|
+
* is drawn, and what to say instead is the app's.
|
|
24
|
+
*/
|
|
25
|
+
items: TreeItem[];
|
|
26
|
+
/** Controlled: the ids of the open parents. Pair it with `onExpandedChange`. */
|
|
27
|
+
expandedIds?: string[];
|
|
28
|
+
/** Uncontrolled: the parents open at first. */
|
|
29
|
+
defaultExpandedIds?: string[];
|
|
30
|
+
/** Every open id, in one argument, each time a parent opens or closes. */
|
|
31
|
+
onExpandedChange?: (ids: string[]) => void;
|
|
32
|
+
/**
|
|
33
|
+
* `none`, the default: Enter, Space and a press on the row open and close a parent. `single` and
|
|
34
|
+
* `multiple`: they select, and the chevron or the Left and Right keys open and close. `single`
|
|
35
|
+
* cannot deselect: pressing the selected item again changes nothing, and only choosing another
|
|
36
|
+
* moves it. `multiple` toggles one item at a time; there is no range selection.
|
|
37
|
+
*/
|
|
38
|
+
selectionMode?: TreeSelectionMode;
|
|
39
|
+
/**
|
|
40
|
+
* Controlled: the selected ids. Pair it with `onSelectedChange`. Under `single` the first id an
|
|
41
|
+
* item holds counts, and under `none` this is ignored. An id no item holds selects nothing.
|
|
42
|
+
*/
|
|
43
|
+
selectedIds?: string[];
|
|
44
|
+
/** Uncontrolled: the ids selected at first. */
|
|
45
|
+
defaultSelectedIds?: string[];
|
|
46
|
+
/** Every selected id, in one argument, and only for a real change. */
|
|
47
|
+
onSelectedChange?: (ids: string[]) => void;
|
|
48
|
+
}
|
|
49
|
+
interface TreeNamedByLabel extends TreeBaseProps {
|
|
50
|
+
/** Names the tree. One of this and `aria-labelledby` is required. */
|
|
51
|
+
'aria-label': string;
|
|
52
|
+
'aria-labelledby'?: undefined;
|
|
53
|
+
}
|
|
54
|
+
interface TreeNamedByElement extends TreeBaseProps {
|
|
55
|
+
'aria-label'?: undefined;
|
|
56
|
+
/** The id of the element that names the tree. */
|
|
57
|
+
'aria-labelledby': string;
|
|
58
|
+
}
|
|
59
|
+
export type TreeProps = TreeNamedByLabel | TreeNamedByElement;
|
|
60
|
+
type TreeViewProps = TreeProps & {
|
|
61
|
+
/** A press on an item that can be chosen, including the one chosen already. `TreeSelect`'s. */
|
|
62
|
+
onItemChoose?: (id: string) => void;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The tree, with one prop more than the public `Tree`. Internal: not exported from `src/index.ts`.
|
|
66
|
+
*
|
|
67
|
+
* Open branches are nested in the DOM, so a browser works out each item's level and position in its
|
|
68
|
+
* set for itself, and `aria-level`, `aria-setsize` and `aria-posinset` would only repeat it.
|
|
69
|
+
*/
|
|
70
|
+
export declare function TreeView({ items, expandedIds, defaultExpandedIds, onExpandedChange, selectionMode, selectedIds, defaultSelectedIds, onSelectedChange, onItemChoose, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, }: TreeViewProps): import("react").JSX.Element | null;
|
|
71
|
+
/**
|
|
72
|
+
* A hierarchy to move through and select from, following the WAI-ARIA tree view pattern: one tab
|
|
73
|
+
* stop, arrow keys, Home, End and type-ahead. Left and Right swap in a right-to-left page.
|
|
74
|
+
*
|
|
75
|
+
* Tab lands on the selected item, or on the nearest open ancestor of one that is collapsed away,
|
|
76
|
+
* else on the first enabled item. Focus never goes with an item: when it is removed or collapsed
|
|
77
|
+
* away, focus moves to the nearest ancestor still shown. Only when every item goes does it fall to
|
|
78
|
+
* the page, and it is not taken back when items return.
|
|
79
|
+
*/
|
|
80
|
+
export declare function Tree(props: TreeProps): import("react").JSX.Element;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { CheckIcon } from "../../icons/CheckIcon.js";
|
|
4
|
+
import { ChevronDownIcon } from "../../icons/ChevronDownIcon.js";
|
|
5
|
+
import { indexItems, visibleNodesOf } from "./treeIndex.js";
|
|
6
|
+
import Tree_module from "./Tree.module.js";
|
|
7
|
+
const TYPE_AHEAD_WINDOW = 500;
|
|
8
|
+
const KEYS_WITHIN_TYPING = new Set([
|
|
9
|
+
'Shift',
|
|
10
|
+
'CapsLock',
|
|
11
|
+
'AltGraph',
|
|
12
|
+
'Dead'
|
|
13
|
+
]);
|
|
14
|
+
function nearestShown(visible, { id, ancestorIds }) {
|
|
15
|
+
return [
|
|
16
|
+
id,
|
|
17
|
+
...ancestorIds
|
|
18
|
+
].map((candidate)=>visible.find((node)=>node.id === candidate)).find((node)=>void 0 !== node);
|
|
19
|
+
}
|
|
20
|
+
function restingNode(visible, nodes, selected) {
|
|
21
|
+
const [firstHeld] = selected;
|
|
22
|
+
const collapsedAway = void 0 === firstHeld ? void 0 : nodes.get(firstHeld);
|
|
23
|
+
return visible.find((node)=>selected.has(node.id)) ?? (void 0 === collapsedAway ? void 0 : nearestShown(visible, collapsedAway)) ?? visible.find((node)=>!node.item.disabled) ?? visible[0];
|
|
24
|
+
}
|
|
25
|
+
function isPrintable(key) {
|
|
26
|
+
return 1 === Array.from(key).length;
|
|
27
|
+
}
|
|
28
|
+
function findTypedMatch(visible, from, typed) {
|
|
29
|
+
const wanted = typed.toLocaleLowerCase();
|
|
30
|
+
for(let offset = 0; offset < visible.length; offset += 1){
|
|
31
|
+
const candidate = visible[(from + offset) % visible.length];
|
|
32
|
+
if (candidate?.item.label.toLocaleLowerCase().startsWith(wanted)) return candidate;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function TreeView({ items, expandedIds, defaultExpandedIds, onExpandedChange, selectionMode = 'none', selectedIds, defaultSelectedIds, onSelectedChange, onItemChoose, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }) {
|
|
36
|
+
const baseId = useId();
|
|
37
|
+
const rootRef = useRef(null);
|
|
38
|
+
const itemElements = useRef(new Map());
|
|
39
|
+
const typedSoFar = useRef({
|
|
40
|
+
text: '',
|
|
41
|
+
at: -1 / 0
|
|
42
|
+
});
|
|
43
|
+
const [heldExpanded, setHeldExpanded] = useState(defaultExpandedIds ?? []);
|
|
44
|
+
const [heldSelected, setHeldSelected] = useState(defaultSelectedIds ?? []);
|
|
45
|
+
const [focused, setFocused] = useState(null);
|
|
46
|
+
const index = useMemo(()=>indexItems(items), [
|
|
47
|
+
items
|
|
48
|
+
]);
|
|
49
|
+
const expanded = expandedIds ?? heldExpanded;
|
|
50
|
+
const expandedSet = useMemo(()=>new Set(expanded), [
|
|
51
|
+
expanded
|
|
52
|
+
]);
|
|
53
|
+
const visible = useMemo(()=>visibleNodesOf(index.roots, expandedSet), [
|
|
54
|
+
index.roots,
|
|
55
|
+
expandedSet
|
|
56
|
+
]);
|
|
57
|
+
const selected = selectedIds ?? heldSelected;
|
|
58
|
+
const selectedSet = useMemo(()=>{
|
|
59
|
+
if ('none' === selectionMode) return new Set();
|
|
60
|
+
const known = selected.filter((id)=>index.nodes.has(id));
|
|
61
|
+
return new Set('single' === selectionMode ? known.slice(0, 1) : known);
|
|
62
|
+
}, [
|
|
63
|
+
selectionMode,
|
|
64
|
+
selected,
|
|
65
|
+
index.nodes
|
|
66
|
+
]);
|
|
67
|
+
const tabStop = (null === focused ? void 0 : nearestShown(visible, index.nodes.get(focused.id) ?? focused)) ?? restingNode(visible, index.nodes, selectedSet);
|
|
68
|
+
useLayoutEffect(()=>{
|
|
69
|
+
if (null === focused) return;
|
|
70
|
+
const stop = void 0 === tabStop ? void 0 : itemElements.current.get(tabStop.id);
|
|
71
|
+
if (void 0 === stop) setFocused(null);
|
|
72
|
+
else if (document.activeElement !== stop) stop.focus();
|
|
73
|
+
});
|
|
74
|
+
useLayoutEffect(()=>{
|
|
75
|
+
if (null !== rootRef.current) rootRef.current.dataset.direction = getComputedStyle(rootRef.current).direction;
|
|
76
|
+
});
|
|
77
|
+
const toggleExpanded = (node)=>{
|
|
78
|
+
if (node.item.disabled || 0 === node.children.length) return;
|
|
79
|
+
const next = expandedSet.has(node.id) ? expanded.filter((id)=>id !== node.id) : [
|
|
80
|
+
...expanded,
|
|
81
|
+
node.id
|
|
82
|
+
];
|
|
83
|
+
setHeldExpanded(next);
|
|
84
|
+
onExpandedChange?.(next);
|
|
85
|
+
};
|
|
86
|
+
const commitSelected = (next)=>{
|
|
87
|
+
setHeldSelected(next);
|
|
88
|
+
onSelectedChange?.(next);
|
|
89
|
+
};
|
|
90
|
+
const activate = (node)=>{
|
|
91
|
+
if ('none' === selectionMode) toggleExpanded(node);
|
|
92
|
+
else if (!node.item.disabled) {
|
|
93
|
+
if ('multiple' === selectionMode) commitSelected(selectedSet.has(node.id) ? selected.filter((id)=>id !== node.id) : [
|
|
94
|
+
...selected,
|
|
95
|
+
node.id
|
|
96
|
+
]);
|
|
97
|
+
else if (!selectedSet.has(node.id)) commitSelected([
|
|
98
|
+
node.id
|
|
99
|
+
]);
|
|
100
|
+
onItemChoose?.(node.id);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const focusNode = (id)=>{
|
|
104
|
+
if (void 0 !== id) itemElements.current.get(id)?.focus();
|
|
105
|
+
};
|
|
106
|
+
const handleKeyDown = (event)=>{
|
|
107
|
+
if (event.altKey || event.ctrlKey || event.metaKey || void 0 === tabStop) return;
|
|
108
|
+
if (!isPrintable(event.key) && !KEYS_WITHIN_TYPING.has(event.key)) typedSoFar.current.text = '';
|
|
109
|
+
const position = visible.indexOf(tabStop);
|
|
110
|
+
const inRightToLeft = 'rtl' === getComputedStyle(event.currentTarget).direction;
|
|
111
|
+
const isOpen = tabStop.children.length > 0 && expandedSet.has(tabStop.id);
|
|
112
|
+
const isTyping = '' !== typedSoFar.current.text && event.timeStamp - typedSoFar.current.at <= TYPE_AHEAD_WINDOW;
|
|
113
|
+
const keyActions = {
|
|
114
|
+
ArrowDown: ()=>focusNode(visible[position + 1]?.id),
|
|
115
|
+
ArrowUp: ()=>focusNode(visible[position - 1]?.id),
|
|
116
|
+
Home: ()=>focusNode(visible[0]?.id),
|
|
117
|
+
End: ()=>focusNode(visible.at(-1)?.id),
|
|
118
|
+
Enter: ()=>activate(tabStop)
|
|
119
|
+
};
|
|
120
|
+
const moveInward = ()=>isOpen ? focusNode(tabStop.children[0]?.id) : toggleExpanded(tabStop);
|
|
121
|
+
const moveOutward = ()=>isOpen && !tabStop.item.disabled ? toggleExpanded(tabStop) : focusNode(tabStop.ancestorIds[0]);
|
|
122
|
+
keyActions[inRightToLeft ? 'ArrowLeft' : 'ArrowRight'] = moveInward;
|
|
123
|
+
keyActions[inRightToLeft ? 'ArrowRight' : 'ArrowLeft'] = moveOutward;
|
|
124
|
+
if (!isTyping) keyActions[' '] = ()=>activate(tabStop);
|
|
125
|
+
const keyAction = keyActions[event.key];
|
|
126
|
+
if (void 0 !== keyAction) {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
keyAction();
|
|
129
|
+
} else if (isPrintable(event.key)) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
const text = (isTyping ? typedSoFar.current.text : '') + event.key;
|
|
132
|
+
typedSoFar.current = {
|
|
133
|
+
text,
|
|
134
|
+
at: event.timeStamp
|
|
135
|
+
};
|
|
136
|
+
const isOneLetter = Array.from(text).every((letter)=>letter === event.key);
|
|
137
|
+
const match = isOneLetter ? findTypedMatch(visible, position + 1, event.key) : findTypedMatch(visible, position, text);
|
|
138
|
+
focusNode(match?.id);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const renderNode = (node, level)=>{
|
|
142
|
+
const hasChildren = node.children.length > 0;
|
|
143
|
+
const isOpen = hasChildren && expandedSet.has(node.id);
|
|
144
|
+
const isSelected = selectedSet.has(node.id);
|
|
145
|
+
const labelId = `${baseId}-${node.ordinal}`;
|
|
146
|
+
const ariaSelected = isSelected || 'multiple' === selectionMode && !node.item.disabled ? isSelected : void 0;
|
|
147
|
+
return /*#__PURE__*/ jsxs("li", {
|
|
148
|
+
ref: (element)=>{
|
|
149
|
+
if (null !== element) itemElements.current.set(node.id, element);
|
|
150
|
+
return ()=>{
|
|
151
|
+
itemElements.current.delete(node.id);
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
role: "treeitem",
|
|
155
|
+
className: Tree_module.item,
|
|
156
|
+
tabIndex: node.id === tabStop?.id ? 0 : -1,
|
|
157
|
+
"aria-labelledby": labelId,
|
|
158
|
+
"aria-expanded": hasChildren ? isOpen : void 0,
|
|
159
|
+
"aria-selected": ariaSelected,
|
|
160
|
+
"aria-disabled": node.item.disabled ? true : void 0,
|
|
161
|
+
onFocus: (event)=>{
|
|
162
|
+
if (event.target === event.currentTarget) setFocused({
|
|
163
|
+
id: node.id,
|
|
164
|
+
ancestorIds: node.ancestorIds
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
children: [
|
|
168
|
+
/*#__PURE__*/ jsxs("div", {
|
|
169
|
+
className: Tree_module.row,
|
|
170
|
+
style: {
|
|
171
|
+
'--tree-level': level
|
|
172
|
+
},
|
|
173
|
+
onClick: ()=>activate(node),
|
|
174
|
+
children: [
|
|
175
|
+
hasChildren ? /*#__PURE__*/ jsx("span", {
|
|
176
|
+
className: Tree_module.toggle,
|
|
177
|
+
"data-toggle": "",
|
|
178
|
+
"aria-hidden": "true",
|
|
179
|
+
onClick: (event)=>{
|
|
180
|
+
event.stopPropagation();
|
|
181
|
+
toggleExpanded(node);
|
|
182
|
+
},
|
|
183
|
+
children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
|
|
184
|
+
}) : /*#__PURE__*/ jsx("span", {
|
|
185
|
+
className: Tree_module.toggle
|
|
186
|
+
}),
|
|
187
|
+
node.item.icon ? /*#__PURE__*/ jsx("span", {
|
|
188
|
+
className: Tree_module.icon,
|
|
189
|
+
"aria-hidden": "true",
|
|
190
|
+
children: node.item.icon
|
|
191
|
+
}) : null,
|
|
192
|
+
/*#__PURE__*/ jsx("span", {
|
|
193
|
+
id: labelId,
|
|
194
|
+
className: Tree_module.label,
|
|
195
|
+
children: node.item.label
|
|
196
|
+
}),
|
|
197
|
+
isSelected ? /*#__PURE__*/ jsx("span", {
|
|
198
|
+
className: Tree_module.check,
|
|
199
|
+
"aria-hidden": "true",
|
|
200
|
+
children: /*#__PURE__*/ jsx(CheckIcon, {})
|
|
201
|
+
}) : null
|
|
202
|
+
]
|
|
203
|
+
}),
|
|
204
|
+
isOpen ? /*#__PURE__*/ jsx("ul", {
|
|
205
|
+
role: "group",
|
|
206
|
+
className: Tree_module.group,
|
|
207
|
+
children: node.children.map((child)=>renderNode(child, level + 1))
|
|
208
|
+
}) : null
|
|
209
|
+
]
|
|
210
|
+
}, node.id);
|
|
211
|
+
};
|
|
212
|
+
if (0 === index.roots.length) return null;
|
|
213
|
+
return /*#__PURE__*/ jsx("ul", {
|
|
214
|
+
ref: rootRef,
|
|
215
|
+
role: "tree",
|
|
216
|
+
className: Tree_module.root,
|
|
217
|
+
"aria-label": ariaLabel,
|
|
218
|
+
"aria-labelledby": ariaLabelledBy,
|
|
219
|
+
"aria-multiselectable": 'multiple' === selectionMode ? true : void 0,
|
|
220
|
+
onKeyDown: handleKeyDown,
|
|
221
|
+
onBlur: (event)=>{
|
|
222
|
+
if (!event.currentTarget.contains(event.relatedTarget)) setFocused(null);
|
|
223
|
+
},
|
|
224
|
+
children: index.roots.map((node)=>renderNode(node, 0))
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function Tree(props) {
|
|
228
|
+
return /*#__PURE__*/ jsx(TreeView, {
|
|
229
|
+
...props
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
export { Tree, TreeView };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./Tree_module.css";
|
|
2
|
+
const Tree_module = {
|
|
3
|
+
root: "root-dqkRl",
|
|
4
|
+
group: "group-nEZG3",
|
|
5
|
+
row: "row-Idt69",
|
|
6
|
+
item: "item-ZpP2D",
|
|
7
|
+
icon: "icon-Vc8zg",
|
|
8
|
+
check: "check-Ccwtp",
|
|
9
|
+
toggle: "toggle-Dv2Gv",
|
|
10
|
+
label: "label-u_zOq"
|
|
11
|
+
};
|
|
12
|
+
export default Tree_module;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
.root-dqkRl, .group-nEZG3 {
|
|
2
|
+
margin: 0;
|
|
3
|
+
padding: 0;
|
|
4
|
+
list-style: none;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.root-dqkRl {
|
|
8
|
+
min-width: 0;
|
|
9
|
+
padding: var(--space-1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.row-Idt69 {
|
|
13
|
+
--tree-indent: min(calc(var(--tree-level) * var(--space-4)), 40%);
|
|
14
|
+
align-items: center;
|
|
15
|
+
gap: var(--space-1);
|
|
16
|
+
min-height: var(--size-touch);
|
|
17
|
+
padding-inline: var(--tree-indent) var(--space-2);
|
|
18
|
+
border-radius: var(--radius-md);
|
|
19
|
+
color: var(--color-text);
|
|
20
|
+
font-size: var(--text-md);
|
|
21
|
+
line-height: var(--leading-snug);
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
-webkit-user-select: none;
|
|
24
|
+
user-select: none;
|
|
25
|
+
transition-property: background-color, color;
|
|
26
|
+
transition-duration: var(--motion-duration-1);
|
|
27
|
+
transition-timing-function: var(--motion-ease);
|
|
28
|
+
-webkit-tap-highlight-color: transparent;
|
|
29
|
+
margin-block-end: var(--space-1);
|
|
30
|
+
display: flex;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.item-ZpP2D:focus-visible {
|
|
34
|
+
outline: none;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.item-ZpP2D:focus-visible > .row-Idt69 {
|
|
38
|
+
outline: var(--focus-ring-width) solid var(--color-focus);
|
|
39
|
+
outline-offset: var(--focus-ring-offset);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@media (hover: hover) {
|
|
43
|
+
.row-Idt69:hover {
|
|
44
|
+
background: var(--color-surface-2);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.item-ZpP2D[aria-selected="true"] > .row-Idt69:hover {
|
|
48
|
+
background: var(--color-accent-hover);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.item-ZpP2D[aria-selected="true"] > .row-Idt69 {
|
|
53
|
+
background: var(--color-accent);
|
|
54
|
+
color: var(--color-accent-text);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.item-ZpP2D[aria-disabled="true"] > .row-Idt69 {
|
|
58
|
+
cursor: not-allowed;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.item-ZpP2D[aria-disabled="true"] > .row-Idt69 > * {
|
|
62
|
+
opacity: .45;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.icon-Vc8zg, .check-Ccwtp {
|
|
66
|
+
flex: none;
|
|
67
|
+
display: inline-flex;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.icon-Vc8zg > svg, .check-Ccwtp > svg {
|
|
71
|
+
width: 1rem;
|
|
72
|
+
height: 1rem;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.toggle-Dv2Gv {
|
|
76
|
+
flex: none;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
align-self: stretch;
|
|
79
|
+
align-items: center;
|
|
80
|
+
width: 2rem;
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.toggle-Dv2Gv > svg {
|
|
85
|
+
width: 1rem;
|
|
86
|
+
height: 1rem;
|
|
87
|
+
transition-property: transform;
|
|
88
|
+
transition-duration: var(--motion-duration-1);
|
|
89
|
+
transition-timing-function: var(--motion-ease);
|
|
90
|
+
transform: rotate(-90deg);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.root-dqkRl[data-direction="rtl"] .toggle-Dv2Gv > svg {
|
|
94
|
+
transform: rotate(90deg);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.item-ZpP2D[aria-expanded="true"] > .row-Idt69 > .toggle-Dv2Gv > svg, .root-dqkRl[data-direction="rtl"] .item-ZpP2D[aria-expanded="true"] > .row-Idt69 > .toggle-Dv2Gv > svg {
|
|
98
|
+
transform: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.label-u_zOq {
|
|
102
|
+
min-width: 0;
|
|
103
|
+
padding-block: var(--space-2);
|
|
104
|
+
overflow-wrap: anywhere;
|
|
105
|
+
flex: 1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@media (forced-colors: active) {
|
|
109
|
+
.item-ZpP2D[aria-selected="true"] > .row-Idt69, .item-ZpP2D[aria-selected="true"] > .row-Idt69:hover {
|
|
110
|
+
forced-color-adjust: none;
|
|
111
|
+
color: highlighttext;
|
|
112
|
+
background: highlight;
|
|
113
|
+
outline-color: canvastext;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.item-ZpP2D[aria-disabled="true"] > .row-Idt69 > * {
|
|
117
|
+
opacity: 1;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.item-ZpP2D[aria-disabled="true"]:not([aria-selected="true"]) > .row-Idt69 {
|
|
121
|
+
color: graytext;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|