@calcifer-design/ui 0.4.0 → 0.6.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 (133) 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/DataGrid/DataGrid.d.ts +3 -0
  10. package/dist/components/DataGrid/DataGrid.js +436 -0
  11. package/dist/components/DataGrid/DataGrid.module.js +36 -0
  12. package/dist/components/DataGrid/DataGrid_module.css +367 -0
  13. package/dist/components/DataGrid/GridCardHeader.d.ts +16 -0
  14. package/dist/components/DataGrid/GridCardHeader.js +40 -0
  15. package/dist/components/DataGrid/GridCheckbox.d.ts +15 -0
  16. package/dist/components/DataGrid/GridCheckbox.js +25 -0
  17. package/dist/components/DataGrid/GridHeaderCell.d.ts +14 -0
  18. package/dist/components/DataGrid/GridHeaderCell.js +29 -0
  19. package/dist/components/DataGrid/GridHeaderRow.d.ts +35 -0
  20. package/dist/components/DataGrid/GridHeaderRow.js +56 -0
  21. package/dist/components/DataGrid/GridRow.d.ts +69 -0
  22. package/dist/components/DataGrid/GridRow.js +139 -0
  23. package/dist/components/DataGrid/GridStateRows.d.ts +24 -0
  24. package/dist/components/DataGrid/GridStateRows.js +59 -0
  25. package/dist/components/DataGrid/columns.d.ts +40 -0
  26. package/dist/components/DataGrid/columns.js +37 -0
  27. package/dist/components/DataGrid/labels.d.ts +20 -0
  28. package/dist/components/DataGrid/labels.js +25 -0
  29. package/dist/components/DataGrid/types.d.ts +88 -0
  30. package/dist/components/DataGrid/types.js +0 -0
  31. package/dist/components/DataGrid/useGridEntries.d.ts +17 -0
  32. package/dist/components/DataGrid/useGridEntries.js +40 -0
  33. package/dist/components/DataGrid/useGridHighlight.d.ts +16 -0
  34. package/dist/components/DataGrid/useGridHighlight.js +24 -0
  35. package/dist/components/DataGrid/useGridKeyboard.d.ts +50 -0
  36. package/dist/components/DataGrid/useGridKeyboard.js +242 -0
  37. package/dist/components/DataGrid/useGridMetrics.d.ts +13 -0
  38. package/dist/components/DataGrid/useGridMetrics.js +35 -0
  39. package/dist/components/DataGrid/useLatest.d.ts +7 -0
  40. package/dist/components/DataGrid/useLatest.js +9 -0
  41. package/dist/components/DataGrid/useLoadMore.d.ts +30 -0
  42. package/dist/components/DataGrid/useLoadMore.js +39 -0
  43. package/dist/components/DataGrid/useRowExpansion.d.ts +14 -0
  44. package/dist/components/DataGrid/useRowExpansion.js +21 -0
  45. package/dist/components/DataGrid/useRowSelection.d.ts +43 -0
  46. package/dist/components/DataGrid/useRowSelection.js +107 -0
  47. package/dist/components/DatePicker/Calendar.d.ts +19 -0
  48. package/dist/components/DatePicker/Calendar.js +207 -0
  49. package/dist/components/DatePicker/DatePicker.d.ts +72 -0
  50. package/dist/components/DatePicker/DatePicker.js +116 -0
  51. package/dist/components/DatePicker/DatePicker.module.js +14 -0
  52. package/dist/components/DatePicker/DatePicker_module.css +112 -0
  53. package/dist/components/DatePicker/calendarDate.d.ts +46 -0
  54. package/dist/components/DatePicker/calendarDate.js +117 -0
  55. package/dist/components/Descriptions/Descriptions.d.ts +25 -0
  56. package/dist/components/Descriptions/Descriptions.js +44 -0
  57. package/dist/components/Descriptions/Descriptions.module.js +8 -0
  58. package/dist/components/Descriptions/Descriptions_module.css +47 -0
  59. package/dist/components/Field/Field.d.ts +1 -1
  60. package/dist/components/Field/Field.js +7 -1
  61. package/dist/components/Field/PickerField.d.ts +41 -0
  62. package/dist/components/Field/PickerField.js +115 -0
  63. package/dist/components/Field/PickerField.module.js +8 -0
  64. package/dist/components/Field/PickerField_module.css +36 -0
  65. package/dist/components/FilterBar/FilterBar.d.ts +55 -0
  66. package/dist/components/FilterBar/FilterBar.js +138 -0
  67. package/dist/components/FilterBar/FilterBar.module.js +13 -0
  68. package/dist/components/FilterBar/FilterBar_module.css +98 -0
  69. package/dist/components/Form/Form.d.ts +48 -0
  70. package/dist/components/Form/Form.js +38 -0
  71. package/dist/components/Form/Form.module.js +5 -0
  72. package/dist/components/Form/FormContext.d.ts +15 -0
  73. package/dist/components/Form/FormContext.js +20 -0
  74. package/dist/components/Form/Form_module.css +6 -0
  75. package/dist/components/PageShell/PageShell.d.ts +27 -0
  76. package/dist/components/PageShell/PageShell.js +35 -0
  77. package/dist/components/PageShell/PageShell.module.js +9 -0
  78. package/dist/components/PageShell/PageShell_module.css +56 -0
  79. package/dist/components/Segmented/Segmented.d.ts +49 -0
  80. package/dist/components/Segmented/Segmented.js +55 -0
  81. package/dist/components/Segmented/Segmented.module.js +7 -0
  82. package/dist/components/Segmented/Segmented_module.css +75 -0
  83. package/dist/components/Steps/Steps.d.ts +30 -0
  84. package/dist/components/Steps/Steps.js +63 -0
  85. package/dist/components/Steps/Steps.module.js +10 -0
  86. package/dist/components/Steps/Steps_module.css +126 -0
  87. package/dist/components/TextArea/TextArea.d.ts +16 -0
  88. package/dist/components/TextArea/TextArea.js +28 -0
  89. package/dist/components/TextArea/TextArea.module.js +5 -0
  90. package/dist/components/TextArea/TextArea_module.css +12 -0
  91. package/dist/components/TimePicker/TimePicker.d.ts +19 -0
  92. package/dist/components/TimePicker/TimePicker.js +17 -0
  93. package/dist/components/Timeline/Timeline.d.ts +39 -0
  94. package/dist/components/Timeline/Timeline.js +109 -0
  95. package/dist/components/Timeline/Timeline.module.js +12 -0
  96. package/dist/components/Timeline/Timeline_module.css +99 -0
  97. package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
  98. package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
  99. package/dist/components/Toolbar/Toolbar.d.ts +46 -0
  100. package/dist/components/Toolbar/Toolbar.js +43 -0
  101. package/dist/components/Toolbar/Toolbar.module.js +7 -0
  102. package/dist/components/Toolbar/Toolbar_module.css +26 -0
  103. package/dist/components/Tree/Tree.d.ts +81 -0
  104. package/dist/components/Tree/Tree.js +232 -0
  105. package/dist/components/Tree/Tree.module.js +12 -0
  106. package/dist/components/Tree/Tree_module.css +124 -0
  107. package/dist/components/Tree/treeIndex.d.ts +23 -0
  108. package/dist/components/Tree/treeIndex.js +33 -0
  109. package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
  110. package/dist/components/TreeSelect/TreeSelect.js +117 -0
  111. package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
  112. package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
  113. package/dist/components/Upload/Upload.d.ts +66 -0
  114. package/dist/components/Upload/Upload.js +287 -0
  115. package/dist/components/Upload/Upload.module.js +12 -0
  116. package/dist/components/Upload/Upload_module.css +96 -0
  117. package/dist/components/ViewField/ViewField.d.ts +26 -0
  118. package/dist/components/ViewField/ViewField.js +29 -0
  119. package/dist/components/ViewField/ViewField.module.js +6 -0
  120. package/dist/components/ViewField/ViewField_module.css +17 -0
  121. package/dist/hooks/useFormReset.d.ts +10 -0
  122. package/dist/hooks/useFormReset.js +34 -0
  123. package/dist/icons/CalendarIcon.d.ts +2 -0
  124. package/dist/icons/CalendarIcon.js +26 -0
  125. package/dist/icons/ChevronRightIcon.d.ts +6 -0
  126. package/dist/icons/ChevronRightIcon.js +17 -0
  127. package/dist/icons/RefreshIcon.d.ts +6 -0
  128. package/dist/icons/RefreshIcon.js +22 -0
  129. package/dist/index.d.ts +39 -0
  130. package/dist/index.js +19 -0
  131. package/dist/styles/pair.module.js +6 -0
  132. package/dist/styles/pair_module.css +18 -0
  133. package/package.json +4 -3
@@ -0,0 +1,117 @@
1
+ const DAY_IN_MILLISECONDS = 86400000;
2
+ const EARLIEST_DATE = '0000-01-01';
3
+ const LATEST_DATE = '9999-12-31';
4
+ function toInstant(date) {
5
+ const instant = new Date(0);
6
+ instant.setUTCFullYear(Number(date.slice(0, 4)), Number(date.slice(5, 7)) - 1, Number(date.slice(8, 10)));
7
+ return instant;
8
+ }
9
+ function formatFields(year, month, day) {
10
+ return [
11
+ String(year).padStart(4, '0'),
12
+ String(month).padStart(2, '0'),
13
+ String(day).padStart(2, '0')
14
+ ].join('-');
15
+ }
16
+ function fromInstant(instant) {
17
+ const year = instant.getUTCFullYear();
18
+ if (year < 0) return EARLIEST_DATE;
19
+ if (year > 9999) return LATEST_DATE;
20
+ return formatFields(year, instant.getUTCMonth() + 1, instant.getUTCDate());
21
+ }
22
+ function parseIsoDate(value) {
23
+ if ('string' != typeof value || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
24
+ return fromInstant(toInstant(value)) === value ? value : null;
25
+ }
26
+ function isDateUnavailable(date, { min, max, isDateDisabled }) {
27
+ return null !== min && date < min || null !== max && date > max || Boolean(isDateDisabled?.(date));
28
+ }
29
+ function todayIn(now) {
30
+ return formatFields(now.getFullYear(), now.getMonth() + 1, now.getDate());
31
+ }
32
+ function addDays(date, amount) {
33
+ return fromInstant(new Date(toInstant(date).getTime() + amount * DAY_IN_MILLISECONDS));
34
+ }
35
+ function firstOfMonth(date) {
36
+ return `${date.slice(0, 7)}-01`;
37
+ }
38
+ function lastOfMonth(date) {
39
+ const instant = toInstant(firstOfMonth(date));
40
+ instant.setUTCMonth(instant.getUTCMonth() + 1, 0);
41
+ return fromInstant(instant);
42
+ }
43
+ function daysInMonth(date) {
44
+ return Number(lastOfMonth(date).slice(8, 10));
45
+ }
46
+ function withDay(date, day) {
47
+ return `${date.slice(0, 8)}${String(day).padStart(2, '0')}`;
48
+ }
49
+ function addMonths(date, amount) {
50
+ const instant = toInstant(firstOfMonth(date));
51
+ instant.setUTCMonth(instant.getUTCMonth() + amount);
52
+ const first = fromInstant(instant);
53
+ return withDay(first, Math.min(Number(date.slice(8, 10)), daysInMonth(first)));
54
+ }
55
+ function weekdayOf(date) {
56
+ return toInstant(date).getUTCDay();
57
+ }
58
+ function daysIntoWeek(date, weekStartsOn) {
59
+ return (weekdayOf(date) - weekStartsOn + 7) % 7;
60
+ }
61
+ function startOfWeek(date, weekStartsOn) {
62
+ return addDays(date, -daysIntoWeek(date, weekStartsOn));
63
+ }
64
+ function endOfWeek(date, weekStartsOn) {
65
+ return addDays(startOfWeek(date, weekStartsOn), 6);
66
+ }
67
+ function weeksOfMonth(date, weekStartsOn) {
68
+ const first = firstOfMonth(date);
69
+ const dayCount = daysInMonth(date);
70
+ const leadingCells = daysIntoWeek(first, weekStartsOn);
71
+ const weekCount = Math.ceil((leadingCells + dayCount) / 7);
72
+ return Array.from({
73
+ length: weekCount
74
+ }, (_unusedWeek, week)=>Array.from({
75
+ length: 7
76
+ }, (_unusedDay, column)=>{
77
+ const day = 7 * week + column - leadingCells + 1;
78
+ return day >= 1 && day <= dayCount ? withDay(first, day) : null;
79
+ }));
80
+ }
81
+ function dateFormatter(locale, options) {
82
+ const formatter = new Intl.DateTimeFormat(locale, {
83
+ ...options,
84
+ calendar: 'gregory',
85
+ timeZone: 'UTC'
86
+ });
87
+ return {
88
+ format: (date)=>formatter.format(toInstant(date))
89
+ };
90
+ }
91
+ function usableLocale(locale) {
92
+ try {
93
+ return void 0 === locale ? void 0 : Intl.getCanonicalLocales(locale)[0];
94
+ } catch {
95
+ return;
96
+ }
97
+ }
98
+ const RIGHT_TO_LEFT_SCRIPTS = new Set([
99
+ 'Adlm',
100
+ 'Arab',
101
+ 'Hebr',
102
+ 'Mand',
103
+ 'Nkoo',
104
+ 'Rohg',
105
+ 'Syrc',
106
+ 'Thaa'
107
+ ]);
108
+ function directionOf(locale) {
109
+ const script = new Intl.Locale(locale).maximize().script ?? '';
110
+ return RIGHT_TO_LEFT_SCRIPTS.has(script) ? 'rtl' : 'ltr';
111
+ }
112
+ function weekStartOf(locale) {
113
+ const resolved = locale ?? new Intl.DateTimeFormat().resolvedOptions().locale;
114
+ const details = new Intl.Locale(resolved);
115
+ return (details.getWeekInfo?.().firstDay ?? details.weekInfo?.firstDay ?? 0) % 7;
116
+ }
117
+ export { addDays, addMonths, dateFormatter, directionOf, endOfWeek, firstOfMonth, isDateUnavailable, lastOfMonth, parseIsoDate, startOfWeek, todayIn, usableLocale, weekStartOf, weekdayOf, weeksOfMonth };
@@ -0,0 +1,25 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface DescriptionsItem {
3
+ /** Identifies the item across renders. */
4
+ id: string;
5
+ label: ReactNode;
6
+ value?: ReactNode;
7
+ /** How many columns it takes. Limited to `columns`, and ignored at narrow widths. */
8
+ span?: 1 | 2 | 3;
9
+ }
10
+ export interface DescriptionsProps {
11
+ items: DescriptionsItem[];
12
+ /**
13
+ * The columns from the `sm` breakpoint up; below it there is one. The breakpoint is the
14
+ * viewport's, so in a narrow place on a wide screen, such as a sidebar, pass `1`.
15
+ */
16
+ columns?: 1 | 2 | 3;
17
+ /** Rendered above the list, and names it through `aria-labelledby`. */
18
+ heading?: ReactNode;
19
+ /** `4` is the extra step `Card` does not have: this often sits inside a card's own `h3`. */
20
+ headingLevel?: 2 | 3 | 4;
21
+ /** Shown instead of a value that is `undefined`, `null`, `false` or `''`. */
22
+ emptyText?: ReactNode;
23
+ }
24
+ /** A set of label and value pairs in one `<dl>`. For a single pair use `ViewField`. */
25
+ export declare function Descriptions({ items, columns, heading, headingLevel, emptyText, }: DescriptionsProps): import("react").JSX.Element;
@@ -0,0 +1,44 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import pair_module from "../../styles/pair.module.js";
4
+ import { DEFAULT_EMPTY_TEXT, isEmptyValue } from "../ViewField/ViewField.js";
5
+ import Descriptions_module from "./Descriptions.module.js";
6
+ function Descriptions({ items, columns = 2, heading, headingLevel = 3, emptyText = DEFAULT_EMPTY_TEXT }) {
7
+ const headingId = useId();
8
+ const Heading = `h${headingLevel}`;
9
+ return /*#__PURE__*/ jsxs("div", {
10
+ className: Descriptions_module.root,
11
+ children: [
12
+ heading ? /*#__PURE__*/ jsx(Heading, {
13
+ id: headingId,
14
+ className: Descriptions_module.heading,
15
+ children: heading
16
+ }) : null,
17
+ /*#__PURE__*/ jsx("dl", {
18
+ className: Descriptions_module.list,
19
+ "data-columns": columns,
20
+ "aria-labelledby": heading ? headingId : void 0,
21
+ children: items.map((item)=>{
22
+ const isEmpty = isEmptyValue(item.value);
23
+ const span = Math.min(item.span ?? 1, columns);
24
+ return /*#__PURE__*/ jsxs("div", {
25
+ className: Descriptions_module.group,
26
+ "data-span": span > 1 ? span : void 0,
27
+ children: [
28
+ /*#__PURE__*/ jsx("dt", {
29
+ className: pair_module.label,
30
+ children: item.label
31
+ }),
32
+ /*#__PURE__*/ jsx("dd", {
33
+ className: pair_module.value,
34
+ "data-empty": isEmpty ? '' : void 0,
35
+ children: isEmpty ? emptyText : item.value
36
+ })
37
+ ]
38
+ }, item.id);
39
+ })
40
+ })
41
+ ]
42
+ });
43
+ }
44
+ export { Descriptions };
@@ -0,0 +1,8 @@
1
+ import "./Descriptions_module.css";
2
+ const Descriptions_module = {
3
+ root: "root-bQlQQ",
4
+ heading: "heading-aHnDT",
5
+ list: "list-Qwuyt",
6
+ group: "group-fd_ih"
7
+ };
8
+ export default Descriptions_module;
@@ -0,0 +1,47 @@
1
+ .root-bQlQQ {
2
+ gap: var(--space-3);
3
+ flex-direction: column;
4
+ display: flex;
5
+ }
6
+
7
+ .heading-aHnDT {
8
+ color: var(--color-text);
9
+ font-size: var(--text-h3);
10
+ line-height: var(--leading-snug);
11
+ letter-spacing: var(--tracking-heading);
12
+ margin: 0;
13
+ }
14
+
15
+ .list-Qwuyt {
16
+ gap: var(--space-4);
17
+ grid-template-columns: minmax(0, 1fr);
18
+ margin: 0;
19
+ display: grid;
20
+ }
21
+
22
+ .group-fd_ih {
23
+ gap: var(--space-1);
24
+ overflow-wrap: anywhere;
25
+ flex-direction: column;
26
+ min-width: 0;
27
+ display: flex;
28
+ }
29
+
30
+ @media (width >= 40rem) {
31
+ .list-Qwuyt[data-columns="2"] {
32
+ grid-template-columns: repeat(2, minmax(0, 1fr));
33
+ }
34
+
35
+ .list-Qwuyt[data-columns="3"] {
36
+ grid-template-columns: repeat(3, minmax(0, 1fr));
37
+ }
38
+
39
+ .group-fd_ih[data-span="2"] {
40
+ grid-column: span 2;
41
+ }
42
+
43
+ .group-fd_ih[data-span="3"] {
44
+ grid-column: span 3;
45
+ }
46
+ }
47
+
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- /** Internal. Read by `TextInput`; not exported from the barrel. */
2
+ /** Internal. Read by `TextInput`, `TextArea` and `TimePicker`; not exported from the barrel. */
3
3
  export declare function useFieldRequired(): boolean;
4
4
  export interface FieldMessagesProps {
5
5
  /** Sits under the control and joins the control's `aria-describedby`. */
@@ -2,12 +2,14 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Field } from "@base-ui/react/field";
3
3
  import { createContext, useContext } from "react";
4
4
  import field_module from "../../styles/field.module.js";
5
+ import { useInsideForm } from "../Form/FormContext.js";
5
6
  const FieldRequiredContext = /*#__PURE__*/ createContext(false);
6
7
  function useFieldRequired() {
7
8
  return useContext(FieldRequiredContext);
8
9
  }
9
10
  function FieldMessages({ description, descriptionId, error, errorId }) {
10
11
  const hasDescription = null != description && false !== description;
12
+ const insideForm = useInsideForm();
11
13
  return /*#__PURE__*/ jsxs(Fragment, {
12
14
  children: [
13
15
  hasDescription ? /*#__PURE__*/ jsx(Field.Description, {
@@ -20,7 +22,11 @@ function FieldMessages({ description, descriptionId, error, errorId }) {
20
22
  className: field_module.error,
21
23
  match: true,
22
24
  children: error
23
- })
25
+ }),
26
+ void 0 === error && insideForm ? /*#__PURE__*/ jsx(Field.Error, {
27
+ id: errorId,
28
+ className: field_module.error
29
+ }) : null
24
30
  ]
25
31
  });
26
32
  }
@@ -0,0 +1,41 @@
1
+ import { Field as BaseField } from '@base-ui/react/field';
2
+ import { Popover as BasePopover } from '@base-ui/react/popover';
3
+ import { type ReactNode } from 'react';
4
+ import { type FieldFrameProps } from './Field.js';
5
+ export interface PickerFieldProps extends FieldFrameProps {
6
+ /** Submitted through the hidden input and given to `Form`. `null` is nothing chosen. */
7
+ value: string | null;
8
+ /** The trigger's words: the value as it reads, or the placeholder. */
9
+ valueText: string;
10
+ /** Sits at the end of the trigger. */
11
+ icon: ReactNode;
12
+ /** Added to the icon's wrapper, for a picker whose icon reacts to the popup. */
13
+ iconClassName?: string;
14
+ /** Joins the trigger's accessible name when the field is `required`. */
15
+ requiredWord: string;
16
+ /** What `Form` asks before it submits: the message to refuse with, or `null`. */
17
+ validate: () => string | null;
18
+ /** Called after a native reset of the surrounding form. */
19
+ onReset: () => void;
20
+ /** Shows a button that clears the value, while there is one. */
21
+ clearable: boolean;
22
+ clearLabel: string;
23
+ /** Focus goes to the trigger after this, as the button is about to go. */
24
+ onClear: () => void;
25
+ onBlur?: () => void;
26
+ onTriggerKeyDown?: BaseField.Control.Props['onKeyDown'];
27
+ open: boolean;
28
+ onOpenChange: (open: boolean) => void;
29
+ modal?: BasePopover.Root.Props['modal'];
30
+ /** The popover's `Portal` and all it holds, which is each picker's own. */
31
+ children: ReactNode;
32
+ }
33
+ /**
34
+ * The frame `DatePicker` and `TreeSelect` share: a button that opens a popover, a clear button
35
+ * beside it, and a value that travels in a hidden input. Internal: not exported from `src/index.ts`.
36
+ *
37
+ * The trigger is the frame's `Field.Control`, holding the value as a button's `value`. That one
38
+ * element gets the name, the description, `aria-invalid`, `Form`'s focus and the clearing of a
39
+ * `Form` error as any Base UI control does, none of which a hidden input could use.
40
+ */
41
+ export declare function PickerField({ label, name, description, error, required, disabled, value, valueText, icon, iconClassName, requiredWord, validate, onReset, clearable, clearLabel, onClear, onBlur, onTriggerKeyDown, open, onOpenChange, modal, children, }: PickerFieldProps): import("react").JSX.Element;
@@ -0,0 +1,115 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Field } from "@base-ui/react/field";
3
+ import { Popover } from "@base-ui/react/popover";
4
+ import { useId, useRef } from "react";
5
+ import { useFormReset } from "../../hooks/useFormReset.js";
6
+ import { CloseIcon } from "../../icons/CloseIcon.js";
7
+ import field_module from "../../styles/field.module.js";
8
+ import { useFormValue } from "../Form/FormContext.js";
9
+ import { IconButton } from "../IconButton/IconButton.js";
10
+ import { FieldMessages, RequiredMark } from "./Field.js";
11
+ import PickerField_module from "./PickerField.module.js";
12
+ function PickerField({ label, name, description, error, required = false, disabled = false, value, valueText, icon, iconClassName, requiredWord, validate, onReset, clearable, clearLabel, onClear, onBlur, onTriggerKeyDown, open, onOpenChange, modal, children }) {
13
+ const labelId = useId();
14
+ const valueId = useId();
15
+ const requiredId = useId();
16
+ const triggerRef = useRef(null);
17
+ const hiddenInputRef = useRef(null);
18
+ useFormValue(disabled ? void 0 : name, value);
19
+ useFormReset(hiddenInputRef, onReset);
20
+ return /*#__PURE__*/ jsxs(Field.Root, {
21
+ className: field_module.frame,
22
+ name: name,
23
+ disabled: disabled,
24
+ invalid: void 0 !== error,
25
+ validate: validate,
26
+ children: [
27
+ /*#__PURE__*/ jsxs(Field.Label, {
28
+ id: labelId,
29
+ className: field_module.label,
30
+ nativeLabel: false,
31
+ render: /*#__PURE__*/ jsx("span", {}),
32
+ children: [
33
+ label,
34
+ /*#__PURE__*/ jsx(RequiredMark, {
35
+ when: required
36
+ })
37
+ ]
38
+ }),
39
+ /*#__PURE__*/ jsxs("div", {
40
+ className: PickerField_module.row,
41
+ children: [
42
+ /*#__PURE__*/ jsxs(Popover.Root, {
43
+ open: open,
44
+ onOpenChange: onOpenChange,
45
+ modal: modal,
46
+ children: [
47
+ /*#__PURE__*/ jsxs(Popover.Trigger, {
48
+ ref: triggerRef,
49
+ disabled: disabled,
50
+ render: /*#__PURE__*/ jsx(Field.Control, {
51
+ className: [
52
+ field_module.control,
53
+ PickerField_module.trigger
54
+ ].join(' '),
55
+ value: value ?? '',
56
+ onBlur: onBlur,
57
+ onKeyDown: onTriggerKeyDown,
58
+ "aria-labelledby": [
59
+ labelId,
60
+ required ? requiredId : null,
61
+ valueId
62
+ ].filter(Boolean).join(' '),
63
+ render: /*#__PURE__*/ jsx("button", {
64
+ type: "button"
65
+ })
66
+ }),
67
+ children: [
68
+ /*#__PURE__*/ jsx("span", {
69
+ id: valueId,
70
+ className: PickerField_module.value,
71
+ "data-placeholder": null === value ? '' : void 0,
72
+ children: valueText
73
+ }),
74
+ /*#__PURE__*/ jsx("span", {
75
+ className: [
76
+ PickerField_module.icon,
77
+ iconClassName
78
+ ].filter(Boolean).join(' '),
79
+ children: icon
80
+ })
81
+ ]
82
+ }),
83
+ children
84
+ ]
85
+ }),
86
+ clearable && null !== value && !disabled ? /*#__PURE__*/ jsx(IconButton, {
87
+ label: clearLabel,
88
+ onClick: ()=>{
89
+ onClear();
90
+ triggerRef.current?.focus();
91
+ },
92
+ children: /*#__PURE__*/ jsx(CloseIcon, {})
93
+ }) : null
94
+ ]
95
+ }),
96
+ required ? /*#__PURE__*/ jsx("span", {
97
+ id: requiredId,
98
+ hidden: true,
99
+ children: requiredWord
100
+ }) : null,
101
+ /*#__PURE__*/ jsx("input", {
102
+ ref: hiddenInputRef,
103
+ type: "hidden",
104
+ name: name,
105
+ value: value ?? '',
106
+ disabled: disabled
107
+ }),
108
+ /*#__PURE__*/ jsx(FieldMessages, {
109
+ description: description,
110
+ error: error
111
+ })
112
+ ]
113
+ });
114
+ }
115
+ export { PickerField };
@@ -0,0 +1,8 @@
1
+ import "./PickerField_module.css";
2
+ const PickerField_module = {
3
+ row: "row-nA5dt",
4
+ trigger: "trigger-EkNQz",
5
+ value: "value-iJ2rA",
6
+ icon: "icon-fNz5y"
7
+ };
8
+ export default PickerField_module;
@@ -0,0 +1,36 @@
1
+ .row-nA5dt {
2
+ align-items: center;
3
+ gap: var(--space-2);
4
+ display: flex;
5
+ }
6
+
7
+ .trigger-EkNQz {
8
+ justify-content: space-between;
9
+ gap: var(--space-3);
10
+ text-align: start;
11
+ cursor: pointer;
12
+ flex: 1;
13
+ min-width: 0;
14
+ }
15
+
16
+ .value-iJ2rA {
17
+ white-space: nowrap;
18
+ text-overflow: ellipsis;
19
+ overflow: hidden;
20
+ }
21
+
22
+ .value-iJ2rA[data-placeholder] {
23
+ color: var(--color-text-muted);
24
+ }
25
+
26
+ .icon-fNz5y {
27
+ color: var(--color-text-muted);
28
+ flex: none;
29
+ display: inline-flex;
30
+ }
31
+
32
+ .icon-fNz5y > svg {
33
+ width: 1rem;
34
+ height: 1rem;
35
+ }
36
+
@@ -0,0 +1,55 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface FilterBarFilter {
3
+ /** What `onRemoveFilter` reports. */
4
+ id: string;
5
+ /** The chip's text, and the end of its remove button's name. */
6
+ label: string;
7
+ }
8
+ export interface FilterBarLabels {
9
+ /** Names the list of chips. */
10
+ activeFilters: string;
11
+ /** The name of one chip's remove button. */
12
+ removeFilter: (label: string) => string;
13
+ /** The words on the button that clears every filter. */
14
+ clearAll: string;
15
+ /** Shown beside the chips, and announced when the count changes. */
16
+ resultCount: (count: number) => string;
17
+ }
18
+ interface FilterBarBaseProps {
19
+ /** The filter controls, each with its own label: a `Select`, a `DatePicker`, a `Segmented`. */
20
+ children?: ReactNode;
21
+ /** Shown as chips, in this order. Which filters are on, and what they do, is the app's. */
22
+ activeFilters?: FilterBarFilter[];
23
+ /** One filter's `id`. Each chip has a named remove button while this is given. */
24
+ onRemoveFilter?: (id: string) => void;
25
+ /** A button clears all the chips while this is given and there are chips to clear. */
26
+ onClearAll?: () => void;
27
+ /** Shown beside the chips and announced politely when it changes, not when first shown. */
28
+ resultCount?: number;
29
+ /** The words the bar says itself, for an app that is not in English. */
30
+ labels?: Partial<FilterBarLabels>;
31
+ }
32
+ interface FilterBarWithSearch extends FilterBarBaseProps {
33
+ /** Controlled, like the filters: the bar holds no filter state of its own. */
34
+ searchValue: string;
35
+ onSearchChange: (value: string) => void;
36
+ /** The search input's visible label and accessible name. */
37
+ searchLabel: string;
38
+ }
39
+ interface FilterBarWithoutSearch extends FilterBarBaseProps {
40
+ searchValue?: undefined;
41
+ onSearchChange?: undefined;
42
+ searchLabel?: undefined;
43
+ }
44
+ export type FilterBarProps = FilterBarWithSearch | FilterBarWithoutSearch;
45
+ /**
46
+ * The row above a results list: a search, slots for filter controls, the active filters as chips
47
+ * and the count. It holds no filter logic, and only says what the app asked for.
48
+ *
49
+ * Focus does not go with what it was on. A removed chip hands it to the next chip, else the one
50
+ * before; when no chip is left, or Clear all has gone, it passes to the first thing here that can
51
+ * take it, usually the search, and at the last to the bar itself. It waits as long as the app takes
52
+ * to remove the chip, and lets go if the user moves on first.
53
+ */
54
+ export declare function FilterBar({ searchValue, onSearchChange, searchLabel, children, activeFilters, onRemoveFilter, onClearAll, resultCount, labels, }: FilterBarProps): import("react").JSX.Element;
55
+ export {};