@calcifer-design/ui 0.3.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.
Files changed (118) hide show
  1. package/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
  2. package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
  3. package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
  4. package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
  5. package/dist/components/CardList/CardList.d.ts +30 -0
  6. package/dist/components/CardList/CardList.js +35 -0
  7. package/dist/components/CardList/CardList.module.js +7 -0
  8. package/dist/components/CardList/CardList_module.css +20 -0
  9. package/dist/components/Checkbox/Checkbox.d.ts +23 -0
  10. package/dist/components/Checkbox/Checkbox.js +33 -0
  11. package/dist/components/Checkbox/Checkbox.module.js +6 -0
  12. package/dist/components/Checkbox/Checkbox_module.css +16 -0
  13. package/dist/components/DatePicker/Calendar.d.ts +19 -0
  14. package/dist/components/DatePicker/Calendar.js +207 -0
  15. package/dist/components/DatePicker/DatePicker.d.ts +72 -0
  16. package/dist/components/DatePicker/DatePicker.js +116 -0
  17. package/dist/components/DatePicker/DatePicker.module.js +14 -0
  18. package/dist/components/DatePicker/DatePicker_module.css +112 -0
  19. package/dist/components/DatePicker/calendarDate.d.ts +46 -0
  20. package/dist/components/DatePicker/calendarDate.js +117 -0
  21. package/dist/components/Descriptions/Descriptions.d.ts +25 -0
  22. package/dist/components/Descriptions/Descriptions.js +44 -0
  23. package/dist/components/Descriptions/Descriptions.module.js +8 -0
  24. package/dist/components/Descriptions/Descriptions_module.css +47 -0
  25. package/dist/components/Field/Field.d.ts +118 -0
  26. package/dist/components/Field/Field.js +90 -0
  27. package/dist/components/Field/PickerField.d.ts +41 -0
  28. package/dist/components/Field/PickerField.js +115 -0
  29. package/dist/components/Field/PickerField.module.js +8 -0
  30. package/dist/components/Field/PickerField_module.css +36 -0
  31. package/dist/components/FilterBar/FilterBar.d.ts +55 -0
  32. package/dist/components/FilterBar/FilterBar.js +138 -0
  33. package/dist/components/FilterBar/FilterBar.module.js +13 -0
  34. package/dist/components/FilterBar/FilterBar_module.css +98 -0
  35. package/dist/components/Form/Form.d.ts +48 -0
  36. package/dist/components/Form/Form.js +38 -0
  37. package/dist/components/Form/Form.module.js +5 -0
  38. package/dist/components/Form/FormContext.d.ts +15 -0
  39. package/dist/components/Form/FormContext.js +20 -0
  40. package/dist/components/Form/Form_module.css +6 -0
  41. package/dist/components/PageShell/PageShell.d.ts +27 -0
  42. package/dist/components/PageShell/PageShell.js +35 -0
  43. package/dist/components/PageShell/PageShell.module.js +9 -0
  44. package/dist/components/PageShell/PageShell_module.css +56 -0
  45. package/dist/components/RadioGroup/RadioGroup.d.ts +35 -0
  46. package/dist/components/RadioGroup/RadioGroup.js +64 -0
  47. package/dist/components/RadioGroup/RadioGroup.module.js +6 -0
  48. package/dist/components/RadioGroup/RadioGroup_module.css +13 -0
  49. package/dist/components/Segmented/Segmented.d.ts +49 -0
  50. package/dist/components/Segmented/Segmented.js +55 -0
  51. package/dist/components/Segmented/Segmented.module.js +7 -0
  52. package/dist/components/Segmented/Segmented_module.css +75 -0
  53. package/dist/components/Select/Select.d.ts +42 -0
  54. package/dist/components/Select/Select.js +90 -0
  55. package/dist/components/Select/Select.module.js +9 -0
  56. package/dist/components/Select/Select_module.css +70 -0
  57. package/dist/components/Steps/Steps.d.ts +30 -0
  58. package/dist/components/Steps/Steps.js +63 -0
  59. package/dist/components/Steps/Steps.module.js +10 -0
  60. package/dist/components/Steps/Steps_module.css +126 -0
  61. package/dist/components/Switch/Switch.d.ts +23 -0
  62. package/dist/components/Switch/Switch.js +25 -0
  63. package/dist/components/Switch/Switch.module.js +6 -0
  64. package/dist/components/Switch/Switch_module.css +41 -0
  65. package/dist/components/TextArea/TextArea.d.ts +16 -0
  66. package/dist/components/TextArea/TextArea.js +28 -0
  67. package/dist/components/TextArea/TextArea.module.js +5 -0
  68. package/dist/components/TextArea/TextArea_module.css +12 -0
  69. package/dist/components/TextInput/TextInput.d.ts +17 -0
  70. package/dist/components/TextInput/TextInput.js +18 -0
  71. package/dist/components/TimePicker/TimePicker.d.ts +19 -0
  72. package/dist/components/TimePicker/TimePicker.js +17 -0
  73. package/dist/components/Timeline/Timeline.d.ts +39 -0
  74. package/dist/components/Timeline/Timeline.js +109 -0
  75. package/dist/components/Timeline/Timeline.module.js +12 -0
  76. package/dist/components/Timeline/Timeline_module.css +99 -0
  77. package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
  78. package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
  79. package/dist/components/Toolbar/Toolbar.d.ts +46 -0
  80. package/dist/components/Toolbar/Toolbar.js +43 -0
  81. package/dist/components/Toolbar/Toolbar.module.js +7 -0
  82. package/dist/components/Toolbar/Toolbar_module.css +26 -0
  83. package/dist/components/Tree/Tree.d.ts +81 -0
  84. package/dist/components/Tree/Tree.js +232 -0
  85. package/dist/components/Tree/Tree.module.js +12 -0
  86. package/dist/components/Tree/Tree_module.css +124 -0
  87. package/dist/components/Tree/treeIndex.d.ts +23 -0
  88. package/dist/components/Tree/treeIndex.js +33 -0
  89. package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
  90. package/dist/components/TreeSelect/TreeSelect.js +117 -0
  91. package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
  92. package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
  93. package/dist/components/Upload/Upload.d.ts +66 -0
  94. package/dist/components/Upload/Upload.js +287 -0
  95. package/dist/components/Upload/Upload.module.js +12 -0
  96. package/dist/components/Upload/Upload_module.css +96 -0
  97. package/dist/components/ViewField/ViewField.d.ts +26 -0
  98. package/dist/components/ViewField/ViewField.js +29 -0
  99. package/dist/components/ViewField/ViewField.module.js +6 -0
  100. package/dist/components/ViewField/ViewField_module.css +17 -0
  101. package/dist/hooks/useFormReset.d.ts +10 -0
  102. package/dist/hooks/useFormReset.js +34 -0
  103. package/dist/icons/CalendarIcon.d.ts +2 -0
  104. package/dist/icons/CalendarIcon.js +26 -0
  105. package/dist/icons/CheckIcon.d.ts +6 -0
  106. package/dist/icons/CheckIcon.js +17 -0
  107. package/dist/icons/ChevronDownIcon.d.ts +6 -0
  108. package/dist/icons/ChevronDownIcon.js +17 -0
  109. package/dist/icons/MinusIcon.d.ts +5 -0
  110. package/dist/icons/MinusIcon.js +16 -0
  111. package/dist/index.d.ts +46 -0
  112. package/dist/index.js +23 -0
  113. package/dist/styles/field.module.js +15 -0
  114. package/dist/styles/field_module.css +133 -0
  115. package/dist/styles/pair.module.js +6 -0
  116. package/dist/styles/pair_module.css +18 -0
  117. package/dist/styles/popup_module.css +6 -0
  118. package/package.json +2 -2
@@ -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
+
@@ -0,0 +1,23 @@
1
+ import type { TreeItem } from './Tree.js';
2
+ /** One item in its place. Internal, as `TreeSelect` and `Tree` share it. */
3
+ export interface TreeNode {
4
+ id: string;
5
+ item: TreeItem;
6
+ /** Nearest first. */
7
+ ancestorIds: string[];
8
+ children: TreeNode[];
9
+ /** Its place in the whole tree, which an element id can hold where any `id` string could not. */
10
+ ordinal: number;
11
+ }
12
+ export interface TreeIndex {
13
+ roots: TreeNode[];
14
+ nodes: Map<string, TreeNode>;
15
+ }
16
+ /**
17
+ * The tree with each id in one place. An id seen before is left out with everything it holds:
18
+ * selection, expansion and focus all speak in ids, so two items sharing one could not be told apart.
19
+ * That also stops an item that holds itself from going round for ever.
20
+ */
21
+ export declare function indexItems(items: TreeItem[]): TreeIndex;
22
+ /** What is shown, top to bottom: every root, and what each open parent holds. */
23
+ export declare function visibleNodesOf(roots: TreeNode[], expanded: ReadonlySet<string>): TreeNode[];
@@ -0,0 +1,33 @@
1
+ function indexItems(items) {
2
+ const nodes = new Map();
3
+ const collect = (level, ancestorIds)=>{
4
+ const collected = [];
5
+ for (const item of level)if (!nodes.has(item.id)) {
6
+ const node = {
7
+ id: item.id,
8
+ item,
9
+ ancestorIds,
10
+ children: [],
11
+ ordinal: nodes.size
12
+ };
13
+ nodes.set(item.id, node);
14
+ node.children = collect(item.children ?? [], [
15
+ item.id,
16
+ ...ancestorIds
17
+ ]);
18
+ collected.push(node);
19
+ }
20
+ return collected;
21
+ };
22
+ return {
23
+ roots: collect(items, []),
24
+ nodes
25
+ };
26
+ }
27
+ function visibleNodesOf(roots, expanded) {
28
+ return roots.flatMap((node)=>[
29
+ node,
30
+ ...expanded.has(node.id) ? visibleNodesOf(node.children, expanded) : []
31
+ ]);
32
+ }
33
+ export { indexItems, visibleNodesOf };
@@ -0,0 +1,61 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { FieldFrameProps } from '../Field/Field.js';
3
+ import { type TreeItem } from '../Tree/Tree.js';
4
+ export interface TreeSelectLabels {
5
+ /** Joins the trigger's accessible name when the field is `required`. */
6
+ required: string;
7
+ /** Shown when `Form` submits a `required` field with nothing chosen. */
8
+ requiredMessage: string;
9
+ /** The clear button's name. Defaults to "Clear" and the field's own label. */
10
+ clear: string;
11
+ /** Shown in the popup, in place of the tree, while `items` is empty. */
12
+ empty: string;
13
+ }
14
+ export interface TreeSelectProps extends FieldFrameProps {
15
+ /** The visible label, the start of the trigger's accessible name and the name of the tree. */
16
+ label: string;
17
+ /**
18
+ * The hierarchy, as `Tree` takes it. A new array of the same ids changes no state. While it is
19
+ * empty the popup still opens, says `labels.empty` and takes focus itself.
20
+ */
21
+ items: TreeItem[];
22
+ /** Sits under the trigger and joins its `aria-describedby`. */
23
+ description?: ReactNode;
24
+ /**
25
+ * Draws the required mark and adds the word to the trigger's name. `Form` refuses to submit while
26
+ * nothing is chosen, with `labels.requiredMessage` on the frame. A plain `<form>` is not blocked:
27
+ * the value travels in a hidden input, which has no constraints, so the app validates.
28
+ */
29
+ required?: boolean;
30
+ /**
31
+ * Controlled: a node's `id`, or `null` for nothing chosen. An id no node holds reads as nothing
32
+ * chosen, and nothing is reported for it. A node that is `disabled` can still be the value, since
33
+ * it is the app's to set: it shows and submits, and only cannot be chosen by the user.
34
+ */
35
+ value?: string | null;
36
+ /**
37
+ * Uncontrolled: the first value, and the one a native reset of the surrounding form goes back to,
38
+ * with `onValueChange` told. A controlled `value` stays through a reset, as the parent's to change.
39
+ */
40
+ defaultValue?: string | null;
41
+ /** The chosen node's `id`, or `null` once cleared, in one argument, and only for a real change. */
42
+ onValueChange?: (value: string | null) => void;
43
+ /** Called when focus leaves the trigger, for a form library's "touched". */
44
+ onBlur?: () => void;
45
+ /** Shown on the trigger while nothing is chosen. */
46
+ placeholder?: string;
47
+ /** Shows a button that clears the choice, while there is one. */
48
+ clearable?: boolean;
49
+ /** The words the control says itself, for an app that is not in English. */
50
+ labels?: Partial<TreeSelectLabels>;
51
+ }
52
+ /**
53
+ * Choose one node from a hierarchy: a button showing the choice opens a `Tree`, with focus on the
54
+ * chosen node and the branches around it opened. Choosing closes it and returns focus, as Escape
55
+ * does. Submits the node's `id` through a hidden input.
56
+ *
57
+ * The popup does not trap focus, as `DatePicker`'s dialog does: there is one tab stop in it, so Tab
58
+ * closes it and moves on. Shift+Tab goes to the trigger and leaves it open, and Escape or a second
59
+ * Shift+Tab closes it from there.
60
+ */
61
+ export declare function TreeSelect({ label, name, items, description, error, required, disabled, value, defaultValue, onValueChange, onBlur, placeholder, clearable, labels, }: TreeSelectProps): import("react").JSX.Element;
@@ -0,0 +1,117 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Popover } from "@base-ui/react/popover";
3
+ import { useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ import { ChevronDownIcon } from "../../icons/ChevronDownIcon.js";
5
+ import popup_module from "../../styles/popup.module.js";
6
+ import { PickerField } from "../Field/PickerField.js";
7
+ import { TreeView } from "../Tree/Tree.js";
8
+ import { indexItems } from "../Tree/treeIndex.js";
9
+ import TreeSelect_module from "./TreeSelect.module.js";
10
+ const DEFAULT_LABELS = {
11
+ required: 'required',
12
+ requiredMessage: 'Choose an option.',
13
+ empty: 'No options'
14
+ };
15
+ function TreeSelect({ label, name, items, description, error, required = false, disabled = false, value, defaultValue, onValueChange, onBlur, placeholder = 'Select…', clearable = false, labels }) {
16
+ const popupRef = useRef(null);
17
+ const [heldValue, setHeldValue] = useState(defaultValue ?? null);
18
+ const [expandedIds, setExpandedIds] = useState([]);
19
+ const [open, setOpen] = useState(false);
20
+ if (open && disabled) setOpen(false);
21
+ const index = useMemo(()=>indexItems(items), [
22
+ items
23
+ ]);
24
+ const nodeOf = (id)=>null === id ? void 0 : index.nodes.get(id);
25
+ const chosenNode = nodeOf(void 0 === value ? heldValue : value);
26
+ const chosen = chosenNode?.id ?? null;
27
+ const words = {
28
+ ...DEFAULT_LABELS,
29
+ clear: `Clear ${label}`,
30
+ ...labels
31
+ };
32
+ const hasItems = index.roots.length > 0;
33
+ const commit = (nextValue)=>{
34
+ setHeldValue(nextValue);
35
+ const nextChosen = nodeOf(nextValue)?.id ?? null;
36
+ if (nextChosen !== chosen) onValueChange?.(nextChosen);
37
+ };
38
+ const changeOpen = (nextOpen)=>{
39
+ if (nextOpen && void 0 !== chosenNode) setExpandedIds([
40
+ ...new Set([
41
+ ...expandedIds,
42
+ ...chosenNode.ancestorIds
43
+ ])
44
+ ]);
45
+ setOpen(nextOpen);
46
+ };
47
+ useLayoutEffect(()=>{
48
+ if (open && !hasItems && document.activeElement === document.body) popupRef.current?.focus();
49
+ }, [
50
+ open,
51
+ hasItems
52
+ ]);
53
+ return /*#__PURE__*/ jsx(PickerField, {
54
+ label: label,
55
+ name: name,
56
+ description: description,
57
+ error: error,
58
+ required: required,
59
+ disabled: disabled,
60
+ value: chosen,
61
+ valueText: void 0 === chosenNode ? placeholder : chosenNode.item.label,
62
+ icon: /*#__PURE__*/ jsx(ChevronDownIcon, {}),
63
+ iconClassName: TreeSelect_module.chevron,
64
+ requiredWord: words.required,
65
+ validate: ()=>required && null === chosen ? words.requiredMessage : null,
66
+ onReset: ()=>{
67
+ if (void 0 === value) commit(defaultValue ?? null);
68
+ },
69
+ clearable: clearable,
70
+ clearLabel: words.clear,
71
+ onClear: ()=>commit(null),
72
+ onBlur: onBlur,
73
+ onTriggerKeyDown: (event)=>{
74
+ if ('ArrowDown' === event.key || 'ArrowUp' === event.key) {
75
+ event.preventDefault();
76
+ if (!open) changeOpen(true);
77
+ }
78
+ },
79
+ open: open,
80
+ onOpenChange: changeOpen,
81
+ children: /*#__PURE__*/ jsx(Popover.Portal, {
82
+ children: /*#__PURE__*/ jsx(Popover.Positioner, {
83
+ className: popup_module.layer,
84
+ align: "start",
85
+ sideOffset: 8,
86
+ children: /*#__PURE__*/ jsx(Popover.Popup, {
87
+ ref: popupRef,
88
+ className: [
89
+ popup_module.surface,
90
+ TreeSelect_module.popup
91
+ ].join(' '),
92
+ "data-popup": "select",
93
+ "aria-label": label,
94
+ initialFocus: ()=>popupRef.current?.querySelector('[tabindex="0"]') ?? true,
95
+ children: hasItems ? /*#__PURE__*/ jsx(TreeView, {
96
+ items: items,
97
+ "aria-label": label,
98
+ selectionMode: "single",
99
+ selectedIds: null === chosen ? [] : [
100
+ chosen
101
+ ],
102
+ expandedIds: expandedIds,
103
+ onExpandedChange: setExpandedIds,
104
+ onItemChoose: (id)=>{
105
+ commit(id);
106
+ setOpen(false);
107
+ }
108
+ }) : /*#__PURE__*/ jsx(Popover.Description, {
109
+ className: TreeSelect_module.empty,
110
+ children: words.empty
111
+ })
112
+ })
113
+ })
114
+ })
115
+ });
116
+ }
117
+ export { TreeSelect };
@@ -0,0 +1,7 @@
1
+ import "./TreeSelect_module.css";
2
+ const TreeSelect_module = {
3
+ chevron: "chevron-HJ0ky",
4
+ popup: "popup-KUQxt",
5
+ empty: "empty-RdOM_"
6
+ };
7
+ export default TreeSelect_module;
@@ -0,0 +1,22 @@
1
+ .chevron-HJ0ky {
2
+ transition-property: transform;
3
+ transition-duration: var(--motion-duration-1);
4
+ transition-timing-function: var(--motion-ease);
5
+ }
6
+
7
+ [data-popup-open] > .chevron-HJ0ky {
8
+ transform: rotate(180deg);
9
+ }
10
+
11
+ .popup-KUQxt[data-popup] {
12
+ width: max(var(--anchor-width), 18rem);
13
+ max-height: min(24rem, var(--available-height));
14
+ }
15
+
16
+ .empty-RdOM_ {
17
+ padding: var(--space-2) var(--space-3);
18
+ color: var(--color-text-muted);
19
+ font-size: var(--text-sm);
20
+ margin: 0;
21
+ }
22
+
@@ -0,0 +1,66 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type FieldFrameProps } from '../Field/Field.js';
3
+ export type UploadRejectionReason = 'type' | 'size' | 'count' | 'duplicate';
4
+ export interface UploadRejection {
5
+ file: File;
6
+ /**
7
+ * `type`: not covered by `accept`. `size`: over `maxSizeBytes`. `count`: a second file when
8
+ * `multiple` is off. `duplicate`: with `multiple`, a file the list already holds. Checked in
9
+ * that order, and a file gets the first reason that applies.
10
+ */
11
+ reason: UploadRejectionReason;
12
+ }
13
+ export interface UploadLabels {
14
+ /** The words on the button. */
15
+ choose: string;
16
+ /** Beside the button. */
17
+ dropHint: string;
18
+ /** The name of one file's remove button. */
19
+ remove: (fileName: string) => string;
20
+ /** Announced when files join the list. */
21
+ added: (fileNames: string) => string;
22
+ /** Announced when a file leaves the list. */
23
+ removed: (fileName: string) => string;
24
+ /** Shown and announced for a file turned away. */
25
+ rejected: (fileName: string, reason: UploadRejectionReason) => string;
26
+ }
27
+ export interface UploadProps extends FieldFrameProps {
28
+ /** The visible label, and the file input's accessible name. */
29
+ label: string;
30
+ /** Sits under the drop zone and joins the input's `aria-describedby`. */
31
+ description?: ReactNode;
32
+ /** Controlled. Pair it with `onFilesChange`; use `defaultFiles` for an uncontrolled one. */
33
+ files?: File[];
34
+ /**
35
+ * Uncontrolled: the first list, and the one a native reset of the surrounding form goes back to,
36
+ * with `onFilesChange` told. A controlled `files` stays through a reset, and goes back in the
37
+ * input the browser just emptied.
38
+ */
39
+ defaultFiles?: File[];
40
+ /**
41
+ * The whole new list. With `multiple` a choice adds to the list, and the same file again goes to
42
+ * `onReject` as a `duplicate`. Without it a choice replaces the file there was, and choosing that
43
+ * same file again is no change: this is not called and nothing is announced.
44
+ */
45
+ onFilesChange?: (files: File[]) => void;
46
+ /**
47
+ * The native `accept` syntax: `.pdf`, `image/*`, `application/pdf`. It is checked here as well,
48
+ * for every file, because a browser only filters its picker: a drop would get anything through.
49
+ */
50
+ accept?: string;
51
+ multiple?: boolean;
52
+ /** The largest file allowed. A file of exactly this size is allowed. */
53
+ maxSizeBytes?: number;
54
+ /** The files turned away from one choice or drop, each with its reason. */
55
+ onReject?: (rejections: UploadRejection[]) => void;
56
+ /** Called when focus leaves the file input, for a form library's "touched". */
57
+ onBlur?: () => void;
58
+ /** The words the control says itself, for an app that is not in English. */
59
+ labels?: Partial<UploadLabels>;
60
+ }
61
+ /**
62
+ * Selects files; it does not transfer them. The real file input lies over the whole zone, so the
63
+ * keyboard, a screen reader and a pointer all use it, and what looks like a button is a picture of
64
+ * one. Dropping is an enhancement over that, and goes through the same checks.
65
+ */
66
+ export declare function Upload({ label, name, description, error, required, disabled, files, defaultFiles, onFilesChange, accept, multiple, maxSizeBytes, onReject, onBlur, labels, }: UploadProps): import("react").JSX.Element;