@calcifer-design/ui 0.6.0 → 0.7.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 (189) hide show
  1. package/dist/components/Alert/Alert.d.ts +5 -2
  2. package/dist/components/Alert/Alert.js +1 -0
  3. package/dist/components/Alert/Alert.module.js +5 -5
  4. package/dist/components/Alert/Alert_module.css +20 -17
  5. package/dist/components/Avatar/Avatar.d.ts +16 -2
  6. package/dist/components/Avatar/Avatar.js +23 -7
  7. package/dist/components/Avatar/Avatar.module.js +3 -3
  8. package/dist/components/Avatar/Avatar_module.css +58 -17
  9. package/dist/components/Avatar/avatarColor.d.ts +12 -0
  10. package/dist/components/Avatar/avatarColor.js +12 -0
  11. package/dist/components/AvatarGroup/AvatarGroup.d.ts +37 -0
  12. package/dist/components/AvatarGroup/AvatarGroup.js +52 -0
  13. package/dist/components/AvatarGroup/AvatarGroup.module.js +8 -0
  14. package/dist/components/AvatarGroup/AvatarGroup_module.css +67 -0
  15. package/dist/components/Breadcrumb/Breadcrumb.module.js +6 -6
  16. package/dist/components/Breadcrumb/Breadcrumb_module.css +7 -7
  17. package/dist/components/Button/Button.d.ts +40 -4
  18. package/dist/components/Button/Button.js +48 -11
  19. package/dist/components/Button/Button.module.js +6 -2
  20. package/dist/components/Button/Button_module.css +143 -17
  21. package/dist/components/Button/LinkButton.d.ts +10 -3
  22. package/dist/components/Button/LinkButton.js +16 -5
  23. package/dist/components/Card/Card.module.js +5 -5
  24. package/dist/components/Card/Card_module.css +15 -9
  25. package/dist/components/CardList/CardList.module.js +3 -3
  26. package/dist/components/CardList/CardList_module.css +5 -3
  27. package/dist/components/Checkbox/Checkbox.module.js +2 -2
  28. package/dist/components/Checkbox/Checkbox_module.css +3 -3
  29. package/dist/components/ChoiceCard/ChoiceCard.d.ts +34 -0
  30. package/dist/components/ChoiceCard/ChoiceCard.js +81 -0
  31. package/dist/components/ChoiceCard/ChoiceCard.module.js +12 -0
  32. package/dist/components/ChoiceCard/ChoiceCard_module.css +161 -0
  33. package/dist/components/Collapsible/Collapsible.d.ts +39 -0
  34. package/dist/components/Collapsible/Collapsible.js +63 -0
  35. package/dist/components/Collapsible/Collapsible.module.js +10 -0
  36. package/dist/components/Collapsible/Collapsible_module.css +80 -0
  37. package/dist/components/DataGrid/DataGrid.module.js +32 -32
  38. package/dist/components/DataGrid/DataGrid_module.css +67 -62
  39. package/dist/components/DataTable/DataTable.module.js +9 -9
  40. package/dist/components/DataTable/DataTable_module.css +24 -21
  41. package/dist/components/DatePicker/DatePicker.d.ts +15 -1
  42. package/dist/components/DatePicker/DatePicker.js +30 -5
  43. package/dist/components/DatePicker/DatePicker.module.js +10 -10
  44. package/dist/components/DatePicker/DatePicker_module.css +22 -21
  45. package/dist/components/Descriptions/Descriptions.module.js +4 -4
  46. package/dist/components/Descriptions/Descriptions_module.css +12 -8
  47. package/dist/components/Dialog/Dialog.d.ts +30 -2
  48. package/dist/components/Dialog/Dialog.js +52 -11
  49. package/dist/components/Dialog/Dialog.module.js +8 -6
  50. package/dist/components/Dialog/Dialog_module.css +60 -13
  51. package/dist/components/EmptyState/EmptyState.d.ts +41 -0
  52. package/dist/components/EmptyState/EmptyState.js +39 -0
  53. package/dist/components/EmptyState/EmptyState.module.js +9 -0
  54. package/dist/components/EmptyState/EmptyState_module.css +65 -0
  55. package/dist/components/ErrorBoundary/ErrorBoundary.d.ts +5 -2
  56. package/dist/components/ErrorBoundary/ErrorBoundary.module.js +1 -1
  57. package/dist/components/ErrorBoundary/ErrorBoundary_module.css +1 -1
  58. package/dist/components/Field/AffixInput.d.ts +28 -0
  59. package/dist/components/Field/AffixInput.js +50 -0
  60. package/dist/components/Field/GroupFrame.d.ts +19 -0
  61. package/dist/components/Field/GroupFrame.js +31 -0
  62. package/dist/components/Field/PickerField.d.ts +8 -2
  63. package/dist/components/Field/PickerField.js +12 -8
  64. package/dist/components/Field/PickerField.module.js +4 -4
  65. package/dist/components/Field/PickerField_module.css +11 -6
  66. package/dist/components/FilterBar/FilterBar.module.js +9 -9
  67. package/dist/components/FilterBar/FilterBar_module.css +13 -13
  68. package/dist/components/Form/Form.d.ts +9 -7
  69. package/dist/components/Form/Form.module.js +1 -1
  70. package/dist/components/Form/Form_module.css +1 -1
  71. package/dist/components/IconButton/IconButton.d.ts +1 -1
  72. package/dist/components/IconButton/IconButton.module.js +2 -2
  73. package/dist/components/IconButton/IconButton_module.css +28 -17
  74. package/dist/components/Menu/Menu.js +3 -0
  75. package/dist/components/Menu/Menu.module.js +2 -2
  76. package/dist/components/Menu/Menu_module.css +5 -4
  77. package/dist/components/NavMenu/NavMenu.d.ts +27 -4
  78. package/dist/components/NavMenu/NavMenu.js +10 -8
  79. package/dist/components/NavMenu/NavMenu.module.js +6 -6
  80. package/dist/components/NavMenu/NavMenu_module.css +37 -19
  81. package/dist/components/NavMenu/currentPath.d.ts +9 -0
  82. package/dist/components/NavMenu/currentPath.js +5 -0
  83. package/dist/components/PageHeading/PageHeading.module.js +3 -3
  84. package/dist/components/PageHeading/PageHeading_module.css +12 -9
  85. package/dist/components/PageShell/PageShell.module.js +5 -5
  86. package/dist/components/PageShell/PageShell_module.css +9 -9
  87. package/dist/components/Popover/Popover.js +3 -0
  88. package/dist/components/Popover/Popover.module.js +2 -2
  89. package/dist/components/Popover/Popover_module.css +6 -3
  90. package/dist/components/ProgressBar/ProgressBar.d.ts +55 -0
  91. package/dist/components/ProgressBar/ProgressBar.js +76 -0
  92. package/dist/components/ProgressBar/ProgressBar.module.js +12 -0
  93. package/dist/components/ProgressBar/ProgressBar_module.css +120 -0
  94. package/dist/components/RadioGroup/RadioGroup.d.ts +1 -1
  95. package/dist/components/RadioGroup/RadioGroup.js +35 -49
  96. package/dist/components/RadioGroup/RadioGroup.module.js +2 -2
  97. package/dist/components/RadioGroup/RadioGroup_module.css +2 -2
  98. package/dist/components/SearchField/SearchField.d.ts +32 -0
  99. package/dist/components/SearchField/SearchField.js +100 -0
  100. package/dist/components/SearchField/SearchField.module.js +8 -0
  101. package/dist/components/SearchField/SearchField_module.css +34 -0
  102. package/dist/components/Segmented/Segmented.d.ts +23 -6
  103. package/dist/components/Segmented/Segmented.js +37 -20
  104. package/dist/components/Segmented/Segmented.module.js +4 -3
  105. package/dist/components/Segmented/Segmented_module.css +46 -20
  106. package/dist/components/Select/Select.js +3 -0
  107. package/dist/components/Select/Select.module.js +5 -5
  108. package/dist/components/Select/Select_module.css +12 -11
  109. package/dist/components/Skeleton/Skeleton.module.js +3 -3
  110. package/dist/components/Skeleton/Skeleton_module.css +9 -9
  111. package/dist/components/SkipLink/SkipLink.module.js +1 -1
  112. package/dist/components/SkipLink/SkipLink_module.css +4 -4
  113. package/dist/components/Spinner/Spinner.module.js +3 -3
  114. package/dist/components/Spinner/Spinner_module.css +7 -7
  115. package/dist/components/StatusDot/StatusDot.module.js +5 -5
  116. package/dist/components/StatusDot/StatusDot_module.css +11 -11
  117. package/dist/components/Steps/Steps.module.js +6 -6
  118. package/dist/components/Steps/Steps_module.css +19 -19
  119. package/dist/components/Switch/Switch.module.js +2 -2
  120. package/dist/components/Switch/Switch_module.css +5 -5
  121. package/dist/components/TabBar/TabBar.d.ts +26 -0
  122. package/dist/components/TabBar/TabBar.js +52 -0
  123. package/dist/components/TabBar/TabBar.module.js +11 -0
  124. package/dist/components/TabBar/TabBar_module.css +100 -0
  125. package/dist/components/Tabs/Tabs.module.js +4 -4
  126. package/dist/components/Tabs/Tabs_module.css +9 -8
  127. package/dist/components/Tag/Tag.module.js +1 -1
  128. package/dist/components/Tag/Tag_module.css +3 -2
  129. package/dist/components/TextArea/TextArea.module.js +1 -1
  130. package/dist/components/TextArea/TextArea_module.css +6 -2
  131. package/dist/components/TextInput/TextInput.d.ts +14 -2
  132. package/dist/components/TextInput/TextInput.js +4 -5
  133. package/dist/components/ThemeScope/PortalContainerContext.d.ts +17 -0
  134. package/dist/components/ThemeScope/PortalContainerContext.js +6 -0
  135. package/dist/components/ThemeScope/ThemeScope.d.ts +23 -0
  136. package/dist/components/ThemeScope/ThemeScope.js +29 -0
  137. package/dist/components/ThemeScope/ThemeScope.module.js +6 -0
  138. package/dist/components/ThemeScope/ThemeScope_module.css +10 -0
  139. package/dist/components/TimePicker/TimePicker.d.ts +15 -2
  140. package/dist/components/TimePicker/TimePicker.js +5 -5
  141. package/dist/components/Timeline/Timeline.module.js +8 -8
  142. package/dist/components/Timeline/Timeline_module.css +15 -13
  143. package/dist/components/ToastRegion/ToastRegion.js +3 -0
  144. package/dist/components/ToastRegion/ToastRegion.module.js +6 -6
  145. package/dist/components/ToastRegion/ToastRegion_module.css +23 -19
  146. package/dist/components/ToggleChip/ToggleChip.d.ts +49 -0
  147. package/dist/components/ToggleChip/ToggleChip.js +45 -0
  148. package/dist/components/ToggleChip/ToggleChip.module.js +9 -0
  149. package/dist/components/ToggleChip/ToggleChipGroup.d.ts +57 -0
  150. package/dist/components/ToggleChip/ToggleChipGroup.js +93 -0
  151. package/dist/components/ToggleChip/ToggleChip_module.css +97 -0
  152. package/dist/components/Toolbar/Toolbar.module.js +3 -3
  153. package/dist/components/Toolbar/Toolbar_module.css +5 -5
  154. package/dist/components/Tooltip/Tooltip.js +3 -0
  155. package/dist/components/Tree/Tree.module.js +8 -8
  156. package/dist/components/Tree/Tree_module.css +20 -20
  157. package/dist/components/TreeSelect/TreeSelect.js +3 -0
  158. package/dist/components/TreeSelect/TreeSelect.module.js +3 -3
  159. package/dist/components/TreeSelect/TreeSelect_module.css +4 -4
  160. package/dist/components/Upload/Upload.module.js +8 -8
  161. package/dist/components/Upload/Upload_module.css +16 -16
  162. package/dist/components/ViewField/ViewField.module.js +2 -2
  163. package/dist/components/ViewField/ViewField_module.css +3 -3
  164. package/dist/hooks/useControllable.d.ts +11 -0
  165. package/dist/hooks/useControllable.js +13 -0
  166. package/dist/hooks/useIndexedToggleGroup.d.ts +30 -0
  167. package/dist/hooks/useIndexedToggleGroup.js +26 -0
  168. package/dist/hooks/useOverflowFocusable.d.ts +17 -0
  169. package/dist/hooks/useOverflowFocusable.js +36 -0
  170. package/dist/icons/SearchIcon.d.ts +9 -0
  171. package/dist/icons/SearchIcon.js +23 -0
  172. package/dist/index.d.ts +26 -0
  173. package/dist/index.js +12 -0
  174. package/dist/styles/a11y.module.js +1 -1
  175. package/dist/styles/a11y_module.css +1 -1
  176. package/dist/styles/base.css +17 -0
  177. package/dist/styles/closeCircle.module.js +5 -0
  178. package/dist/styles/closeCircle_module.css +12 -0
  179. package/dist/styles/field.module.js +14 -11
  180. package/dist/styles/field_module.css +92 -23
  181. package/dist/styles/pair.module.js +2 -2
  182. package/dist/styles/pair_module.css +5 -3
  183. package/dist/styles/popup.module.js +5 -5
  184. package/dist/styles/popup_module.css +35 -28
  185. package/dist/utils/focusInputFromPill.d.ts +12 -0
  186. package/dist/utils/focusInputFromPill.js +7 -0
  187. package/dist/utils/hasContent.d.ts +8 -0
  188. package/dist/utils/hasContent.js +4 -0
  189. package/package.json +2 -2
@@ -0,0 +1,120 @@
1
+ .ui0-7-0-root-mQ6gu {
2
+ --progress-bar-fill: var(--color-accent);
3
+ gap: var(--space-2);
4
+ flex-direction: column;
5
+ display: flex;
6
+ position: relative;
7
+ }
8
+
9
+ .ui0-7-0-root-mQ6gu[data-tone="selected"] {
10
+ --progress-bar-fill: var(--color-selected);
11
+ }
12
+
13
+ .ui0-7-0-root-mQ6gu[data-status="finished"] {
14
+ --progress-bar-fill: var(--color-success);
15
+ }
16
+
17
+ .ui0-7-0-root-mQ6gu[data-status="error"] {
18
+ --progress-bar-fill: var(--color-danger);
19
+ }
20
+
21
+ .ui0-7-0-row-fP05m {
22
+ justify-content: space-between;
23
+ align-items: baseline;
24
+ gap: var(--space-2);
25
+ display: flex;
26
+ }
27
+
28
+ .ui0-7-0-label-rERKj, .ui0-7-0-value-v0kJr {
29
+ color: var(--color-text);
30
+ font-family: var(--font-sans);
31
+ font-size: var(--text-sm);
32
+ line-height: var(--leading-snug);
33
+ }
34
+
35
+ .ui0-7-0-label-rERKj {
36
+ min-width: 0;
37
+ font-weight: var(--font-weight-label);
38
+ overflow-wrap: anywhere;
39
+ }
40
+
41
+ .ui0-7-0-value-v0kJr {
42
+ font-weight: var(--font-weight-button);
43
+ font-variant-numeric: tabular-nums;
44
+ white-space: nowrap;
45
+ flex: none;
46
+ margin-inline-start: auto;
47
+ }
48
+
49
+ .ui0-7-0-track-kT3yt {
50
+ height: var(--progress-bar-track-size, .5rem);
51
+ border-radius: var(--radius-full);
52
+ background: var(--color-surface-3);
53
+ position: relative;
54
+ overflow: hidden;
55
+ }
56
+
57
+ .ui0-7-0-root-mQ6gu[data-size="sm"] .ui0-7-0-track-kT3yt {
58
+ height: var(--progress-bar-track-size, .25rem);
59
+ }
60
+
61
+ .ui0-7-0-indicator-Ss0J6 {
62
+ border-radius: var(--radius-full);
63
+ background: var(--progress-bar-fill);
64
+ transition-property: width;
65
+ transition-duration: var(--motion-duration-2);
66
+ transition-timing-function: var(--motion-ease);
67
+ }
68
+
69
+ .ui0-7-0-indicator-Ss0J6[data-indeterminate] {
70
+ block-size: 100%;
71
+ inline-size: 40%;
72
+ animation-name: ui0-7-0-slide-RfrrH;
73
+ animation-duration: var(--motion-duration-4);
74
+ animation-timing-function: var(--motion-ease);
75
+ transition: none;
76
+ animation-iteration-count: infinite;
77
+ position: absolute;
78
+ inset-inline-start: 30%;
79
+ }
80
+
81
+ @keyframes ui0-7-0-slide-RfrrH {
82
+ from {
83
+ translate: -175%;
84
+ }
85
+
86
+ to {
87
+ translate: 175%;
88
+ }
89
+ }
90
+
91
+ @media (prefers-reduced-motion: reduce) {
92
+ .ui0-7-0-indicator-Ss0J6[data-indeterminate] {
93
+ animation-name: none;
94
+ }
95
+ }
96
+
97
+ .ui0-7-0-helper-hJu00 {
98
+ color: var(--color-text-muted);
99
+ font-family: var(--font-body);
100
+ font-weight: var(--font-weight-body);
101
+ font-size: var(--text-xs);
102
+ line-height: var(--leading-snug);
103
+ }
104
+
105
+ .ui0-7-0-root-mQ6gu[data-status="error"] .ui0-7-0-helper-hJu00 {
106
+ color: var(--color-danger);
107
+ }
108
+
109
+ @media (forced-colors: active) {
110
+ .ui0-7-0-track-kT3yt {
111
+ outline-offset: -1px;
112
+ outline: 1px solid canvastext;
113
+ }
114
+
115
+ .ui0-7-0-indicator-Ss0J6 {
116
+ forced-color-adjust: none;
117
+ background: highlight;
118
+ }
119
+ }
120
+
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
- import { type FieldFrameProps } from '../Field/Field.js';
2
+ import type { FieldFrameProps } from '../Field/Field.js';
3
3
  export interface RadioOption {
4
4
  /** Submitted with the form, and what `value`/`onValueChange` speak in. */
5
5
  value: string;
@@ -4,61 +4,47 @@ import { Radio } from "@base-ui/react/radio";
4
4
  import { RadioGroup } from "@base-ui/react/radio-group";
5
5
  import { useId } from "react";
6
6
  import field_module from "../../styles/field.module.js";
7
- import { FieldMessages, RequiredMark } from "../Field/Field.js";
7
+ import { GroupFrame } from "../Field/GroupFrame.js";
8
8
  import RadioGroup_module from "./RadioGroup.module.js";
9
9
  function RadioGroup_RadioGroup({ label, options, name, description, error, value, defaultValue, onValueChange, onBlur, required = false, disabled = false, orientation = 'vertical' }) {
10
10
  const labelId = useId();
11
- return /*#__PURE__*/ jsxs(Field.Root, {
12
- className: field_module.frame,
11
+ return /*#__PURE__*/ jsx(GroupFrame, {
12
+ labelId: labelId,
13
+ label: label,
13
14
  name: name,
15
+ description: description,
16
+ error: error,
17
+ required: required,
14
18
  disabled: disabled,
15
- invalid: void 0 !== error,
16
- children: [
17
- /*#__PURE__*/ jsxs("span", {
18
- className: field_module.legend,
19
- id: labelId,
20
- "data-disabled": disabled ? '' : void 0,
21
- children: [
22
- label,
23
- /*#__PURE__*/ jsx(RequiredMark, {
24
- when: required
19
+ children: /*#__PURE__*/ jsx(RadioGroup, {
20
+ className: field_module.options,
21
+ "data-orientation": orientation,
22
+ "aria-labelledby": labelId,
23
+ value: value,
24
+ defaultValue: defaultValue,
25
+ onValueChange: (nextValue)=>onValueChange?.(nextValue),
26
+ onBlur: onBlur,
27
+ required: required,
28
+ children: options.map((option)=>/*#__PURE__*/ jsx(Field.Item, {
29
+ disabled: option.disabled,
30
+ children: /*#__PURE__*/ jsxs(Field.Label, {
31
+ className: field_module.optionLabel,
32
+ children: [
33
+ /*#__PURE__*/ jsx(Radio.Root, {
34
+ className: [
35
+ field_module.controlBox,
36
+ RadioGroup_module.dot
37
+ ].join(' '),
38
+ value: option.value,
39
+ children: /*#__PURE__*/ jsx(Radio.Indicator, {
40
+ className: RadioGroup_module.mark
41
+ })
42
+ }),
43
+ option.label
44
+ ]
25
45
  })
26
- ]
27
- }),
28
- /*#__PURE__*/ jsx(RadioGroup, {
29
- className: field_module.options,
30
- "data-orientation": orientation,
31
- "aria-labelledby": labelId,
32
- value: value,
33
- defaultValue: defaultValue,
34
- onValueChange: (nextValue)=>onValueChange?.(nextValue),
35
- onBlur: onBlur,
36
- required: required,
37
- children: options.map((option)=>/*#__PURE__*/ jsx(Field.Item, {
38
- disabled: option.disabled,
39
- children: /*#__PURE__*/ jsxs(Field.Label, {
40
- className: field_module.optionLabel,
41
- children: [
42
- /*#__PURE__*/ jsx(Radio.Root, {
43
- className: [
44
- field_module.controlBox,
45
- RadioGroup_module.dot
46
- ].join(' '),
47
- value: option.value,
48
- children: /*#__PURE__*/ jsx(Radio.Indicator, {
49
- className: RadioGroup_module.mark
50
- })
51
- }),
52
- option.label
53
- ]
54
- })
55
- }, option.value))
56
- }),
57
- /*#__PURE__*/ jsx(FieldMessages, {
58
- description: description,
59
- error: error
60
- })
61
- ]
46
+ }, option.value))
47
+ })
62
48
  });
63
49
  }
64
50
  export { RadioGroup_RadioGroup as RadioGroup };
@@ -1,6 +1,6 @@
1
1
  import "./RadioGroup_module.css";
2
2
  const RadioGroup_module = {
3
- dot: "dot-A51b6",
4
- mark: "mark-zVMGA"
3
+ dot: "ui0-7-0-dot-A51b6",
4
+ mark: "ui0-7-0-mark-zVMGA"
5
5
  };
6
6
  export default RadioGroup_module;
@@ -1,10 +1,10 @@
1
- .dot-A51b6 {
1
+ .ui0-7-0-dot-A51b6 {
2
2
  border-radius: var(--radius-full);
3
3
  width: 1.25rem;
4
4
  height: 1.25rem;
5
5
  }
6
6
 
7
- .mark-zVMGA {
7
+ .ui0-7-0-mark-zVMGA {
8
8
  border-radius: var(--radius-full);
9
9
  background: var(--color-accent-text);
10
10
  width: .5rem;
@@ -0,0 +1,32 @@
1
+ import { type ComponentPropsWithoutRef } from 'react';
2
+ export interface SearchFieldProps extends Omit<ComponentPropsWithoutRef<'input'>, 'className' | 'type' | 'value' | 'defaultValue' | 'onChange' | 'onSubmit' | 'size' | 'disabled'> {
3
+ /** The accessible name; visible unless `hideLabel`. */
4
+ label: string;
5
+ /** Hides the label from the eye and keeps it as the field's name. */
6
+ hideLabel?: boolean;
7
+ /** Controlled. Pair it with `onValueChange`; use `defaultValue` for an uncontrolled field. */
8
+ value?: string;
9
+ defaultValue?: string;
10
+ /** One argument, as on every other control in the library: the new value, `''` after a clear. */
11
+ onValueChange?: (value: string) => void;
12
+ /**
13
+ * Enter, or the clear control or Escape: the current value, `''` after a clear. Enter is left
14
+ * alone, so an enclosing `<form>` submits as well.
15
+ */
16
+ onSubmit?: (value: string) => void;
17
+ /** The accessible name of the clear control. */
18
+ clearLabel?: string;
19
+ size?: 'sm' | 'md';
20
+ disabled?: boolean;
21
+ className?: string;
22
+ }
23
+ /**
24
+ * A pill search field with a leading search glyph and, while it holds a value, a clear control.
25
+ *
26
+ * Escape with a value clears it exactly as the clear control does and says so with `preventDefault`
27
+ * and `stopPropagation`: the first stops the browser's own clearing of a `type="search"` input,
28
+ * whose `input` event would call `onValueChange('')` a second time, and the second keeps an
29
+ * enclosing `Dialog` open, which Base UI dismisses on the document's Escape. Escape in an empty
30
+ * field does neither, so a dialog around it still closes.
31
+ */
32
+ export declare function SearchField({ label, hideLabel, value, defaultValue, onValueChange, onSubmit, clearLabel, size, disabled, className, ...inputProps }: SearchFieldProps): import("react").JSX.Element;
@@ -0,0 +1,100 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useId, useRef } from "react";
3
+ import { useControllable } from "../../hooks/useControllable.js";
4
+ import { CloseIcon } from "../../icons/CloseIcon.js";
5
+ import { SearchIcon } from "../../icons/SearchIcon.js";
6
+ import a11y_module from "../../styles/a11y.module.js";
7
+ import closeCircle_module from "../../styles/closeCircle.module.js";
8
+ import field_module from "../../styles/field.module.js";
9
+ import { focusInputFromPill } from "../../utils/focusInputFromPill.js";
10
+ import { useFormValue } from "../Form/FormContext.js";
11
+ import { IconButton } from "../IconButton/IconButton.js";
12
+ import SearchField_module from "./SearchField.module.js";
13
+ function SearchField({ label, hideLabel = false, value, defaultValue, onValueChange, onSubmit, clearLabel = 'Clear search', size = 'md', disabled = false, className, ...inputProps }) {
14
+ const generatedId = useId();
15
+ const inputId = inputProps.id ?? generatedId;
16
+ const inputRef = useRef(null);
17
+ const [current, setCurrent] = useControllable(value, defaultValue ?? '');
18
+ useFormValue(disabled ? void 0 : inputProps.name, current);
19
+ function change(nextValue) {
20
+ setCurrent(nextValue);
21
+ onValueChange?.(nextValue);
22
+ }
23
+ function clear() {
24
+ change('');
25
+ onSubmit?.('');
26
+ inputRef.current?.focus();
27
+ }
28
+ function handleKeyDown(event) {
29
+ inputProps.onKeyDown?.(event);
30
+ if (event.nativeEvent.isComposing || 229 === event.keyCode) return;
31
+ if ('Enter' === event.key) onSubmit?.(current);
32
+ else if ('Escape' === event.key && '' !== current) {
33
+ event.preventDefault();
34
+ event.stopPropagation();
35
+ clear();
36
+ }
37
+ }
38
+ const labelId = `${inputId}-label`;
39
+ return /*#__PURE__*/ jsxs("div", {
40
+ role: "search",
41
+ "aria-labelledby": labelId,
42
+ className: [
43
+ field_module.frame,
44
+ SearchField_module.root,
45
+ className
46
+ ].filter(Boolean).join(' '),
47
+ "data-size": size,
48
+ children: [
49
+ /*#__PURE__*/ jsx("label", {
50
+ id: labelId,
51
+ htmlFor: inputId,
52
+ className: hideLabel ? a11y_module.visuallyHidden : field_module.label,
53
+ "data-disabled": disabled ? '' : void 0,
54
+ children: label
55
+ }),
56
+ /*#__PURE__*/ jsxs("div", {
57
+ className: [
58
+ field_module.control,
59
+ field_module.affix,
60
+ SearchField_module.box
61
+ ].join(' '),
62
+ "data-disabled": disabled ? '' : void 0,
63
+ onMouseDown: (event)=>focusInputFromPill(event, inputRef.current),
64
+ children: [
65
+ /*#__PURE__*/ jsx("span", {
66
+ className: field_module.affixIcon,
67
+ "aria-hidden": "true",
68
+ children: /*#__PURE__*/ jsx(SearchIcon, {})
69
+ }),
70
+ /*#__PURE__*/ jsx("input", {
71
+ ...inputProps,
72
+ ref: inputRef,
73
+ id: inputId,
74
+ type: "search",
75
+ className: [
76
+ field_module.affixInput,
77
+ SearchField_module.input
78
+ ].join(' '),
79
+ value: current,
80
+ disabled: disabled,
81
+ onChange: (event)=>change(event.currentTarget.value),
82
+ onKeyDown: handleKeyDown
83
+ }),
84
+ '' === current || disabled ? null : /*#__PURE__*/ jsx(IconButton, {
85
+ variant: "ghost",
86
+ size: "sm",
87
+ label: clearLabel,
88
+ className: [
89
+ SearchField_module.clear,
90
+ closeCircle_module.close
91
+ ].join(' '),
92
+ onClick: clear,
93
+ children: /*#__PURE__*/ jsx(CloseIcon, {})
94
+ })
95
+ ]
96
+ })
97
+ ]
98
+ });
99
+ }
100
+ export { SearchField };
@@ -0,0 +1,8 @@
1
+ import "./SearchField_module.css";
2
+ const SearchField_module = {
3
+ root: "ui0-7-0-root-v2qcn",
4
+ box: "ui0-7-0-box-EP5Wy",
5
+ clear: "ui0-7-0-clear-WukbI",
6
+ input: "ui0-7-0-input-zuTre"
7
+ };
8
+ export default SearchField_module;
@@ -0,0 +1,34 @@
1
+ .ui0-7-0-root-v2qcn .ui0-7-0-box-EP5Wy {
2
+ padding-block: 0;
3
+ padding-inline: var(--space-4) var(--space-1);
4
+ min-height: max(var(--size-touch), calc(var(--size-close) + 2px));
5
+ }
6
+
7
+ .ui0-7-0-root-v2qcn[data-size="sm"] .ui0-7-0-box-EP5Wy {
8
+ min-height: max(var(--size-control-sm), calc(var(--size-close) + 2px));
9
+ }
10
+
11
+ .ui0-7-0-root-v2qcn[data-size="sm"] .ui0-7-0-clear-WukbI[data-size]:before {
12
+ inset-block: -1px;
13
+ }
14
+
15
+ @media (hover: hover) {
16
+ .ui0-7-0-root-v2qcn .ui0-7-0-clear-WukbI[data-size]:hover:not([data-disabled]) {
17
+ background: var(--color-surface-3);
18
+ }
19
+ }
20
+
21
+ .ui0-7-0-root-v2qcn[data-size="sm"] .ui0-7-0-clear-WukbI:focus-visible {
22
+ outline-offset: calc(-1 * var(--focus-ring-width));
23
+ }
24
+
25
+ .ui0-7-0-input-zuTre {
26
+ appearance: none;
27
+ font-family: var(--font-body);
28
+ font-weight: var(--font-weight-body);
29
+ }
30
+
31
+ .ui0-7-0-input-zuTre::-webkit-search-cancel-button {
32
+ appearance: none;
33
+ }
34
+
@@ -6,6 +6,20 @@ export interface SegmentedOption {
6
6
  label: string;
7
7
  /** Sits before the label. Decorative: it stays out of the accessible name. */
8
8
  icon?: ReactNode;
9
+ /**
10
+ * A count or short status shown after the label, such as the `2` in "Requests 2". It is part of
11
+ * the option's accessible name, and pressing it chooses the option. In the chosen option it sits
12
+ * on `--color-selected`: a bare count keeps the option's text colour, and a pill made from the
13
+ * surface, accent-wash, border and text tokens (a `Tag`) is drawn as the option's inverse. A
14
+ * badge painted any other way is the consumer's to keep legible on that fill.
15
+ */
16
+ badge?: ReactNode;
17
+ /**
18
+ * Hides the label from the eye and keeps it for assistive technology, so the option is named by
19
+ * its label while `icon` is all that shows. It takes effect only on an option that has an
20
+ * `icon`: with none, the label stays visible rather than leave a blank button.
21
+ */
22
+ hideLabel?: boolean;
9
23
  disabled?: boolean;
10
24
  }
11
25
  interface SegmentedBaseProps {
@@ -23,6 +37,12 @@ interface SegmentedBaseProps {
23
37
  */
24
38
  onValueChange?: (value: string) => void;
25
39
  size?: 'sm' | 'md';
40
+ /**
41
+ * Stretches the group across its row and shares the row equally between the options. The options
42
+ * stay on that one row, so it suits a few short ones; without `fill`, many or long options wrap
43
+ * to a second row instead.
44
+ */
45
+ fill?: boolean;
26
46
  }
27
47
  interface SegmentedNamedByLabel extends SegmentedBaseProps {
28
48
  /** Names the group. One of this and `aria-labelledby` is required. */
@@ -39,11 +59,8 @@ export type SegmentedProps = SegmentedNamedByLabel | SegmentedNamedByElement;
39
59
  * Choose exactly one of a few options. Each is a toggle button, and the group is one tab stop
40
60
  * whose arrow keys, Home and End move focus without changing the choice.
41
61
  *
42
- * Tab lands on the chosen option. Base UI's `ToggleGroup` has no prop for that and roves from the
43
- * first enabled option, so while focus is outside the group each `Toggle` is told its `tabIndex`.
44
- * Inside it Base UI roves as usual: an override there would leave the chosen option as a second
45
- * stop on the way out. A disabled chosen option cannot take focus, so Base UI decides then too,
46
- * and inside a `Toolbar` the toolbar owns the stop.
62
+ * Tab lands on the chosen option (`useIndexedToggleGroup` records how), except inside a `Toolbar`,
63
+ * where the toolbar owns the stop.
47
64
  */
48
- export declare function Segmented({ options, value, defaultValue, onValueChange, size, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, }: SegmentedProps): import("react").JSX.Element;
65
+ export declare function Segmented({ options, value, defaultValue, onValueChange, size, fill, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, }: SegmentedProps): import("react").JSX.Element;
49
66
  export {};
@@ -1,55 +1,72 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Toggle } from "@base-ui/react/toggle";
3
3
  import { ToggleGroup } from "@base-ui/react/toggle-group";
4
4
  import { useContext, useState } from "react";
5
+ import { useIndexedToggleGroup } from "../../hooks/useIndexedToggleGroup.js";
6
+ import a11y_module from "../../styles/a11y.module.js";
7
+ import { hasContent } from "../../utils/hasContent.js";
5
8
  import { InsideToolbarContext } from "../Toolbar/InsideToolbarContext.js";
6
9
  import Segmented_module from "./Segmented.module.js";
7
10
  function chosenIndexOf(options, value) {
8
11
  const namedIndex = options.findIndex((option)=>option.value === value);
9
12
  return -1 === namedIndex ? options.findIndex((option)=>!option.disabled) : namedIndex;
10
13
  }
11
- function Segmented({ options, value, defaultValue, onValueChange, size = 'md', 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }) {
14
+ function renderLabel(option, hasBadge) {
15
+ if (option.hideLabel && option.icon) return /*#__PURE__*/ jsx("span", {
16
+ className: a11y_module.visuallyHidden,
17
+ children: option.label
18
+ });
19
+ return hasBadge ? /*#__PURE__*/ jsx("span", {
20
+ children: option.label
21
+ }) : option.label;
22
+ }
23
+ function Segmented({ options, value, defaultValue, onValueChange, size = 'md', fill = false, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }) {
12
24
  const insideToolbar = useContext(InsideToolbarContext);
13
25
  const [heldValue, setHeldValue] = useState(defaultValue);
14
- const [focusedValue, setFocusedValue] = useState(null);
15
26
  const chosenIndex = chosenIndexOf(options, value ?? heldValue);
16
- const focusIsInside = options.some((option)=>option.value === focusedValue && !option.disabled);
17
- const chosenOption = options[chosenIndex];
18
- const placesTabStop = !insideToolbar && !focusIsInside && chosenOption && !chosenOption.disabled;
27
+ const toggleGroup = useIndexedToggleGroup(options, insideToolbar ? -1 : chosenIndex);
19
28
  return /*#__PURE__*/ jsx(ToggleGroup, {
20
29
  className: Segmented_module.root,
21
30
  "data-size": size,
31
+ "data-fill": fill ? '' : void 0,
22
32
  "aria-label": ariaLabel,
23
33
  "aria-labelledby": ariaLabelledBy,
24
- value: -1 === chosenIndex ? [] : [
25
- String(chosenIndex)
26
- ],
27
- onBlur: (event)=>{
28
- if (!event.currentTarget.contains(event.relatedTarget)) setFocusedValue(null);
29
- },
34
+ value: toggleGroup.groupValue(-1 === chosenIndex ? [] : [
35
+ chosenIndex
36
+ ]),
37
+ onBlur: toggleGroup.onGroupBlur,
30
38
  onValueChange: (nextIndexes)=>{
31
- const nextOption = options[Number(nextIndexes[0] ?? -1)];
39
+ const [nextOption] = toggleGroup.optionsAt(nextIndexes);
32
40
  if (!nextOption) return;
33
41
  setHeldValue(nextOption.value);
34
42
  onValueChange?.(nextOption.value);
35
43
  },
36
- children: options.map((option, index)=>/*#__PURE__*/ jsxs(Toggle, {
44
+ children: options.map((option, index)=>{
45
+ const hasBadge = hasContent(option.badge);
46
+ return /*#__PURE__*/ jsxs(Toggle, {
37
47
  className: Segmented_module.option,
38
48
  value: String(index),
39
49
  disabled: option.disabled,
40
- onFocus: ()=>setFocusedValue(option.value),
41
- ...placesTabStop ? {
42
- tabIndex: index === chosenIndex ? 0 : -1
43
- } : null,
50
+ ...toggleGroup.itemProps(option, index),
44
51
  children: [
45
52
  option.icon ? /*#__PURE__*/ jsx("span", {
46
53
  className: Segmented_module.icon,
47
54
  "aria-hidden": "true",
48
55
  children: option.icon
49
56
  }) : null,
50
- option.label
57
+ renderLabel(option, hasBadge),
58
+ hasBadge ? /*#__PURE__*/ jsxs(Fragment, {
59
+ children: [
60
+ ' ',
61
+ /*#__PURE__*/ jsx("span", {
62
+ className: Segmented_module.badge,
63
+ children: option.badge
64
+ })
65
+ ]
66
+ }) : null
51
67
  ]
52
- }, option.value))
68
+ }, option.value);
69
+ })
53
70
  });
54
71
  }
55
72
  export { Segmented };
@@ -1,7 +1,8 @@
1
1
  import "./Segmented_module.css";
2
2
  const Segmented_module = {
3
- root: "root-FcEzI",
4
- option: "option-l_IQ8",
5
- icon: "icon-kkAqg"
3
+ root: "ui0-7-0-root-FcEzI",
4
+ option: "ui0-7-0-option-l_IQ8",
5
+ icon: "ui0-7-0-icon-kkAqg",
6
+ badge: "ui0-7-0-badge-p1JLg"
6
7
  };
7
8
  export default Segmented_module;