@omer-x/tailwind-ui-kit 1.0.0-alpha.18 → 1.0.0-alpha.19

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 (67) hide show
  1. package/MIGRATION.md +164 -0
  2. package/README.md +390 -0
  3. package/dist/components/button/BaseButton.d.ts +27 -11
  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/AnimatedPopup.d.ts +3 -6
  8. package/dist/components/dialog/AnimatedPopup.js +6 -31
  9. package/dist/components/dialog/DialogBackdrop.d.ts +3 -6
  10. package/dist/components/dialog/DialogBackdrop.js +6 -22
  11. package/dist/components/dialog/DialogTitle.d.ts +3 -6
  12. package/dist/components/dialog/DialogTitle.js +6 -15
  13. package/dist/components/dialog/index.d.ts +4 -5
  14. package/dist/components/dialog/index.js +4 -8
  15. package/dist/components/elements/JustAnchor.d.ts +3 -6
  16. package/dist/components/elements/JustAnchor.js +8 -13
  17. package/dist/components/elements/JustButton.d.ts +3 -6
  18. package/dist/components/elements/JustButton.js +8 -13
  19. package/dist/components/elements/JustDiv.d.ts +3 -6
  20. package/dist/components/elements/JustDiv.js +8 -13
  21. package/dist/components/elements/JustInput.d.ts +3 -6
  22. package/dist/components/elements/JustInput.js +8 -13
  23. package/dist/components/form/BaseForm.d.ts +12 -15
  24. package/dist/components/form/BaseForm.js +72 -75
  25. package/dist/components/form/BaseFormField.d.ts +12 -19
  26. package/dist/components/form/BaseFormField.js +29 -24
  27. package/dist/components/form/BaseInput.d.ts +5 -9
  28. package/dist/components/form/BaseInput.js +20 -31
  29. package/dist/components/form/BaseSwitch.d.ts +6 -9
  30. package/dist/components/form/BaseSwitch.js +18 -51
  31. package/dist/components/form/ClientSideError.d.ts +9 -0
  32. package/dist/components/form/ClientSideError.js +39 -0
  33. package/dist/components/form/FieldRoot.d.ts +6 -9
  34. package/dist/components/form/FieldRoot.js +16 -18
  35. package/dist/components/form/FormContext.d.ts +26 -9
  36. package/dist/components/form/FormContext.js +9 -7
  37. package/dist/components/form/ServerSideError.d.ts +6 -10
  38. package/dist/components/form/ServerSideError.js +10 -14
  39. package/dist/components/form/index.d.ts +7 -11
  40. package/dist/components/form/index.js +6 -10
  41. package/dist/components/form/useFormMessages.d.ts +10 -0
  42. package/dist/components/form/useFormMessages.js +16 -0
  43. package/dist/components/layout/Container.d.ts +5 -8
  44. package/dist/components/layout/Container.js +8 -10
  45. package/dist/components/layout/index.d.ts +2 -2
  46. package/dist/components/layout/index.js +1 -4
  47. package/dist/components/page/Pagination.d.ts +11 -15
  48. package/dist/components/page/Pagination.js +60 -48
  49. package/dist/components/page/index.d.ts +2 -5
  50. package/dist/components/page/index.js +1 -4
  51. package/dist/components/table/Tdx.d.ts +5 -8
  52. package/dist/components/table/Tdx.js +13 -9
  53. package/dist/components/table/index.d.ts +2 -2
  54. package/dist/components/table/index.js +1 -4
  55. package/dist/hooks/useRipples.d.ts +2 -5
  56. package/dist/hooks/useRipples.js +46 -33
  57. package/dist/styles/ripple.module.css +1 -0
  58. package/dist/utils/cn.d.ts +6 -5
  59. package/dist/utils/cn.js +8 -6
  60. package/dist/utils/dirty-form.d.ts +1 -3
  61. package/dist/utils/dirty-form.js +24 -39
  62. package/dist/utils/index.d.ts +2 -2
  63. package/dist/utils/index.js +1 -4
  64. package/package.json +27 -24
  65. package/dist/components/button/PulseButton.d.ts +0 -8
  66. package/dist/components/button/PulseButton.js +0 -41
  67. package/dist/styles/ripple.module.d.ts +0 -2
package/MIGRATION.md ADDED
@@ -0,0 +1,164 @@
1
+ # Migrating from 1.0.0-alpha.18 to 1.0.0-alpha.19+
2
+
3
+ Each breaking change has its own section with before / after code and the reason for it.
4
+
5
+ - **Mechanical:** a rename or a type change. The compiler points you to every place to fix.
6
+ - **Check manually:** behavior changed. Code still compiles, but may act differently.
7
+
8
+ ## Button
9
+
10
+ ### Font Awesome is removed: pass a `spinner` (mechanical, #5, #8)
11
+
12
+ The kit no longer depends on Font Awesome. `BaseButton` used to show Font Awesome's spinner while pending; now it shows the `spinner` you pass, and nothing without one. Set it once in your themed wrapper:
13
+
14
+ ```diff
15
+ <BaseButton
16
+ {...props}
17
+ + spinner={<FontAwesomeIcon icon={faSpinner} spinPulse />}
18
+ className={...}
19
+ />
20
+ ```
21
+
22
+ You can remove the Font Awesome peer dependencies and the `@fortawesome/fontawesome-svg-core/styles.css` import if your app doesn't use Font Awesome itself.
23
+
24
+ **Why:** the kit needed three peer dependencies and Font Awesome's CSS for one spinner, and apps couldn't choose their own icon.
25
+
26
+ ### Submit buttons get the full pending state while their form submits (check manually, #5)
27
+
28
+ A submit button inside a submitting form now behaves exactly like `pending`: it shows the spinner, ignores clicks, **keeps keyboard focus**, and sets `aria-busy="true"` and `data-pending`. `pending` itself now really blocks clicks (before, a pending button could still be clicked and submit twice).
29
+
30
+ `data-submitting` is replaced by `data-pending`:
31
+
32
+ ```diff
33
+ - className="data-submitting:opacity-50"
34
+ + className="data-pending:opacity-50"
35
+ ```
36
+
37
+ Remove any `pending={isSubmitting}` you wired up by hand for submit buttons of `BaseForm`.
38
+
39
+ **Why:** "submitting" and "pending" were two states that looked and behaved differently: a submitting button was disabled with no spinner and lost focus.
40
+
41
+ ### Icon-only buttons: use `iconOnly` (mechanical, #5)
42
+
43
+ ```diff
44
+ - <Button className="w-10 px-0"><TrashIcon /></Button>
45
+ + <Button iconOnly aria-label="Delete"><TrashIcon /></Button>
46
+ ```
47
+
48
+ `iconOnly` makes the button square at every size, and the types require an `aria-label`. While pending, the spinner replaces the icon.
49
+
50
+ ## Form
51
+
52
+ ### Fields are validated in the browser (check manually, #65)
53
+
54
+ `BaseFormField`'s constraints (`required`, `minLength`, `max`, … from the schema) used to block nothing: every submit reached the action. Now an invalid field blocks the submit and shows its browser error (`valueMissing`, `tooShort`, …) through `formatMessage`, so add those codes to your translations.
55
+
56
+ The `control` you pass is rendered as Base UI's field control, so it now gets `aria-invalid` and `data-invalid` when it has an error.
57
+
58
+ **Why:** the control was a plain `<input>` that Base UI's form didn't know about, and the form turns off the browser's own validation.
59
+
60
+ ### `BaseForm` takes a `@omer-x/next-form-actions` v2 action (mechanical, #10)
61
+
62
+ The action now returns the typed `FormActionState` of `@omer-x/next-form-actions` v2 instead of a flat `Record<string, string>`. Install it, and migrate your actions with [its own guide](https://github.com/omermecitoglu/next-form-actions/blob/main/MIGRATION.md).
63
+
64
+ ```sh
65
+ npm install @omer-x/next-form-actions@^2.0.0-alpha.1
66
+ ```
67
+
68
+ ```diff
69
+ - export async function saveProfile(_state: unknown, formData: FormData) {
70
+ - if (await isTaken(name)) return { name: "name_taken" };
71
+ - return { "[success]": "saved" };
72
+ - }
73
+ + export const saveProfile = defineFormAction({
74
+ + schema: z.object({ name: z.string().refine(async name => !(await isTaken(name)), { params: { customErrorCode: "taken" } }) }),
75
+ + action: input => async () => save(input),
76
+ + });
77
+ ```
78
+
79
+ **Why:** the flat record mixed field errors and form messages in one namespace, its rules were invisible in the types, it couldn't carry data, and success had to be guessed from a `[success]` key.
80
+
81
+ ### `messages` and `clientSideErrors` are replaced by `formatMessage` (mechanical, #10)
82
+
83
+ `BaseForm`'s `messages`, and `BaseFormField`'s `messages` and `clientSideErrors`, are removed. One `formatMessage(code, params)` on `BaseForm` formats every text: server error codes, browser validity states and form message texts. Set it in your themed form wrapper:
84
+
85
+ ```diff
86
+ // src/components/Form.tsx
87
+ "use client";
88
+ + const t = useTranslations("Form");
89
+ - <BaseForm {...props} messages={messages} />
90
+ + <BaseForm {...props} formatMessage={(code, params) => t(code, params)} />
91
+ ```
92
+
93
+ ```diff
94
+ <BaseFormField
95
+ name="username"
96
+ schema={z.string().min(3)}
97
+ - clientSideErrors={{ valueMissing: "Required", tooShort: min => `At least ${min} characters` }}
98
+ />
99
+ ```
100
+
101
+ ```diff
102
+ // en.json
103
+ "Form": {
104
+ - "REQUIRED": "This field is required",
105
+ + "required": "This field is required",
106
+ + "valueMissing": "This field is required",
107
+ + "tooShort": "At least {minimum} characters",
108
+ + "too_small": "At least {minimum} characters"
109
+ }
110
+ ```
111
+
112
+ Server codes are now lowercase Zod issue codes (`required`, `too_small`, …) with params like `{ minimum, origin }`. Browser validity states get `{ minimum }` (`tooShort`, `rangeUnderflow`) or `{ maximum }` (`tooLong`, `rangeOverflow`). See the README for the full list.
113
+
114
+ **Why:** server and browser errors were configured in two places, and plain lookup maps couldn't use error params ("at least 3 characters") or plurals.
115
+
116
+ ### `BaseForm` renders no messages: use `useFormMessages()` (mechanical, #58)
117
+
118
+ `renderMessages` is removed, and `BaseForm` no longer renders form-level messages at the top of the form. Render them yourself, wherever you want:
119
+
120
+ ```diff
121
+ - <Form action={save} renderMessages={<div className="rounded p-3 data-[message-type=default]:bg-red-100" />}>
122
+ + <Form action={save}>
123
+ + <FormAlerts />
124
+ ...
125
+ </Form>
126
+ ```
127
+
128
+ ```tsx
129
+ const FormAlerts = () => {
130
+ const { messages } = useFormMessages();
131
+ return messages.map(m => <Alert key={m.key} type={m.type}>{m.text}</Alert>);
132
+ };
133
+ ```
134
+
135
+ `data-message-type` is gone. Each message has a `type` (`"error"` or `"warning"`) instead. For toasts, run your effect on `submissionId`, which changes once per submission.
136
+
137
+ **Why:** apps couldn't show messages as toasts, use their own alert boxes, or move them (next to the submit button, into a dialog footer, …).
138
+
139
+ ### `onStateChange` is replaced by `onResult` (check manually, #62)
140
+
141
+ ```diff
142
+ - <Form action={update} onStateChange={state => state["[success]"] && dialog.close()}>
143
+ + <Form action={update} onResult={result => result.status === "success" && dialog.close()}>
144
+ ```
145
+
146
+ `onResult` is called once per completed submission, right when the action returns. Unlike `onStateChange`, it is **not** called on mount, and two identical results in a row trigger two calls. Remove any guard you added against the initial call.
147
+
148
+ **Why:** `onStateChange` ran from an effect, so it fired on mount with the empty initial state, and success had to be guessed from the result's keys.
149
+
150
+ ### Forms no longer reset after submit (check manually, #4)
151
+
152
+ `BaseForm` used to submit through `<form action>`, which made React reset the form after every submission. That also put controlled checkboxes and selects back to their first rendered values in the DOM. Now nothing is reset: after a failure the user keeps what they typed.
153
+
154
+ Remove the workarounds:
155
+
156
+ - hidden inputs that mirrored controlled checkbox or select values,
157
+ - a `key` on fields or on the form that changed after each submit.
158
+
159
+ If a form should be cleared after a **successful** submit (e.g. "add another"), use the new `resetOnSuccess` prop instead of changing its `key`:
160
+
161
+ ```diff
162
+ - <Form key={formKey} action={create} onStateChange={() => setFormKey(k => k + 1)}>
163
+ + <Form action={create} resetOnSuccess>
164
+ ```
package/README.md ADDED
@@ -0,0 +1,390 @@
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, exactly like [Base UI's `render`](https://base-ui.com/react/handbook/composition).
13
+ 3. **Style states with data attributes.** Base UI sets attributes such as `data-disabled`, `data-checked` and `data-starting-style`. Target them with Tailwind variants (`data-disabled:opacity-50`).
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. 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
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) for its `schema` prop.
34
+
35
+ ## Setup
36
+
37
+ ### 1. Let Tailwind scan the package
38
+
39
+ 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:
40
+
41
+ ```css
42
+ /* src/app/globals.css */
43
+ @import "tailwindcss";
44
+ @source "../../node_modules/@omer-x/tailwind-ui-kit";
45
+ ```
46
+
47
+ Some components use the `dark:` variant (e.g. `DialogBackdrop`). They follow whatever `dark` variant your app defines.
48
+
49
+ ### 2. Your bundler must support CSS modules
50
+
51
+ The ripple effect imports a CSS module from `node_modules`. Next.js and Vite handle this out of the box.
52
+
53
+ ## Theming: wrap once, use everywhere
54
+
55
+ Create your themed versions in your app and import those instead of the base components:
56
+
57
+ ```tsx
58
+ // src/components/Button.tsx
59
+ "use client";
60
+ import { BaseButton } from "@omer-x/tailwind-ui-kit/button";
61
+ import { cn } from "cn";
62
+ import Spinner from "./Spinner";
63
+ import type { ComponentProps } from "react";
64
+
65
+ type ButtonProps = ComponentProps<typeof BaseButton> & {
66
+ variant?: "primary" | "secondary",
67
+ };
68
+
69
+ const Button = ({ variant = "primary", className, ...props }: ButtonProps) => (
70
+ <BaseButton
71
+ {...props}
72
+ spinner={<Spinner />} // your app's icon; the kit bundles no icons
73
+ className={cn({
74
+ "bg-blue-600 text-white hover:bg-blue-700 focus-visible:outline-blue-600": variant === "primary",
75
+ "bg-neutral-200 text-neutral-900 hover:bg-neutral-300 focus-visible:outline-neutral-500": variant === "secondary",
76
+ }, "data-disabled:opacity-50", className)}
77
+ />
78
+ );
79
+
80
+ export default Button;
81
+ ```
82
+
83
+ ## Components
84
+
85
+ There is no root entry point. Import from the subpaths below.
86
+
87
+ ### `@omer-x/tailwind-ui-kit/button`
88
+
89
+ #### `BaseButton`
90
+
91
+ A Base UI [`Button`](https://base-ui.com/react/components/button) with sizes, a pending state and a ripple effect on click.
92
+
93
+ | Prop | Type | Default | Description |
94
+ |------|------|---------|-------------|
95
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | Height, padding, font size and gap |
96
+ | `pending` | `boolean` | `false` | Shows the spinner, blocks clicks and keeps the button focusable |
97
+ | `spinner` | `ReactNode` | | Shown while pending. Without it nothing is shown, and `data-pending` still marks the state |
98
+ | `iconOnly` | `boolean` | `false` | A square button for a single icon. Requires `aria-label`. While pending, the spinner replaces the icon |
99
+ | …rest | Base UI `Button` props | | `disabled`, `focusableWhenDisabled`, `type`, `onClick`, `render`, `nativeButton`, … |
100
+
101
+ - **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`.
102
+ - Children are laid out with flex and a size-based gap, so icons and text line up without extra markup.
103
+ - 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.
104
+ - The kit bundles no icons. Pass your own `spinner` (and icons as children), usually once in your themed wrapper.
105
+
106
+ ```tsx
107
+ <Button size="sm" pending={isSaving}>Save</Button>
108
+ <Button iconOnly aria-label="Delete"><TrashIcon /></Button>
109
+ ```
110
+
111
+ **Links that look like buttons:** render your app's own link (so typed routes keep working) and tell Base UI it isn't a native button:
112
+
113
+ ```tsx
114
+ <Button render={<Link href="/products/new" />} nativeButton={false}>New product</Button>
115
+ ```
116
+
117
+ ### `@omer-x/tailwind-ui-kit/form`
118
+
119
+ #### `BaseInput`
120
+
121
+ A plain `<input>` with sizes, rounded corners and a transparent outline ready for focus styles. It accepts all input props plus `render`.
122
+
123
+ | Prop | Type | Default |
124
+ |------|------|---------|
125
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` |
126
+
127
+ ```tsx
128
+ <BaseInput name="email" className="border border-neutral-300 focus:outline-blue-500" />
129
+ ```
130
+
131
+ #### `BaseSwitch`
132
+
133
+ 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.
134
+
135
+ | Prop | Type | Default | Description |
136
+ |------|------|---------|-------------|
137
+ | `label` | `ReactNode` | | Text next to the switch (required) |
138
+ | `renderThumb` | render prop | | Style the thumb |
139
+ | `value` | `string` | `"true"` | Submitted when checked |
140
+ | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
141
+ | …rest | Base UI `Switch.Root` props | | `name`, `checked`, `defaultChecked`, `onCheckedChange`, … |
142
+
143
+ ```tsx
144
+ <BaseSwitch
145
+ name="active"
146
+ label="Active"
147
+ className="rounded-full bg-neutral-300 data-checked:bg-blue-600"
148
+ renderThumb={<span className="rounded-full bg-white" />}
149
+ />
150
+ ```
151
+
152
+ #### `BaseForm`
153
+
154
+ 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:
155
+
156
+ ```sh
157
+ npm install @omer-x/next-form-actions@^2.0.0-alpha.1
158
+ ```
159
+
160
+ | Prop | Type | Description |
161
+ |------|------|-------------|
162
+ | `action` | `FormAction<Data>` | The action, e.g. `saveProduct` or `completeSale.bind(null, saleId)`. `Data` is what it returns on success |
163
+ | `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 |
164
+ | `onResult` | `(result: FormActionState<Data>) => void` | Called once per completed submission, when the action returns. Never on mount |
165
+ | `resetOnSuccess` | `boolean` | After a successful result, reset every field inside the form to its default (see below) |
166
+ | `defaultValues` | `Record<string, unknown>` | Initial values, used by `onlyDirty` |
167
+ | `onlyDirty` | `boolean` | Submit only the fields whose value differs from `defaultValues` |
168
+ | …rest | `<form>` props | Except `action` |
169
+
170
+ **How the result is used.** The action resolves to `{ status: "idle" }`, `{ status: "success", data }` or `{ status: "failure", fieldErrors, message? }`:
171
+
172
+ - `fieldErrors[name]` are shown under the `BaseFormField` with that `name`. A field can have several errors.
173
+ - `message` (`{ type: "error" | "warning", text }`) is a **form-level message**.
174
+ - 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.
175
+ - `BaseForm` renders no form-level messages itself. Show them wherever you like with `useFormMessages()`.
176
+
177
+ The form never resets after a submission, so after a failure the user keeps what they typed. That includes controlled checkboxes and selects.
178
+
179
+ **`formatMessage`** receives every text the form shows:
180
+
181
+ | What | `code` | `params` |
182
+ |------|--------|----------|
183
+ | 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" }` |
184
+ | 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) |
185
+ | Form message | The message's `text`, e.g. `SALE_ALREADY_COMPLETED` | none |
186
+
187
+ 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:
188
+
189
+ ```tsx
190
+ // src/components/Form.tsx
191
+ "use client";
192
+ import { BaseForm } from "@omer-x/tailwind-ui-kit/form";
193
+ import { useTranslations } from "next-intl";
194
+ import type { ComponentProps } from "react";
195
+
196
+ const Form = <Data,>(props: ComponentProps<typeof BaseForm<Data>>) => {
197
+ const t = useTranslations("Form");
198
+ return <BaseForm {...props} formatMessage={(code, params) => t(code, params as Record<string, string>)} />;
199
+ };
200
+
201
+ export default Form;
202
+ ```
203
+
204
+ ```json
205
+ {
206
+ "Form": {
207
+ "required": "This field is required",
208
+ "valueMissing": "This field is required",
209
+ "too_small": "{origin, select, string {At least {minimum, plural, one {# character} other {# characters}}} other {At least {minimum}}}",
210
+ "tooShort": "At least {minimum, plural, one {# character} other {# characters}}",
211
+ "SALE_ALREADY_COMPLETED": "This sale is already completed"
212
+ }
213
+ }
214
+ ```
215
+
216
+ **`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.
217
+
218
+ ```tsx
219
+ // actions.ts
220
+ "use server";
221
+ export const saveProfile = defineFormAction({
222
+ schema: z.object({ name: z.string().min(3) }),
223
+ action: input => async () => {
224
+ if (await isDown()) displayMessage("error", "SERVER_DOWN");
225
+ return await save(input); // becomes state.data
226
+ },
227
+ });
228
+ ```
229
+
230
+ ```tsx
231
+ <Form action={saveProfile} onResult={result => result.status === "success" && dialog.close()} className="flex flex-col gap-4">
232
+ <FormAlerts />
233
+ <FormField name="name" label="Name" schema={z.string().min(3)} />
234
+ <Button type="submit">Save</Button>
235
+ </Form>
236
+ ```
237
+
238
+ Forms can be nested. A submit inside an inner form does not submit the outer one.
239
+
240
+ #### `useFormMessages`
241
+
242
+ Returns the form-level messages of the latest result of the surrounding `BaseForm`, already passed through `formatMessage`. Call it anywhere inside the form.
243
+
244
+ ```ts
245
+ const { messages, submissionId } = useFormMessages();
246
+ // messages: { key: string, type: "error" | "warning", text: string }[]
247
+ // submissionId: changes once per completed submission
248
+ ```
249
+
250
+ ```tsx
251
+ // Inline alerts, placed anywhere in the form
252
+ const FormAlerts = () => {
253
+ const { messages } = useFormMessages();
254
+ return messages.map(m => <Alert key={m.key} type={m.type}>{m.text}</Alert>);
255
+ };
256
+
257
+ // Toasts: fire once per submission, not on every re-render
258
+ const FormToasts = () => {
259
+ const { messages, submissionId } = useFormMessages();
260
+ useEffect(() => {
261
+ messages.forEach(m => toast(m.type, m.text));
262
+ }, [submissionId]);
263
+ return null;
264
+ };
265
+ ```
266
+
267
+ #### `BaseFormField`
268
+
269
+ 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`.
270
+
271
+ | Prop | Type | Description |
272
+ |------|------|-------------|
273
+ | `name` | `string` | Field name. It also links the server errors in `fieldErrors[name]` |
274
+ | `schema` | `ZodType` | Source of the HTML constraints applied to the control |
275
+ | `label` | `string` | Label text. No label is rendered when omitted |
276
+ | `control` | render prop | 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 |
277
+ | `renderLabel` | render prop | Style the label |
278
+ | `renderErrors` | render prop | Style client-side and server-side error messages. Each error is its own element |
279
+ | `className` | `string` | Classes for the field root (a flex column by default) |
280
+
281
+ Error texts come from `BaseForm`'s `formatMessage`.
282
+
283
+ ```tsx
284
+ <BaseFormField
285
+ name="username"
286
+ label="Username"
287
+ schema={z.string().min(3).max(20)}
288
+ control={<Input />}
289
+ renderErrors={<p className="text-sm text-red-600" />}
290
+ />
291
+ ```
292
+
293
+ ### `@omer-x/tailwind-ui-kit/dialog`
294
+
295
+ Styling pieces for Base UI's [`Dialog`](https://base-ui.com/react/components/dialog). Pass them to its parts through `render`.
296
+
297
+ > For now this is the one place where an app has to import Base UI directly. Wrapping all dialog parts is tracked in #52.
298
+
299
+ | Component | Use with | What it provides |
300
+ |-----------|----------|------------------|
301
+ | `DialogBackdrop` | `Dialog.Backdrop` | Fixed full-screen dim overlay (lighter in light mode, darker in dark mode) with a fade transition |
302
+ | `AnimatedPopup` | `Dialog.Popup` | A centered, fixed-width (`w-96`, never wider than the viewport) popup with scale and fade transitions. Nested dialogs stack with an offset and scale-down |
303
+ | `DialogTitle` | `Dialog.Title` | Title typography (`text-xl font-semibold`) |
304
+
305
+ ```tsx
306
+ import { Dialog } from "@base-ui/react/dialog";
307
+ import { AnimatedPopup, DialogBackdrop, DialogTitle } from "@omer-x/tailwind-ui-kit/dialog";
308
+
309
+ <Dialog.Root>
310
+ <Dialog.Trigger render={<Button />}>Open</Dialog.Trigger>
311
+ <Dialog.Portal>
312
+ <Dialog.Backdrop render={<DialogBackdrop />} />
313
+ <Dialog.Popup render={<AnimatedPopup className="rounded-lg bg-white p-6 shadow-lg" />}>
314
+ <Dialog.Title render={<DialogTitle />}>Delete item?</Dialog.Title>
315
+ <Dialog.Close render={<Button />}>Cancel</Dialog.Close>
316
+ </Dialog.Popup>
317
+ </Dialog.Portal>
318
+ </Dialog.Root>
319
+ ```
320
+
321
+ ### `@omer-x/tailwind-ui-kit/layout`
322
+
323
+ #### `Container`
324
+
325
+ Tailwind's `container`, centered with horizontal padding (`container mx-auto px-3`). Accepts `className` and `children`.
326
+
327
+ ### `@omer-x/tailwind-ui-kit/page`
328
+
329
+ #### `Pagination`
330
+
331
+ Pagination built from links. It shows previous/next arrows, the first and last pages, up to two pages on each side of the current one, and ellipses for gaps. Each link points to `?page=N`, and page 1 has no `page` parameter.
332
+
333
+ | Prop | Type | Description |
334
+ |------|------|-------------|
335
+ | `totalItems` | `number` | Total number of items |
336
+ | `itemsPerPage` | `number` | Items per page |
337
+ | `currentPage` | `number` | Current page, starting at 1 |
338
+ | `queryParams` | `Record<string, unknown>` | Other query parameters to keep in every link (e.g. filters) |
339
+ | `renderLink` | render prop | Renders a page link (an `<a>` with `href`). Use it for your router's link component |
340
+ | `renderButton` | render prop | Renders the current page, ellipses and disabled arrows (a disabled `<button>`) |
341
+
342
+ ```tsx
343
+ import Link from "next/link";
344
+
345
+ <Pagination
346
+ totalItems={total}
347
+ itemsPerPage={20}
348
+ currentPage={page}
349
+ queryParams={{ q: search }}
350
+ renderLink={props => <Link {...props} href={props.href!} className="px-3 py-1 hover:underline" />}
351
+ renderButton={<button className="px-3 py-1 font-bold disabled:opacity-50" />}
352
+ />
353
+ ```
354
+
355
+ ### `@omer-x/tailwind-ui-kit/table`
356
+
357
+ #### `Tdx`
358
+
359
+ A `<td>` whose content is cut to a single line with an ellipsis instead of widening the column. Accepts `className` and `children`.
360
+
361
+ ```tsx
362
+ <tr>
363
+ <Tdx className="max-w-48">{longDescription}</Tdx>
364
+ </tr>
365
+ ```
366
+
367
+ ### `@omer-x/tailwind-ui-kit/utils`
368
+
369
+ #### `cn` (deprecated)
370
+
371
+ Kept for backward compatibility. Import from the [`cn`](https://www.npmjs.com/package/cn) package directly instead:
372
+
373
+ ```ts
374
+ import { cn } from "cn";
375
+ ```
376
+
377
+ ## Development
378
+
379
+ ```sh
380
+ npm run dev # Storybook on http://localhost:3000
381
+ npm test # Vitest with coverage: unit tests and every story (headless Chromium)
382
+ npm run lint
383
+ npm run build # tsdown → dist/
384
+ ```
385
+
386
+ Contributor and agent guidelines live in [`AGENTS.md`](./AGENTS.md) and [`ai/`](./ai).
387
+
388
+ ## License
389
+
390
+ MIT
@@ -1,12 +1,28 @@
1
- import * as react from 'react';
2
- import { ComponentProps } from 'react';
3
- import PulseButton from './PulseButton.js';
4
- import '@base-ui/react/button';
5
-
6
- type BaseButtonProps = ComponentProps<typeof PulseButton> & {
7
- size?: "lg" | "md" | "sm" | "xs";
8
- pending?: boolean;
1
+ import { Button } from "@base-ui/react/button";
2
+ import { ComponentProps, ReactNode } from "react";
3
+ type CommonProps = ComponentProps<typeof Button> & {
4
+ size?: "lg" | "md" | "sm" | "xs";
5
+ /**
6
+ * Shows the spinner, blocks clicks and keeps the button focusable.
7
+ * A submit button is also pending while its form is submitting.
8
+ */
9
+ pending?: boolean;
10
+ /**
11
+ * Shown while pending. Nothing is shown when it's missing; `data-pending` still marks the state.
12
+ */
13
+ spinner?: ReactNode;
9
14
  };
10
- declare const BaseButton: ({ size, pending, disabled, focusableWhenDisabled, className, children, ...otherProps }: BaseButtonProps) => react.JSX.Element;
11
-
12
- export { BaseButton as default };
15
+ type TextButtonProps = {
16
+ iconOnly?: false;
17
+ };
18
+ type IconOnlyButtonProps = {
19
+ /**
20
+ * A square button whose only content is an icon. It needs an `aria-label`,
21
+ * and the spinner replaces the icon while pending.
22
+ */
23
+ "iconOnly": true;
24
+ "aria-label": string;
25
+ };
26
+ type BaseButtonProps = CommonProps & (TextButtonProps | IconOnlyButtonProps);
27
+ declare const BaseButton: ({ size, pending: pendingProp, spinner, iconOnly, type, disabled, focusableWhenDisabled, onClick, className, children, ...otherProps }: BaseButtonProps) => import("react").JSX.Element;
28
+ export { BaseButton as default };