@omer-x/tailwind-ui-kit 1.0.0-alpha.44 → 1.0.0-alpha.46

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 (85) hide show
  1. package/README.md +52 -1707
  2. package/dist/components/form/BaseAutocomplete.d.ts +1 -1
  3. package/dist/components/form/BaseSlider.d.ts +136 -0
  4. package/dist/components/form/BaseSlider.js +66 -0
  5. package/dist/components/form/BaseSliderControl.d.ts +12 -0
  6. package/dist/components/form/BaseSliderControl.js +14 -0
  7. package/dist/components/form/BaseSliderIndicator.d.ts +12 -0
  8. package/dist/components/form/BaseSliderIndicator.js +14 -0
  9. package/dist/components/form/BaseSliderLabel.d.ts +9 -0
  10. package/dist/components/form/BaseSliderLabel.js +7 -0
  11. package/dist/components/form/BaseSliderThumb.d.ts +30 -0
  12. package/dist/components/form/BaseSliderThumb.js +15 -0
  13. package/dist/components/form/BaseSliderTrack.d.ts +12 -0
  14. package/dist/components/form/BaseSliderTrack.js +12 -0
  15. package/dist/components/form/BaseSliderValue.d.ts +14 -0
  16. package/dist/components/form/BaseSliderValue.js +10 -0
  17. package/dist/components/form/index.d.ts +3 -1
  18. package/dist/components/form/index.js +2 -1
  19. package/dist/components/form/sliderStyles.d.ts +5 -0
  20. package/dist/components/form/sliderStyles.js +32 -0
  21. package/dist/components/menu/BaseMenu.d.ts +1 -1
  22. package/dist/components/menu/BaseMenubar.d.ts +1 -1
  23. package/dist/components/navigation/BaseTabs.d.ts +44 -0
  24. package/dist/components/navigation/BaseTabs.js +24 -0
  25. package/dist/components/navigation/BaseTabsIndicator.d.ts +30 -0
  26. package/dist/components/navigation/BaseTabsIndicator.js +16 -0
  27. package/dist/components/navigation/BaseTabsList.d.ts +19 -0
  28. package/dist/components/navigation/BaseTabsList.js +14 -0
  29. package/dist/components/navigation/BaseTabsPanel.d.ts +19 -0
  30. package/dist/components/navigation/BaseTabsPanel.js +11 -0
  31. package/dist/components/navigation/BaseTabsTab.d.ts +20 -0
  32. package/dist/components/navigation/BaseTabsTab.js +11 -0
  33. package/dist/components/navigation/index.d.ts +6 -0
  34. package/dist/components/navigation/index.js +1 -0
  35. package/dist/components/navigation/tabsTypes.d.ts +8 -0
  36. package/dist/components/navigation/tabsTypes.js +1 -0
  37. package/docs/button/BaseButton.md +32 -0
  38. package/docs/button/BaseToggle.md +29 -0
  39. package/docs/button/BaseToggleGroup.md +28 -0
  40. package/docs/dialog/BaseAlertDialog.md +36 -0
  41. package/docs/dialog/BaseDialog.md +61 -0
  42. package/docs/dialog/createAlertDialogHandle.md +21 -0
  43. package/docs/dialog/createDialogHandle.md +31 -0
  44. package/docs/disclosure/BaseAccordion.md +67 -0
  45. package/docs/disclosure/BaseCollapsible.md +56 -0
  46. package/docs/display/BaseAvatar.md +48 -0
  47. package/docs/display/BaseMeter.md +62 -0
  48. package/docs/elements/README.md +9 -0
  49. package/docs/feedback/BaseToast.md +91 -0
  50. package/docs/feedback/createToastManager.md +19 -0
  51. package/docs/feedback/useToast.md +37 -0
  52. package/docs/form/BaseAutocomplete.md +110 -0
  53. package/docs/form/BaseCheckbox.md +33 -0
  54. package/docs/form/BaseCheckboxGroup.md +28 -0
  55. package/docs/form/BaseFieldset.md +24 -0
  56. package/docs/form/BaseForm.md +89 -0
  57. package/docs/form/BaseFormField.md +47 -0
  58. package/docs/form/BaseInput.md +13 -0
  59. package/docs/form/BaseRadio.md +28 -0
  60. package/docs/form/BaseRadioGroup.md +35 -0
  61. package/docs/form/BaseSelect.md +109 -0
  62. package/docs/form/BaseSlider.md +93 -0
  63. package/docs/form/BaseSwitch.md +27 -0
  64. package/docs/form/useFormMessages.md +29 -0
  65. package/docs/hooks/useRipples.md +26 -0
  66. package/docs/layout/BaseSeparator.md +24 -0
  67. package/docs/layout/Container.md +5 -0
  68. package/docs/menu/BaseContextMenu.md +96 -0
  69. package/docs/menu/BaseMenu.md +84 -0
  70. package/docs/menu/BaseMenubar.md +45 -0
  71. package/docs/menu/createMenuHandle.md +31 -0
  72. package/docs/navigation/BaseTabs.md +69 -0
  73. package/docs/overlay/BaseTooltip.md +74 -0
  74. package/docs/overlay/createTooltipHandle.md +29 -0
  75. package/docs/page/Pagination.md +37 -0
  76. package/docs/page/usePagination.md +17 -0
  77. package/docs/providers/ToastProvider.md +11 -0
  78. package/docs/providers/TooltipProvider.md +17 -0
  79. package/docs/table/TableCell.md +16 -0
  80. package/docs/table/Tdx.md +5 -0
  81. package/docs/utils/RenderProp.md +5 -0
  82. package/docs/utils/cn.md +9 -0
  83. package/docs/utils/mergeProps.md +9 -0
  84. package/docs/utils/useRender.md +26 -0
  85. package/package.json +6 -1
package/README.md CHANGED
@@ -9,12 +9,12 @@ Colorless React components built on [Base UI](https://base-ui.com) and [Tailwind
9
9
  Read these before using or changing any component.
10
10
 
11
11
  1. **Colorless bases.** Components ship without colors, background colors, border colors or any theme. You give them your look by wrapping them once in your app and using the wrapper everywhere.
12
- 2. **Everything is styleable.** Each component accepts `className`, and sub-parts are exposed through `render*` props (`renderLabel`, `renderErrors`, `renderThumb`, …). A `render` prop accepts an element, or a function that gets the props to spread and the component's state: `(props, state) => <a {...props} />` (the kit's [`RenderProp`](#renderprop) type).
12
+ 2. **Everything is styleable.** Each component accepts `className`, and sub-parts are exposed through `render*` props (`renderLabel`, `renderErrors`, `renderThumb`, …). A `render` prop accepts an element, or a function that gets the props to spread and the component's state: `(props, state) => <a {...props} />` (the kit's [`RenderProp`](docs/utils/RenderProp.md) type).
13
13
  3. **Style states with data attributes.** Components set attributes such as `data-disabled`, `data-checked` and `data-starting-style`. Target them with Tailwind variants (`data-disabled:opacity-50`). They are part of the kit's API and stay the same if Base UI is replaced.
14
14
  4. **Naming.** `Base*` components are meant to be wrapped and themed. `Just*` components are bare elements that only add a `render` prop. Unprefixed components are layout and composition helpers.
15
15
  5. **Client components.** All components are client components.
16
16
  6. **Short for the common case, without losing power.** Each component is designed on its own: parts that always go together are combined, and Base UI's full capabilities stay available through props or optional parts.
17
- 7. **Never import Base UI in apps.** Base UI is an implementation detail and may be replaced someday. Apps use the kit's components only, and the kit's types never name Base UI types. To build your own component with a `render` prop, use the kit's [`useRender`](#userender) and [`mergeProps`](#mergeprops). If something you need isn't covered yet, add it to the kit instead of importing `@base-ui/react` (progress is tracked in #56).
17
+ 7. **Never import Base UI in apps.** Base UI is an implementation detail and may be replaced someday. Apps use the kit's components only, and the kit's types never name Base UI types. To build your own component with a `render` prop, use the kit's [`useRender`](docs/utils/useRender.md) and [`mergeProps`](docs/utils/mergeProps.md). If something you need isn't covered yet, add it to the kit instead of importing `@base-ui/react` (progress is tracked in #56).
18
18
 
19
19
  ## Installation
20
20
 
@@ -78,1760 +78,105 @@ export default Button;
78
78
 
79
79
  ## Components
80
80
 
81
- There is no root entry point. Import from the subpaths below.
81
+ There is no root entry point. Import from the subpaths below. Each component has its own page under [`docs/`](./docs), which ships with the package (`node_modules/@omer-x/tailwind-ui-kit/docs/`).
82
82
 
83
83
  ### `@omer-x/tailwind-ui-kit/button`
84
84
 
85
- #### `BaseButton`
86
-
87
- A Base UI [`Button`](https://base-ui.com/react/components/button) with sizes, a pending state and a ripple effect on click.
88
-
89
- | Prop | Type | Default | Description |
90
- |------|------|---------|-------------|
91
- | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | Height, padding, font size and gap |
92
- | `pending` | `boolean` | `false` | Shows the spinner, blocks clicks and keeps the button focusable |
93
- | `spinner` | `ReactNode` | | Shown while pending. Without it nothing is shown, and `data-pending` still marks the state |
94
- | `iconOnly` | `boolean` | `false` | A square button for a single icon. Requires `aria-label`. While pending, the spinner replaces the icon |
95
- | `render` | `RenderProp<"button", ButtonState>` | | Render another element, e.g. your app's link. The state is `{ disabled }` |
96
- | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
97
- | `focusableWhenDisabled` | `boolean` | `false` | Keeps a disabled button in the tab order |
98
- | …rest | `<button>` props | | `disabled`, `type`, `onClick`, … |
99
-
100
- - **Pending** means the `pending` prop is set, **or** the button has `type="submit"` and its form is submitting (a `BaseForm` or a form with a native action). Either way the button shows `spinner`, ignores clicks, keeps keyboard focus, and sets `aria-busy="true"` and `data-pending`.
101
- - Children are laid out with flex and a size-based gap, so icons and text line up without extra markup.
102
- - The ripple uses `bg-current`, so it follows the button's text color. It is skipped when `onClick` calls `preventDefault()`, and hidden when the user prefers reduced motion.
103
- - The kit bundles no icons. Pass your own `spinner` (and icons as children), usually once in your themed wrapper.
104
-
105
- ```tsx
106
- <Button size="sm" pending={isSaving}>Save</Button>
107
- <Button iconOnly aria-label="Delete"><TrashIcon /></Button>
108
- ```
109
-
110
- **Links that look like buttons:** render your app's own link (so typed routes keep working) and set `nativeButton={false}`:
111
-
112
- ```tsx
113
- <Button render={<Link href="/products/new" />} nativeButton={false}>New product</Button>
114
- ```
115
-
116
- #### `BaseToggle`
117
-
118
- A Base UI [`Toggle`](https://base-ui.com/react/components/toggle): a two-state button that is pressed or not. It shares `BaseButton`'s sizes and ripple effect.
119
-
120
- | Prop | Type | Default | Description |
121
- |------|------|---------|-------------|
122
- | `pressed` | `boolean` | | Whether it's pressed, when controlled |
123
- | `defaultPressed` | `boolean` | `false` | Whether it's pressed at first |
124
- | `onPressedChange` | `(pressed: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
125
- | `value` | `string` | | Identifies the toggle inside a `BaseToggleGroup` |
126
- | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | Same heights, padding, font sizes and gaps as `BaseButton` |
127
- | `iconOnly` | `boolean` | `false` | A square toggle for a single icon. Requires `aria-label` |
128
- | `render` | `RenderProp<"button", ToggleState>` | | Render another element. The state is `{ pressed, disabled }` |
129
- | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
130
- | …rest | `<button>` props | | `disabled`, `onClick`, `aria-label`, … (`type` is always `"button"`) |
131
-
132
- It sets `aria-pressed`, plus `data-pressed` while pressed, `data-disabled` and `data-icon-only`. Style the pressed look with `data-pressed:`. The ripple is skipped when `onClick` calls `preventDefault()`.
133
-
134
- ```tsx
135
- <BaseToggle
136
- iconOnly
137
- aria-label="Favorite"
138
- className="border border-neutral-400 data-pressed:bg-neutral-700 data-pressed:text-white"
139
- >
140
- <StarIcon />
141
- </BaseToggle>
142
- ```
143
-
144
- #### `BaseToggleGroup`
145
-
146
- A Base UI [`Toggle Group`](https://base-ui.com/react/components/toggle-group): shared state for the `BaseToggle`s inside it. Give every toggle a `value`. By default pressing one releases the others; arrow keys move focus between them.
147
-
148
- | Prop | Type | Default | Description |
149
- |------|------|---------|-------------|
150
- | `value` | `readonly string[]` | | The `value`s of the pressed toggles, when controlled |
151
- | `defaultValue` | `readonly string[]` | | The `value`s of the toggles pressed at first |
152
- | `onValueChange` | `(value: string[], event: Event) => void` | | Called with the pressed `value`s and the DOM event that changed them |
153
- | `multiple` | `boolean` | `false` | Lets several toggles be pressed at once |
154
- | `disabled` | `boolean` | `false` | Disables every toggle in the group |
155
- | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Arrow-key direction, and the layout direction |
156
- | `loopFocus` | `boolean` | `true` | Moves focus from the last toggle back to the first with the arrow keys |
157
- | `className` | `string` | | Classes for the group `<div>` (default `flex`, `flex-col` when vertical) |
158
- | `render` | `RenderProp<"div", ToggleGroupState>` | | Render another element for the group |
159
- | …rest | `<div>` props | | Name the group with `aria-label` or `aria-labelledby` |
160
-
161
- Render functions get `ToggleGroupState`: `{ disabled, multiple, orientation }`. The group has `role="group"` and sets `data-orientation`, `data-disabled` and `data-multiple`. Each toggle keeps its own `data-pressed` / `data-disabled`.
162
-
163
- ```tsx
164
- <BaseToggleGroup aria-label="Text alignment" defaultValue={["left"]} className="gap-1">
165
- <Toggle value="left">Left</Toggle>
166
- <Toggle value="center">Center</Toggle>
167
- <Toggle value="right">Right</Toggle>
168
- </BaseToggleGroup>
169
- ```
85
+ - [`BaseButton`](docs/button/BaseButton.md) — A Base UI [`Button`](https://base-ui.com/react/components/button) with sizes, a pending state and a ripple effect on click
86
+ - [`BaseToggle`](docs/button/BaseToggle.md) — A Base UI [`Toggle`](https://base-ui.com/react/components/toggle)
87
+ - [`BaseToggleGroup`](docs/button/BaseToggleGroup.md) — A Base UI [`Toggle Group`](https://base-ui.com/react/components/toggle-group)
170
88
 
171
89
  ### `@omer-x/tailwind-ui-kit/form`
172
90
 
173
- #### `BaseInput`
174
-
175
- A plain `<input>` with sizes, rounded corners and a transparent outline ready for focus styles. It accepts all input props plus `render`.
176
-
177
- | Prop | Type | Default |
178
- |------|------|---------|
179
- | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` |
180
-
181
- ```tsx
182
- <BaseInput name="email" className="border border-neutral-300 focus:outline-blue-500" />
183
- ```
184
-
185
- #### `BaseSwitch`
186
-
187
- A Base UI [`Switch`](https://base-ui.com/react/components/switch) with its label. It submits `"true"` / `"false"` by default, so its value always appears in form data.
188
-
189
- | Prop | Type | Default | Description |
190
- |------|------|---------|-------------|
191
- | `label` | `ReactNode` | | Text next to the switch (required) |
192
- | `labelClassName` | `string` | | Classes for the `<label>` around the switch and its text (default `flex items-center gap-2 text-sm font-normal`) |
193
- | `renderThumb` | `RenderProp<"span", SwitchState>` | | Style the thumb |
194
- | `value` | `string` | `"true"` | Submitted when checked |
195
- | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
196
- | `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
197
- | `render` | `RenderProp<"span", SwitchState>` | | Render another element for the track |
198
- | …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
199
-
200
- Render functions get `SwitchState`: `{ checked, disabled, readOnly, required }`.
201
-
202
- ```tsx
203
- <BaseSwitch
204
- name="active"
205
- label="Active"
206
- className="rounded-full bg-neutral-300 data-checked:bg-blue-600"
207
- renderThumb={<span className="rounded-full bg-white" />}
208
- />
209
- ```
210
-
211
- #### `BaseCheckbox`
212
-
213
- A Base UI [`Checkbox`](https://base-ui.com/react/components/checkbox) with its label. Like `BaseSwitch`, it submits `"true"` / `"false"` by default, so its value always appears in form data, also inside `BaseForm`.
214
-
215
- | Prop | Type | Default | Description |
216
- |------|------|---------|-------------|
217
- | `label` | `ReactNode` | | Text next to the checkbox (required) |
218
- | `labelClassName` | `string` | | Classes for the `<label>` around the checkbox and its text (default `flex items-center gap-2 text-sm font-normal`) |
219
- | `icon` | `ReactNode` | | Shown inside the box when checked. The kit bundles none |
220
- | `indeterminateIcon` | `ReactNode` | `icon` | Shown inside the box when indeterminate |
221
- | `renderIndicator` | `RenderProp<"span", CheckboxState>` | | Style the indicator that holds the icon |
222
- | `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when unchecked (e.g. to animate it out) |
223
- | `indeterminate` | `boolean` | `false` | Show the mixed state (`aria-checked="mixed"`). It doesn't change `checked` |
224
- | `parent` | `boolean` | `false` | Make it the "select all" checkbox of a `BaseCheckboxGroup` with `allValues`. It checks or clears the whole group, is indeterminate when only some are checked, and isn't submitted |
225
- | `value` | `string` | `"true"` | Submitted when checked |
226
- | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
227
- | `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
228
- | `render` | `RenderProp<"span", CheckboxState>` | | Render another element for the box |
229
- | …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
230
-
231
- Render functions get `CheckboxState`: `{ checked, disabled, readOnly, required, indeterminate }`. The box and the indicator set `data-checked` / `data-unchecked`, `data-indeterminate`, `data-disabled`, `data-readonly` and `data-required`. The indicator also sets `data-starting-style` / `data-ending-style` while it enters and leaves.
232
-
233
- ```tsx
234
- <BaseCheckbox
235
- name="terms"
236
- label="I accept the terms"
237
- className="rounded border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
238
- renderIndicator={<span className="text-white" />}
239
- icon={<CheckIcon />}
240
- />
241
- ```
242
-
243
- #### `BaseCheckboxGroup`
244
-
245
- A Base UI [`Checkbox Group`](https://base-ui.com/react/components/checkbox-group): shared state for the checkboxes inside it. Its `name` is passed to every checkbox in the group, and each checked box submits its own `value` under that name, so the server reads them all with `formData.getAll(name)`. Checkboxes in a group never submit an unchecked value.
246
-
247
- | Prop | Type | Default | Description |
248
- |------|------|---------|-------------|
249
- | `name` | `string` | | Submitted name of every checkbox in the group |
250
- | `value` | `string[]` | | The `value`s of the checked boxes, when controlled |
251
- | `defaultValue` | `string[]` | | The `value`s of the boxes checked at first |
252
- | `onValueChange` | `(value: string[], event: Event) => void` | | Called with the new checked `value`s and the DOM event that changed it |
253
- | `allValues` | `string[]` | | Every child `value`. Needed by a `BaseCheckbox` with `parent` ("select all") |
254
- | `disabled` | `boolean` | | Disables every checkbox in the group |
255
- | `className` | `string` | | Classes for the group `<div>` (default `flex flex-col gap-2`) |
256
- | `render` | `RenderProp<"div", CheckboxGroupState>` | | Render another element for the group |
257
- | …rest | | | `<div>` props. Give the group an accessible name with `aria-label` or `aria-labelledby` |
258
-
259
- Render functions get `CheckboxGroupState`: `{ disabled }`. The group sets `data-disabled` when disabled.
260
-
261
- With `BaseForm`'s `onlyDirty`, give the group an array default (`defaultValues={{ channels: ["email"] }}`). It is sent only when the set of checked values changed, and as an empty value when everything was unchecked.
262
-
263
- ```tsx
264
- <BaseCheckboxGroup name="channels" aria-label="Channels" defaultValue={["email"]}>
265
- <BaseCheckbox value="email" label="Email" />
266
- <BaseCheckbox value="sms" label="SMS" />
267
- </BaseCheckboxGroup>
268
- ```
269
-
270
- #### `BaseRadioGroup`
271
-
272
- A Base UI [`Radio Group`](https://base-ui.com/react/components/radio-group): shared state for the `BaseRadio`s inside it. Only one radio is selected at a time, and its `value` is submitted under the group's `name`. Arrow keys move the selection.
273
-
274
- | Prop | Type | Default | Description |
275
- |------|------|---------|-------------|
276
- | `name` | `string` | | Submitted name of the group |
277
- | `value` | `string` | | The `value` of the selected radio, when controlled |
278
- | `defaultValue` | `string` | | The `value` of the radio selected at first |
279
- | `onValueChange` | `(value: string, event: Event) => void` | | Called with the selected `value` and the DOM event that changed it |
280
- | `disabled` | `boolean` | | Disables every radio in the group |
281
- | `readOnly` | `boolean` | | Keeps the selection from changing |
282
- | `required` | `boolean` | | A radio must be selected before the form submits |
283
- | `form` | `string` | | The `id` of a `<form>` to submit with, when the group isn't inside it |
284
- | `inputRef` | `Ref<HTMLInputElement>` | | The hidden `<input>` of the selected (or first enabled) radio |
285
- | `className` | `string` | | Classes for the group `<div>` (default `flex flex-col gap-2`) |
286
- | `render` | `RenderProp<"div", RadioGroupState>` | | Render another element for the group |
287
- | …rest | | | `<div>` props. Give the group an accessible name with `aria-label` or `aria-labelledby` (inside `BaseFormField`, its `label` names the group) |
288
-
289
- Render functions get `RadioGroupState`: `{ disabled, readOnly, required }`. The group sets `data-disabled`, `data-readonly` and `data-required`.
290
-
291
- Inside `BaseForm`, use it alone with a `name`, or in `BaseFormField`'s `children` to get the field's name, label, `required` from the schema and server errors. With `onlyDirty`, give it a string default (`defaultValues={{ plan: "free" }}`). It is sent only when the selection differs from it.
292
-
293
- ```tsx
294
- <BaseFormField name="plan" label="Plan" schema={Schema.shape.plan}>
295
- {constraints => (
296
- <BaseRadioGroup required={constraints.required} defaultValue="free">
297
- <BaseRadio value="free" label="Free" />
298
- <BaseRadio value="pro" label="Pro" />
299
- </BaseRadioGroup>
300
- )}
301
- </BaseFormField>
302
- ```
303
-
304
- #### `BaseRadio`
305
-
306
- A Base UI [`Radio`](https://base-ui.com/react/components/radio-group) with its label, for use inside `BaseRadioGroup`.
307
-
308
- | Prop | Type | Default | Description |
309
- |------|------|---------|-------------|
310
- | `label` | `ReactNode` | | Text next to the radio (required) |
311
- | `value` | `string` | | Submitted under the group's `name` when selected (required) |
312
- | `labelClassName` | `string` | | Classes for the `<label>` around the radio and its text (default `flex items-center gap-2 text-sm font-normal`) |
313
- | `icon` | `ReactNode` | | Shown inside the radio when selected, e.g. a dot (`<span className="size-1.5 rounded-full bg-white" />`). The kit bundles none |
314
- | `renderIndicator` | `RenderProp<"span", RadioState>` | | Style the indicator that holds the icon |
315
- | `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when not selected (e.g. to animate it out) |
316
- | `className` | `string` | | Classes for the radio (default is a `size-4` `rounded-full` box with a focus ring offset) |
317
- | `render` | `RenderProp<"span", RadioState>` | | Render another element for the radio |
318
- | …rest | | | `disabled`, `readOnly`, `required`, `inputRef`, `nativeButton`, and `<span>` props |
319
-
320
- Render functions get `RadioState`: `{ checked, disabled, readOnly, required }`. The radio and the indicator set `data-checked` / `data-unchecked`, `data-disabled`, `data-readonly` and `data-required`. The indicator also sets `data-starting-style` / `data-ending-style` while it enters and leaves. The `<label>` sets `data-disabled` when the radio itself is `disabled`.
321
-
322
- ```tsx
323
- <BaseRadio
324
- value="pro"
325
- label="Pro"
326
- className="border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
327
- icon={<span className="size-1.5 rounded-full bg-white" />}
328
- />
329
- ```
330
-
331
- #### `BaseFieldset`
332
-
333
- A Base UI [`Fieldset`](https://base-ui.com/react/components/fieldset): a native `<fieldset>` that groups related controls under a stylable legend. The legend is linked to the fieldset (`aria-labelledby`), so screen readers announce it as the group's name.
334
-
335
- | Prop | Type | Default | Description |
336
- |------|------|---------|-------------|
337
- | `legend` | `ReactNode` | | The caption, rendered before the children. Without it, no legend is rendered |
338
- | `legendClassName` | `string` | | Classes for the legend `<div>` (default `font-semibold`) |
339
- | `renderLegend` | `RenderProp<"div", FieldsetState>` | | Render another element for the legend (e.g. a heading) |
340
- | `disabled` | `boolean` | | Disables every control inside, `BaseFormField`s included |
341
- | `className` | `string` | | Classes for the `<fieldset>` (default `flex min-w-0 flex-col gap-3`) |
342
- | `render` | `RenderProp<"fieldset", FieldsetState>` | | Render another element for the fieldset |
343
- | …rest | | | `<fieldset>` props |
344
-
345
- Render functions get `FieldsetState`: `{ disabled }`. The fieldset and the legend set `data-disabled` when disabled.
346
-
347
- ```tsx
348
- <BaseFieldset legend="Billing address" className="rounded border p-4" legendClassName="border-b pb-2">
349
- <BaseFormField name="street" label="Street" schema={Schema.shape.street} />
350
- <BaseFormField name="city" label="City" schema={Schema.shape.city} />
351
- </BaseFieldset>
352
- ```
353
-
354
- #### `BaseForm`
355
-
356
- A Base UI [`Form`](https://base-ui.com/react/components/form) connected to an action through React's `useActionState`. Actions are made with [`@omer-x/next-form-actions`](https://github.com/omermecitoglu/next-form-actions) (v2), which defines the result shape. Install it next to the kit:
357
-
358
- ```sh
359
- npm install @omer-x/next-form-actions@^2.0.0-alpha.1
360
- ```
361
-
362
- | Prop | Type | Description |
363
- |------|------|-------------|
364
- | `action` | `FormAction<Data>` | The action, e.g. `saveProduct` or `completeSale.bind(null, saleId)`. `Data` is what it returns on success |
365
- | `formatMessage` | `(code: string, params?: Record<string, unknown>) => string` | Turns error codes and message texts into display text (see below). Without it, codes are shown as they are |
366
- | `onResult` | `(result: FormActionState<Data>) => void` | Called once per completed submission, when the action returns. Never on mount |
367
- | `resetOnSuccess` | `boolean` | After a successful result, reset every field inside the form to its default (see below) |
368
- | `defaultValues` | `Record<string, unknown>` | Initial values, used by `onlyDirty` |
369
- | `onlyDirty` | `boolean` | Submit only the fields whose value differs from `defaultValues`. Fields are compared by name, so multi-selects and checkbox groups take an array default. A changed field with no value (an unchecked checkbox, a cleared multi-select) is sent as an empty value |
370
- | …rest | `<form>` props | Except `action` |
371
-
372
- **How the result is used.** The action resolves to `{ status: "idle" }`, `{ status: "success", data }` or `{ status: "failure", fieldErrors, message? }`:
373
-
374
- - `fieldErrors[name]` are shown under the `BaseFormField` with that `name`. A field can have several errors.
375
- - `message` (`{ type: "error" | "warning", text }`) is a **form-level message**.
376
- - Field errors with no matching field in the form (a schema field you didn't render, or an object-level refine without a `path`, under the `""` key) also become form-level messages, so they are never silently lost.
377
- - `BaseForm` renders no form-level messages itself. Show them wherever you like with `useFormMessages()`.
378
-
379
- The form never resets after a submission, so after a failure the user keeps what they typed. That includes controlled checkboxes and selects.
380
-
381
- **`formatMessage`** receives every text the form shows:
382
-
383
- | What | `code` | `params` |
384
- |------|--------|----------|
385
- | Server field error | Zod issue code or your custom code: `required`, `too_small`, `invalid_email`, `taken`, … | From the error, e.g. `{ minimum: 3, origin: "string" }` |
386
- | Browser validity state | `valueMissing`, `typeMismatch`, `patternMismatch`, `tooShort`, `tooLong`, `rangeUnderflow`, `rangeOverflow`, `stepMismatch`, `badInput` | `{ minimum }` for `tooShort` / `rangeUnderflow`, `{ maximum }` for `tooLong` / `rangeOverflow` (taken from the field's schema) |
387
- | Form message | The message's `text`, e.g. `SALE_ALREADY_COMPLETED` | none |
388
-
389
- It is a function, so it can't be passed from a server component. Set it once in your themed form wrapper, and every form in the app gets translated messages:
390
-
391
- ```tsx
392
- // src/components/Form.tsx
393
- "use client";
394
- import { BaseForm } from "@omer-x/tailwind-ui-kit/form";
395
- import { useTranslations } from "next-intl";
396
- import type { ComponentProps } from "react";
397
-
398
- const Form = <Data,>(props: ComponentProps<typeof BaseForm<Data>>) => {
399
- const t = useTranslations("Form");
400
- return <BaseForm {...props} formatMessage={(code, params) => t(code, params as Record<string, string>)} />;
401
- };
402
-
403
- export default Form;
404
- ```
405
-
406
- ```json
407
- {
408
- "Form": {
409
- "required": "This field is required",
410
- "valueMissing": "This field is required",
411
- "too_small": "{origin, select, string {At least {minimum, plural, one {# character} other {# characters}}} other {At least {minimum}}}",
412
- "tooShort": "At least {minimum, plural, one {# character} other {# characters}}",
413
- "SALE_ALREADY_COMPLETED": "This sale is already completed"
414
- }
415
- }
416
- ```
417
-
418
- **`resetOnSuccess`** remounts the form's children after a successful result. Uncontrolled inputs go back to their `defaultValue`, and components inside the form lose their state, including controlled ones. State kept *outside* the form (e.g. in the page that renders it) is not reset.
419
-
420
- ```tsx
421
- // actions.ts
422
- "use server";
423
- export const saveProfile = defineFormAction({
424
- schema: z.object({ name: z.string().min(3) }),
425
- action: input => async () => {
426
- if (await isDown()) displayMessage("error", "SERVER_DOWN");
427
- return await save(input); // becomes state.data
428
- },
429
- });
430
- ```
431
-
432
- ```tsx
433
- <Form action={saveProfile} onResult={result => result.status === "success" && dialog.close()} className="flex flex-col gap-4">
434
- <FormAlerts />
435
- <FormField name="name" label="Name" schema={z.string().min(3)} />
436
- <Button type="submit">Save</Button>
437
- </Form>
438
- ```
439
-
440
- Forms can be nested. A submit inside an inner form does not submit the outer one.
441
-
442
- #### `useFormMessages`
443
-
444
- Returns the form-level messages of the latest result of the surrounding `BaseForm`, already passed through `formatMessage`. Call it anywhere inside the form.
445
-
446
- ```ts
447
- const { messages, submissionId } = useFormMessages();
448
- // messages: { key: string, type: "error" | "warning", text: string }[]
449
- // submissionId: changes once per completed submission
450
- ```
451
-
452
- ```tsx
453
- // Inline alerts, placed anywhere in the form
454
- const FormAlerts = () => {
455
- const { messages } = useFormMessages();
456
- return messages.map(m => <Alert key={m.key} type={m.type}>{m.text}</Alert>);
457
- };
458
-
459
- // Toasts: fire once per submission, not on every re-render
460
- const FormToasts = () => {
461
- const { messages, submissionId } = useFormMessages();
462
- const { add } = useToast();
463
- useEffect(() => {
464
- messages.forEach(m => add({ type: m.type, description: m.text }));
465
- }, [submissionId]);
466
- return null;
467
- };
468
- ```
469
-
470
- #### `BaseFormField`
471
-
472
- A Base UI [`Field`](https://base-ui.com/react/components/field) made of a label, a control and error messages. It reads native validation constraints (`required`, `minLength`, `max`, …) from a Zod schema, and the form checks them in the browser before the action runs: an invalid field blocks the submit and shows its error (`valueMissing`, `tooShort`, …) through `formatMessage`.
473
-
474
- | Prop | Type | Description |
475
- |------|------|-------------|
476
- | `name` | `string` | Field name. It also links the server errors in `fieldErrors[name]` |
477
- | `schema` | `ZodType` | Source of the HTML constraints applied to the control |
478
- | `label` | `string` | Label text. No label is rendered when omitted |
479
- | `control` | `RenderProp<"input", FieldState>` | The input to render, as Base UI's `Field.Control` (so it gets `aria-invalid`, `data-invalid`, … and is validated). Defaults to a plain `<input>`. Pass your themed input here |
480
- | `children` | `(constraints: FieldConstraints) => ReactNode` | Renders a control that isn't a single `<input>` (e.g. [`BaseAutocomplete`](#baseautocomplete)) instead of `control`. Gets the constraints read from `schema` (`required`, `minLength`, …); pass on the ones the control supports. The control takes the field's `name` by itself |
481
- | `renderLabel` | `RenderProp<"label", FieldState>` | Style the label |
482
- | `renderErrors` | `RenderProp<"div", FieldState>` | Style client-side and server-side error messages. Each error is its own element |
483
- | `className` | `string` | Classes for the field root (a flex column by default) |
484
-
485
- Error texts come from `BaseForm`'s `formatMessage`. Render functions get `FieldState`: `{ disabled, touched, dirty, valid, filled, focused }` (`valid` is `null` until the field is validated).
486
-
487
- ```tsx
488
- <BaseFormField
489
- name="username"
490
- label="Username"
491
- schema={z.string().min(3).max(20)}
492
- control={<Input />}
493
- renderErrors={<p className="text-sm text-red-600" />}
494
- />
495
- ```
496
-
497
- **One schema for the server and the client.** Define one Zod object schema per form. Use it to validate in the server action, and pass its fields to `BaseFormField`. The browser checks then always match the server rules:
498
-
499
- ```ts
500
- // src/schemas/user.ts
501
- import { z } from "zod";
502
-
503
- export const UserSchema = z.object({
504
- username: z.string().min(3).max(20),
505
- email: z.email(),
506
- });
507
- ```
508
-
509
- ```tsx
510
- <BaseFormField name="username" label="Username" schema={UserSchema.shape.username} control={<Input />} />
511
- <BaseFormField name="email" label="Email" schema={UserSchema.shape.email} control={<Input type="email" />} />
512
- ```
513
-
514
- The browser can check only the rules that map to HTML attributes (`required`, `minLength`, `maxLength`, `min`, `max`, …). Refinements, transforms, cross-field rules and async checks such as "username taken" only run on the server, and come back as `fieldErrors`. Users can also bypass browser checks, so **the server action must always validate the full schema**. The client constraints only give earlier feedback.
515
-
516
- #### `BaseAutocomplete`
517
-
518
- A Base UI [`Autocomplete`](https://base-ui.com/react/components/autocomplete): a text input that suggests matching items as you type. The input is free text; choosing an item fills it in. A simple one needs no more than this:
519
-
520
- ```tsx
521
- import { BaseAutocomplete } from "@omer-x/tailwind-ui-kit/form";
522
-
523
- <BaseAutocomplete items={fruits}>
524
- <BaseAutocomplete.Input aria-label="Fruit" className="border border-neutral-300" />
525
- <BaseAutocomplete.Popup sideOffset={4} className="rounded-md bg-white py-1 shadow-lg">
526
- <BaseAutocomplete.Empty className="px-3 not-empty:py-1.5">No fruits found</BaseAutocomplete.Empty>
527
- <BaseAutocomplete.List>
528
- {(fruit: string) => (
529
- <BaseAutocomplete.Item key={fruit} value={fruit} className="px-3 py-1.5 data-highlighted:bg-blue-600">
530
- {fruit}
531
- </BaseAutocomplete.Item>
532
- )}
533
- </BaseAutocomplete.List>
534
- </BaseAutocomplete.Popup>
535
- </BaseAutocomplete>
536
- ```
537
-
538
- The parts are reached with dot notation, which only works in client components. Build autocompletes in a `"use client"` file, e.g. your app's themed wrapper.
539
-
540
- | Part | Renders | Description |
541
- |------|---------|-------------|
542
- | `BaseAutocomplete` | nothing | Groups the parts, holds the input's value and filters `items` |
543
- | `.Input` | `<input>` | The text input. Takes `size` (`"lg" \| "md" \| "sm" \| "xs"`, default `"md"`), the same sizes as `BaseInput` |
544
- | `.InputGroup` | `<div>` | Optional. Wraps the input with a trigger and a clear button (`relative flex items-center`). The popup is placed against it |
545
- | `.Trigger` | `<button>` | Opens the popup. `data-popup-open` while it's open |
546
- | `.Icon` | `<span>` | A decorative icon, hidden from assistive technology. Bring your own icon as children |
547
- | `.Clear` | `<button>` | Clears the input. Only rendered while the input has a value (`keepMounted` keeps it) |
548
- | `.Value` | nothing | The input's value, or a function of it, anywhere inside the root |
549
- | `.Popup` | `<div>` | The floating container, portaled and positioned. As wide as the input, never taller than the space left (max `24rem`), with scale and fade transitions |
550
- | `.Status` | `<div>` | A live region for screen readers ("Loading…", "12 results") |
551
- | `.Empty` | `<div>` | Its children show only when no item matches. Always rendered (it's a live region): style it with `not-empty:` / `empty:` |
552
- | `.List` | `<div>` | The scrollable list. Children can be a function that renders each filtered item (or group). `data-empty` when nothing matches |
553
- | `.Item` | `<div>` | An option (`flex items-center gap-2`). `value` is the item. `data-highlighted`, `data-disabled` |
554
- | `.Group` | `<div>` | A group of items. Pass the group's `items` to use `.Collection` inside |
555
- | `.GroupLabel` | `<div>` | Names a group |
556
- | `.Collection` | nothing | Renders the filtered items of the surrounding group with a function |
557
- | `.Separator` | `<div>` | A `role="separator"` line, with `data-orientation` |
558
- | `.Row` | `<div>` | A row of items when the root has `grid` |
559
-
560
- Every part takes `className` and a `render` prop. Render functions get the part's state (`AutocompleteInputState`, `AutocompleteItemState`, `AutocompletePopupState`, …), which is also set as data attributes: `data-open`, `data-popup-side`, `data-list-empty`, `data-highlighted`, `data-side`, `data-align`, `data-starting-style`, … The input, input group and trigger also carry the field's state (`data-invalid`, `data-dirty`, `data-touched`, `data-filled`, `data-focused`).
561
-
562
- `BaseAutocomplete` props:
563
-
564
- | Prop | Type | Description |
565
- |------|------|-------------|
566
- | `items` | `Item[] \| { items: Item[] }[]` | The items, flat or in groups. Filtered by the input's value and passed to `List`'s function children |
567
- | `filteredItems` | same as `items` | Items you filtered yourself, shown instead |
568
- | `filter` | `(item, query, itemToString?) => boolean \| null` | Decides what matches. `null` turns filtering off. Defaults to a case-insensitive "contains" |
569
- | `limit` | `number` | Shows at most this many matches |
570
- | `mode` | `"list" \| "both" \| "inline" \| "none"` | `list` (default) filters; `both` also fills the input with the highlighted item; `inline` only fills; `none` does neither |
571
- | `itemToStringValue` | `(item) => string` | Text of an object item. `{ value, label }` objects use `label` without it |
572
- | `value` / `defaultValue` | `string` | The input's value, controlled / uncontrolled |
573
- | `onValueChange` | `(value, event) => void` | Called with the new value and the DOM event (none when changed from code) |
574
- | `open` / `defaultOpen` | `boolean` | The popup's state |
575
- | `onOpenChange` | `(open, event) => void` | Called with the new state and the DOM event |
576
- | `onOpenChangeComplete` | `(open) => void` | Called after the transition ends |
577
- | `openOnInputClick` | `boolean` | Opens the popup on click |
578
- | `autoHighlight` | `boolean \| "always"` | Highlights the first match while typing (`"always"`: also on open) |
579
- | `keepHighlight` | `boolean` | Keeps the highlight when the pointer leaves the list |
580
- | `highlightItemOnHover` | `boolean` | Default `true`. `false` lets `:hover` and `data-highlighted` differ |
581
- | `onItemHighlighted` | `(item, { reason, index }) => void` | `reason` is `"keyboard"`, `"pointer"` or `"none"` |
582
- | `loopFocus` | `boolean` | Default `true`. Arrow keys wrap around the list |
583
- | `submitOnItemClick` | `boolean` | Submits the form when an item is chosen (e.g. a search box) |
584
- | `grid` | `boolean` | Items in `Row`s, navigated with all four arrow keys |
585
- | `inline` | `boolean` | Renders the list in place, without a popup. Use with `open` |
586
- | `modal` | `boolean` | Locks page scroll and outside pointer input while open |
587
- | `virtualized` | `boolean` | For lists rendered by a virtualizer (give each item its `index`) |
588
- | `locale` | `Intl.LocalesArgument` | Locale of the default filter |
589
- | `name`, `form`, `id`, `required`, `disabled`, `readOnly` | | Form props. Inside `BaseFormField`, the field's `name` is used |
590
- | `inputRef` | `Ref<HTMLInputElement>` | The hidden input used for validation |
591
- | `actionsRef` | `RefObject<AutocompleteActions>` | `actionsRef.current?.close()` |
592
-
593
- `BaseAutocomplete.Popup` props, besides `<div>` props:
594
-
595
- | Prop | Description |
596
- |------|-------------|
597
- | `side`, `align` | Placement against the input (group). Default `"bottom"`, `"start"` |
598
- | `sideOffset`, `alignOffset` | Offsets in pixels, or a function of the placement and sizes |
599
- | `anchor`, `positionMethod`, `collisionBoundary`, `collisionPadding`, `collisionAvoidance`, `sticky`, `disableAnchorTracking` | Positioning control |
600
- | `renderPositioner` | Replaces the element that positions the popup, e.g. `<div className="z-50" />` |
601
- | `container`, `keepMounted` | Portal target (default `<body>`), and keeping the popup in the DOM while closed |
602
- | `backdrop`, `renderBackdrop` | Renders a `fixed inset-0` backdrop (off by default, use it with `modal`) |
603
- | `arrow`, `renderArrow`, `arrowPadding` | An arrow pointing at the input. Rendered when `arrow` (its content, e.g. an `<svg>`) or `renderArrow` is given |
604
- | `finalFocus` | The element focused when the popup closes |
605
-
606
- **Your own filtering.** `useAutocompleteFilter(options?)` returns locale-aware matchers (`contains`, `startsWith`, `endsWith`, accent- and case-insensitive by default). Pass one as `filter`, or filter items yourself and pass `filteredItems`:
607
-
608
- ```tsx
609
- const filter = useAutocompleteFilter();
610
- <BaseAutocomplete items={fruits} filter={filter.startsWith}>…</BaseAutocomplete>
611
- ```
612
-
613
- **In a form.** Put it in `BaseFormField`'s `children`. The field gives it its `name`, label, validation, server errors and `data-invalid`, and `onlyDirty` sees its value. Only `required` is checked in the browser; other schema rules are checked by the server:
614
-
615
- ```tsx
616
- <BaseFormField name="fruit" label="Fruit" schema={Schema.shape.fruit}>
617
- {constraints => (
618
- <BaseAutocomplete items={fruits} required={constraints.required}>
619
- …
620
- </BaseAutocomplete>
621
- )}
622
- </BaseFormField>
623
- ```
624
-
625
- #### `BaseSelect`
626
-
627
- A Base UI [`Select`](https://base-ui.com/react/components/select): choose a predefined value from a dropdown. Like a native `<select>`, the popup opens over the trigger with the selected item on top of the value. A simple one:
628
-
629
- ```tsx
630
- import { BaseSelect } from "@omer-x/tailwind-ui-kit/form";
631
-
632
- const fruits = { apple: "Apple", banana: "Banana", cherry: "Cherry" };
633
-
634
- <BaseSelect items={fruits}>
635
- <BaseSelect.Label>Fruit</BaseSelect.Label>
636
- <BaseSelect.Trigger className="border border-neutral-300">
637
- <BaseSelect.Value placeholder="Pick a fruit" className="data-placeholder:text-neutral-500" />
638
- <BaseSelect.Icon><ChevronIcon /></BaseSelect.Icon>
639
- </BaseSelect.Trigger>
640
- <BaseSelect.Popup className="rounded-md bg-white py-1 shadow-lg">
641
- <BaseSelect.List>
642
- {Object.entries(fruits).map(([value, label]) => (
643
- <BaseSelect.Item key={value} value={value} className="px-2 py-1.5 data-highlighted:bg-blue-600">
644
- <BaseSelect.ItemIndicator><CheckIcon /></BaseSelect.ItemIndicator>
645
- <BaseSelect.ItemText>{label}</BaseSelect.ItemText>
646
- </BaseSelect.Item>
647
- ))}
648
- </BaseSelect.List>
649
- </BaseSelect.Popup>
650
- </BaseSelect>
651
- ```
652
-
653
- The parts are reached with dot notation, which only works in client components. Build selects in a `"use client"` file, e.g. your app's themed wrapper.
654
-
655
- | Part | Renders | Description |
656
- |------|---------|-------------|
657
- | `BaseSelect` | a hidden `<input>` | Groups the parts and holds the value. The hidden input carries the value for the form |
658
- | `.Label` | `<div>` | Names the trigger. Not needed inside `BaseFormField`, whose `label` names it |
659
- | `.Trigger` | `<button>` | Shows the value and opens the popup (`flex items-center justify-between gap-2`). Takes `size` (`"lg" \| "md" \| "sm" \| "xs"`, default `"md"`), the same sizes as `BaseInput`. `data-popup-open`, `data-placeholder` |
660
- | `.Value` | `<span>` | The selected item's label (`min-w-0 flex-1 truncate`). `placeholder` shows while nothing is selected (`data-placeholder`). Children can be a function of the value |
661
- | `.Icon` | `<span>` | A decorative icon (e.g. a chevron), hidden from assistive technology. Bring your own icon as children |
662
- | `.Popup` | `<div>` | The floating container, portaled and positioned. At least as wide as the trigger, with scale and fade transitions (none while it's over the trigger) |
663
- | `.List` | `<div>` | The scrollable list, never taller than the space left in the viewport |
664
- | `.Item` | `<div>` | An option (`flex items-center gap-2`). `value` is what it selects (`null` clears the selection), `label` its typeahead text. `data-selected`, `data-highlighted`, `data-disabled` |
665
- | `.ItemText` | `<div>` | The item's text. Over the trigger, it's lined up with the value |
666
- | `.ItemIndicator` | `<span>` | Marks the selected item. Only rendered while selected (`keepMounted` keeps it, e.g. to keep texts lined up). Bring your own icon, and give it `aria-hidden` so it stays out of the item's accessible name |
667
- | `.Group` | `<div>` | A group of items |
668
- | `.GroupLabel` | `<div>` | Names a group |
669
- | `.Separator` | `<div>` | A line between items or groups, with `data-orientation`. It has `role="presentation"`: a listbox can't hold separators |
670
- | `.ScrollUpArrow`, `.ScrollDownArrow` | `<div>` | Put them in `.Popup`, next to `.List`. They scroll the list while hovered, and are only rendered while it can scroll their way (`keepMounted` keeps them). Pinned to the popup's top / bottom edge. No content by default: bring your own icon |
671
-
672
- Every part takes `className` and a `render` prop. Render functions get the part's state (`SelectTriggerState`, `SelectItemState`, `SelectPopupState`, …), which is also set as data attributes: `data-open`, `data-popup-side`, `data-placeholder`, `data-selected`, `data-highlighted`, `data-side`, `data-align`, `data-starting-style`, … The trigger and `.Label` also carry the field's state (`data-invalid`, `data-dirty`, `data-touched`, `data-filled`, `data-focused`).
673
-
674
- `BaseSelect` props:
675
-
676
- | Prop | Type | Description |
677
- |------|------|-------------|
678
- | `value` / `defaultValue` | `Value \| null` (an array with `multiple`) | The selected value, controlled / uncontrolled |
679
- | `onValueChange` | `(value, event) => void` | Called with the new value and the DOM event (none when changed from code) |
680
- | `multiple` | `boolean` | Lets the user select several items. The popup stays open while choosing |
681
- | `items` | `Record<string, ReactNode> \| { value, label }[] \| { items }[]` | The items' labels, so `.Value` shows the selected label (not the raw value) before the popup has ever opened |
682
- | `itemToStringLabel` | `(value) => string` | Text shown for an object value. `{ value, label }` objects use `label` without it |
683
- | `itemToStringValue` | `(value) => string` | Text submitted for an object value. `{ value, label }` objects use `value` without it |
684
- | `isItemEqualToValue` | `(itemValue, value) => boolean` | Matches object values, e.g. by id. Defaults to `Object.is` |
685
- | `open` / `defaultOpen` | `boolean` | The popup's state |
686
- | `onOpenChange` | `(open, event) => void` | Called with the new state and the DOM event |
687
- | `onOpenChangeComplete` | `(open) => void` | Called after the transition ends |
688
- | `modal` | `boolean` | Default `true`. Locks page scroll and outside pointer input while open |
689
- | `highlightItemOnHover` | `boolean` | Default `true`. `false` lets `:hover` and `data-highlighted` differ |
690
- | `name`, `form`, `autoComplete`, `id`, `required`, `disabled`, `readOnly` | | Form props. Inside `BaseFormField`, the field's `name` is used |
691
- | `inputRef` | `Ref<HTMLInputElement>` | The hidden input |
692
- | `actionsRef` | `RefObject<SelectActions>` | `actionsRef.current?.close()` |
693
-
694
- `BaseSelect.Popup` props, besides `<div>` props:
695
-
696
- | Prop | Description |
697
- |------|-------------|
698
- | `alignItemWithTrigger` | Default `true`: the popup opens over the trigger (`data-side="none"`), and `side`, `align` and their offsets don't apply. Touch input and too little space fall back to a regular placement. `false` always places it beside the trigger |
699
- | `side`, `align` | Placement against the trigger. Default `"bottom"`, `"center"` |
700
- | `sideOffset`, `alignOffset` | Offsets in pixels, or a function of the placement and sizes |
701
- | `anchor`, `positionMethod`, `collisionBoundary`, `collisionPadding`, `collisionAvoidance`, `sticky`, `disableAnchorTracking` | Positioning control |
702
- | `renderPositioner` | Replaces the element that positions the popup, e.g. `<div className="z-50" />` |
703
- | `container` | Portal target (default `<body>`) |
704
- | `backdrop`, `renderBackdrop` | Renders a `fixed inset-0` backdrop (off by default) |
705
- | `arrow`, `renderArrow`, `arrowPadding` | An arrow pointing at the trigger. Rendered when `arrow` (its content, e.g. an `<svg>`) or `renderArrow` is given. Only shows while the popup is beside the trigger |
706
- | `finalFocus` | The element focused when the popup closes. Defaults to the trigger |
707
-
708
- **Several values.** With `multiple`, the value is an array. Render it in `.Value` with a function:
709
-
710
- ```tsx
711
- <BaseSelect multiple items={fruits}>
712
- <BaseSelect.Trigger>
713
- <BaseSelect.Value placeholder="Pick fruits">
714
- {(values: string[]) => values.map(value => fruits[value]).join(", ")}
715
- </BaseSelect.Value>
716
- </BaseSelect.Trigger>
717
- …
718
- </BaseSelect>
719
- ```
720
-
721
- **In a form.** Put it in `BaseFormField`'s `children`. The field gives it its `name`, label, validation, server errors and `data-invalid`, and `onlyDirty` sees its value (`defaultValues` holds the item values, an array with `multiple`). `BaseForm` never resets the form after a submit (#4), so the select keeps its value. Only `required` is checked in the browser; other schema rules are checked by the server:
722
-
723
- ```tsx
724
- <BaseFormField name="fruit" label="Fruit" schema={Schema.shape.fruit}>
725
- {constraints => (
726
- <BaseSelect items={fruits} required={constraints.required}>
727
- …
728
- </BaseSelect>
729
- )}
730
- </BaseFormField>
731
- ```
91
+ - [`BaseInput`](docs/form/BaseInput.md) — A plain `<input>` with sizes, rounded corners and a transparent outline ready for focus styles
92
+ - [`BaseSwitch`](docs/form/BaseSwitch.md) — A Base UI [`Switch`](https://base-ui.com/react/components/switch) with its label
93
+ - [`BaseCheckbox`](docs/form/BaseCheckbox.md) — A Base UI [`Checkbox`](https://base-ui.com/react/components/checkbox) with its label
94
+ - [`BaseCheckboxGroup`](docs/form/BaseCheckboxGroup.md) — A Base UI [`Checkbox Group`](https://base-ui.com/react/components/checkbox-group)
95
+ - [`BaseRadioGroup`](docs/form/BaseRadioGroup.md) — A Base UI [`Radio Group`](https://base-ui.com/react/components/radio-group)
96
+ - [`BaseRadio`](docs/form/BaseRadio.md) — A Base UI [`Radio`](https://base-ui.com/react/components/radio-group) with its label, for use inside `BaseRadioGroup`
97
+ - [`BaseFieldset`](docs/form/BaseFieldset.md) — A Base UI [`Fieldset`](https://base-ui.com/react/components/fieldset)
98
+ - [`BaseForm`](docs/form/BaseForm.md) — A Base UI [`Form`](https://base-ui.com/react/components/form) connected to an action through React's `useActionState`
99
+ - [`useFormMessages`](docs/form/useFormMessages.md) — Returns the form-level messages of the latest result of the surrounding `BaseForm`, already passed through `formatMessage`
100
+ - [`BaseFormField`](docs/form/BaseFormField.md) — A Base UI [`Field`](https://base-ui.com/react/components/field) made of a label, a control and error messages
101
+ - [`BaseAutocomplete`](docs/form/BaseAutocomplete.md) — A Base UI [`Autocomplete`](https://base-ui.com/react/components/autocomplete)
102
+ - [`BaseSelect`](docs/form/BaseSelect.md) — A Base UI [`Select`](https://base-ui.com/react/components/select)
103
+ - [`BaseSlider`](docs/form/BaseSlider.md) — A Base UI [`Slider`](https://base-ui.com/react/components/slider)
732
104
 
733
105
  ### `@omer-x/tailwind-ui-kit/dialog`
734
106
 
735
- #### `BaseDialog`
736
-
737
- A Base UI [`Dialog`](https://base-ui.com/react/components/dialog) made of a few parts. `Popup` brings its portal and backdrop, so a simple dialog needs no more than this:
738
-
739
- ```tsx
740
- import { BaseDialog } from "@omer-x/tailwind-ui-kit/dialog";
741
-
742
- <BaseDialog>
743
- <BaseDialog.Trigger render={<Button />}>Delete</BaseDialog.Trigger>
744
- <BaseDialog.Popup className="rounded-lg bg-white p-6 shadow-lg">
745
- <BaseDialog.Title>Delete item?</BaseDialog.Title>
746
- <BaseDialog.Description>This can't be undone.</BaseDialog.Description>
747
- <BaseDialog.Close render={<Button />}>Cancel</BaseDialog.Close>
748
- </BaseDialog.Popup>
749
- </BaseDialog>
750
- ```
751
-
752
- The parts are reached with dot notation (`BaseDialog.Popup`), which only works in client components. Build dialogs in a `"use client"` file, e.g. your app's themed wrapper.
753
-
754
- | Part | Renders | Description |
755
- |------|---------|-------------|
756
- | `BaseDialog` | nothing | Groups the parts and holds the open state |
757
- | `BaseDialog.Trigger` | `<button>` | Opens the dialog. `data-popup-open` while its dialog is open |
758
- | `BaseDialog.Popup` | `<div>` | The dialog's window, portaled with a backdrop. Centered, with scale and fade transitions. Nested dialogs stack with an offset and scale down |
759
- | `BaseDialog.Title` | `<h2>` | The heading that names the dialog (`text-xl font-semibold`) |
760
- | `BaseDialog.Description` | `<p>` | Describes the dialog to assistive technology |
761
- | `BaseDialog.Close` | `<button>` | Closes the dialog |
762
-
763
- Every part takes `className` and `render`. `Trigger` and `Close` also take `nativeButton` (set it to `false` when `render` doesn't render a `<button>`).
764
-
765
- `BaseDialog` props:
766
-
767
- | Prop | Type | Default | Description |
768
- |------|------|---------|-------------|
769
- | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
770
- | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
771
- | `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
772
- | `modal` | `boolean \| "trap-focus"` | `true` | `true` traps focus, locks page scroll and blocks outside pointer input. `"trap-focus"` only traps focus. `false` leaves the page usable |
773
- | `disablePointerDismissal` | `boolean` | `false` | Keeps the dialog open on outside presses |
774
- | `handle` | `DialogHandle<Payload>` | | Connects triggers outside the dialog and opens it from code (see below) |
775
- | `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open dialog belongs to |
776
- | `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the dialog |
777
-
778
- `BaseDialog.Popup` props:
779
-
780
- | Prop | Type | Default | Description |
781
- |------|------|---------|-------------|
782
- | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | Width: `xs` 288px, `sm` 320px, `md` 384px, `lg` 512px. Never wider than the viewport. Other widths go through `className` |
783
- | `initialFocus` | `DialogFocusTarget` | `true` | The element focused on open: `true` (first tabbable element), `false` (don't move focus), a ref, or a function of the interaction type (`"mouse"`, `"touch"`, `"pen"`, `"keyboard"`) |
784
- | `finalFocus` | `DialogFocusTarget` | `true` | The element focused on close. `true` is the trigger |
785
- | `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the popup is portaled to |
786
- | `keepMounted` | `boolean` | `false` | Keeps the popup in the DOM while closed |
787
- | `backdrop` | `boolean` | `true` | Set to `false` for no backdrop. Nested dialogs never render one |
788
- | `renderBackdrop` | `RenderProp<"div", DialogBackdropState>` | | Style or replace the backdrop: a fixed full-screen black overlay (`opacity-20`, `dark:opacity-70`) with a fade transition. A `className` on the element wins over the kit's conflicting classes (`<div className="opacity-50" />`). A function gets the kit's classes in `props.className` |
789
- | `render` | `RenderProp<"div", DialogPopupState>` | | The state is `{ open, nested, nestedDialogOpen }` |
790
-
791
- Data attributes: the popup and backdrop have `data-open` / `data-closed` and `data-starting-style` / `data-ending-style` during transitions. The popup also has `data-nested` (inside another dialog) and `data-nested-dialog-open` (a dialog inside it is open).
792
-
793
- **Nested dialogs:** put a `BaseDialog` inside another one's `Popup`. It stacks on top, and the outer popup gets a light overlay while the inner one is open.
794
-
795
- #### `createDialogHandle`
796
-
797
- Opens one dialog from triggers anywhere on the page, or from code. Each trigger can pass a `payload`, which the dialog's function children receive:
798
-
799
- ```tsx
800
- import { BaseDialog, createDialogHandle } from "@omer-x/tailwind-ui-kit/dialog";
801
-
802
- const deleteDialog = createDialogHandle<{ id: string, name: string }>();
803
-
804
- // triggers anywhere on the page
805
- <BaseDialog.Trigger handle={deleteDialog} payload={{ id: p.id, name: p.name }} render={<Button />}>Delete</BaseDialog.Trigger>
806
-
807
- // one dialog on the page
808
- <BaseDialog handle={deleteDialog}>
809
- {({ payload }) => payload && (
810
- <BaseDialog.Popup size="sm">
811
- <BaseDialog.Title>Delete {payload.name}?</BaseDialog.Title>
812
- </BaseDialog.Popup>
813
- )}
814
- </BaseDialog>
815
-
816
- // from code
817
- deleteDialog.openWithPayload({ id, name });
818
- ```
819
-
820
- A `DialogHandle<Payload>` has `open(triggerId?)`, `openWithPayload(payload)`, `close()` and `isOpen`.
821
-
822
- - Calls are **ignored while the dialog isn't mounted**. Keep the `BaseDialog` with the handle rendered.
823
- - Call them **from event handlers or effects, never during render**.
824
-
825
- #### `BaseAlertDialog`
826
-
827
- A Base UI [`Alert Dialog`](https://base-ui.com/react/components/alert-dialog): a modal dialog the user has to respond to. It works like `BaseDialog`, with these differences:
828
-
829
- - The popup has `role="alertdialog"`.
830
- - It is always modal, and outside presses don't close it. Escape and `Close` buttons still do. There are no `modal` or `disablePointerDismissal` props.
831
- - `Popup`, `Title`, `Description` and `Close` are `BaseDialog`'s parts, so they look the same and take the same props (`size`, `initialFocus`, `renderBackdrop`, …).
832
-
833
- ```tsx
834
- import { BaseAlertDialog } from "@omer-x/tailwind-ui-kit/dialog";
835
-
836
- <BaseAlertDialog>
837
- <BaseAlertDialog.Trigger render={<Button />}>Discard draft</BaseAlertDialog.Trigger>
838
- <BaseAlertDialog.Popup size="sm" className="rounded-lg bg-white p-6 shadow-lg">
839
- <BaseAlertDialog.Title>Discard draft?</BaseAlertDialog.Title>
840
- <BaseAlertDialog.Description>You can't undo this action.</BaseAlertDialog.Description>
841
- <BaseAlertDialog.Close render={<Button />}>Cancel</BaseAlertDialog.Close>
842
- <BaseAlertDialog.Close render={<Button />} onClick={discard}>Discard</BaseAlertDialog.Close>
843
- </BaseAlertDialog.Popup>
844
- </BaseAlertDialog>
845
- ```
846
-
847
- | Part | Renders | Description |
848
- |------|---------|-------------|
849
- | `BaseAlertDialog` | nothing | Groups the parts and holds the open state |
850
- | `BaseAlertDialog.Trigger` | `<button>` | Opens the alert dialog. `data-popup-open` while its alert dialog is open |
851
- | `BaseAlertDialog.Popup` | `<div>` | Same as `BaseDialog.Popup` |
852
- | `BaseAlertDialog.Title` | `<h2>` | Same as `BaseDialog.Title` |
853
- | `BaseAlertDialog.Description` | `<p>` | Same as `BaseDialog.Description` |
854
- | `BaseAlertDialog.Close` | `<button>` | Same as `BaseDialog.Close` |
855
-
856
- `BaseAlertDialog` takes `BaseDialog`'s props except `modal` and `disablePointerDismissal`: `open`, `defaultOpen`, `onOpenChange`, `onOpenChangeComplete`, `handle` (an `AlertDialogHandle<Payload>`), `triggerId`, `defaultTriggerId` and `children` (parts, or a function of `{ payload }`).
857
-
858
- Put it inside a `BaseDialog.Popup` to confirm something from a dialog: it stacks on top like a nested dialog.
859
-
860
- #### `createAlertDialogHandle`
861
-
862
- `createDialogHandle` for alert dialogs. It returns an `AlertDialogHandle<Payload>` with the same methods (`open`, `openWithPayload`, `close`, `isOpen`) and the same rules. Pass it to `BaseAlertDialog` and `BaseAlertDialog.Trigger`:
863
-
864
- ```tsx
865
- import { BaseAlertDialog, createAlertDialogHandle } from "@omer-x/tailwind-ui-kit/dialog";
866
-
867
- const removeAlert = createAlertDialogHandle<{ id: string, name: string }>();
868
-
869
- <BaseAlertDialog.Trigger handle={removeAlert} payload={member} render={<Button />}>Remove</BaseAlertDialog.Trigger>
870
-
871
- <BaseAlertDialog handle={removeAlert}>
872
- {({ payload }) => payload && (
873
- <BaseAlertDialog.Popup size="sm">
874
- <BaseAlertDialog.Title>Remove {payload.name}?</BaseAlertDialog.Title>
875
- </BaseAlertDialog.Popup>
876
- )}
877
- </BaseAlertDialog>
878
- ```
107
+ - [`BaseDialog`](docs/dialog/BaseDialog.md) — A Base UI [`Dialog`](https://base-ui.com/react/components/dialog) made of a few parts
108
+ - [`createDialogHandle`](docs/dialog/createDialogHandle.md) — Opens one dialog from triggers anywhere on the page, or from code
109
+ - [`BaseAlertDialog`](docs/dialog/BaseAlertDialog.md) — A Base UI [`Alert Dialog`](https://base-ui.com/react/components/alert-dialog)
110
+ - [`createAlertDialogHandle`](docs/dialog/createAlertDialogHandle.md) — `createDialogHandle` for alert dialogs
879
111
 
880
112
  ### `@omer-x/tailwind-ui-kit/menu`
881
113
 
882
- #### `BaseContextMenu`
883
-
884
- A Base UI [`Context Menu`](https://base-ui.com/react/components/context-menu): a menu that opens at the pointer on right click or long press. `Popup` brings its portal and positioner, so a simple context menu needs no more than this:
885
-
886
- ```tsx
887
- import { BaseContextMenu } from "@omer-x/tailwind-ui-kit/menu";
888
-
889
- <BaseContextMenu>
890
- <BaseContextMenu.Trigger className="h-40 rounded border border-dashed">Right click here</BaseContextMenu.Trigger>
891
- <BaseContextMenu.Popup className="rounded-md border bg-white shadow-lg">
892
- <BaseContextMenu.Item className="data-highlighted:bg-neutral-100" onClick={reload}>Reload</BaseContextMenu.Item>
893
- <BaseContextMenu.Separator className="bg-neutral-200" />
894
- <BaseContextMenu.LinkItem className="data-highlighted:bg-neutral-100" href="/help">Help</BaseContextMenu.LinkItem>
895
- </BaseContextMenu.Popup>
896
- </BaseContextMenu>
897
- ```
898
-
899
- Like `BaseDialog`, the parts use dot notation, so build menus in a `"use client"` file. Every part except the root and `Trigger` is shared with `BaseMenu`, so one set of popup and item styles themes both.
900
-
901
- | Part | Renders | Description |
902
- |------|---------|-------------|
903
- | `BaseContextMenu` | nothing | Groups the parts and holds the open state |
904
- | `BaseContextMenu.Trigger` | `<div>` | The area that opens the menu on right click or long press. `data-popup-open` while the menu is open |
905
- | `BaseContextMenu.Popup` | `<div>` | The menu, portaled and placed at the pointer (or next to its submenu trigger), with scale and fade transitions. Scrolls when taller than the viewport. Optional backdrop |
906
- | `BaseContextMenu.Arrow` | `<div>` | An arrow pointing at the anchor, inside `Popup`. Draw it yourself |
907
- | `BaseContextMenu.Item` | `<div>` | An action. Closes the menu when clicked (`closeOnClick`, default `true`) |
908
- | `BaseContextMenu.LinkItem` | `<a>` | A link. Use `render` for your router's link. Doesn't close the menu (`closeOnClick`, default `false`) |
909
- | `BaseContextMenu.Separator` | `<div>` | A `1px` line between items (`my-1 h-px`). Give it a color with `className` |
910
- | `BaseContextMenu.Group` | `<div>` | Groups related items, labelled by the `GroupLabel` inside it |
911
- | `BaseContextMenu.GroupLabel` | `<div>` | The group's name (`text-xs font-medium`) |
912
- | `BaseContextMenu.RadioGroup` | `<div>` | Holds `RadioItem`s: `value` / `defaultValue`, `onValueChange(value, event)`, `disabled` |
913
- | `BaseContextMenu.RadioItem` | `<div>` | An option of a `RadioGroup` (`value`) |
914
- | `BaseContextMenu.CheckboxItem` | `<div>` | A toggle: `checked` / `defaultChecked`, `onCheckedChange(checked, event)` |
915
- | `BaseContextMenu.Submenu` | nothing | Holds a `SubmenuTrigger` and a nested `Popup`. Takes `open` / `defaultOpen`, `onOpenChange`, `onOpenChangeComplete`, `disabled`, `loopFocus`, `highlightItemOnHover` and `closeParentOnEsc` |
916
- | `BaseContextMenu.SubmenuTrigger` | `<div>` | The item that opens its submenu, on click or hover (`openOnHover`, `delay`, `closeDelay`). `icon` is shown at the end (e.g. a chevron), with `iconClassName` for its `<span>` |
917
-
918
- Every part that renders an element takes `className` and `render`.
919
-
920
- Items (`Item`, `LinkItem`, `SubmenuTrigger`, `CheckboxItem`, `RadioItem`) share one layout: `flex items-center gap-2 px-3 py-1.5 text-sm`, no outline, faded and inert while disabled. They take `label` (the text for keyboard text navigation), and the `<div>` ones take `disabled` and `nativeButton` (set it to `true` when `render` renders a `<button>`). Style the highlighted item with `data-highlighted:`.
921
-
922
- `CheckboxItem` and `RadioItem` put their indicator in a first `1rem` column, so labels line up whether it shows or not. Indicator props:
923
-
924
- | Prop | Type | Description |
925
- |------|------|-------------|
926
- | `indicator` | `ReactNode` | Shown when checked, e.g. a check mark or a dot. Nothing by default |
927
- | `renderIndicator` | `RenderProp<"span", State>` | Style or replace the indicator's `<span>` |
928
- | `keepIndicatorMounted` | `boolean` | Keeps the indicator in the DOM when unchecked, e.g. to animate it out |
929
- | `closeOnClick` | `boolean` | Closes the menu when clicked. Default `false` |
930
-
931
- `BaseContextMenu` props:
932
-
933
- | Prop | Type | Default | Description |
934
- |------|------|---------|-------------|
935
- | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
936
- | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
937
- | `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
938
- | `disabled` | `boolean` | `false` | Doesn't open, so the browser's own context menu shows |
939
- | `loopFocus` | `boolean` | `true` | Arrow keys wrap from the last item to the first |
940
- | `highlightItemOnHover` | `boolean` | `true` | Highlights items under the pointer. Turn it off to style `:hover` apart from `data-highlighted` |
941
- | `orientation` | `"vertical" \| "horizontal"` | `"vertical"` | Which arrow keys move between items |
942
-
943
- `BaseContextMenu.Popup` props:
944
-
945
- | Prop | Type | Default | Description |
946
- |------|------|---------|-------------|
947
- | `side` / `align` | `MenuSide` / `MenuAlign` | at the pointer | Where the popup sits against its anchor (`"top"`, `"bottom"`, `"left"`, `"right"`, `"inline-start"`, `"inline-end"` / `"start"`, `"center"`, `"end"`). Submenus default to `"inline-end"` / `"start"` |
948
- | `sideOffset` / `alignOffset` | `number \| MenuOffsetFunction` | | Offsets from the anchor, in pixels, or a function of the placement and sizes |
949
- | `collisionPadding` | `number \| { top, right, bottom, left }` | `5` | Space kept from the viewport edges |
950
- | `collisionBoundary` / `collisionAvoidance` | | `"clipping-ancestors"` | The area the popup stays inside, and how it avoids its edges (flip or shift) |
951
- | `anchor` | `Element \| RefObject \| () => Element \| null` | the trigger | The element the popup is placed against |
952
- | `disableAnchorTracking` | `boolean` | `false` | Stops following the anchor when it moves |
953
- | `arrowPadding` | `number` | `5` | Minimum distance between an `Arrow` and the popup's corners |
954
- | `sticky` | `boolean` | `false` | Stays in view while the anchor scrolls away |
955
- | `positionMethod` | `"absolute" \| "fixed"` | `"absolute"` | Use `"fixed"` when the anchor is inside a fixed container |
956
- | `positionerClassName` / `renderPositioner` | `string` / `RenderProp<"div", MenuPositionerState>` | | Style or replace the positioner, the `<div>` around the popup that places it (`z-50`) |
957
- | `finalFocus` | `MenuFocusTarget` | `true` | The element focused on close: `true` (default), `false` (don't move focus), a ref, or a function of the interaction type |
958
- | `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the popup is portaled to |
959
- | `keepMounted` | `boolean` | `false` | Keeps the popup in the DOM while closed |
960
- | `backdrop` | `boolean` | `false` | Renders a transparent full-screen backdrop (`fixed inset-0`) behind the popup |
961
- | `renderBackdrop` | `RenderProp<"div", MenuBackdropState>` | | Style or replace the backdrop. A `className` on the element wins over the kit's conflicting classes |
962
- | `render` | `RenderProp<"div", MenuPopupState>` | | The state is `{ open, side, align, nested }` |
963
-
964
- Data attributes: the popup has `data-open` / `data-closed`, `data-side`, `data-align`, `data-nested` (in a submenu) and `data-starting-style` / `data-ending-style` during transitions. Items have `data-highlighted` and `data-disabled`; checkbox and radio items and their indicators also have `data-checked` / `data-unchecked`.
965
-
966
- **Submenus:** put a `Submenu` among the items, with a `SubmenuTrigger` and another `Popup` inside:
967
-
968
- ```tsx
969
- <BaseContextMenu.Submenu>
970
- <BaseContextMenu.SubmenuTrigger icon={<ChevronRight />}>Share</BaseContextMenu.SubmenuTrigger>
971
- <BaseContextMenu.Popup className="rounded-md border bg-white shadow-lg">
972
- <BaseContextMenu.Item>Email</BaseContextMenu.Item>
973
- </BaseContextMenu.Popup>
974
- </BaseContextMenu.Submenu>
975
- ```
976
-
977
-
978
- #### `BaseMenu`
979
-
980
- A Base UI [`Menu`](https://base-ui.com/react/components/menu): a list of actions opened from a button, with keyboard navigation, submenus, checkbox and radio items, and optional filtering. It uses the same `Popup`, `Arrow`, items, groups and submenus as `BaseContextMenu` (see above), so one set of styles themes both. A simple menu needs no more than this:
981
-
982
- ```tsx
983
- import { BaseMenu } from "@omer-x/tailwind-ui-kit/menu";
984
-
985
- <BaseMenu>
986
- <BaseMenu.Trigger render={<Button />}>Actions</BaseMenu.Trigger>
987
- <BaseMenu.Popup sideOffset={4} className="rounded-md border bg-white shadow-lg">
988
- <BaseMenu.Item className="data-highlighted:bg-neutral-100" onClick={edit}>Edit</BaseMenu.Item>
989
- <BaseMenu.Separator className="bg-neutral-200" />
990
- <BaseMenu.Item className="data-highlighted:bg-neutral-100" onClick={remove}>Delete</BaseMenu.Item>
991
- </BaseMenu.Popup>
992
- </BaseMenu>
993
- ```
994
-
995
- Parts besides the shared ones (`Popup`, `Arrow`, `Item`, `LinkItem`, `Separator`, `Group`, `GroupLabel`, `RadioGroup`, `RadioItem`, `CheckboxItem`, `Submenu`, `SubmenuTrigger`):
996
-
997
- | Part | Renders | Description |
998
- |------|---------|-------------|
999
- | `BaseMenu` | nothing | Groups the parts and holds the open state |
1000
- | `BaseMenu.Trigger` | `<button>` | Opens the menu. `data-popup-open` while its menu is open. Takes `handle`, `payload`, `openOnHover` (also open on hover), `delay` / `closeDelay` (hover delays in ms, default `100` / `0`) and `nativeButton` |
1001
- | `BaseMenu.Input` | `<input>` | The search box of a `filterable` menu (`role="searchbox"`) |
1002
- | `BaseMenu.Clear` | `<button>` | Clears the search box. Only rendered while there's a query. A pointer shortcut: out of the tab order and `aria-hidden` |
1003
- | `BaseMenu.Empty` | `<div>` | Shown only when no item matches (`role="status"`). Not rendered otherwise |
1004
- | `BaseMenu.List` | `<div>` | Holds the items when the popup has other content too (the search box). Scrolls when the popup runs out of space (`min-h-0 flex-1 overflow-y-auto`) |
1005
- | `BaseMenu.Viewport` | `<div>` | Animates the content when one menu is opened by several triggers and its content depends on the trigger. `data-activation-direction`, `data-transitioning` |
1006
-
1007
- The popup is placed below the trigger and centered by default (`side="bottom"`, `align="center"`).
1008
-
1009
- `BaseMenu` props:
1010
-
1011
- | Prop | Type | Default | Description |
1012
- |------|------|---------|-------------|
1013
- | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
1014
- | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
1015
- | `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
1016
- | `modal` | `boolean` | `true` | Locks page scroll and blocks outside pointer input while open. Menus opened by hover never are |
1017
- | `disabled` | `boolean` | `false` | |
1018
- | `loopFocus` | `boolean` | `true` | Arrow keys wrap from the last item to the first |
1019
- | `highlightItemOnHover` | `boolean` | `true` | Turn it off to style `:hover` apart from `data-highlighted` |
1020
- | `orientation` | `"vertical" \| "horizontal"` | `"vertical"` | Which arrow keys move between items |
1021
- | `onItemHighlighted` | `(item, { reason, label }) => void` | | The highlighted element (or `undefined`). `reason` is `"keyboard"`, `"pointer"` or `"none"` |
1022
- | `actionsRef` | `RefObject<MenuActions>` | | `actionsRef.current?.close()` |
1023
- | `handle` | `MenuHandle<Payload>` | | Connects triggers outside the menu and opens it from code (see below) |
1024
- | `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open menu belongs to |
1025
- | `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the menu |
1026
- | `filterable` | `boolean` | `false` | Adds filtering (see below) |
1027
-
1028
- `Submenu` also takes `orientation`, `onItemHighlighted`, `actionsRef` and the filtering props.
1029
-
1030
- **Router links.** `LinkItem` renders an `<a>`. Pass your router's link as `render`, and it gets the item's props and behavior:
1031
-
1032
- ```tsx
1033
- import Link from "next/link";
1034
-
1035
- <BaseMenu.LinkItem render={<Link href="/settings" />}>Settings</BaseMenu.LinkItem>
1036
- ```
1037
-
1038
- **Filtering.** `filterable` (on `BaseMenu` or a `Submenu`) lets the user filter the items by typing in an `Input`. Put the items in a `List`; items that don't match are removed. The popup becomes a `role="dialog"` holding the search box and the `role="menu"` list. Make the popup a flex column (`flex flex-col`) so only the list scrolls:
1039
-
1040
- ```tsx
1041
- <BaseMenu filterable>
1042
- <BaseMenu.Trigger render={<Button />}>Labels</BaseMenu.Trigger>
1043
- <BaseMenu.Popup className="flex flex-col">
1044
- <BaseMenu.Input aria-label="Search labels" placeholder="Search labels" />
1045
- <BaseMenu.Empty className="py-1.5">No labels found</BaseMenu.Empty>
1046
- <BaseMenu.List>
1047
- {labels.map(label => <BaseMenu.CheckboxItem key={label}>{label}</BaseMenu.CheckboxItem>)}
1048
- </BaseMenu.List>
1049
- </BaseMenu.Popup>
1050
- </BaseMenu>
1051
- ```
1052
-
1053
- | Prop | Type | Description |
1054
- |------|------|-------------|
1055
- | `filter` | `(text, query) => boolean \| null` | Decides what matches, from the item's `label` (or text) and the trimmed query. Defaults to "contains", ignoring case, accents and punctuation. `null` shows every item (filter them yourself) |
1056
- | `autoHighlight` | `boolean \| "always"` | Highlights the first match while there's a query (`"always"`: also without one) |
1057
- | `locale` | `Intl.LocalesArgument` | Locale of the default filter |
1058
- | `query` / `defaultQuery` | `string` | The query, controlled / uncontrolled. It's cleared when the menu closes |
1059
- | `onQueryChange` | `(query, event) => void` | Called with the new query and the DOM event |
1060
-
1061
- #### `createMenuHandle`
1062
-
1063
- Opens one menu from triggers anywhere on the page, or from code. Each trigger can pass a `payload`, which the menu's function children receive:
1064
-
1065
- ```tsx
1066
- import { BaseMenu, createMenuHandle } from "@omer-x/tailwind-ui-kit/menu";
1067
-
1068
- const rowMenu = createMenuHandle<{ id: string, name: string }>();
1069
-
1070
- // triggers anywhere on the page
1071
- <BaseMenu.Trigger id={`row-${row.id}`} handle={rowMenu} payload={row} render={<Button />}>Options</BaseMenu.Trigger>
1072
-
1073
- // one menu on the page
1074
- <BaseMenu handle={rowMenu}>
1075
- {({ payload }) => payload && (
1076
- <BaseMenu.Popup>
1077
- <BaseMenu.Item onClick={() => rename(payload.id)}>Rename {payload.name}</BaseMenu.Item>
1078
- </BaseMenu.Popup>
1079
- )}
1080
- </BaseMenu>
1081
-
1082
- // from code
1083
- rowMenu.open(`row-${id}`);
1084
- ```
1085
-
1086
- A `MenuHandle<Payload>` has `open(triggerId)`, `close()` and `isOpen`. Unlike the dialog handles, it has no `openWithPayload`: a menu is placed against its trigger, so `open` needs the `id` of a trigger with the same handle (it throws when there's none).
1087
-
1088
- - Calls are **ignored while the menu isn't mounted**. Keep the `BaseMenu` with the handle rendered.
1089
- - Call them **from event handlers or effects, never during render**.
1090
-
1091
- #### `BaseMenubar`
1092
-
1093
- A Base UI [`Menubar`](https://base-ui.com/react/components/menubar): an application menu bar holding several `BaseMenu`s. Once one menu is open, hovering another trigger switches to its menu, and the arrow keys move between the triggers. `BaseMenu` is attached as `BaseMenubar.Menu`, so one import is enough:
1094
-
1095
- ```tsx
1096
- import { BaseMenubar } from "@omer-x/tailwind-ui-kit/menu";
1097
-
1098
- <BaseMenubar className="gap-1 rounded-md border p-1">
1099
- <BaseMenubar.Menu>
1100
- <BaseMenubar.Menu.Trigger className="rounded px-3 py-1 data-popup-open:bg-neutral-200">File</BaseMenubar.Menu.Trigger>
1101
- <BaseMenubar.Menu.Popup sideOffset={6} className="rounded-md border bg-white shadow-lg">
1102
- <BaseMenubar.Menu.Item className="data-highlighted:bg-neutral-100" onClick={save}>Save</BaseMenubar.Menu.Item>
1103
- </BaseMenubar.Menu.Popup>
1104
- </BaseMenubar.Menu>
1105
- <BaseMenubar.Menu>
1106
- <BaseMenubar.Menu.Trigger className="rounded px-3 py-1 data-popup-open:bg-neutral-200">Edit</BaseMenubar.Menu.Trigger>
1107
- <BaseMenubar.Menu.Popup sideOffset={6} className="rounded-md border bg-white shadow-lg">
1108
- <BaseMenubar.Menu.Item className="data-highlighted:bg-neutral-100" onClick={undo}>Undo</BaseMenubar.Menu.Item>
1109
- </BaseMenubar.Menu.Popup>
1110
- </BaseMenubar.Menu>
1111
- </BaseMenubar>
1112
- ```
1113
-
1114
- `<BaseMenu>` inside a `<BaseMenubar>` works the same. Every menu part (`Popup`, items, submenus, …) behaves as described for `BaseMenu`, with these differences:
1115
-
1116
- - Triggers are items of the menubar (`role="menuitem"`), with one tab stop for the whole bar.
1117
- - Popups open below a horizontal menubar's triggers and start-aligned (`side="bottom"`, `align="start"`), or beside a vertical one's.
1118
- - The menubar's `modal` and `disabled` apply to every menu in it. `BaseMenu`'s own `modal` is ignored there.
1119
-
1120
- | Part | Renders | Description |
1121
- |------|---------|-------------|
1122
- | `BaseMenubar` | `<div>` | The bar (`role="menubar"`, `flex`, `flex-col` when vertical). `data-orientation`, `data-modal`, `data-has-submenu-open` (one of its menus is open) |
1123
- | `BaseMenubar.Menu` | nothing | `BaseMenu`, with all its parts (`BaseMenubar.Menu.Trigger`, `BaseMenubar.Menu.Popup`, …) |
1124
-
1125
- `BaseMenubar` props:
1126
-
1127
- | Prop | Type | Default | Description |
1128
- |------|------|---------|-------------|
1129
- | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | The direction of the bar, and the arrow keys that move between its triggers |
1130
- | `modal` | `boolean` | `true` | Locks page scroll and blocks outside pointer input while a menu is open |
1131
- | `disabled` | `boolean` | `false` | Disables every menu (`data-disabled` on the triggers) |
1132
- | `loopFocus` | `boolean` | `true` | Arrow keys wrap from the last trigger to the first |
1133
- | `render` | `RenderProp<"div", MenubarState>` | | The state is `{ orientation, modal, hasSubmenuOpen }` |
114
+ - [`BaseContextMenu`](docs/menu/BaseContextMenu.md) — A Base UI [`Context Menu`](https://base-ui.com/react/components/context-menu)
115
+ - [`BaseMenu`](docs/menu/BaseMenu.md) — A Base UI [`Menu`](https://base-ui.com/react/components/menu)
116
+ - [`createMenuHandle`](docs/menu/createMenuHandle.md) — Opens one menu from triggers anywhere on the page, or from code
117
+ - [`BaseMenubar`](docs/menu/BaseMenubar.md) — A Base UI [`Menubar`](https://base-ui.com/react/components/menubar)
1134
118
 
1135
119
  ### `@omer-x/tailwind-ui-kit/overlay`
1136
120
 
1137
- #### `BaseTooltip`
1138
-
1139
- A Base UI [`Tooltip`](https://base-ui.com/react/components/tooltip): a popup that shows a hint when its trigger is hovered or focused. `Popup` brings its portal and positioner, so a tooltip needs no more than this:
1140
-
1141
- ```tsx
1142
- import { BaseTooltip } from "@omer-x/tailwind-ui-kit/overlay";
1143
-
1144
- <BaseTooltip>
1145
- <BaseTooltip.Trigger render={<Button />}>Save</BaseTooltip.Trigger>
1146
- <BaseTooltip.Popup className="rounded bg-neutral-900 px-2 py-1 text-xs text-white" sideOffset={8}>
1147
- Saves your changes
1148
- <BaseTooltip.Arrow className="size-2 rotate-45 bg-neutral-900 data-[side=top]:-bottom-1 data-[side=bottom]:-top-1" />
1149
- </BaseTooltip.Popup>
1150
- </BaseTooltip>
1151
- ```
1152
-
1153
- The parts use dot notation, so build tooltips in a `"use client"` file. A tooltip is only a visual hint: it isn't announced to screen readers, so keep the trigger's accessible name (text or `aria-label`) meaningful without it.
1154
-
1155
- | Part | Renders | Description |
1156
- |------|---------|-------------|
1157
- | `BaseTooltip` | nothing | Groups the parts and holds the open state |
1158
- | `BaseTooltip.Trigger` | `<button>` | Opens the tooltip on hover (after `delay`) or keyboard focus. `data-popup-open` while its tooltip is open, `data-trigger-disabled` when `disabled` |
1159
- | `BaseTooltip.Popup` | `<div>` | The tooltip, portaled and placed against the trigger, with scale and fade transitions (skipped while `data-instant`) |
1160
- | `BaseTooltip.Arrow` | `<div>` | An arrow pointing at the trigger, inside `Popup`. `data-side`, `data-align`, `data-uncentered`. Draw it yourself |
1161
- | `BaseTooltip.Viewport` | `<div>` | Animates the content when one tooltip is opened by several triggers and its content depends on the trigger. `data-activation-direction`, `data-transitioning` |
1162
- | `BaseTooltip.Provider` | nothing | The same component as [`TooltipProvider`](#tooltipprovider) |
1163
-
1164
- `BaseTooltip` props:
1165
-
1166
- | Prop | Type | Default | Description |
1167
- |------|------|---------|-------------|
1168
- | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
1169
- | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
1170
- | `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
1171
- | `disableHoverablePopup` | `boolean` | `false` | Closes the tooltip as soon as the pointer leaves the trigger, even onto the popup |
1172
- | `trackCursorAxis` | `"none" \| "x" \| "y" \| "both"` | `"none"` | Makes the popup follow the pointer along this axis |
1173
- | `disabled` | `boolean` | `false` | No trigger opens the tooltip |
1174
- | `actionsRef` | `RefObject<TooltipActions>` | | `actionsRef.current?.close()` |
1175
- | `handle` | `TooltipHandle<Payload>` | | Connects triggers outside the tooltip and opens it from code (see below) |
1176
- | `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open tooltip belongs to |
1177
- | `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the tooltip |
1178
-
1179
- `BaseTooltip.Trigger` props:
1180
-
1181
- | Prop | Type | Default | Description |
1182
- |------|------|---------|-------------|
1183
- | `delay` | `number` | `600` | The wait before opening on hover, in ms. Overrides `TooltipProvider`'s |
1184
- | `closeDelay` | `number` | `0` | The wait before closing, in ms. Overrides `TooltipProvider`'s |
1185
- | `closeOnClick` | `boolean` | `true` | Closes the tooltip when the trigger is clicked |
1186
- | `disabled` | `boolean` | `false` | Stops this trigger from opening the tooltip. The element stays enabled: to disable the button too, pass `disabled` to the `render` element |
1187
- | `handle` / `payload` | `TooltipHandle<Payload>` / `Payload` | | Connects a trigger outside its `BaseTooltip`, and the payload it passes (see below) |
1188
- | `render` | `RenderProp<"button", TooltipTriggerState>` | | The state is `{ open }`. Use it to render your themed button, or any other element |
1189
-
1190
- `BaseTooltip.Popup` props:
1191
-
1192
- | Prop | Type | Default | Description |
1193
- |------|------|---------|-------------|
1194
- | `side` / `align` | `TooltipSide` / `TooltipAlign` | `"top"` / `"center"` | Where the popup sits against the trigger (`"top"`, `"bottom"`, `"left"`, `"right"`, `"inline-start"`, `"inline-end"` / `"start"`, `"center"`, `"end"`). It flips when there's no room |
1195
- | `sideOffset` / `alignOffset` | `number \| TooltipOffsetFunction` | | Offsets from the anchor, in pixels, or a function of the placement and sizes |
1196
- | `collisionPadding` | `number \| { top, right, bottom, left }` | `5` | Space kept from the viewport edges |
1197
- | `collisionBoundary` / `collisionAvoidance` | | `"clipping-ancestors"` | The area the popup stays inside, and how it avoids its edges (flip or shift) |
1198
- | `anchor` | `Element \| RefObject \| () => Element \| null` | the trigger | The element the popup is placed against |
1199
- | `disableAnchorTracking` | `boolean` | `false` | Stops following the anchor when it moves |
1200
- | `arrowPadding` | `number` | `5` | Minimum distance between an `Arrow` and the popup's corners |
1201
- | `sticky` | `boolean` | `false` | Stays in view while the anchor scrolls away |
1202
- | `positionMethod` | `"absolute" \| "fixed"` | `"absolute"` | Use `"fixed"` when the anchor is inside a fixed container |
1203
- | `positionerClassName` / `renderPositioner` | `string` / `RenderProp<"div", TooltipPositionerState>` | | Style or replace the positioner, the `<div>` around the popup that places it (`z-50`) |
1204
- | `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the popup is portaled to |
1205
- | `keepMounted` | `boolean` | `false` | Keeps the popup in the DOM while closed |
1206
- | `render` | `RenderProp<"div", TooltipPopupState>` | | The state is `{ open, side, align, instant }` |
1207
-
1208
- Data attributes: the popup has `data-open` / `data-closed`, `data-side`, `data-align` and `data-starting-style` / `data-ending-style` during transitions. `data-instant` is set when the transition should be skipped: `"delay"` (another tooltip was just open), `"focus"` (opened by keyboard focus) or `"dismiss"` (closed by Escape or a click). The popup's own transition is turned off then (`data-instant:transition-none`).
1209
-
1210
- #### `createTooltipHandle`
1211
-
1212
- Opens one tooltip from triggers anywhere on the page, or from code. Each trigger can pass a `payload`, which the tooltip's function children receive:
1213
-
1214
- ```tsx
1215
- import { BaseTooltip, createTooltipHandle } from "@omer-x/tailwind-ui-kit/overlay";
1216
-
1217
- const shortcutTooltip = createTooltipHandle<{ id: string, keys: string }>();
1218
-
1219
- // triggers anywhere on the page
1220
- <BaseTooltip.Trigger id={`shortcut-${s.id}`} handle={shortcutTooltip} payload={s} render={<Button />}>{s.label}</BaseTooltip.Trigger>
1221
-
1222
- // one tooltip on the page
1223
- <BaseTooltip handle={shortcutTooltip}>
1224
- {({ payload }) => payload && (
1225
- <BaseTooltip.Popup>{payload.keys}</BaseTooltip.Popup>
1226
- )}
1227
- </BaseTooltip>
1228
-
1229
- // from code
1230
- shortcutTooltip.open("shortcut-copy");
1231
- ```
1232
-
1233
- A `TooltipHandle<Payload>` has `open(triggerId)`, `close()` and `isOpen`. Like `MenuHandle`, it has no `openWithPayload`: a tooltip is placed against its trigger, so `open` needs the `id` of a trigger with the same handle.
1234
-
1235
- - Calls are **ignored while the tooltip isn't mounted**. Keep the `BaseTooltip` with the handle rendered.
1236
- - Call them **from event handlers or effects, never during render**.
121
+ - [`BaseTooltip`](docs/overlay/BaseTooltip.md) — A Base UI [`Tooltip`](https://base-ui.com/react/components/tooltip)
122
+ - [`createTooltipHandle`](docs/overlay/createTooltipHandle.md) — Opens one tooltip from triggers anywhere on the page, or from code
1237
123
 
1238
124
  ### `@omer-x/tailwind-ui-kit/providers`
1239
125
 
1240
- #### `TooltipProvider`
1241
-
1242
- Shares the hover delay between the tooltips inside it: once one tooltip is shown, the next one opens instantly. Place it once around your app (or a toolbar) in a `"use client"` file. It renders no element and is also available as `BaseTooltip.Provider`.
126
+ - [`TooltipProvider`](docs/providers/TooltipProvider.md) — Shares the hover delay between the tooltips inside it
127
+ - [`ToastProvider`](docs/providers/ToastProvider.md) — Holds the toasts of the app (or a part of it)
1243
128
 
1244
- ```tsx
1245
- import { TooltipProvider } from "@omer-x/tailwind-ui-kit/providers";
129
+ ### `@omer-x/tailwind-ui-kit/navigation`
1246
130
 
1247
- <TooltipProvider delay={300}>{children}</TooltipProvider>
1248
- ```
1249
-
1250
- | Prop | Type | Default | Description |
1251
- |------|------|---------|-------------|
1252
- | `delay` | `number` | `600` | The wait before opening a tooltip on hover, in ms. A trigger's own `delay` wins |
1253
- | `closeDelay` | `number` | `0` | The wait before closing a tooltip, in ms. A trigger's own `closeDelay` wins |
1254
- | `timeout` | `number` | `400` | A tooltip opened within this time after another one closed opens without a delay, in ms |
1255
-
1256
- #### `ToastProvider`
1257
-
1258
- Holds the toasts of the app (or a part of it). [`useToast`](#usetoast) and [`BaseToast.Viewport`](#basetoast) work inside it. Renders no element and is also available as `BaseToast.Provider`.
1259
-
1260
- | Prop | Type | Default | Description |
1261
- |------|------|---------|-------------|
1262
- | `timeout` | `number` | `5000` | Milliseconds before a toast closes by itself. `0` keeps toasts open until they are closed |
1263
- | `limit` | `number` | `3` | The most toasts shown at once. Older ones get `data-limited`, and the kit hides them |
1264
- | `manager` | `ToastManager` | | Shows the toasts of a [`createToastManager`](#createtoastmanager) manager |
131
+ - [`BaseTabs`](docs/navigation/BaseTabs.md) — A Base UI [`Tabs`](https://base-ui.com/react/components/tabs)
1265
132
 
1266
133
  ### `@omer-x/tailwind-ui-kit/disclosure`
1267
134
 
1268
- #### `BaseAccordion`
1269
-
1270
- A Base UI [`Accordion`](https://base-ui.com/react/components/accordion): collapsible panels with headings. `Trigger` brings the heading around it, so each item needs three parts:
1271
-
1272
- ```tsx
1273
- import { BaseAccordion } from "@omer-x/tailwind-ui-kit/disclosure";
1274
-
1275
- <BaseAccordion className="rounded-md border">
1276
- <BaseAccordion.Item value="shipping" className="border-b last:border-b-0">
1277
- <BaseAccordion.Trigger className="px-5 py-4 data-panel-open:bg-blue-50" icon={<ChevronDown />} iconClassName="in-data-panel-open:rotate-180">
1278
- Shipping
1279
- </BaseAccordion.Trigger>
1280
- <BaseAccordion.Panel>
1281
- <div className="px-5 py-4">Orders ship within two days.</div>
1282
- </BaseAccordion.Panel>
1283
- </BaseAccordion.Item>
1284
- </BaseAccordion>
1285
- ```
1286
-
1287
- The parts are reached with dot notation (`BaseAccordion.Item`), which only works in client components. Build accordions in a `"use client"` file, e.g. your app's themed wrapper.
1288
-
1289
- | Part | Renders | Description |
1290
- |------|---------|-------------|
1291
- | `BaseAccordion` | `<div>` | Groups the items and holds which ones are open |
1292
- | `BaseAccordion.Item` | `<div>` | Groups a trigger with its panel |
1293
- | `BaseAccordion.Trigger` | `<h3>` around a `<button>` | The heading that labels the panel, and the button that opens and closes it. A full-width flex row (`justify-between`) with a focus outline |
1294
- | `BaseAccordion.Panel` | `<div>` | The item's content, with a height transition (shared with Collapsible). **Put padding on an element inside it**, so it can shrink to zero |
1295
-
1296
- Every part takes `className` and `render`.
1297
-
1298
- `BaseAccordion` props:
1299
-
1300
- | Prop | Type | Default | Description |
1301
- |------|------|---------|-------------|
1302
- | `value` / `defaultValue` | `Value[]` | `[]` | Controlled / initial values of the open items |
1303
- | `onValueChange` | `(value, event) => void` | | Called with the open items' values and the DOM event that changed them (`undefined` when changed from code) |
1304
- | `multiple` | `boolean` | `false` | Lets several items be open at once |
1305
- | `disabled` | `boolean` | `false` | Ignores user interaction on every item |
1306
- | `keepMounted` | `boolean` | `false` | Keeps closed panels in the DOM |
1307
- | `hiddenUntilFound` | `boolean` | `false` | Keeps closed panels hidden with `hidden="until-found"`, so the browser's page search finds and opens them. Overrides `keepMounted` |
1308
- | `render` | `RenderProp<"div", AccordionState>` | | The state is `{ value, disabled }` |
1309
-
1310
- `BaseAccordion.Item` props:
1311
-
1312
- | Prop | Type | Default | Description |
1313
- |------|------|---------|-------------|
1314
- | `value` | `unknown` | generated | Identifies the item in the accordion's `value` |
1315
- | `disabled` | `boolean` | `false` | Ignores user interaction on this item |
1316
- | `onOpenChange` | `(open, event) => void` | | Called with the item's new state and the DOM event |
1317
- | `render` | `RenderProp<"div", AccordionItemState>` | | The state is `{ open, disabled, index }` |
1318
-
1319
- `BaseAccordion.Trigger` props:
1320
-
1321
- | Prop | Type | Default | Description |
1322
- |------|------|---------|-------------|
1323
- | `icon` | `ReactNode` | | Shown after the text, in a `<span>` with a transform transition. Nothing is rendered without it |
1324
- | `iconClassName` | `string` | | Classes for the icon's `<span>`, e.g. `in-data-panel-open:rotate-180` |
1325
- | `headerClassName` | `string` | | Classes for the heading |
1326
- | `renderHeader` | `RenderProp<"h3", AccordionItemState>` | | Replaces the heading, e.g. `<h2 />` for another level |
1327
- | `render` | `RenderProp<"button", AccordionItemState>` | | Replaces the button |
1328
- | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
1329
-
1330
- `BaseAccordion.Panel` takes `keepMounted` and `hiddenUntilFound` (overriding the accordion's) and `render` (`RenderProp<"div", AccordionPanelState>`, the item's state plus `transitionStatus`).
1331
-
1332
- Data attributes: the item, heading and panel have `data-open` and `data-index`. The trigger has `data-panel-open`. Disabled parts have `data-disabled`. The panel has `data-starting-style` / `data-ending-style` during its transition.
1333
-
1334
- #### `BaseCollapsible`
1335
-
1336
- A Base UI [`Collapsible`](https://base-ui.com/react/components/collapsible): a panel shown or hidden by a button.
1337
-
1338
- ```tsx
1339
- import { BaseCollapsible } from "@omer-x/tailwind-ui-kit/disclosure";
1340
-
1341
- <BaseCollapsible>
1342
- <BaseCollapsible.Trigger className="rounded-md px-3 py-1.5" icon={<ChevronDown />} iconClassName="in-data-panel-open:rotate-180">
1343
- Recovery keys
1344
- </BaseCollapsible.Trigger>
1345
- <BaseCollapsible.Panel>
1346
- <div className="p-4">alien-bean-pasta</div>
1347
- </BaseCollapsible.Panel>
1348
- </BaseCollapsible>
1349
- ```
1350
-
1351
- Like `BaseAccordion`, the parts use dot notation, so build collapsibles in a `"use client"` file.
1352
-
1353
- | Part | Renders | Description |
1354
- |------|---------|-------------|
1355
- | `BaseCollapsible` | `<div>` | Groups the trigger with the panel and holds whether it is open |
1356
- | `BaseCollapsible.Trigger` | `<button>` | Opens and closes the panel. An inline flex row with a focus outline |
1357
- | `BaseCollapsible.Panel` | `<div>` | The content, with a height transition (shared with Accordion). **Put padding on an element inside it**, so it can shrink to zero |
1358
-
1359
- Every part takes `className` and `render`.
1360
-
1361
- `BaseCollapsible` props:
1362
-
1363
- | Prop | Type | Default | Description |
1364
- |------|------|---------|-------------|
1365
- | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial state of the panel |
1366
- | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
1367
- | `disabled` | `boolean` | `false` | Ignores user interaction |
1368
- | `render` | `RenderProp<"div", CollapsibleState>` | | The state is `{ open, disabled }` |
1369
-
1370
- `BaseCollapsible.Trigger` props:
1371
-
1372
- | Prop | Type | Default | Description |
1373
- |------|------|---------|-------------|
1374
- | `icon` | `ReactNode` | | Shown after the text, in a `<span>` with a transform transition. Nothing is rendered without it |
1375
- | `iconClassName` | `string` | | Classes for the icon's `<span>`, e.g. `in-data-panel-open:rotate-180` |
1376
- | `render` | `RenderProp<"button", CollapsibleState>` | | Replaces the button |
1377
- | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
1378
-
1379
- `BaseCollapsible.Panel` props:
1380
-
1381
- | Prop | Type | Default | Description |
1382
- |------|------|---------|-------------|
1383
- | `keepMounted` | `boolean` | `false` | Keeps the closed panel in the DOM |
1384
- | `hiddenUntilFound` | `boolean` | `false` | Keeps the closed panel hidden with `hidden="until-found"`, so the browser's page search finds and opens it. Overrides `keepMounted` |
1385
- | `render` | `RenderProp<"div", CollapsiblePanelState>` | | The state is `{ open, disabled, transitionStatus }` |
1386
-
1387
- Data attributes: the root and panel have `data-open` / `data-closed`. The trigger has `data-panel-open`. Disabled parts have `data-disabled`. The panel has `data-starting-style` / `data-ending-style` during its transition.
135
+ - [`BaseAccordion`](docs/disclosure/BaseAccordion.md) — A Base UI [`Accordion`](https://base-ui.com/react/components/accordion)
136
+ - [`BaseCollapsible`](docs/disclosure/BaseCollapsible.md) — A Base UI [`Collapsible`](https://base-ui.com/react/components/collapsible)
1388
137
 
1389
138
  ### `@omer-x/tailwind-ui-kit/display`
1390
139
 
1391
- #### `BaseAvatar`
1392
-
1393
- A Base UI [`Avatar`](https://base-ui.com/react/components/avatar): a profile picture with a fallback (initials or an icon) shown while it is missing, loading or broken.
1394
-
1395
- ```tsx
1396
- import { BaseAvatar } from "@omer-x/tailwind-ui-kit/display";
1397
-
1398
- <BaseAvatar size="sm" className="bg-neutral-200 font-medium">
1399
- <BaseAvatar.Image src={user.photoUrl} alt={user.name} />
1400
- <BaseAvatar.Fallback>{initials}</BaseAvatar.Fallback>
1401
- </BaseAvatar>
1402
- ```
1403
-
1404
- The parts are reached with dot notation (`BaseAvatar.Image`), which only works in client components. Build avatars in a `"use client"` file, e.g. your app's themed wrapper.
1405
-
1406
- | Part | Renders | Description |
1407
- |------|---------|-------------|
1408
- | `BaseAvatar` | `<span>` | A round, centered, `overflow-hidden` box of the given size. Make it square with `className="rounded-md"` |
1409
- | `BaseAvatar.Image` | `<img>` | The picture, covering the box (`size-full object-cover`). Rendered only once it has loaded |
1410
- | `BaseAvatar.Fallback` | `<span>` | Fills the box and centers its content. Rendered until the image has loaded |
1411
-
1412
- Every part takes `className` and `render`.
1413
-
1414
- `BaseAvatar` props:
1415
-
1416
- | Prop | Type | Default | Description |
1417
- |------|------|---------|-------------|
1418
- | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | `size-12 text-lg` / `size-10 text-base` / `size-8 text-sm` / `size-6 text-xs` |
1419
- | `render` | `RenderProp<"span", AvatarState>` | | The state is `{ imageLoadingStatus }`: `"idle"`, `"loading"`, `"loaded"` or `"error"` |
1420
-
1421
- `BaseAvatar.Image` props:
1422
-
1423
- | Prop | Type | Default | Description |
1424
- |------|------|---------|-------------|
1425
- | `onLoadingStatusChange` | `(status) => void` | | Called when the image starts loading, loads or fails |
1426
- | `keepMounted` | `boolean` | `false` | Keeps the `<img>` in the DOM and loads it in place instead of preloading it. Use it for `loading="lazy"` or an optimized image component (`render={<NextImage … />}`). Hide it until it loads with `data-loading:invisible data-error:hidden` |
1427
- | `render` | `RenderProp<"img", AvatarImageState>` | | The avatar's state plus `transitionStatus` |
1428
-
1429
- `BaseAvatar.Fallback` props:
1430
-
1431
- | Prop | Type | Default | Description |
1432
- |------|------|---------|-------------|
1433
- | `delay` | `number` | `0` | Milliseconds to wait before showing, so a fast image doesn't flash it |
1434
- | `render` | `RenderProp<"span", AvatarState>` | | |
1435
-
1436
- Data attributes: the image has `data-starting-style` / `data-ending-style` while it appears and disappears, so it can fade in (`transition-opacity data-starting-style:opacity-0`). With `keepMounted`, it has `data-loading` while loading and `data-error` when it failed.
1437
-
1438
- #### `BaseMeter`
1439
-
1440
- A Base UI [`Meter`](https://base-ui.com/react/components/meter): a graphical display of a numeric value within a known range, like disk usage or battery level. It renders a `<div role="meter">` with the label and the value on top and the track below (`flex flex-wrap`). For a task's completion, use a progress bar instead.
1441
-
1442
- ```tsx
1443
- import { BaseMeter } from "@omer-x/tailwind-ui-kit/display";
1444
-
1445
- <BaseMeter
1446
- value={usedGb}
1447
- max={quotaGb}
1448
- label="Storage used"
1449
- showValue
1450
- trackClassName="bg-neutral-200"
1451
- indicatorClassName="bg-blue-600"
1452
- />
1453
- ```
1454
-
1455
- | Prop | Type | Default | Description |
1456
- |------|------|---------|-------------|
1457
- | `value` | `number` | | The current value, clamped to `min`…`max` |
1458
- | `min` / `max` | `number` | `0` / `100` | The range |
1459
- | `format` | `Intl.NumberFormatOptions` | | How the value is formatted. Without it, it is shown as a percentage of the range |
1460
- | `locale` | `Intl.LocalesArgument` | runtime locale | The locale used to format the value |
1461
- | `getAriaValueText` | `(formattedValue, value) => string` | | What screen readers announce for the value |
1462
- | `label` | `ReactNode` | | The visible name. It labels the meter. Without it, nothing is rendered for it: use `aria-label` |
1463
- | `labelClassName` | `string` | | Classes for the label `<span>` (default `grow`) |
1464
- | `renderLabel` | `RenderProp<"span", MeterState>` | | Render another element for the label |
1465
- | `showValue` | `boolean \| (formattedValue, value) => ReactNode` | `false` | Shows the value as text next to the label. A function shows something else, e.g. `` (f) => `${f} of 5 kWh` `` |
1466
- | `valueClassName` | `string` | | Classes for the value `<span>` (default `ms-auto tabular-nums`). It is `aria-hidden`: screen readers read the meter's value |
1467
- | `renderValue` | `RenderProp<"span", MeterState>` | | Render another element for the value |
1468
- | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | The track's height: `h-3` / `h-2` / `h-1.5` / `h-1` |
1469
- | `trackClassName` | `string` | | Classes for the track `<div>` (default `relative block w-full overflow-hidden rounded-full`) |
1470
- | `renderTrack` | `RenderProp<"div", MeterState>` | | Render another element for the track |
1471
- | `indicatorClassName` | `string` | | Classes for the indicator `<div>`, the filled part. Its width is set inline and transitions (`transition-[width] duration-500`) |
1472
- | `renderIndicator` | `RenderProp<"div", MeterState>` | | Render another element for the indicator |
1473
- | `children` | `ReactNode` | | Lays out the parts yourself (see below). The built-in label, value and track aren't rendered then |
1474
- | `className` | `string` | | Classes for the root `<div>` |
1475
- | `render` | `RenderProp<"div", MeterState>` | | Render another element for the root |
1476
- | …rest | | | `<div>` props |
1477
-
1478
- To place the parts yourself, e.g. the value inside the track, pass them as children. Dot notation only works in client components.
1479
-
1480
- ```tsx
1481
- <BaseMeter value={24}>
1482
- <BaseMeter.Label className="sr-only">Upload quota</BaseMeter.Label>
1483
- <BaseMeter.Track className="h-5 bg-neutral-200">
1484
- <BaseMeter.Indicator className="bg-blue-600" />
1485
- <BaseMeter.Value className="absolute inset-0 flex items-center justify-center" />
1486
- </BaseMeter.Track>
1487
- </BaseMeter>
1488
- ```
1489
-
1490
- | Part | Renders | Props |
1491
- |------|---------|-------|
1492
- | `BaseMeter.Label` | `<span>` | `className`, `render` |
1493
- | `BaseMeter.Track` | `<div>` | `size`, `className`, `render` |
1494
- | `BaseMeter.Indicator` | `<div>` | `className`, `render` |
1495
- | `BaseMeter.Value` | `<span>` | `className`, `render`, `children?: (formattedValue, value) => ReactNode` |
1496
-
1497
- Render functions get `MeterState`, which is empty for now. The meter sets no data attributes: style value ranges in your wrapper (e.g. pick the indicator color from `value`).
140
+ - [`BaseAvatar`](docs/display/BaseAvatar.md) — A Base UI [`Avatar`](https://base-ui.com/react/components/avatar)
141
+ - [`BaseMeter`](docs/display/BaseMeter.md) — A Base UI [`Meter`](https://base-ui.com/react/components/meter)
1498
142
 
1499
143
  ### `@omer-x/tailwind-ui-kit/feedback`
1500
144
 
1501
- #### `BaseToast`
1502
-
1503
- A Base UI [`Toast`](https://base-ui.com/react/components/toast): short notifications that stack in a corner of the screen and close by themselves. Toasts live in a [`ToastProvider`](#toastprovider), are created with [`useToast`](#usetoast) (or a [`createToastManager`](#createtoastmanager) manager outside React) and are shown by one `BaseToast.Viewport`, which renders each toast with your parts.
1504
-
1505
- Theme it once, next to the provider:
1506
-
1507
- ```tsx
1508
- // src/components/Toasts.tsx
1509
- "use client";
1510
- import { BaseToast } from "@omer-x/tailwind-ui-kit/feedback";
1511
- import { ToastProvider } from "@omer-x/tailwind-ui-kit/providers";
1512
- import type { ReactNode } from "react";
1513
-
1514
- const Toasts = ({ children }: { children: ReactNode }) => (
1515
- <ToastProvider>
1516
- {children}
1517
- <BaseToast.Viewport>
1518
- {toast => (
1519
- <BaseToast
1520
- toast={toast}
1521
- className="rounded-md border bg-white p-4 shadow-lg data-[type=error]:border-red-300 data-[type=error]:bg-red-50"
1522
- >
1523
- <BaseToast.Content className="pr-6">
1524
- <BaseToast.Title className="font-semibold" />
1525
- <BaseToast.Description className="text-neutral-600" />
1526
- <BaseToast.Action className="mt-2 rounded border px-2 py-1 text-xs" />
1527
- <BaseToast.Close aria-label="Close" className="absolute top-2 right-2"><XIcon /></BaseToast.Close>
1528
- </BaseToast.Content>
1529
- </BaseToast>
1530
- )}
1531
- </BaseToast.Viewport>
1532
- </ToastProvider>
1533
- );
1534
-
1535
- export default Toasts;
1536
- ```
1537
-
1538
- Then show toasts from any client component inside it:
1539
-
1540
- ```tsx
1541
- const { add } = useToast();
1542
-
1543
- add({ title: "Saved", description: "Your changes were saved.", type: "success" });
1544
- ```
1545
-
1546
- | Part | Renders | Description |
1547
- |------|---------|-------------|
1548
- | `BaseToast.Viewport` | `<div>` | The region the toasts are shown in (`role="region"`, `aria-label="Notifications"`: pass your own `aria-label` to translate it), with its portal. Fixed to the bottom right corner (`fixed right-4 bottom-4 w-80`); move it with `className`. F6 moves focus into it. `data-expanded` while hovered or focused |
1549
- | `BaseToast` | `<div>` | One toast (`role="dialog"`, or `"alertdialog"` for `priority: "high"`), named by its title and described by its description. In the viewport, toasts stack from the bottom: the newest in front, older ones peeking behind it, all of them spread out while the viewport is expanded. It can be swiped away. An anchored toast is placed next to its anchor instead (see below) |
1550
- | `BaseToast.Content` | `<div>` | The toast's content. Hidden (`data-behind`) while the toast is behind another one in a collapsed stack |
1551
- | `BaseToast.Title` | `<h2>` | Shows the toast's `title` unless it has children. Renders nothing when both are empty |
1552
- | `BaseToast.Description` | `<p>` | Shows the toast's `description` unless it has children. Renders nothing when both are empty |
1553
- | `BaseToast.Action` | `<button>` | Gets the toast's `actionProps` (`children`, `onClick`, …). Renders nothing without children |
1554
- | `BaseToast.Close` | `<button>` | Closes the toast. Give it an `aria-label` when its content is an icon. It is `aria-hidden` until the viewport is expanded or focus is inside the toast |
1555
- | `BaseToast.Arrow` | `<div>` | Points at an anchored toast's anchor. Size and draw it with `className` or `children`. `data-side`, `data-align`, `data-uncentered` |
1556
-
1557
- Every part takes `className` and `render`.
1558
-
1559
- `BaseToast.Viewport` props:
1560
-
1561
- | Prop | Type | Default | Description |
1562
- |------|------|---------|-------------|
1563
- | `children` | `(toast: ToastObject<Data>) => ReactNode` | | Renders one toast, usually a `BaseToast` (no `key` needed) |
1564
- | `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the viewport is portaled to |
1565
- | `render` | `RenderProp<"div", ToastViewportState>` | | The state is `{ expanded }` |
1566
-
1567
- `BaseToast` props:
1568
-
1569
- | Prop | Type | Default | Description |
1570
- |------|------|---------|-------------|
1571
- | `toast` | `ToastObject` | | The toast to show, from the viewport's children function |
1572
- | `swipeDirection` | `ToastSwipeDirection \| ToastSwipeDirection[]` | `["down", "right"]` | The directions (`"up"`, `"down"`, `"left"`, `"right"`) it can be swiped to close it. Anchored toasts can't be swiped |
1573
- | `positionerClassName` | `string` | | Classes for an anchored toast's positioner, the `<div>` that places it (`z-50`) |
1574
- | `renderPositioner` | `RenderProp<"div", ToastPositionerState>` | | The state is `{ side, align, anchorHidden }` |
1575
- | `render` | `RenderProp<"div", ToastState>` | | The state is `{ transitionStatus, expanded, limited, type, swiping, swipeDirection }` |
1576
-
1577
- `Title`, `Description`, `Action` and `Close` render functions get `{ type }`. `Action` and `Close` take `nativeButton={false}` when `render` isn't a `<button>`.
1578
-
1579
- Data attributes: every part except the viewport and the arrow has `data-type` (the toast's `type`). `BaseToast` also has `data-expanded`, `data-limited` (over the provider's `limit`; the kit hides it), `data-swiping`, `data-swipe-direction` and `data-starting-style` / `data-ending-style` during its transitions. `BaseToast.Content` has `data-expanded` and `data-behind`.
1580
-
1581
- **Types.** `type` is any string, set as `data-type`. The kit defines no type names: style yours with `data-[type=…]:` variants. Form messages fit as they are: `add({ type: m.type, description: m.text })` for each message of [`useFormMessages`](#useformmessages) (`"error"` or `"warning"`).
1582
-
1583
- **Anchored toasts.** A toast created with `positionerProps.anchor` is wrapped in a positioner and placed against that element, like a tooltip that closes by itself (e.g. "Copied" next to a copy button). It fades and scales in instead of stacking. Put a `BaseToast.Arrow` in it to point at the anchor:
1584
-
1585
- ```tsx
1586
- add({ title: "Copied", positionerProps: { anchor: buttonRef.current, side: "top", sideOffset: 8 } });
1587
- ```
1588
-
1589
- `positionerProps` (`ToastPositionerOptions`) takes `anchor`, `side` (`"top"`), `align` (`"center"`), `sideOffset` (`0`), `alignOffset` (`0`), `collisionPadding` (`5`), `arrowPadding` (`5`), `sticky`, `positionMethod` (`"absolute"`) and `disableAnchorTracking`. Anchored and stacked toasts usually get separate providers (and viewports) so they don't share a stack and a `limit`.
1590
-
1591
- #### `useToast`
1592
-
1593
- Shows, updates and closes the toasts of the surrounding `ToastProvider`. Pass a type for your toasts' custom `data`: `useToast<{ icon: string }>()`.
1594
-
1595
- ```ts
1596
- const { toasts, add, update, close, promise } = useToast();
1597
-
1598
- const id = add({ title: "Uploading…", timeout: 0 });
1599
- update(id, { title: "Uploaded", type: "success", timeout: 5000 });
1600
- close(id); // or close() for every toast
1601
-
1602
- await promise(upload(file), {
1603
- loading: "Uploading…", // a string is a shortcut for { description }
1604
- success: result => ({ title: "Uploaded", description: result.name, type: "success" }),
1605
- error: error => ({ title: "Upload failed", type: "error" }),
1606
- });
1607
- ```
1608
-
1609
- `add` options (`ToastOptions`):
1610
-
1611
- | Option | Type | Default | Description |
1612
- |--------|------|---------|-------------|
1613
- | `title` | `ReactNode` | | |
1614
- | `description` | `ReactNode` | | |
1615
- | `type` | `string` | | Set as `data-type` |
1616
- | `timeout` | `number` | the provider's | Milliseconds before it closes by itself. `0` keeps it open. Timers pause while the viewport is hovered or focused, or the window loses focus |
1617
- | `priority` | `"low" \| "high"` | `"low"` | Announced politely, or urgently (`role="alertdialog"`) |
1618
- | `id` | `string` | generated | Adding a toast with an existing `id` updates it in place and restarts its timer |
1619
- | `actionProps` | `ComponentProps<"button">` | | Props of `BaseToast.Action` |
1620
- | `data` | `Data` | | Your own data, e.g. to pick an icon in the viewport |
1621
- | `onClose` | `() => void` | | Called when it starts closing |
1622
- | `onRemove` | `() => void` | | Called when it is removed, after its exit transition |
1623
- | `positionerProps` | `ToastPositionerOptions` | | Anchors the toast to an element |
1624
-
1625
- `toasts` (`ToastObject[]`, newest first) are the shown toasts, with their `id`. `BaseToast.Viewport` already renders them; use it to show a count, for example.
1626
-
1627
- #### `createToastManager`
1628
-
1629
- Creates a toast manager (`ToastManager`, with `add`, `update`, `close` and `promise` as in `useToast`) for code outside React, such as a fetch wrapper. Give it to a provider, which shows its toasts. Calls are ignored while no provider uses it.
1630
-
1631
- ```ts
1632
- // src/toasts.ts
1633
- export const toastManager = createToastManager();
1634
-
1635
- // anywhere
1636
- toastManager.add({ title: "Session expired", type: "error" });
1637
- ```
1638
-
1639
- ```tsx
1640
- <ToastProvider manager={toastManager}>…</ToastProvider>
1641
- ```
1642
-
1643
- `useToast` inside that provider manages the same toasts.
145
+ - [`BaseToast`](docs/feedback/BaseToast.md) — A Base UI [`Toast`](https://base-ui.com/react/components/toast)
146
+ - [`useToast`](docs/feedback/useToast.md) — Shows, updates and closes the toasts of the surrounding `ToastProvider`
147
+ - [`createToastManager`](docs/feedback/createToastManager.md) — Creates a toast manager (`ToastManager`, with `add`, `update`, `close` and `promise` as in `useToast`) for code outside React, such as a fetch wrapper
1644
148
 
1645
149
  ### `@omer-x/tailwind-ui-kit/layout`
1646
150
 
1647
- #### `BaseSeparator`
1648
-
1649
- A Base UI [`Separator`](https://base-ui.com/react/components/separator): a `1px` line between blocks that screen readers announce. Renders a `<div>` with `role="separator"`, `aria-orientation` and `data-orientation`. It has no color: give it one with `className`.
1650
-
1651
- ```tsx
1652
- import { BaseSeparator } from "@omer-x/tailwind-ui-kit/layout";
1653
-
1654
- <BaseSeparator className="bg-neutral-300" />
1655
-
1656
- <nav className="flex items-center gap-3">
1657
- <a href="/">Home</a>
1658
- <BaseSeparator orientation="vertical" className="h-4 bg-neutral-300" />
1659
- <a href="/pricing">Pricing</a>
1660
- </nav>
1661
- ```
1662
-
1663
- | Prop | Type | Default | Description |
1664
- |------|------|---------|-------------|
1665
- | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Horizontal: `h-px w-full`. Vertical: `w-px self-stretch` (the height of its flex row; set a height with `className` otherwise) |
1666
- | `render` | `RenderProp<"div", SeparatorState>` | | The state is `{ orientation }`. E.g. `render={<hr />}` (add `border-0`: Tailwind's preflight gives `<hr>` a top border) |
1667
-
1668
- Style each orientation with `data-[orientation=vertical]:…`.
1669
-
1670
- #### `Container`
1671
-
1672
- Tailwind's `container`, centered with horizontal padding (`container mx-auto px-3`). Accepts all `<div>` props.
151
+ - [`BaseSeparator`](docs/layout/BaseSeparator.md) — A Base UI [`Separator`](https://base-ui.com/react/components/separator)
152
+ - [`Container`](docs/layout/Container.md) — Tailwind's `container`, centered with horizontal padding (`container mx-auto px-3`)
1673
153
 
1674
154
  ### `@omer-x/tailwind-ui-kit/page`
1675
155
 
1676
- #### `Pagination`
1677
-
1678
- Pagination inside a `<nav>`. It shows previous/next arrows, the first and last pages, `siblings` pages on each side of the current one, and ellipses for gaps. It only decides which pages to show: **your app builds each link**, so typed routes stay type-safe.
1679
-
1680
- | Prop | Type | Description |
1681
- |------|------|-------------|
1682
- | `totalItems` | `number` | Total number of items |
1683
- | `itemsPerPage` | `number` | Items per page |
1684
- | `currentPage` | `number` | Current page, starting at 1 |
1685
- | `siblings` | `number` | Pages shown on each side of the current one. Default `2`. `0` gives `« 1 … [50] … 100 »` |
1686
- | `renderLink` | `(page: number, props: PaginationLinkProps) => ReactElement` | Builds the link to `page`. Spread `props` (`children`, `aria-current="page"` on the current page, `aria-label` on the arrows) onto it. It can also be a `<button onClick>` for pagination without URLs |
1687
- | `renderButton` | render prop | Renders a disabled arrow (a disabled `<button>`) |
1688
- | `renderEllipsis` | render prop | Renders an ellipsis (a `<span aria-hidden>`) |
1689
- | `aria-label` | `string` | The navigation's label. Default `"Pagination"` |
1690
- | `previousLabel` / `nextLabel` | `string` | The arrows' accessible names. Default `"Previous page"` / `"Next page"` |
1691
- | `previousContent` / `nextContent` | `ReactNode` | The arrows' content, e.g. icons. Default `«` / `»` |
1692
- | `className` | `string` | Classes for the `<nav>`. Default `flex gap-3` |
1693
- | …rest | `<nav>` props | |
1694
-
1695
- Style the current page with `aria-[current=page]:`.
1696
-
1697
- ```tsx
1698
- import { Link } from "@/i18n/navigation";
1699
-
1700
- <Pagination
1701
- totalItems={total}
1702
- itemsPerPage={20}
1703
- currentPage={page}
1704
- renderLink={(page, props) => (
1705
- <Link {...props} href={{ pathname: "/products", query: { ...searchParams, page } }} className="px-3 py-1 aria-[current=page]:font-bold" />
1706
- )}
1707
- renderButton={<button className="px-3 py-1 disabled:opacity-50" />}
1708
- renderEllipsis={<span className="px-3 py-1" />}
1709
- />
1710
- ```
1711
-
1712
- #### `usePagination`
1713
-
1714
- The logic behind `Pagination`, for a completely custom layout. It holds no state, so it also works in server components.
1715
-
1716
- ```tsx
1717
- const items = usePagination({ totalItems, itemsPerPage, currentPage, siblings: 1 });
1718
- // [
1719
- // { type: "previous", page: 9, disabled: false },
1720
- // { type: "page", page: 1, current: false },
1721
- // { type: "ellipsis" },
1722
- // { type: "page", page: 10, current: true },
1723
- // …
1724
- // { type: "next", page: 11, disabled: false },
1725
- // ]
1726
- ```
156
+ - [`Pagination`](docs/page/Pagination.md) — Pagination inside a `<nav>`
157
+ - [`usePagination`](docs/page/usePagination.md) — The logic behind `Pagination`, for a completely custom layout
1727
158
 
1728
159
  ### `@omer-x/tailwind-ui-kit/table`
1729
160
 
1730
- #### `TableCell`
1731
-
1732
- A `<td>` that accepts all `<td>` props (`colSpan`, `rowSpan`, `title`, event handlers, …).
1733
-
1734
- | Prop | Type | Description |
1735
- |------|------|-------------|
1736
- | `overflow` | `"wrap" \| "truncate"` | `"wrap"` (default) is a normal `<td>`. `"truncate"` keeps the content on one line and cuts it with an ellipsis instead of widening the column. Exposed as `data-overflow`. |
1737
-
1738
- ```tsx
1739
- <tr>
1740
- <TableCell overflow="truncate" className="max-w-48">{product.description}</TableCell>
1741
- <TableCell overflow={expanded ? "wrap" : "truncate"}>{product.notes}</TableCell>
1742
- </tr>
1743
- ```
1744
-
1745
- #### `Tdx` (deprecated)
1746
-
1747
- Use `<TableCell overflow="truncate">` instead. `Tdx` is kept as an alias for it and accepts the same `<td>` props.
161
+ - [`TableCell`](docs/table/TableCell.md) — A `<td>` that accepts all `<td>` props (`colSpan`, `rowSpan`, `title`, event handlers, …)
162
+ - [`Tdx` (deprecated)](docs/table/Tdx.md) — Use `<TableCell overflow="truncate">` instead
1748
163
 
1749
164
  ### `@omer-x/tailwind-ui-kit/elements`
1750
165
 
1751
- Bare HTML elements whose only addition is a `render` prop (`RenderProp<Tag>`): `JustAnchor` (`<a>`), `JustButton` (`<button>`), `JustDiv` (`<div>`), `JustInput` (`<input>`) and `JustSpan` (`<span>`). They take all props of their element and add no styles.
1752
-
1753
- ```tsx
1754
- import { JustDiv } from "@omer-x/tailwind-ui-kit/elements";
1755
-
1756
- <JustDiv className="p-4" render={<section />}>…</JustDiv>
1757
- ```
166
+ - [`Just*` elements](docs/elements/README.md) — Bare HTML elements whose only addition is a `render` prop (`RenderProp<Tag>`)
1758
167
 
1759
168
  ### `@omer-x/tailwind-ui-kit/hooks`
1760
169
 
1761
- #### `useRipples`
1762
-
1763
- The ripple effect of `BaseButton` and `BaseToggle`, for your own clickable elements. Returns `[handleClick, ripples]`: call `handleClick` from `onClick` and render `ripples` inside the element.
1764
-
1765
- - The element needs `relative` (the ripples are positioned absolutely and clipped to its rounded corners).
1766
- - Ripples use `bg-current`, so they follow the text color. They start from the center on keyboard clicks and are hidden when the user prefers reduced motion.
1767
- - It imports a CSS module (see [Setup](#2-your-bundler-must-support-css-modules)).
1768
-
1769
- ```tsx
1770
- import { useRipples } from "@omer-x/tailwind-ui-kit/hooks";
1771
-
1772
- const Chip = ({ children, onClick, ...props }: ComponentProps<"button">) => {
1773
- const [handleRipple, ripples] = useRipples();
1774
- return (
1775
- <button
1776
- {...props}
1777
- className="relative rounded-full px-3 py-1"
1778
- onClick={event => { handleRipple(event); onClick?.(event); }}
1779
- >
1780
- {children}
1781
- {ripples}
1782
- </button>
1783
- );
1784
- };
1785
- ```
170
+ - [`useRipples`](docs/hooks/useRipples.md) — The ripple effect of `BaseButton` and `BaseToggle`, for your own clickable elements
1786
171
 
1787
172
  ### `@omer-x/tailwind-ui-kit/utils`
1788
173
 
1789
174
  Helpers for building your own components on the kit, so you never import Base UI.
1790
175
 
1791
- #### `RenderProp`
1792
-
1793
- The type of every `render` and `render*` prop: `RenderProp<Tag, State>` is an element, or a function `(props, state) => ReactElement`. `props` are the props of `Tag` (spread them onto your element) and `state` is the component's state (`object` when it has none).
1794
-
1795
- #### `useRender`
1796
-
1797
- Renders an element that can be replaced through a `render` prop, with your props merged into it.
1798
-
1799
- | Option | Type | Description |
1800
- |--------|------|-------------|
1801
- | `defaultTagName` | `keyof JSX.IntrinsicElements` | The element rendered when `render` is missing |
1802
- | `render` | `RenderProp<Tag, State>` | The `render` prop of your component |
1803
- | `props` | props of `Tag` | Merged into the rendered element |
1804
- | `state` | `State` | Passed to a `render` function, and set as data attributes (`{ active: true }` becomes `data-active`) |
1805
-
1806
- ```tsx
1807
- import { type RenderProp, useRender } from "@omer-x/tailwind-ui-kit/utils";
1808
-
1809
- type BadgeProps = ComponentProps<"span"> & {
1810
- render?: RenderProp<"span">,
1811
- };
1812
-
1813
- const Badge = ({ render, className, ...props }: BadgeProps) => useRender({
1814
- defaultTagName: "span",
1815
- render,
1816
- props: { ...props, className: cn("rounded px-2 text-xs", className) },
1817
- });
1818
- ```
1819
-
1820
- #### `mergeProps`
1821
-
1822
- Merges props for one element, later ones winning. Event handlers are all called (later ones first), `className`s are joined and `style`s are merged. `ref` is not merged.
1823
-
1824
- ```tsx
1825
- useRender({ defaultTagName: "div", render, props: mergeProps<"div">({ className: "p-4", onClick: track }, props) });
1826
- ```
1827
-
1828
- #### `cn` (deprecated)
1829
-
1830
- Kept for backward compatibility. Import from the [`cn`](https://www.npmjs.com/package/cn) package directly instead:
1831
-
1832
- ```ts
1833
- import { cn } from "cn";
1834
- ```
176
+ - [`RenderProp`](docs/utils/RenderProp.md) — The type of every `render` and `render*` prop
177
+ - [`useRender`](docs/utils/useRender.md) — Renders an element that can be replaced through a `render` prop, with your props merged into it
178
+ - [`mergeProps`](docs/utils/mergeProps.md) — Merges props for one element, later ones winning
179
+ - [`cn` (deprecated)](docs/utils/cn.md) — Kept for backward compatibility
1835
180
 
1836
181
  ## Development
1837
182