@omer-x/tailwind-ui-kit 1.0.0-alpha.3 → 1.0.0-alpha.31

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 (122) hide show
  1. package/MIGRATION.md +283 -0
  2. package/README.md +792 -0
  3. package/dist/components/button/BaseButton.d.ts +39 -12
  4. package/dist/components/button/BaseButton.js +57 -51
  5. package/dist/components/button/index.d.ts +2 -4
  6. package/dist/components/button/index.js +1 -4
  7. package/dist/components/dialog/BaseAlertDialog.d.ts +49 -0
  8. package/dist/components/dialog/BaseAlertDialog.js +27 -0
  9. package/dist/components/dialog/BaseAlertDialogTrigger.d.ts +16 -0
  10. package/dist/components/dialog/BaseAlertDialogTrigger.js +11 -0
  11. package/dist/components/dialog/BaseDialog.d.ts +58 -0
  12. package/dist/components/dialog/BaseDialog.js +24 -0
  13. package/dist/components/dialog/BaseDialogClose.d.ts +13 -0
  14. package/dist/components/dialog/BaseDialogClose.js +7 -0
  15. package/dist/components/dialog/BaseDialogDescription.d.ts +8 -0
  16. package/dist/components/dialog/BaseDialogDescription.js +7 -0
  17. package/dist/components/dialog/BaseDialogPopup.d.ts +41 -0
  18. package/dist/components/dialog/BaseDialogPopup.js +42 -0
  19. package/dist/components/dialog/BaseDialogTitle.d.ts +8 -0
  20. package/dist/components/dialog/BaseDialogTitle.js +11 -0
  21. package/dist/components/dialog/BaseDialogTrigger.d.ts +20 -0
  22. package/dist/components/dialog/BaseDialogTrigger.js +11 -0
  23. package/dist/components/dialog/createAlertDialogHandle.d.ts +14 -0
  24. package/dist/components/dialog/createAlertDialogHandle.js +11 -0
  25. package/dist/components/dialog/createDialogHandle.d.ts +36 -0
  26. package/dist/components/dialog/createDialogHandle.js +31 -0
  27. package/dist/components/dialog/index.d.ts +8 -5
  28. package/dist/components/dialog/index.js +5 -8
  29. package/dist/components/disclosure/BaseAccordion.d.ts +48 -0
  30. package/dist/components/disclosure/BaseAccordion.js +18 -0
  31. package/dist/components/disclosure/BaseAccordionItem.d.ts +20 -0
  32. package/dist/components/disclosure/BaseAccordionItem.js +10 -0
  33. package/dist/components/disclosure/BaseAccordionPanel.d.ts +20 -0
  34. package/dist/components/disclosure/BaseAccordionPanel.js +15 -0
  35. package/dist/components/disclosure/BaseAccordionTrigger.d.ts +22 -0
  36. package/dist/components/disclosure/BaseAccordionTrigger.js +23 -0
  37. package/dist/components/disclosure/index.d.ts +4 -0
  38. package/dist/components/disclosure/index.js +1 -0
  39. package/dist/components/disclosure/panelTransition.d.ts +7 -0
  40. package/dist/components/disclosure/panelTransition.js +9 -0
  41. package/dist/components/display/BaseAvatar.d.ts +24 -0
  42. package/dist/components/display/BaseAvatar.js +35 -0
  43. package/dist/components/display/BaseAvatarFallback.d.ts +14 -0
  44. package/dist/components/display/BaseAvatarFallback.js +14 -0
  45. package/dist/components/display/BaseAvatarImage.d.ts +23 -0
  46. package/dist/components/display/BaseAvatarImage.js +14 -0
  47. package/dist/components/display/index.d.ts +3 -0
  48. package/dist/components/display/index.js +1 -0
  49. package/dist/components/elements/JustAnchor.d.ts +7 -0
  50. package/dist/components/elements/JustAnchor.js +11 -0
  51. package/dist/components/elements/JustButton.d.ts +7 -0
  52. package/dist/components/elements/JustButton.js +11 -0
  53. package/dist/components/elements/JustDiv.d.ts +7 -0
  54. package/dist/components/elements/JustDiv.js +11 -0
  55. package/dist/components/elements/JustInput.d.ts +7 -0
  56. package/dist/components/elements/JustInput.js +11 -0
  57. package/dist/components/elements/JustSpan.d.ts +7 -0
  58. package/dist/components/elements/JustSpan.js +11 -0
  59. package/dist/components/elements/index.d.ts +6 -0
  60. package/dist/components/elements/index.js +6 -0
  61. package/dist/components/form/BaseCheckbox.d.ts +44 -0
  62. package/dist/components/form/BaseCheckbox.js +24 -0
  63. package/dist/components/form/BaseForm.d.ts +13 -0
  64. package/dist/components/form/BaseForm.js +78 -0
  65. package/dist/components/form/BaseFormField.d.ts +24 -0
  66. package/dist/components/form/BaseFormField.js +33 -0
  67. package/dist/components/form/BaseInput.d.ts +7 -0
  68. package/dist/components/form/BaseInput.js +22 -0
  69. package/dist/components/form/BaseSwitch.d.ts +35 -0
  70. package/dist/components/form/BaseSwitch.js +21 -0
  71. package/dist/components/form/ClientSideError.d.ts +9 -0
  72. package/dist/components/form/ClientSideError.js +39 -0
  73. package/dist/components/form/FieldRoot.d.ts +8 -0
  74. package/dist/components/form/FieldRoot.js +21 -0
  75. package/dist/components/form/FormContext.d.ts +28 -0
  76. package/dist/components/form/FormContext.js +12 -0
  77. package/dist/components/form/ServerSideError.d.ts +8 -0
  78. package/dist/components/form/ServerSideError.js +15 -0
  79. package/dist/components/form/index.d.ts +8 -0
  80. package/dist/components/form/index.js +7 -0
  81. package/dist/components/form/useFormMessages.d.ts +10 -0
  82. package/dist/components/form/useFormMessages.js +16 -0
  83. package/dist/components/layout/Container.d.ts +4 -10
  84. package/dist/components/layout/Container.js +9 -10
  85. package/dist/components/layout/index.d.ts +2 -3
  86. package/dist/components/layout/index.js +1 -4
  87. package/dist/components/page/Pagination.d.ts +27 -0
  88. package/dist/components/page/Pagination.js +68 -0
  89. package/dist/components/page/index.d.ts +3 -0
  90. package/dist/components/page/index.js +3 -0
  91. package/dist/components/page/usePagination.d.ts +30 -0
  92. package/dist/components/page/usePagination.js +41 -0
  93. package/dist/components/table/TableCell.d.ts +13 -0
  94. package/dist/components/table/TableCell.js +17 -0
  95. package/dist/components/table/Tdx.d.ts +6 -10
  96. package/dist/components/table/Tdx.js +11 -9
  97. package/dist/components/table/index.d.ts +3 -3
  98. package/dist/components/table/index.js +3 -4
  99. package/dist/hooks/index.d.ts +2 -0
  100. package/dist/hooks/index.js +1 -0
  101. package/dist/hooks/useRipples.d.ts +2 -5
  102. package/dist/hooks/useRipples.js +44 -32
  103. package/dist/utils/cn.d.ts +6 -5
  104. package/dist/utils/cn.js +8 -6
  105. package/dist/utils/dirty-form.d.ts +7 -0
  106. package/dist/utils/dirty-form.js +40 -0
  107. package/dist/utils/index.d.ts +3 -2
  108. package/dist/utils/index.js +2 -3
  109. package/dist/utils/render.d.ts +31 -0
  110. package/dist/utils/render.js +24 -0
  111. package/package.json +60 -26
  112. package/typescript-badge.d.ts +4 -0
  113. package/dist/components/button/PulseButton.d.ts +0 -10
  114. package/dist/components/button/PulseButton.js +0 -24
  115. package/dist/components/dialog/AnimatedPopup.d.ts +0 -6
  116. package/dist/components/dialog/AnimatedPopup.js +0 -34
  117. package/dist/components/dialog/DialogBackdrop.d.ts +0 -6
  118. package/dist/components/dialog/DialogBackdrop.js +0 -26
  119. package/dist/components/dialog/DialogTitle.d.ts +0 -6
  120. package/dist/components/dialog/DialogTitle.js +0 -19
  121. package/dist/styles/ripple.module.css +0 -10
  122. package/dist/styles/ripple.module.d.ts +0 -2
package/README.md ADDED
@@ -0,0 +1,792 @@
1
+ # @omer-x/tailwind-ui-kit
2
+
3
+ Colorless React components built on [Base UI](https://base-ui.com) and [Tailwind CSS v4](https://tailwindcss.com). They handle structure and behavior: sizing, spacing, focus, transitions, loading states and form wiring. **Your app decides how they look.**
4
+
5
+ > **Status:** under active development. The API may change between versions.
6
+
7
+ ## Principles
8
+
9
+ Read these before using or changing any component.
10
+
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).
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
+ 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
+ 5. **Client components.** All components are client components.
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).
18
+
19
+ ## Installation
20
+
21
+ > Upgrading from `1.0.0-alpha.18`? See [`MIGRATION.md`](./MIGRATION.md) (also in `node_modules/@omer-x/tailwind-ui-kit/MIGRATION.md`).
22
+
23
+ ```sh
24
+ npm install @omer-x/tailwind-ui-kit
25
+ ```
26
+
27
+ Peer dependencies:
28
+
29
+ ```sh
30
+ npm install react@19 react-dom@19 tailwindcss@4 @base-ui/react@1 zod@4
31
+ ```
32
+
33
+ `BaseForm` needs [`@omer-x/next-form-actions`](https://github.com/omermecitoglu/next-form-actions) v2 for its action and result types, and `BaseFormField` needs [`zod`](https://zod.dev) v4 for its `schema` prop.
34
+
35
+ ## Setup
36
+
37
+ Tailwind v4 does not scan `node_modules`, so the classes used inside the components won't be generated unless you add an `@source` line to your global CSS. The path is relative to the CSS file:
38
+
39
+ ```css
40
+ /* src/app/globals.css */
41
+ @import "tailwindcss";
42
+ @source "../../node_modules/@omer-x/tailwind-ui-kit/dist";
43
+ ```
44
+
45
+ That's the only setup. The kit ships no CSS files: everything, including the ripple animation, is Tailwind utilities.
46
+
47
+ Some components use the `dark:` variant (e.g. the backdrop of `BaseDialog.Popup`). They follow whatever `dark` variant your app defines.
48
+
49
+ ## Theming: wrap once, use everywhere
50
+
51
+ Create your themed versions in your app and import those instead of the base components:
52
+
53
+ ```tsx
54
+ // src/components/Button.tsx
55
+ "use client";
56
+ import { BaseButton } from "@omer-x/tailwind-ui-kit/button";
57
+ import { cn } from "cn";
58
+ import Spinner from "./Spinner";
59
+ import type { ComponentProps } from "react";
60
+
61
+ type ButtonProps = ComponentProps<typeof BaseButton> & {
62
+ variant?: "primary" | "secondary",
63
+ };
64
+
65
+ const Button = ({ variant = "primary", className, ...props }: ButtonProps) => (
66
+ <BaseButton
67
+ {...props}
68
+ spinner={<Spinner />} // your app's icon; the kit bundles no icons
69
+ className={cn({
70
+ "bg-blue-600 text-white hover:bg-blue-700 focus-visible:outline-blue-600": variant === "primary",
71
+ "bg-neutral-200 text-neutral-900 hover:bg-neutral-300 focus-visible:outline-neutral-500": variant === "secondary",
72
+ }, "data-disabled:opacity-50", className)}
73
+ />
74
+ );
75
+
76
+ export default Button;
77
+ ```
78
+
79
+ ## Components
80
+
81
+ There is no root entry point. Import from the subpaths below.
82
+
83
+ ### `@omer-x/tailwind-ui-kit/button`
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
+ ### `@omer-x/tailwind-ui-kit/form`
117
+
118
+ #### `BaseInput`
119
+
120
+ A plain `<input>` with sizes, rounded corners and a transparent outline ready for focus styles. It accepts all input props plus `render`.
121
+
122
+ | Prop | Type | Default |
123
+ |------|------|---------|
124
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` |
125
+
126
+ ```tsx
127
+ <BaseInput name="email" className="border border-neutral-300 focus:outline-blue-500" />
128
+ ```
129
+
130
+ #### `BaseSwitch`
131
+
132
+ 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.
133
+
134
+ | Prop | Type | Default | Description |
135
+ |------|------|---------|-------------|
136
+ | `label` | `ReactNode` | | Text next to the switch (required) |
137
+ | `labelClassName` | `string` | | Classes for the `<label>` around the switch and its text (default `flex items-center gap-2 text-sm font-normal`) |
138
+ | `renderThumb` | `RenderProp<"span", SwitchState>` | | Style the thumb |
139
+ | `value` | `string` | `"true"` | Submitted when checked |
140
+ | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
141
+ | `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
142
+ | `render` | `RenderProp<"span", SwitchState>` | | Render another element for the track |
143
+ | …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
144
+
145
+ Render functions get `SwitchState`: `{ checked, disabled, readOnly, required }`.
146
+
147
+ ```tsx
148
+ <BaseSwitch
149
+ name="active"
150
+ label="Active"
151
+ className="rounded-full bg-neutral-300 data-checked:bg-blue-600"
152
+ renderThumb={<span className="rounded-full bg-white" />}
153
+ />
154
+ ```
155
+
156
+ #### `BaseCheckbox`
157
+
158
+ 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`.
159
+
160
+ | Prop | Type | Default | Description |
161
+ |------|------|---------|-------------|
162
+ | `label` | `ReactNode` | | Text next to the checkbox (required) |
163
+ | `labelClassName` | `string` | | Classes for the `<label>` around the checkbox and its text (default `flex items-center gap-2 text-sm font-normal`) |
164
+ | `icon` | `ReactNode` | | Shown inside the box when checked. The kit bundles none |
165
+ | `indeterminateIcon` | `ReactNode` | `icon` | Shown inside the box when indeterminate |
166
+ | `renderIndicator` | `RenderProp<"span", CheckboxState>` | | Style the indicator that holds the icon |
167
+ | `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when unchecked (e.g. to animate it out) |
168
+ | `indeterminate` | `boolean` | `false` | Show the mixed state (`aria-checked="mixed"`). It doesn't change `checked` |
169
+ | `value` | `string` | `"true"` | Submitted when checked |
170
+ | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
171
+ | `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
172
+ | `render` | `RenderProp<"span", CheckboxState>` | | Render another element for the box |
173
+ | …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
174
+
175
+ 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.
176
+
177
+ ```tsx
178
+ <BaseCheckbox
179
+ name="terms"
180
+ label="I accept the terms"
181
+ className="rounded border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
182
+ renderIndicator={<span className="text-white" />}
183
+ icon={<CheckIcon />}
184
+ />
185
+ ```
186
+
187
+ #### `BaseForm`
188
+
189
+ 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:
190
+
191
+ ```sh
192
+ npm install @omer-x/next-form-actions@^2.0.0-alpha.1
193
+ ```
194
+
195
+ | Prop | Type | Description |
196
+ |------|------|-------------|
197
+ | `action` | `FormAction<Data>` | The action, e.g. `saveProduct` or `completeSale.bind(null, saleId)`. `Data` is what it returns on success |
198
+ | `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 |
199
+ | `onResult` | `(result: FormActionState<Data>) => void` | Called once per completed submission, when the action returns. Never on mount |
200
+ | `resetOnSuccess` | `boolean` | After a successful result, reset every field inside the form to its default (see below) |
201
+ | `defaultValues` | `Record<string, unknown>` | Initial values, used by `onlyDirty` |
202
+ | `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 |
203
+ | …rest | `<form>` props | Except `action` |
204
+
205
+ **How the result is used.** The action resolves to `{ status: "idle" }`, `{ status: "success", data }` or `{ status: "failure", fieldErrors, message? }`:
206
+
207
+ - `fieldErrors[name]` are shown under the `BaseFormField` with that `name`. A field can have several errors.
208
+ - `message` (`{ type: "error" | "warning", text }`) is a **form-level message**.
209
+ - 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.
210
+ - `BaseForm` renders no form-level messages itself. Show them wherever you like with `useFormMessages()`.
211
+
212
+ The form never resets after a submission, so after a failure the user keeps what they typed. That includes controlled checkboxes and selects.
213
+
214
+ **`formatMessage`** receives every text the form shows:
215
+
216
+ | What | `code` | `params` |
217
+ |------|--------|----------|
218
+ | 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" }` |
219
+ | 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) |
220
+ | Form message | The message's `text`, e.g. `SALE_ALREADY_COMPLETED` | none |
221
+
222
+ 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:
223
+
224
+ ```tsx
225
+ // src/components/Form.tsx
226
+ "use client";
227
+ import { BaseForm } from "@omer-x/tailwind-ui-kit/form";
228
+ import { useTranslations } from "next-intl";
229
+ import type { ComponentProps } from "react";
230
+
231
+ const Form = <Data,>(props: ComponentProps<typeof BaseForm<Data>>) => {
232
+ const t = useTranslations("Form");
233
+ return <BaseForm {...props} formatMessage={(code, params) => t(code, params as Record<string, string>)} />;
234
+ };
235
+
236
+ export default Form;
237
+ ```
238
+
239
+ ```json
240
+ {
241
+ "Form": {
242
+ "required": "This field is required",
243
+ "valueMissing": "This field is required",
244
+ "too_small": "{origin, select, string {At least {minimum, plural, one {# character} other {# characters}}} other {At least {minimum}}}",
245
+ "tooShort": "At least {minimum, plural, one {# character} other {# characters}}",
246
+ "SALE_ALREADY_COMPLETED": "This sale is already completed"
247
+ }
248
+ }
249
+ ```
250
+
251
+ **`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.
252
+
253
+ ```tsx
254
+ // actions.ts
255
+ "use server";
256
+ export const saveProfile = defineFormAction({
257
+ schema: z.object({ name: z.string().min(3) }),
258
+ action: input => async () => {
259
+ if (await isDown()) displayMessage("error", "SERVER_DOWN");
260
+ return await save(input); // becomes state.data
261
+ },
262
+ });
263
+ ```
264
+
265
+ ```tsx
266
+ <Form action={saveProfile} onResult={result => result.status === "success" && dialog.close()} className="flex flex-col gap-4">
267
+ <FormAlerts />
268
+ <FormField name="name" label="Name" schema={z.string().min(3)} />
269
+ <Button type="submit">Save</Button>
270
+ </Form>
271
+ ```
272
+
273
+ Forms can be nested. A submit inside an inner form does not submit the outer one.
274
+
275
+ #### `useFormMessages`
276
+
277
+ Returns the form-level messages of the latest result of the surrounding `BaseForm`, already passed through `formatMessage`. Call it anywhere inside the form.
278
+
279
+ ```ts
280
+ const { messages, submissionId } = useFormMessages();
281
+ // messages: { key: string, type: "error" | "warning", text: string }[]
282
+ // submissionId: changes once per completed submission
283
+ ```
284
+
285
+ ```tsx
286
+ // Inline alerts, placed anywhere in the form
287
+ const FormAlerts = () => {
288
+ const { messages } = useFormMessages();
289
+ return messages.map(m => <Alert key={m.key} type={m.type}>{m.text}</Alert>);
290
+ };
291
+
292
+ // Toasts: fire once per submission, not on every re-render
293
+ const FormToasts = () => {
294
+ const { messages, submissionId } = useFormMessages();
295
+ useEffect(() => {
296
+ messages.forEach(m => toast(m.type, m.text));
297
+ }, [submissionId]);
298
+ return null;
299
+ };
300
+ ```
301
+
302
+ #### `BaseFormField`
303
+
304
+ 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`.
305
+
306
+ | Prop | Type | Description |
307
+ |------|------|-------------|
308
+ | `name` | `string` | Field name. It also links the server errors in `fieldErrors[name]` |
309
+ | `schema` | `ZodType` | Source of the HTML constraints applied to the control |
310
+ | `label` | `string` | Label text. No label is rendered when omitted |
311
+ | `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 |
312
+ | `renderLabel` | `RenderProp<"label", FieldState>` | Style the label |
313
+ | `renderErrors` | `RenderProp<"div", FieldState>` | Style client-side and server-side error messages. Each error is its own element |
314
+ | `className` | `string` | Classes for the field root (a flex column by default) |
315
+
316
+ 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).
317
+
318
+ ```tsx
319
+ <BaseFormField
320
+ name="username"
321
+ label="Username"
322
+ schema={z.string().min(3).max(20)}
323
+ control={<Input />}
324
+ renderErrors={<p className="text-sm text-red-600" />}
325
+ />
326
+ ```
327
+
328
+ **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:
329
+
330
+ ```ts
331
+ // src/schemas/user.ts
332
+ import { z } from "zod";
333
+
334
+ export const UserSchema = z.object({
335
+ username: z.string().min(3).max(20),
336
+ email: z.email(),
337
+ });
338
+ ```
339
+
340
+ ```tsx
341
+ <BaseFormField name="username" label="Username" schema={UserSchema.shape.username} control={<Input />} />
342
+ <BaseFormField name="email" label="Email" schema={UserSchema.shape.email} control={<Input type="email" />} />
343
+ ```
344
+
345
+ 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.
346
+
347
+ ### `@omer-x/tailwind-ui-kit/dialog`
348
+
349
+ #### `BaseDialog`
350
+
351
+ 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:
352
+
353
+ ```tsx
354
+ import { BaseDialog } from "@omer-x/tailwind-ui-kit/dialog";
355
+
356
+ <BaseDialog>
357
+ <BaseDialog.Trigger render={<Button />}>Delete</BaseDialog.Trigger>
358
+ <BaseDialog.Popup className="rounded-lg bg-white p-6 shadow-lg">
359
+ <BaseDialog.Title>Delete item?</BaseDialog.Title>
360
+ <BaseDialog.Description>This can't be undone.</BaseDialog.Description>
361
+ <BaseDialog.Close render={<Button />}>Cancel</BaseDialog.Close>
362
+ </BaseDialog.Popup>
363
+ </BaseDialog>
364
+ ```
365
+
366
+ 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.
367
+
368
+ | Part | Renders | Description |
369
+ |------|---------|-------------|
370
+ | `BaseDialog` | nothing | Groups the parts and holds the open state |
371
+ | `BaseDialog.Trigger` | `<button>` | Opens the dialog. `data-popup-open` while its dialog is open |
372
+ | `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 |
373
+ | `BaseDialog.Title` | `<h2>` | The heading that names the dialog (`text-xl font-semibold`) |
374
+ | `BaseDialog.Description` | `<p>` | Describes the dialog to assistive technology |
375
+ | `BaseDialog.Close` | `<button>` | Closes the dialog |
376
+
377
+ Every part takes `className` and `render`. `Trigger` and `Close` also take `nativeButton` (set it to `false` when `render` doesn't render a `<button>`).
378
+
379
+ `BaseDialog` props:
380
+
381
+ | Prop | Type | Default | Description |
382
+ |------|------|---------|-------------|
383
+ | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
384
+ | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
385
+ | `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
386
+ | `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 |
387
+ | `disablePointerDismissal` | `boolean` | `false` | Keeps the dialog open on outside presses |
388
+ | `handle` | `DialogHandle<Payload>` | | Connects triggers outside the dialog and opens it from code (see below) |
389
+ | `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open dialog belongs to |
390
+ | `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the dialog |
391
+
392
+ `BaseDialog.Popup` props:
393
+
394
+ | Prop | Type | Default | Description |
395
+ |------|------|---------|-------------|
396
+ | `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` |
397
+ | `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"`) |
398
+ | `finalFocus` | `DialogFocusTarget` | `true` | The element focused on close. `true` is the trigger |
399
+ | `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the popup is portaled to |
400
+ | `keepMounted` | `boolean` | `false` | Keeps the popup in the DOM while closed |
401
+ | `backdrop` | `boolean` | `true` | Set to `false` for no backdrop. Nested dialogs never render one |
402
+ | `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` |
403
+ | `render` | `RenderProp<"div", DialogPopupState>` | | The state is `{ open, nested, nestedDialogOpen }` |
404
+
405
+ 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).
406
+
407
+ **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.
408
+
409
+ #### `createDialogHandle`
410
+
411
+ 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:
412
+
413
+ ```tsx
414
+ import { BaseDialog, createDialogHandle } from "@omer-x/tailwind-ui-kit/dialog";
415
+
416
+ const deleteDialog = createDialogHandle<{ id: string, name: string }>();
417
+
418
+ // triggers anywhere on the page
419
+ <BaseDialog.Trigger handle={deleteDialog} payload={{ id: p.id, name: p.name }} render={<Button />}>Delete</BaseDialog.Trigger>
420
+
421
+ // one dialog on the page
422
+ <BaseDialog handle={deleteDialog}>
423
+ {({ payload }) => payload && (
424
+ <BaseDialog.Popup size="sm">
425
+ <BaseDialog.Title>Delete {payload.name}?</BaseDialog.Title>
426
+ </BaseDialog.Popup>
427
+ )}
428
+ </BaseDialog>
429
+
430
+ // from code
431
+ deleteDialog.openWithPayload({ id, name });
432
+ ```
433
+
434
+ A `DialogHandle<Payload>` has `open(triggerId?)`, `openWithPayload(payload)`, `close()` and `isOpen`.
435
+
436
+ - Calls are **ignored while the dialog isn't mounted**. Keep the `BaseDialog` with the handle rendered.
437
+ - Call them **from event handlers or effects, never during render**.
438
+
439
+ #### `BaseAlertDialog`
440
+
441
+ 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:
442
+
443
+ - The popup has `role="alertdialog"`.
444
+ - It is always modal, and outside presses don't close it. Escape and `Close` buttons still do. There are no `modal` or `disablePointerDismissal` props.
445
+ - `Popup`, `Title`, `Description` and `Close` are `BaseDialog`'s parts, so they look the same and take the same props (`size`, `initialFocus`, `renderBackdrop`, …).
446
+
447
+ ```tsx
448
+ import { BaseAlertDialog } from "@omer-x/tailwind-ui-kit/dialog";
449
+
450
+ <BaseAlertDialog>
451
+ <BaseAlertDialog.Trigger render={<Button />}>Discard draft</BaseAlertDialog.Trigger>
452
+ <BaseAlertDialog.Popup size="sm" className="rounded-lg bg-white p-6 shadow-lg">
453
+ <BaseAlertDialog.Title>Discard draft?</BaseAlertDialog.Title>
454
+ <BaseAlertDialog.Description>You can't undo this action.</BaseAlertDialog.Description>
455
+ <BaseAlertDialog.Close render={<Button />}>Cancel</BaseAlertDialog.Close>
456
+ <BaseAlertDialog.Close render={<Button />} onClick={discard}>Discard</BaseAlertDialog.Close>
457
+ </BaseAlertDialog.Popup>
458
+ </BaseAlertDialog>
459
+ ```
460
+
461
+ | Part | Renders | Description |
462
+ |------|---------|-------------|
463
+ | `BaseAlertDialog` | nothing | Groups the parts and holds the open state |
464
+ | `BaseAlertDialog.Trigger` | `<button>` | Opens the alert dialog. `data-popup-open` while its alert dialog is open |
465
+ | `BaseAlertDialog.Popup` | `<div>` | Same as `BaseDialog.Popup` |
466
+ | `BaseAlertDialog.Title` | `<h2>` | Same as `BaseDialog.Title` |
467
+ | `BaseAlertDialog.Description` | `<p>` | Same as `BaseDialog.Description` |
468
+ | `BaseAlertDialog.Close` | `<button>` | Same as `BaseDialog.Close` |
469
+
470
+ `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 }`).
471
+
472
+ Put it inside a `BaseDialog.Popup` to confirm something from a dialog: it stacks on top like a nested dialog.
473
+
474
+ #### `createAlertDialogHandle`
475
+
476
+ `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`:
477
+
478
+ ```tsx
479
+ import { BaseAlertDialog, createAlertDialogHandle } from "@omer-x/tailwind-ui-kit/dialog";
480
+
481
+ const removeAlert = createAlertDialogHandle<{ id: string, name: string }>();
482
+
483
+ <BaseAlertDialog.Trigger handle={removeAlert} payload={member} render={<Button />}>Remove</BaseAlertDialog.Trigger>
484
+
485
+ <BaseAlertDialog handle={removeAlert}>
486
+ {({ payload }) => payload && (
487
+ <BaseAlertDialog.Popup size="sm">
488
+ <BaseAlertDialog.Title>Remove {payload.name}?</BaseAlertDialog.Title>
489
+ </BaseAlertDialog.Popup>
490
+ )}
491
+ </BaseAlertDialog>
492
+ ```
493
+
494
+ ### `@omer-x/tailwind-ui-kit/disclosure`
495
+
496
+ #### `BaseAccordion`
497
+
498
+ 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:
499
+
500
+ ```tsx
501
+ import { BaseAccordion } from "@omer-x/tailwind-ui-kit/disclosure";
502
+
503
+ <BaseAccordion className="rounded-md border">
504
+ <BaseAccordion.Item value="shipping" className="border-b last:border-b-0">
505
+ <BaseAccordion.Trigger className="px-5 py-4 data-panel-open:bg-blue-50" icon={<ChevronDown />} iconClassName="in-data-panel-open:rotate-180">
506
+ Shipping
507
+ </BaseAccordion.Trigger>
508
+ <BaseAccordion.Panel>
509
+ <div className="px-5 py-4">Orders ship within two days.</div>
510
+ </BaseAccordion.Panel>
511
+ </BaseAccordion.Item>
512
+ </BaseAccordion>
513
+ ```
514
+
515
+ 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.
516
+
517
+ | Part | Renders | Description |
518
+ |------|---------|-------------|
519
+ | `BaseAccordion` | `<div>` | Groups the items and holds which ones are open |
520
+ | `BaseAccordion.Item` | `<div>` | Groups a trigger with its panel |
521
+ | `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 |
522
+ | `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 |
523
+
524
+ Every part takes `className` and `render`.
525
+
526
+ `BaseAccordion` props:
527
+
528
+ | Prop | Type | Default | Description |
529
+ |------|------|---------|-------------|
530
+ | `value` / `defaultValue` | `Value[]` | `[]` | Controlled / initial values of the open items |
531
+ | `onValueChange` | `(value, event) => void` | | Called with the open items' values and the DOM event that changed them (`undefined` when changed from code) |
532
+ | `multiple` | `boolean` | `false` | Lets several items be open at once |
533
+ | `disabled` | `boolean` | `false` | Ignores user interaction on every item |
534
+ | `keepMounted` | `boolean` | `false` | Keeps closed panels in the DOM |
535
+ | `hiddenUntilFound` | `boolean` | `false` | Keeps closed panels hidden with `hidden="until-found"`, so the browser's page search finds and opens them. Overrides `keepMounted` |
536
+ | `render` | `RenderProp<"div", AccordionState>` | | The state is `{ value, disabled }` |
537
+
538
+ `BaseAccordion.Item` props:
539
+
540
+ | Prop | Type | Default | Description |
541
+ |------|------|---------|-------------|
542
+ | `value` | `unknown` | generated | Identifies the item in the accordion's `value` |
543
+ | `disabled` | `boolean` | `false` | Ignores user interaction on this item |
544
+ | `onOpenChange` | `(open, event) => void` | | Called with the item's new state and the DOM event |
545
+ | `render` | `RenderProp<"div", AccordionItemState>` | | The state is `{ open, disabled, index }` |
546
+
547
+ `BaseAccordion.Trigger` props:
548
+
549
+ | Prop | Type | Default | Description |
550
+ |------|------|---------|-------------|
551
+ | `icon` | `ReactNode` | | Shown after the text, in a `<span>` with a transform transition. Nothing is rendered without it |
552
+ | `iconClassName` | `string` | | Classes for the icon's `<span>`, e.g. `in-data-panel-open:rotate-180` |
553
+ | `headerClassName` | `string` | | Classes for the heading |
554
+ | `renderHeader` | `RenderProp<"h3", AccordionItemState>` | | Replaces the heading, e.g. `<h2 />` for another level |
555
+ | `render` | `RenderProp<"button", AccordionItemState>` | | Replaces the button |
556
+ | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
557
+
558
+ `BaseAccordion.Panel` takes `keepMounted` and `hiddenUntilFound` (overriding the accordion's) and `render` (`RenderProp<"div", AccordionPanelState>`, the item's state plus `transitionStatus`).
559
+
560
+ 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.
561
+
562
+ ### `@omer-x/tailwind-ui-kit/display`
563
+
564
+ #### `BaseAvatar`
565
+
566
+ 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.
567
+
568
+ ```tsx
569
+ import { BaseAvatar } from "@omer-x/tailwind-ui-kit/display";
570
+
571
+ <BaseAvatar size="sm" className="bg-neutral-200 font-medium">
572
+ <BaseAvatar.Image src={user.photoUrl} alt={user.name} />
573
+ <BaseAvatar.Fallback>{initials}</BaseAvatar.Fallback>
574
+ </BaseAvatar>
575
+ ```
576
+
577
+ 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.
578
+
579
+ | Part | Renders | Description |
580
+ |------|---------|-------------|
581
+ | `BaseAvatar` | `<span>` | A round, centered, `overflow-hidden` box of the given size. Make it square with `className="rounded-md"` |
582
+ | `BaseAvatar.Image` | `<img>` | The picture, covering the box (`size-full object-cover`). Rendered only once it has loaded |
583
+ | `BaseAvatar.Fallback` | `<span>` | Fills the box and centers its content. Rendered until the image has loaded |
584
+
585
+ Every part takes `className` and `render`.
586
+
587
+ `BaseAvatar` props:
588
+
589
+ | Prop | Type | Default | Description |
590
+ |------|------|---------|-------------|
591
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | `size-12 text-lg` / `size-10 text-base` / `size-8 text-sm` / `size-6 text-xs` |
592
+ | `render` | `RenderProp<"span", AvatarState>` | | The state is `{ imageLoadingStatus }`: `"idle"`, `"loading"`, `"loaded"` or `"error"` |
593
+
594
+ `BaseAvatar.Image` props:
595
+
596
+ | Prop | Type | Default | Description |
597
+ |------|------|---------|-------------|
598
+ | `onLoadingStatusChange` | `(status) => void` | | Called when the image starts loading, loads or fails |
599
+ | `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` |
600
+ | `render` | `RenderProp<"img", AvatarImageState>` | | The avatar's state plus `transitionStatus` |
601
+
602
+ `BaseAvatar.Fallback` props:
603
+
604
+ | Prop | Type | Default | Description |
605
+ |------|------|---------|-------------|
606
+ | `delay` | `number` | `0` | Milliseconds to wait before showing, so a fast image doesn't flash it |
607
+ | `render` | `RenderProp<"span", AvatarState>` | | |
608
+
609
+ 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.
610
+
611
+ ### `@omer-x/tailwind-ui-kit/layout`
612
+
613
+ #### `Container`
614
+
615
+ Tailwind's `container`, centered with horizontal padding (`container mx-auto px-3`). Accepts all `<div>` props.
616
+
617
+ ### `@omer-x/tailwind-ui-kit/page`
618
+
619
+ #### `Pagination`
620
+
621
+ 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.
622
+
623
+ | Prop | Type | Description |
624
+ |------|------|-------------|
625
+ | `totalItems` | `number` | Total number of items |
626
+ | `itemsPerPage` | `number` | Items per page |
627
+ | `currentPage` | `number` | Current page, starting at 1 |
628
+ | `siblings` | `number` | Pages shown on each side of the current one. Default `2`. `0` gives `« 1 … [50] … 100 »` |
629
+ | `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 |
630
+ | `renderButton` | render prop | Renders a disabled arrow (a disabled `<button>`) |
631
+ | `renderEllipsis` | render prop | Renders an ellipsis (a `<span aria-hidden>`) |
632
+ | `aria-label` | `string` | The navigation's label. Default `"Pagination"` |
633
+ | `previousLabel` / `nextLabel` | `string` | The arrows' accessible names. Default `"Previous page"` / `"Next page"` |
634
+ | `previousContent` / `nextContent` | `ReactNode` | The arrows' content, e.g. icons. Default `«` / `»` |
635
+ | `className` | `string` | Classes for the `<nav>`. Default `flex gap-3` |
636
+ | …rest | `<nav>` props | |
637
+
638
+ Style the current page with `aria-[current=page]:`.
639
+
640
+ ```tsx
641
+ import { Link } from "@/i18n/navigation";
642
+
643
+ <Pagination
644
+ totalItems={total}
645
+ itemsPerPage={20}
646
+ currentPage={page}
647
+ renderLink={(page, props) => (
648
+ <Link {...props} href={{ pathname: "/products", query: { ...searchParams, page } }} className="px-3 py-1 aria-[current=page]:font-bold" />
649
+ )}
650
+ renderButton={<button className="px-3 py-1 disabled:opacity-50" />}
651
+ renderEllipsis={<span className="px-3 py-1" />}
652
+ />
653
+ ```
654
+
655
+ #### `usePagination`
656
+
657
+ The logic behind `Pagination`, for a completely custom layout. It holds no state, so it also works in server components.
658
+
659
+ ```tsx
660
+ const items = usePagination({ totalItems, itemsPerPage, currentPage, siblings: 1 });
661
+ // [
662
+ // { type: "previous", page: 9, disabled: false },
663
+ // { type: "page", page: 1, current: false },
664
+ // { type: "ellipsis" },
665
+ // { type: "page", page: 10, current: true },
666
+ // …
667
+ // { type: "next", page: 11, disabled: false },
668
+ // ]
669
+ ```
670
+
671
+ ### `@omer-x/tailwind-ui-kit/table`
672
+
673
+ #### `TableCell`
674
+
675
+ A `<td>` that accepts all `<td>` props (`colSpan`, `rowSpan`, `title`, event handlers, …).
676
+
677
+ | Prop | Type | Description |
678
+ |------|------|-------------|
679
+ | `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`. |
680
+
681
+ ```tsx
682
+ <tr>
683
+ <TableCell overflow="truncate" className="max-w-48">{product.description}</TableCell>
684
+ <TableCell overflow={expanded ? "wrap" : "truncate"}>{product.notes}</TableCell>
685
+ </tr>
686
+ ```
687
+
688
+ #### `Tdx` (deprecated)
689
+
690
+ Use `<TableCell overflow="truncate">` instead. `Tdx` is kept as an alias for it and accepts the same `<td>` props.
691
+
692
+ ### `@omer-x/tailwind-ui-kit/elements`
693
+
694
+ 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.
695
+
696
+ ```tsx
697
+ import { JustDiv } from "@omer-x/tailwind-ui-kit/elements";
698
+
699
+ <JustDiv className="p-4" render={<section />}>…</JustDiv>
700
+ ```
701
+
702
+ ### `@omer-x/tailwind-ui-kit/hooks`
703
+
704
+ #### `useRipples`
705
+
706
+ The ripple effect of `BaseButton`, for your own clickable elements. Returns `[handleClick, ripples]`: call `handleClick` from `onClick` and render `ripples` inside the element.
707
+
708
+ - The element needs `relative` (the ripples are positioned absolutely and clipped to its rounded corners).
709
+ - 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.
710
+ - It imports a CSS module (see [Setup](#2-your-bundler-must-support-css-modules)).
711
+
712
+ ```tsx
713
+ import { useRipples } from "@omer-x/tailwind-ui-kit/hooks";
714
+
715
+ const Chip = ({ children, onClick, ...props }: ComponentProps<"button">) => {
716
+ const [handleRipple, ripples] = useRipples();
717
+ return (
718
+ <button
719
+ {...props}
720
+ className="relative rounded-full px-3 py-1"
721
+ onClick={event => { handleRipple(event); onClick?.(event); }}
722
+ >
723
+ {children}
724
+ {ripples}
725
+ </button>
726
+ );
727
+ };
728
+ ```
729
+
730
+ ### `@omer-x/tailwind-ui-kit/utils`
731
+
732
+ Helpers for building your own components on the kit, so you never import Base UI.
733
+
734
+ #### `RenderProp`
735
+
736
+ 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).
737
+
738
+ #### `useRender`
739
+
740
+ Renders an element that can be replaced through a `render` prop, with your props merged into it.
741
+
742
+ | Option | Type | Description |
743
+ |--------|------|-------------|
744
+ | `defaultTagName` | `keyof JSX.IntrinsicElements` | The element rendered when `render` is missing |
745
+ | `render` | `RenderProp<Tag, State>` | The `render` prop of your component |
746
+ | `props` | props of `Tag` | Merged into the rendered element |
747
+ | `state` | `State` | Passed to a `render` function, and set as data attributes (`{ active: true }` becomes `data-active`) |
748
+
749
+ ```tsx
750
+ import { type RenderProp, useRender } from "@omer-x/tailwind-ui-kit/utils";
751
+
752
+ type BadgeProps = ComponentProps<"span"> & {
753
+ render?: RenderProp<"span">,
754
+ };
755
+
756
+ const Badge = ({ render, className, ...props }: BadgeProps) => useRender({
757
+ defaultTagName: "span",
758
+ render,
759
+ props: { ...props, className: cn("rounded px-2 text-xs", className) },
760
+ });
761
+ ```
762
+
763
+ #### `mergeProps`
764
+
765
+ 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.
766
+
767
+ ```tsx
768
+ useRender({ defaultTagName: "div", render, props: mergeProps<"div">({ className: "p-4", onClick: track }, props) });
769
+ ```
770
+
771
+ #### `cn` (deprecated)
772
+
773
+ Kept for backward compatibility. Import from the [`cn`](https://www.npmjs.com/package/cn) package directly instead:
774
+
775
+ ```ts
776
+ import { cn } from "cn";
777
+ ```
778
+
779
+ ## Development
780
+
781
+ ```sh
782
+ npm run dev # Storybook on http://localhost:3000
783
+ npm test # Vitest with coverage: unit tests and every story (headless Chromium)
784
+ npm run lint
785
+ npm run build # tsdown → dist/
786
+ ```
787
+
788
+ Contributor and agent guidelines live in [`AGENTS.md`](./AGENTS.md) and [`ai/`](./ai).
789
+
790
+ ## License
791
+
792
+ MIT