@omer-x/tailwind-ui-kit 1.0.0-alpha.45 → 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 (65) hide show
  1. package/README.md +52 -1799
  2. package/dist/components/menu/menuTypes.d.ts +1 -1
  3. package/dist/components/navigation/BaseTabs.d.ts +44 -0
  4. package/dist/components/navigation/BaseTabs.js +24 -0
  5. package/dist/components/navigation/BaseTabsIndicator.d.ts +30 -0
  6. package/dist/components/navigation/BaseTabsIndicator.js +16 -0
  7. package/dist/components/navigation/BaseTabsList.d.ts +19 -0
  8. package/dist/components/navigation/BaseTabsList.js +14 -0
  9. package/dist/components/navigation/BaseTabsPanel.d.ts +19 -0
  10. package/dist/components/navigation/BaseTabsPanel.js +11 -0
  11. package/dist/components/navigation/BaseTabsTab.d.ts +20 -0
  12. package/dist/components/navigation/BaseTabsTab.js +11 -0
  13. package/dist/components/navigation/index.d.ts +6 -0
  14. package/dist/components/navigation/index.js +1 -0
  15. package/dist/components/navigation/tabsTypes.d.ts +8 -0
  16. package/dist/components/navigation/tabsTypes.js +1 -0
  17. package/docs/button/BaseButton.md +32 -0
  18. package/docs/button/BaseToggle.md +29 -0
  19. package/docs/button/BaseToggleGroup.md +28 -0
  20. package/docs/dialog/BaseAlertDialog.md +36 -0
  21. package/docs/dialog/BaseDialog.md +61 -0
  22. package/docs/dialog/createAlertDialogHandle.md +21 -0
  23. package/docs/dialog/createDialogHandle.md +31 -0
  24. package/docs/disclosure/BaseAccordion.md +67 -0
  25. package/docs/disclosure/BaseCollapsible.md +56 -0
  26. package/docs/display/BaseAvatar.md +48 -0
  27. package/docs/display/BaseMeter.md +62 -0
  28. package/docs/elements/README.md +9 -0
  29. package/docs/feedback/BaseToast.md +91 -0
  30. package/docs/feedback/createToastManager.md +19 -0
  31. package/docs/feedback/useToast.md +37 -0
  32. package/docs/form/BaseAutocomplete.md +110 -0
  33. package/docs/form/BaseCheckbox.md +33 -0
  34. package/docs/form/BaseCheckboxGroup.md +28 -0
  35. package/docs/form/BaseFieldset.md +24 -0
  36. package/docs/form/BaseForm.md +89 -0
  37. package/docs/form/BaseFormField.md +47 -0
  38. package/docs/form/BaseInput.md +13 -0
  39. package/docs/form/BaseRadio.md +28 -0
  40. package/docs/form/BaseRadioGroup.md +35 -0
  41. package/docs/form/BaseSelect.md +109 -0
  42. package/docs/form/BaseSlider.md +93 -0
  43. package/docs/form/BaseSwitch.md +27 -0
  44. package/docs/form/useFormMessages.md +29 -0
  45. package/docs/hooks/useRipples.md +26 -0
  46. package/docs/layout/BaseSeparator.md +24 -0
  47. package/docs/layout/Container.md +5 -0
  48. package/docs/menu/BaseContextMenu.md +96 -0
  49. package/docs/menu/BaseMenu.md +84 -0
  50. package/docs/menu/BaseMenubar.md +45 -0
  51. package/docs/menu/createMenuHandle.md +31 -0
  52. package/docs/navigation/BaseTabs.md +69 -0
  53. package/docs/overlay/BaseTooltip.md +74 -0
  54. package/docs/overlay/createTooltipHandle.md +29 -0
  55. package/docs/page/Pagination.md +37 -0
  56. package/docs/page/usePagination.md +17 -0
  57. package/docs/providers/ToastProvider.md +11 -0
  58. package/docs/providers/TooltipProvider.md +17 -0
  59. package/docs/table/TableCell.md +16 -0
  60. package/docs/table/Tdx.md +5 -0
  61. package/docs/utils/RenderProp.md +5 -0
  62. package/docs/utils/cn.md +9 -0
  63. package/docs/utils/mergeProps.md +9 -0
  64. package/docs/utils/useRender.md +26 -0
  65. package/package.json +6 -1
@@ -0,0 +1,48 @@
1
+ # `BaseAvatar`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/display`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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.
6
+
7
+ ```tsx
8
+ import { BaseAvatar } from "@omer-x/tailwind-ui-kit/display";
9
+
10
+ <BaseAvatar size="sm" className="bg-neutral-200 font-medium">
11
+ <BaseAvatar.Image src={user.photoUrl} alt={user.name} />
12
+ <BaseAvatar.Fallback>{initials}</BaseAvatar.Fallback>
13
+ </BaseAvatar>
14
+ ```
15
+
16
+ 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.
17
+
18
+ | Part | Renders | Description |
19
+ |------|---------|-------------|
20
+ | `BaseAvatar` | `<span>` | A round, centered, `overflow-hidden` box of the given size. Make it square with `className="rounded-md"` |
21
+ | `BaseAvatar.Image` | `<img>` | The picture, covering the box (`size-full object-cover`). Rendered only once it has loaded |
22
+ | `BaseAvatar.Fallback` | `<span>` | Fills the box and centers its content. Rendered until the image has loaded |
23
+
24
+ Every part takes `className` and `render`.
25
+
26
+ `BaseAvatar` props:
27
+
28
+ | Prop | Type | Default | Description |
29
+ |------|------|---------|-------------|
30
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | `size-12 text-lg` / `size-10 text-base` / `size-8 text-sm` / `size-6 text-xs` |
31
+ | `render` | `RenderProp<"span", AvatarState>` | | The state is `{ imageLoadingStatus }`: `"idle"`, `"loading"`, `"loaded"` or `"error"` |
32
+
33
+ `BaseAvatar.Image` props:
34
+
35
+ | Prop | Type | Default | Description |
36
+ |------|------|---------|-------------|
37
+ | `onLoadingStatusChange` | `(status) => void` | | Called when the image starts loading, loads or fails |
38
+ | `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` |
39
+ | `render` | `RenderProp<"img", AvatarImageState>` | | The avatar's state plus `transitionStatus` |
40
+
41
+ `BaseAvatar.Fallback` props:
42
+
43
+ | Prop | Type | Default | Description |
44
+ |------|------|---------|-------------|
45
+ | `delay` | `number` | `0` | Milliseconds to wait before showing, so a fast image doesn't flash it |
46
+ | `render` | `RenderProp<"span", AvatarState>` | | |
47
+
48
+ 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.
@@ -0,0 +1,62 @@
1
+ # `BaseMeter`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/display`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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.
6
+
7
+ ```tsx
8
+ import { BaseMeter } from "@omer-x/tailwind-ui-kit/display";
9
+
10
+ <BaseMeter
11
+ value={usedGb}
12
+ max={quotaGb}
13
+ label="Storage used"
14
+ showValue
15
+ trackClassName="bg-neutral-200"
16
+ indicatorClassName="bg-blue-600"
17
+ />
18
+ ```
19
+
20
+ | Prop | Type | Default | Description |
21
+ |------|------|---------|-------------|
22
+ | `value` | `number` | | The current value, clamped to `min`…`max` |
23
+ | `min` / `max` | `number` | `0` / `100` | The range |
24
+ | `format` | `Intl.NumberFormatOptions` | | How the value is formatted. Without it, it is shown as a percentage of the range |
25
+ | `locale` | `Intl.LocalesArgument` | runtime locale | The locale used to format the value |
26
+ | `getAriaValueText` | `(formattedValue, value) => string` | | What screen readers announce for the value |
27
+ | `label` | `ReactNode` | | The visible name. It labels the meter. Without it, nothing is rendered for it: use `aria-label` |
28
+ | `labelClassName` | `string` | | Classes for the label `<span>` (default `grow`) |
29
+ | `renderLabel` | `RenderProp<"span", MeterState>` | | Render another element for the label |
30
+ | `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` `` |
31
+ | `valueClassName` | `string` | | Classes for the value `<span>` (default `ms-auto tabular-nums`). It is `aria-hidden`: screen readers read the meter's value |
32
+ | `renderValue` | `RenderProp<"span", MeterState>` | | Render another element for the value |
33
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | The track's height: `h-3` / `h-2` / `h-1.5` / `h-1` |
34
+ | `trackClassName` | `string` | | Classes for the track `<div>` (default `relative block w-full overflow-hidden rounded-full`) |
35
+ | `renderTrack` | `RenderProp<"div", MeterState>` | | Render another element for the track |
36
+ | `indicatorClassName` | `string` | | Classes for the indicator `<div>`, the filled part. Its width is set inline and transitions (`transition-[width] duration-500`) |
37
+ | `renderIndicator` | `RenderProp<"div", MeterState>` | | Render another element for the indicator |
38
+ | `children` | `ReactNode` | | Lays out the parts yourself (see below). The built-in label, value and track aren't rendered then |
39
+ | `className` | `string` | | Classes for the root `<div>` |
40
+ | `render` | `RenderProp<"div", MeterState>` | | Render another element for the root |
41
+ | …rest | | | `<div>` props |
42
+
43
+ To place the parts yourself, e.g. the value inside the track, pass them as children. Dot notation only works in client components.
44
+
45
+ ```tsx
46
+ <BaseMeter value={24}>
47
+ <BaseMeter.Label className="sr-only">Upload quota</BaseMeter.Label>
48
+ <BaseMeter.Track className="h-5 bg-neutral-200">
49
+ <BaseMeter.Indicator className="bg-blue-600" />
50
+ <BaseMeter.Value className="absolute inset-0 flex items-center justify-center" />
51
+ </BaseMeter.Track>
52
+ </BaseMeter>
53
+ ```
54
+
55
+ | Part | Renders | Props |
56
+ |------|---------|-------|
57
+ | `BaseMeter.Label` | `<span>` | `className`, `render` |
58
+ | `BaseMeter.Track` | `<div>` | `size`, `className`, `render` |
59
+ | `BaseMeter.Indicator` | `<div>` | `className`, `render` |
60
+ | `BaseMeter.Value` | `<span>` | `className`, `render`, `children?: (formattedValue, value) => ReactNode` |
61
+
62
+ 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`).
@@ -0,0 +1,9 @@
1
+ # `@omer-x/tailwind-ui-kit/elements`
2
+
3
+ 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.
4
+
5
+ ```tsx
6
+ import { JustDiv } from "@omer-x/tailwind-ui-kit/elements";
7
+
8
+ <JustDiv className="p-4" render={<section />}>…</JustDiv>
9
+ ```
@@ -0,0 +1,91 @@
1
+ # `BaseToast`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/feedback`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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`](../providers/ToastProvider.md), are created with [`useToast`](../feedback/useToast.md) (or a [`createToastManager`](../feedback/createToastManager.md) manager outside React) and are shown by one `BaseToast.Viewport`, which renders each toast with your parts.
6
+
7
+ Theme it once, next to the provider:
8
+
9
+ ```tsx
10
+ // src/components/Toasts.tsx
11
+ "use client";
12
+ import { BaseToast } from "@omer-x/tailwind-ui-kit/feedback";
13
+ import { ToastProvider } from "@omer-x/tailwind-ui-kit/providers";
14
+ import type { ReactNode } from "react";
15
+
16
+ const Toasts = ({ children }: { children: ReactNode }) => (
17
+ <ToastProvider>
18
+ {children}
19
+ <BaseToast.Viewport>
20
+ {toast => (
21
+ <BaseToast
22
+ toast={toast}
23
+ className="rounded-md border bg-white p-4 shadow-lg data-[type=error]:border-red-300 data-[type=error]:bg-red-50"
24
+ >
25
+ <BaseToast.Content className="pr-6">
26
+ <BaseToast.Title className="font-semibold" />
27
+ <BaseToast.Description className="text-neutral-600" />
28
+ <BaseToast.Action className="mt-2 rounded border px-2 py-1 text-xs" />
29
+ <BaseToast.Close aria-label="Close" className="absolute top-2 right-2"><XIcon /></BaseToast.Close>
30
+ </BaseToast.Content>
31
+ </BaseToast>
32
+ )}
33
+ </BaseToast.Viewport>
34
+ </ToastProvider>
35
+ );
36
+
37
+ export default Toasts;
38
+ ```
39
+
40
+ Then show toasts from any client component inside it:
41
+
42
+ ```tsx
43
+ const { add } = useToast();
44
+
45
+ add({ title: "Saved", description: "Your changes were saved.", type: "success" });
46
+ ```
47
+
48
+ | Part | Renders | Description |
49
+ |------|---------|-------------|
50
+ | `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 |
51
+ | `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) |
52
+ | `BaseToast.Content` | `<div>` | The toast's content. Hidden (`data-behind`) while the toast is behind another one in a collapsed stack |
53
+ | `BaseToast.Title` | `<h2>` | Shows the toast's `title` unless it has children. Renders nothing when both are empty |
54
+ | `BaseToast.Description` | `<p>` | Shows the toast's `description` unless it has children. Renders nothing when both are empty |
55
+ | `BaseToast.Action` | `<button>` | Gets the toast's `actionProps` (`children`, `onClick`, …). Renders nothing without children |
56
+ | `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 |
57
+ | `BaseToast.Arrow` | `<div>` | Points at an anchored toast's anchor. Size and draw it with `className` or `children`. `data-side`, `data-align`, `data-uncentered` |
58
+
59
+ Every part takes `className` and `render`.
60
+
61
+ `BaseToast.Viewport` props:
62
+
63
+ | Prop | Type | Default | Description |
64
+ |------|------|---------|-------------|
65
+ | `children` | `(toast: ToastObject<Data>) => ReactNode` | | Renders one toast, usually a `BaseToast` (no `key` needed) |
66
+ | `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the viewport is portaled to |
67
+ | `render` | `RenderProp<"div", ToastViewportState>` | | The state is `{ expanded }` |
68
+
69
+ `BaseToast` props:
70
+
71
+ | Prop | Type | Default | Description |
72
+ |------|------|---------|-------------|
73
+ | `toast` | `ToastObject` | | The toast to show, from the viewport's children function |
74
+ | `swipeDirection` | `ToastSwipeDirection \| ToastSwipeDirection[]` | `["down", "right"]` | The directions (`"up"`, `"down"`, `"left"`, `"right"`) it can be swiped to close it. Anchored toasts can't be swiped |
75
+ | `positionerClassName` | `string` | | Classes for an anchored toast's positioner, the `<div>` that places it (`z-50`) |
76
+ | `renderPositioner` | `RenderProp<"div", ToastPositionerState>` | | The state is `{ side, align, anchorHidden }` |
77
+ | `render` | `RenderProp<"div", ToastState>` | | The state is `{ transitionStatus, expanded, limited, type, swiping, swipeDirection }` |
78
+
79
+ `Title`, `Description`, `Action` and `Close` render functions get `{ type }`. `Action` and `Close` take `nativeButton={false}` when `render` isn't a `<button>`.
80
+
81
+ 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`.
82
+
83
+ **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`](../form/useFormMessages.md) (`"error"` or `"warning"`).
84
+
85
+ **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:
86
+
87
+ ```tsx
88
+ add({ title: "Copied", positionerProps: { anchor: buttonRef.current, side: "top", sideOffset: 8 } });
89
+ ```
90
+
91
+ `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`.
@@ -0,0 +1,19 @@
1
+ # `createToastManager`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/feedback`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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.
6
+
7
+ ```ts
8
+ // src/toasts.ts
9
+ export const toastManager = createToastManager();
10
+
11
+ // anywhere
12
+ toastManager.add({ title: "Session expired", type: "error" });
13
+ ```
14
+
15
+ ```tsx
16
+ <ToastProvider manager={toastManager}>…</ToastProvider>
17
+ ```
18
+
19
+ `useToast` inside that provider manages the same toasts.
@@ -0,0 +1,37 @@
1
+ # `useToast`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/feedback`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ Shows, updates and closes the toasts of the surrounding `ToastProvider`. Pass a type for your toasts' custom `data`: `useToast<{ icon: string }>()`.
6
+
7
+ ```ts
8
+ const { toasts, add, update, close, promise } = useToast();
9
+
10
+ const id = add({ title: "Uploading…", timeout: 0 });
11
+ update(id, { title: "Uploaded", type: "success", timeout: 5000 });
12
+ close(id); // or close() for every toast
13
+
14
+ await promise(upload(file), {
15
+ loading: "Uploading…", // a string is a shortcut for { description }
16
+ success: result => ({ title: "Uploaded", description: result.name, type: "success" }),
17
+ error: error => ({ title: "Upload failed", type: "error" }),
18
+ });
19
+ ```
20
+
21
+ `add` options (`ToastOptions`):
22
+
23
+ | Option | Type | Default | Description |
24
+ |--------|------|---------|-------------|
25
+ | `title` | `ReactNode` | | |
26
+ | `description` | `ReactNode` | | |
27
+ | `type` | `string` | | Set as `data-type` |
28
+ | `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 |
29
+ | `priority` | `"low" \| "high"` | `"low"` | Announced politely, or urgently (`role="alertdialog"`) |
30
+ | `id` | `string` | generated | Adding a toast with an existing `id` updates it in place and restarts its timer |
31
+ | `actionProps` | `ComponentProps<"button">` | | Props of `BaseToast.Action` |
32
+ | `data` | `Data` | | Your own data, e.g. to pick an icon in the viewport |
33
+ | `onClose` | `() => void` | | Called when it starts closing |
34
+ | `onRemove` | `() => void` | | Called when it is removed, after its exit transition |
35
+ | `positionerProps` | `ToastPositionerOptions` | | Anchors the toast to an element |
36
+
37
+ `toasts` (`ToastObject[]`, newest first) are the shown toasts, with their `id`. `BaseToast.Viewport` already renders them; use it to show a count, for example.
@@ -0,0 +1,110 @@
1
+ # `BaseAutocomplete`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/form`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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:
6
+
7
+ ```tsx
8
+ import { BaseAutocomplete } from "@omer-x/tailwind-ui-kit/form";
9
+
10
+ <BaseAutocomplete items={fruits}>
11
+ <BaseAutocomplete.Input aria-label="Fruit" className="border border-neutral-300" />
12
+ <BaseAutocomplete.Popup sideOffset={4} className="rounded-md bg-white py-1 shadow-lg">
13
+ <BaseAutocomplete.Empty className="px-3 not-empty:py-1.5">No fruits found</BaseAutocomplete.Empty>
14
+ <BaseAutocomplete.List>
15
+ {(fruit: string) => (
16
+ <BaseAutocomplete.Item key={fruit} value={fruit} className="px-3 py-1.5 data-highlighted:bg-blue-600">
17
+ {fruit}
18
+ </BaseAutocomplete.Item>
19
+ )}
20
+ </BaseAutocomplete.List>
21
+ </BaseAutocomplete.Popup>
22
+ </BaseAutocomplete>
23
+ ```
24
+
25
+ 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.
26
+
27
+ | Part | Renders | Description |
28
+ |------|---------|-------------|
29
+ | `BaseAutocomplete` | nothing | Groups the parts, holds the input's value and filters `items` |
30
+ | `.Input` | `<input>` | The text input. Takes `size` (`"lg" \| "md" \| "sm" \| "xs"`, default `"md"`), the same sizes as `BaseInput` |
31
+ | `.InputGroup` | `<div>` | Optional. Wraps the input with a trigger and a clear button (`relative flex items-center`). The popup is placed against it |
32
+ | `.Trigger` | `<button>` | Opens the popup. `data-popup-open` while it's open |
33
+ | `.Icon` | `<span>` | A decorative icon, hidden from assistive technology. Bring your own icon as children |
34
+ | `.Clear` | `<button>` | Clears the input. Only rendered while the input has a value (`keepMounted` keeps it) |
35
+ | `.Value` | nothing | The input's value, or a function of it, anywhere inside the root |
36
+ | `.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 |
37
+ | `.Status` | `<div>` | A live region for screen readers ("Loading…", "12 results") |
38
+ | `.Empty` | `<div>` | Its children show only when no item matches. Always rendered (it's a live region): style it with `not-empty:` / `empty:` |
39
+ | `.List` | `<div>` | The scrollable list. Children can be a function that renders each filtered item (or group). `data-empty` when nothing matches |
40
+ | `.Item` | `<div>` | An option (`flex items-center gap-2`). `value` is the item. `data-highlighted`, `data-disabled` |
41
+ | `.Group` | `<div>` | A group of items. Pass the group's `items` to use `.Collection` inside |
42
+ | `.GroupLabel` | `<div>` | Names a group |
43
+ | `.Collection` | nothing | Renders the filtered items of the surrounding group with a function |
44
+ | `.Separator` | `<div>` | A `role="separator"` line, with `data-orientation` |
45
+ | `.Row` | `<div>` | A row of items when the root has `grid` |
46
+
47
+ 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`).
48
+
49
+ `BaseAutocomplete` props:
50
+
51
+ | Prop | Type | Description |
52
+ |------|------|-------------|
53
+ | `items` | `Item[] \| { items: Item[] }[]` | The items, flat or in groups. Filtered by the input's value and passed to `List`'s function children |
54
+ | `filteredItems` | same as `items` | Items you filtered yourself, shown instead |
55
+ | `filter` | `(item, query, itemToString?) => boolean \| null` | Decides what matches. `null` turns filtering off. Defaults to a case-insensitive "contains" |
56
+ | `limit` | `number` | Shows at most this many matches |
57
+ | `mode` | `"list" \| "both" \| "inline" \| "none"` | `list` (default) filters; `both` also fills the input with the highlighted item; `inline` only fills; `none` does neither |
58
+ | `itemToStringValue` | `(item) => string` | Text of an object item. `{ value, label }` objects use `label` without it |
59
+ | `value` / `defaultValue` | `string` | The input's value, controlled / uncontrolled |
60
+ | `onValueChange` | `(value, event) => void` | Called with the new value and the DOM event (none when changed from code) |
61
+ | `open` / `defaultOpen` | `boolean` | The popup's state |
62
+ | `onOpenChange` | `(open, event) => void` | Called with the new state and the DOM event |
63
+ | `onOpenChangeComplete` | `(open) => void` | Called after the transition ends |
64
+ | `openOnInputClick` | `boolean` | Opens the popup on click |
65
+ | `autoHighlight` | `boolean \| "always"` | Highlights the first match while typing (`"always"`: also on open) |
66
+ | `keepHighlight` | `boolean` | Keeps the highlight when the pointer leaves the list |
67
+ | `highlightItemOnHover` | `boolean` | Default `true`. `false` lets `:hover` and `data-highlighted` differ |
68
+ | `onItemHighlighted` | `(item, { reason, index }) => void` | `reason` is `"keyboard"`, `"pointer"` or `"none"` |
69
+ | `loopFocus` | `boolean` | Default `true`. Arrow keys wrap around the list |
70
+ | `submitOnItemClick` | `boolean` | Submits the form when an item is chosen (e.g. a search box) |
71
+ | `grid` | `boolean` | Items in `Row`s, navigated with all four arrow keys |
72
+ | `inline` | `boolean` | Renders the list in place, without a popup. Use with `open` |
73
+ | `modal` | `boolean` | Locks page scroll and outside pointer input while open |
74
+ | `virtualized` | `boolean` | For lists rendered by a virtualizer (give each item its `index`) |
75
+ | `locale` | `Intl.LocalesArgument` | Locale of the default filter |
76
+ | `name`, `form`, `id`, `required`, `disabled`, `readOnly` | | Form props. Inside `BaseFormField`, the field's `name` is used |
77
+ | `inputRef` | `Ref<HTMLInputElement>` | The hidden input used for validation |
78
+ | `actionsRef` | `RefObject<AutocompleteActions>` | `actionsRef.current?.close()` |
79
+
80
+ `BaseAutocomplete.Popup` props, besides `<div>` props:
81
+
82
+ | Prop | Description |
83
+ |------|-------------|
84
+ | `side`, `align` | Placement against the input (group). Default `"bottom"`, `"start"` |
85
+ | `sideOffset`, `alignOffset` | Offsets in pixels, or a function of the placement and sizes |
86
+ | `anchor`, `positionMethod`, `collisionBoundary`, `collisionPadding`, `collisionAvoidance`, `sticky`, `disableAnchorTracking` | Positioning control |
87
+ | `renderPositioner` | Replaces the element that positions the popup, e.g. `<div className="z-50" />` |
88
+ | `container`, `keepMounted` | Portal target (default `<body>`), and keeping the popup in the DOM while closed |
89
+ | `backdrop`, `renderBackdrop` | Renders a `fixed inset-0` backdrop (off by default, use it with `modal`) |
90
+ | `arrow`, `renderArrow`, `arrowPadding` | An arrow pointing at the input. Rendered when `arrow` (its content, e.g. an `<svg>`) or `renderArrow` is given |
91
+ | `finalFocus` | The element focused when the popup closes |
92
+
93
+ **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`:
94
+
95
+ ```tsx
96
+ const filter = useAutocompleteFilter();
97
+ <BaseAutocomplete items={fruits} filter={filter.startsWith}>…</BaseAutocomplete>
98
+ ```
99
+
100
+ **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:
101
+
102
+ ```tsx
103
+ <BaseFormField name="fruit" label="Fruit" schema={Schema.shape.fruit}>
104
+ {constraints => (
105
+ <BaseAutocomplete items={fruits} required={constraints.required}>
106
+ …
107
+ </BaseAutocomplete>
108
+ )}
109
+ </BaseFormField>
110
+ ```
@@ -0,0 +1,33 @@
1
+ # `BaseCheckbox`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/form`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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`.
6
+
7
+ | Prop | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `label` | `ReactNode` | | Text next to the checkbox (required) |
10
+ | `labelClassName` | `string` | | Classes for the `<label>` around the checkbox and its text (default `flex items-center gap-2 text-sm font-normal`) |
11
+ | `icon` | `ReactNode` | | Shown inside the box when checked. The kit bundles none |
12
+ | `indeterminateIcon` | `ReactNode` | `icon` | Shown inside the box when indeterminate |
13
+ | `renderIndicator` | `RenderProp<"span", CheckboxState>` | | Style the indicator that holds the icon |
14
+ | `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when unchecked (e.g. to animate it out) |
15
+ | `indeterminate` | `boolean` | `false` | Show the mixed state (`aria-checked="mixed"`). It doesn't change `checked` |
16
+ | `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 |
17
+ | `value` | `string` | `"true"` | Submitted when checked |
18
+ | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
19
+ | `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
20
+ | `render` | `RenderProp<"span", CheckboxState>` | | Render another element for the box |
21
+ | …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
22
+
23
+ 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.
24
+
25
+ ```tsx
26
+ <BaseCheckbox
27
+ name="terms"
28
+ label="I accept the terms"
29
+ className="rounded border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
30
+ renderIndicator={<span className="text-white" />}
31
+ icon={<CheckIcon />}
32
+ />
33
+ ```
@@ -0,0 +1,28 @@
1
+ # `BaseCheckboxGroup`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/form`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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.
6
+
7
+ | Prop | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `name` | `string` | | Submitted name of every checkbox in the group |
10
+ | `value` | `string[]` | | The `value`s of the checked boxes, when controlled |
11
+ | `defaultValue` | `string[]` | | The `value`s of the boxes checked at first |
12
+ | `onValueChange` | `(value: string[], event: Event) => void` | | Called with the new checked `value`s and the DOM event that changed it |
13
+ | `allValues` | `string[]` | | Every child `value`. Needed by a `BaseCheckbox` with `parent` ("select all") |
14
+ | `disabled` | `boolean` | | Disables every checkbox in the group |
15
+ | `className` | `string` | | Classes for the group `<div>` (default `flex flex-col gap-2`) |
16
+ | `render` | `RenderProp<"div", CheckboxGroupState>` | | Render another element for the group |
17
+ | …rest | | | `<div>` props. Give the group an accessible name with `aria-label` or `aria-labelledby` |
18
+
19
+ Render functions get `CheckboxGroupState`: `{ disabled }`. The group sets `data-disabled` when disabled.
20
+
21
+ 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.
22
+
23
+ ```tsx
24
+ <BaseCheckboxGroup name="channels" aria-label="Channels" defaultValue={["email"]}>
25
+ <BaseCheckbox value="email" label="Email" />
26
+ <BaseCheckbox value="sms" label="SMS" />
27
+ </BaseCheckboxGroup>
28
+ ```
@@ -0,0 +1,24 @@
1
+ # `BaseFieldset`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/form`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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.
6
+
7
+ | Prop | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `legend` | `ReactNode` | | The caption, rendered before the children. Without it, no legend is rendered |
10
+ | `legendClassName` | `string` | | Classes for the legend `<div>` (default `font-semibold`) |
11
+ | `renderLegend` | `RenderProp<"div", FieldsetState>` | | Render another element for the legend (e.g. a heading) |
12
+ | `disabled` | `boolean` | | Disables every control inside, `BaseFormField`s included |
13
+ | `className` | `string` | | Classes for the `<fieldset>` (default `flex min-w-0 flex-col gap-3`) |
14
+ | `render` | `RenderProp<"fieldset", FieldsetState>` | | Render another element for the fieldset |
15
+ | …rest | | | `<fieldset>` props |
16
+
17
+ Render functions get `FieldsetState`: `{ disabled }`. The fieldset and the legend set `data-disabled` when disabled.
18
+
19
+ ```tsx
20
+ <BaseFieldset legend="Billing address" className="rounded border p-4" legendClassName="border-b pb-2">
21
+ <BaseFormField name="street" label="Street" schema={Schema.shape.street} />
22
+ <BaseFormField name="city" label="City" schema={Schema.shape.city} />
23
+ </BaseFieldset>
24
+ ```
@@ -0,0 +1,89 @@
1
+ # `BaseForm`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/form`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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:
6
+
7
+ ```sh
8
+ npm install @omer-x/next-form-actions@^2.0.0-alpha.1
9
+ ```
10
+
11
+ | Prop | Type | Description |
12
+ |------|------|-------------|
13
+ | `action` | `FormAction<Data>` | The action, e.g. `saveProduct` or `completeSale.bind(null, saleId)`. `Data` is what it returns on success |
14
+ | `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 |
15
+ | `onResult` | `(result: FormActionState<Data>) => void` | Called once per completed submission, when the action returns. Never on mount |
16
+ | `resetOnSuccess` | `boolean` | After a successful result, reset every field inside the form to its default (see below) |
17
+ | `defaultValues` | `Record<string, unknown>` | Initial values, used by `onlyDirty` |
18
+ | `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 |
19
+ | …rest | `<form>` props | Except `action` |
20
+
21
+ **How the result is used.** The action resolves to `{ status: "idle" }`, `{ status: "success", data }` or `{ status: "failure", fieldErrors, message? }`:
22
+
23
+ - `fieldErrors[name]` are shown under the `BaseFormField` with that `name`. A field can have several errors.
24
+ - `message` (`{ type: "error" | "warning", text }`) is a **form-level message**.
25
+ - 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.
26
+ - `BaseForm` renders no form-level messages itself. Show them wherever you like with `useFormMessages()`.
27
+
28
+ The form never resets after a submission, so after a failure the user keeps what they typed. That includes controlled checkboxes and selects.
29
+
30
+ **`formatMessage`** receives every text the form shows:
31
+
32
+ | What | `code` | `params` |
33
+ |------|--------|----------|
34
+ | 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" }` |
35
+ | 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) |
36
+ | Form message | The message's `text`, e.g. `SALE_ALREADY_COMPLETED` | none |
37
+
38
+ 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:
39
+
40
+ ```tsx
41
+ // src/components/Form.tsx
42
+ "use client";
43
+ import { BaseForm } from "@omer-x/tailwind-ui-kit/form";
44
+ import { useTranslations } from "next-intl";
45
+ import type { ComponentProps } from "react";
46
+
47
+ const Form = <Data,>(props: ComponentProps<typeof BaseForm<Data>>) => {
48
+ const t = useTranslations("Form");
49
+ return <BaseForm {...props} formatMessage={(code, params) => t(code, params as Record<string, string>)} />;
50
+ };
51
+
52
+ export default Form;
53
+ ```
54
+
55
+ ```json
56
+ {
57
+ "Form": {
58
+ "required": "This field is required",
59
+ "valueMissing": "This field is required",
60
+ "too_small": "{origin, select, string {At least {minimum, plural, one {# character} other {# characters}}} other {At least {minimum}}}",
61
+ "tooShort": "At least {minimum, plural, one {# character} other {# characters}}",
62
+ "SALE_ALREADY_COMPLETED": "This sale is already completed"
63
+ }
64
+ }
65
+ ```
66
+
67
+ **`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.
68
+
69
+ ```tsx
70
+ // actions.ts
71
+ "use server";
72
+ export const saveProfile = defineFormAction({
73
+ schema: z.object({ name: z.string().min(3) }),
74
+ action: input => async () => {
75
+ if (await isDown()) displayMessage("error", "SERVER_DOWN");
76
+ return await save(input); // becomes state.data
77
+ },
78
+ });
79
+ ```
80
+
81
+ ```tsx
82
+ <Form action={saveProfile} onResult={result => result.status === "success" && dialog.close()} className="flex flex-col gap-4">
83
+ <FormAlerts />
84
+ <FormField name="name" label="Name" schema={z.string().min(3)} />
85
+ <Button type="submit">Save</Button>
86
+ </Form>
87
+ ```
88
+
89
+ Forms can be nested. A submit inside an inner form does not submit the outer one.
@@ -0,0 +1,47 @@
1
+ # `BaseFormField`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/form`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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`.
6
+
7
+ | Prop | Type | Description |
8
+ |------|------|-------------|
9
+ | `name` | `string` | Field name. It also links the server errors in `fieldErrors[name]` |
10
+ | `schema` | `ZodType` | Source of the HTML constraints applied to the control |
11
+ | `label` | `string` | Label text. No label is rendered when omitted |
12
+ | `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 |
13
+ | `children` | `(constraints: FieldConstraints) => ReactNode` | Renders a control that isn't a single `<input>` (e.g. [`BaseAutocomplete`](../form/BaseAutocomplete.md)) 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 |
14
+ | `renderLabel` | `RenderProp<"label", FieldState>` | Style the label |
15
+ | `renderErrors` | `RenderProp<"div", FieldState>` | Style client-side and server-side error messages. Each error is its own element |
16
+ | `className` | `string` | Classes for the field root (a flex column by default) |
17
+
18
+ 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).
19
+
20
+ ```tsx
21
+ <BaseFormField
22
+ name="username"
23
+ label="Username"
24
+ schema={z.string().min(3).max(20)}
25
+ control={<Input />}
26
+ renderErrors={<p className="text-sm text-red-600" />}
27
+ />
28
+ ```
29
+
30
+ **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:
31
+
32
+ ```ts
33
+ // src/schemas/user.ts
34
+ import { z } from "zod";
35
+
36
+ export const UserSchema = z.object({
37
+ username: z.string().min(3).max(20),
38
+ email: z.email(),
39
+ });
40
+ ```
41
+
42
+ ```tsx
43
+ <BaseFormField name="username" label="Username" schema={UserSchema.shape.username} control={<Input />} />
44
+ <BaseFormField name="email" label="Email" schema={UserSchema.shape.email} control={<Input type="email" />} />
45
+ ```
46
+
47
+ 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.
@@ -0,0 +1,13 @@
1
+ # `BaseInput`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/form`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ A plain `<input>` with sizes, rounded corners and a transparent outline ready for focus styles. It accepts all input props plus `render`.
6
+
7
+ | Prop | Type | Default |
8
+ |------|------|---------|
9
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` |
10
+
11
+ ```tsx
12
+ <BaseInput name="email" className="border border-neutral-300 focus:outline-blue-500" />
13
+ ```