@omer-x/tailwind-ui-kit 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (73) hide show
  1. package/MIGRATION.md +247 -0
  2. package/README.md +460 -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/AnimatedPopup.d.ts +7 -6
  8. package/dist/components/dialog/AnimatedPopup.js +8 -33
  9. package/dist/components/dialog/DialogBackdrop.d.ts +7 -6
  10. package/dist/components/dialog/DialogBackdrop.js +7 -24
  11. package/dist/components/dialog/DialogTitle.d.ts +7 -6
  12. package/dist/components/dialog/DialogTitle.js +7 -17
  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 +7 -0
  16. package/dist/components/elements/JustAnchor.js +10 -0
  17. package/dist/components/elements/JustButton.d.ts +7 -0
  18. package/dist/components/elements/JustButton.js +10 -0
  19. package/dist/components/elements/JustDiv.d.ts +7 -0
  20. package/dist/components/elements/JustDiv.js +10 -0
  21. package/dist/components/elements/JustInput.d.ts +7 -0
  22. package/dist/components/elements/JustInput.js +10 -0
  23. package/dist/components/elements/JustSpan.d.ts +7 -0
  24. package/dist/components/elements/JustSpan.js +10 -0
  25. package/dist/components/form/BaseForm.d.ts +13 -0
  26. package/dist/components/form/BaseForm.js +78 -0
  27. package/dist/components/form/BaseFormField.d.ts +24 -0
  28. package/dist/components/form/BaseFormField.js +32 -0
  29. package/dist/components/form/BaseInput.d.ts +7 -0
  30. package/dist/components/form/BaseInput.js +21 -0
  31. package/dist/components/form/BaseSwitch.d.ts +33 -0
  32. package/dist/components/form/BaseSwitch.js +20 -0
  33. package/dist/components/form/ClientSideError.d.ts +9 -0
  34. package/dist/components/form/ClientSideError.js +39 -0
  35. package/dist/components/form/FieldRoot.d.ts +8 -0
  36. package/dist/components/form/FieldRoot.js +21 -0
  37. package/dist/components/form/FormContext.d.ts +28 -0
  38. package/dist/components/form/FormContext.js +12 -0
  39. package/dist/components/form/ServerSideError.d.ts +8 -0
  40. package/dist/components/form/ServerSideError.js +15 -0
  41. package/dist/components/form/index.d.ts +7 -0
  42. package/dist/components/form/index.js +6 -0
  43. package/dist/components/form/useFormMessages.d.ts +10 -0
  44. package/dist/components/form/useFormMessages.js +16 -0
  45. package/dist/components/layout/Container.d.ts +5 -8
  46. package/dist/components/layout/Container.js +8 -10
  47. package/dist/components/layout/index.d.ts +2 -3
  48. package/dist/components/layout/index.js +1 -4
  49. package/dist/components/page/Pagination.d.ts +21 -0
  50. package/dist/components/page/Pagination.js +65 -0
  51. package/dist/components/page/index.d.ts +3 -0
  52. package/dist/components/page/index.js +3 -0
  53. package/dist/components/page/usePagination.d.ts +30 -0
  54. package/dist/components/page/usePagination.js +41 -0
  55. package/dist/components/table/Tdx.d.ts +5 -8
  56. package/dist/components/table/Tdx.js +13 -9
  57. package/dist/components/table/index.d.ts +2 -3
  58. package/dist/components/table/index.js +1 -4
  59. package/dist/hooks/useRipples.d.ts +2 -0
  60. package/dist/hooks/useRipples.js +49 -0
  61. package/dist/styles/ripple.module.css +1 -0
  62. package/dist/utils/cn.d.ts +6 -5
  63. package/dist/utils/cn.js +8 -6
  64. package/dist/utils/dirty-form.d.ts +7 -0
  65. package/dist/utils/dirty-form.js +40 -0
  66. package/dist/utils/index.d.ts +3 -2
  67. package/dist/utils/index.js +2 -3
  68. package/dist/utils/render.d.ts +31 -0
  69. package/dist/utils/render.js +24 -0
  70. package/package.json +38 -23
  71. package/dist/components/button/PulseButton.d.ts +0 -10
  72. package/dist/components/button/PulseButton.js +0 -24
  73. package/dist/styles/ripple.module.d.ts +0 -2
package/README.md ADDED
@@ -0,0 +1,460 @@
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
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
+ | `render` | `RenderProp<"button", ButtonState>` | | Render another element, e.g. your app's link. The state is `{ disabled }` |
100
+ | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
101
+ | `focusableWhenDisabled` | `boolean` | `false` | Keeps a disabled button in the tab order |
102
+ | …rest | `<button>` props | | `disabled`, `type`, `onClick`, … |
103
+
104
+ - **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`.
105
+ - Children are laid out with flex and a size-based gap, so icons and text line up without extra markup.
106
+ - 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.
107
+ - The kit bundles no icons. Pass your own `spinner` (and icons as children), usually once in your themed wrapper.
108
+
109
+ ```tsx
110
+ <Button size="sm" pending={isSaving}>Save</Button>
111
+ <Button iconOnly aria-label="Delete"><TrashIcon /></Button>
112
+ ```
113
+
114
+ **Links that look like buttons:** render your app's own link (so typed routes keep working) and set `nativeButton={false}`:
115
+
116
+ ```tsx
117
+ <Button render={<Link href="/products/new" />} nativeButton={false}>New product</Button>
118
+ ```
119
+
120
+ ### `@omer-x/tailwind-ui-kit/form`
121
+
122
+ #### `BaseInput`
123
+
124
+ A plain `<input>` with sizes, rounded corners and a transparent outline ready for focus styles. It accepts all input props plus `render`.
125
+
126
+ | Prop | Type | Default |
127
+ |------|------|---------|
128
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` |
129
+
130
+ ```tsx
131
+ <BaseInput name="email" className="border border-neutral-300 focus:outline-blue-500" />
132
+ ```
133
+
134
+ #### `BaseSwitch`
135
+
136
+ 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.
137
+
138
+ | Prop | Type | Default | Description |
139
+ |------|------|---------|-------------|
140
+ | `label` | `ReactNode` | | Text next to the switch (required) |
141
+ | `renderThumb` | `RenderProp<"span", SwitchState>` | | Style the thumb |
142
+ | `value` | `string` | `"true"` | Submitted when checked |
143
+ | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
144
+ | `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
145
+ | `render` | `RenderProp<"span", SwitchState>` | | Render another element for the track |
146
+ | …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
147
+
148
+ Render functions get `SwitchState`: `{ checked, disabled, readOnly, required }`.
149
+
150
+ ```tsx
151
+ <BaseSwitch
152
+ name="active"
153
+ label="Active"
154
+ className="rounded-full bg-neutral-300 data-checked:bg-blue-600"
155
+ renderThumb={<span className="rounded-full bg-white" />}
156
+ />
157
+ ```
158
+
159
+ #### `BaseForm`
160
+
161
+ 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:
162
+
163
+ ```sh
164
+ npm install @omer-x/next-form-actions@^2.0.0-alpha.1
165
+ ```
166
+
167
+ | Prop | Type | Description |
168
+ |------|------|-------------|
169
+ | `action` | `FormAction<Data>` | The action, e.g. `saveProduct` or `completeSale.bind(null, saleId)`. `Data` is what it returns on success |
170
+ | `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 |
171
+ | `onResult` | `(result: FormActionState<Data>) => void` | Called once per completed submission, when the action returns. Never on mount |
172
+ | `resetOnSuccess` | `boolean` | After a successful result, reset every field inside the form to its default (see below) |
173
+ | `defaultValues` | `Record<string, unknown>` | Initial values, used by `onlyDirty` |
174
+ | `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 |
175
+ | …rest | `<form>` props | Except `action` |
176
+
177
+ **How the result is used.** The action resolves to `{ status: "idle" }`, `{ status: "success", data }` or `{ status: "failure", fieldErrors, message? }`:
178
+
179
+ - `fieldErrors[name]` are shown under the `BaseFormField` with that `name`. A field can have several errors.
180
+ - `message` (`{ type: "error" | "warning", text }`) is a **form-level message**.
181
+ - 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.
182
+ - `BaseForm` renders no form-level messages itself. Show them wherever you like with `useFormMessages()`.
183
+
184
+ The form never resets after a submission, so after a failure the user keeps what they typed. That includes controlled checkboxes and selects.
185
+
186
+ **`formatMessage`** receives every text the form shows:
187
+
188
+ | What | `code` | `params` |
189
+ |------|--------|----------|
190
+ | 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" }` |
191
+ | 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) |
192
+ | Form message | The message's `text`, e.g. `SALE_ALREADY_COMPLETED` | none |
193
+
194
+ 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:
195
+
196
+ ```tsx
197
+ // src/components/Form.tsx
198
+ "use client";
199
+ import { BaseForm } from "@omer-x/tailwind-ui-kit/form";
200
+ import { useTranslations } from "next-intl";
201
+ import type { ComponentProps } from "react";
202
+
203
+ const Form = <Data,>(props: ComponentProps<typeof BaseForm<Data>>) => {
204
+ const t = useTranslations("Form");
205
+ return <BaseForm {...props} formatMessage={(code, params) => t(code, params as Record<string, string>)} />;
206
+ };
207
+
208
+ export default Form;
209
+ ```
210
+
211
+ ```json
212
+ {
213
+ "Form": {
214
+ "required": "This field is required",
215
+ "valueMissing": "This field is required",
216
+ "too_small": "{origin, select, string {At least {minimum, plural, one {# character} other {# characters}}} other {At least {minimum}}}",
217
+ "tooShort": "At least {minimum, plural, one {# character} other {# characters}}",
218
+ "SALE_ALREADY_COMPLETED": "This sale is already completed"
219
+ }
220
+ }
221
+ ```
222
+
223
+ **`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.
224
+
225
+ ```tsx
226
+ // actions.ts
227
+ "use server";
228
+ export const saveProfile = defineFormAction({
229
+ schema: z.object({ name: z.string().min(3) }),
230
+ action: input => async () => {
231
+ if (await isDown()) displayMessage("error", "SERVER_DOWN");
232
+ return await save(input); // becomes state.data
233
+ },
234
+ });
235
+ ```
236
+
237
+ ```tsx
238
+ <Form action={saveProfile} onResult={result => result.status === "success" && dialog.close()} className="flex flex-col gap-4">
239
+ <FormAlerts />
240
+ <FormField name="name" label="Name" schema={z.string().min(3)} />
241
+ <Button type="submit">Save</Button>
242
+ </Form>
243
+ ```
244
+
245
+ Forms can be nested. A submit inside an inner form does not submit the outer one.
246
+
247
+ #### `useFormMessages`
248
+
249
+ Returns the form-level messages of the latest result of the surrounding `BaseForm`, already passed through `formatMessage`. Call it anywhere inside the form.
250
+
251
+ ```ts
252
+ const { messages, submissionId } = useFormMessages();
253
+ // messages: { key: string, type: "error" | "warning", text: string }[]
254
+ // submissionId: changes once per completed submission
255
+ ```
256
+
257
+ ```tsx
258
+ // Inline alerts, placed anywhere in the form
259
+ const FormAlerts = () => {
260
+ const { messages } = useFormMessages();
261
+ return messages.map(m => <Alert key={m.key} type={m.type}>{m.text}</Alert>);
262
+ };
263
+
264
+ // Toasts: fire once per submission, not on every re-render
265
+ const FormToasts = () => {
266
+ const { messages, submissionId } = useFormMessages();
267
+ useEffect(() => {
268
+ messages.forEach(m => toast(m.type, m.text));
269
+ }, [submissionId]);
270
+ return null;
271
+ };
272
+ ```
273
+
274
+ #### `BaseFormField`
275
+
276
+ 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`.
277
+
278
+ | Prop | Type | Description |
279
+ |------|------|-------------|
280
+ | `name` | `string` | Field name. It also links the server errors in `fieldErrors[name]` |
281
+ | `schema` | `ZodType` | Source of the HTML constraints applied to the control |
282
+ | `label` | `string` | Label text. No label is rendered when omitted |
283
+ | `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 |
284
+ | `renderLabel` | `RenderProp<"label", FieldState>` | Style the label |
285
+ | `renderErrors` | `RenderProp<"div", FieldState>` | Style client-side and server-side error messages. Each error is its own element |
286
+ | `className` | `string` | Classes for the field root (a flex column by default) |
287
+
288
+ 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).
289
+
290
+ ```tsx
291
+ <BaseFormField
292
+ name="username"
293
+ label="Username"
294
+ schema={z.string().min(3).max(20)}
295
+ control={<Input />}
296
+ renderErrors={<p className="text-sm text-red-600" />}
297
+ />
298
+ ```
299
+
300
+ ### `@omer-x/tailwind-ui-kit/dialog`
301
+
302
+ Styling pieces for Base UI's [`Dialog`](https://base-ui.com/react/components/dialog). Pass them to its parts through `render`.
303
+
304
+ > For now this is the one place where an app has to import Base UI directly. Wrapping all dialog parts is tracked in #52.
305
+
306
+ | Component | Use with | What it provides |
307
+ |-----------|----------|------------------|
308
+ | `DialogBackdrop` | `Dialog.Backdrop` | Fixed full-screen dim overlay (lighter in light mode, darker in dark mode) with a fade transition |
309
+ | `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 |
310
+ | `DialogTitle` | `Dialog.Title` | Title typography (`text-xl font-semibold`) |
311
+
312
+ ```tsx
313
+ import { Dialog } from "@base-ui/react/dialog";
314
+ import { AnimatedPopup, DialogBackdrop, DialogTitle } from "@omer-x/tailwind-ui-kit/dialog";
315
+
316
+ <Dialog.Root>
317
+ <Dialog.Trigger render={<Button />}>Open</Dialog.Trigger>
318
+ <Dialog.Portal>
319
+ <Dialog.Backdrop render={<DialogBackdrop />} />
320
+ <Dialog.Popup render={<AnimatedPopup className="rounded-lg bg-white p-6 shadow-lg" />}>
321
+ <Dialog.Title render={<DialogTitle />}>Delete item?</Dialog.Title>
322
+ <Dialog.Close render={<Button />}>Cancel</Dialog.Close>
323
+ </Dialog.Popup>
324
+ </Dialog.Portal>
325
+ </Dialog.Root>
326
+ ```
327
+
328
+ ### `@omer-x/tailwind-ui-kit/layout`
329
+
330
+ #### `Container`
331
+
332
+ Tailwind's `container`, centered with horizontal padding (`container mx-auto px-3`). Accepts `className` and `children`.
333
+
334
+ ### `@omer-x/tailwind-ui-kit/page`
335
+
336
+ #### `Pagination`
337
+
338
+ 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.
339
+
340
+ | Prop | Type | Description |
341
+ |------|------|-------------|
342
+ | `totalItems` | `number` | Total number of items |
343
+ | `itemsPerPage` | `number` | Items per page |
344
+ | `currentPage` | `number` | Current page, starting at 1 |
345
+ | `siblings` | `number` | Pages shown on each side of the current one. Default `2`. `0` gives `« 1 … [50] … 100 »` |
346
+ | `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 |
347
+ | `renderButton` | render prop | Renders a disabled arrow (a disabled `<button>`) |
348
+ | `renderEllipsis` | render prop | Renders an ellipsis (a `<span aria-hidden>`) |
349
+ | `aria-label` | `string` | The navigation's label. Default `"Pagination"` |
350
+ | `previousLabel` / `nextLabel` | `string` | The arrows' accessible names. Default `"Previous page"` / `"Next page"` |
351
+ | …rest | `<nav>` props | |
352
+
353
+ Style the current page with `aria-[current=page]:`.
354
+
355
+ ```tsx
356
+ import { Link } from "@/i18n/navigation";
357
+
358
+ <Pagination
359
+ totalItems={total}
360
+ itemsPerPage={20}
361
+ currentPage={page}
362
+ renderLink={(page, props) => (
363
+ <Link {...props} href={{ pathname: "/products", query: { ...searchParams, page } }} className="px-3 py-1 aria-[current=page]:font-bold" />
364
+ )}
365
+ renderButton={<button className="px-3 py-1 disabled:opacity-50" />}
366
+ renderEllipsis={<span className="px-3 py-1" />}
367
+ />
368
+ ```
369
+
370
+ #### `usePagination`
371
+
372
+ The logic behind `Pagination`, for a completely custom layout. It holds no state, so it also works in server components.
373
+
374
+ ```tsx
375
+ const items = usePagination({ totalItems, itemsPerPage, currentPage, siblings: 1 });
376
+ // [
377
+ // { type: "previous", page: 9, disabled: false },
378
+ // { type: "page", page: 1, current: false },
379
+ // { type: "ellipsis" },
380
+ // { type: "page", page: 10, current: true },
381
+ // …
382
+ // { type: "next", page: 11, disabled: false },
383
+ // ]
384
+ ```
385
+
386
+ ### `@omer-x/tailwind-ui-kit/table`
387
+
388
+ #### `Tdx`
389
+
390
+ A `<td>` whose content is cut to a single line with an ellipsis instead of widening the column. Accepts `className` and `children`.
391
+
392
+ ```tsx
393
+ <tr>
394
+ <Tdx className="max-w-48">{longDescription}</Tdx>
395
+ </tr>
396
+ ```
397
+
398
+ ### `@omer-x/tailwind-ui-kit/utils`
399
+
400
+ Helpers for building your own components on the kit, so you never import Base UI.
401
+
402
+ #### `RenderProp`
403
+
404
+ 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).
405
+
406
+ #### `useRender`
407
+
408
+ Renders an element that can be replaced through a `render` prop, with your props merged into it.
409
+
410
+ | Option | Type | Description |
411
+ |--------|------|-------------|
412
+ | `defaultTagName` | `keyof JSX.IntrinsicElements` | The element rendered when `render` is missing |
413
+ | `render` | `RenderProp<Tag, State>` | The `render` prop of your component |
414
+ | `props` | props of `Tag` | Merged into the rendered element |
415
+ | `state` | `State` | Passed to a `render` function, and set as data attributes (`{ active: true }` becomes `data-active`) |
416
+
417
+ ```tsx
418
+ import { type RenderProp, useRender } from "@omer-x/tailwind-ui-kit/utils";
419
+
420
+ type BadgeProps = ComponentProps<"span"> & {
421
+ render?: RenderProp<"span">,
422
+ };
423
+
424
+ const Badge = ({ render, className, ...props }: BadgeProps) => useRender({
425
+ defaultTagName: "span",
426
+ render,
427
+ props: { ...props, className: cn("rounded px-2 text-xs", className) },
428
+ });
429
+ ```
430
+
431
+ #### `mergeProps`
432
+
433
+ 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.
434
+
435
+ ```tsx
436
+ useRender({ defaultTagName: "div", render, props: mergeProps<"div">({ className: "p-4", onClick: track }, props) });
437
+ ```
438
+
439
+ #### `cn` (deprecated)
440
+
441
+ Kept for backward compatibility. Import from the [`cn`](https://www.npmjs.com/package/cn) package directly instead:
442
+
443
+ ```ts
444
+ import { cn } from "cn";
445
+ ```
446
+
447
+ ## Development
448
+
449
+ ```sh
450
+ npm run dev # Storybook on http://localhost:3000
451
+ npm test # Vitest with coverage: unit tests and every story (headless Chromium)
452
+ npm run lint
453
+ npm run build # tsdown → dist/
454
+ ```
455
+
456
+ Contributor and agent guidelines live in [`AGENTS.md`](./AGENTS.md) and [`ai/`](./ai).
457
+
458
+ ## License
459
+
460
+ MIT
@@ -1,12 +1,39 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ComponentProps, ReactNode } from 'react';
3
- import { Button } from '@base-ui/react/button';
4
-
5
- type BaseButtonProps = ComponentProps<typeof Button> & {
6
- size?: "lg" | "md" | "sm" | "xs";
7
- pending?: boolean;
8
- children: ReactNode;
9
- };
10
- declare const BaseButton: ({ size, pending, disabled, focusableWhenDisabled, className, children, ...otherProps }: BaseButtonProps) => react_jsx_runtime.JSX.Element;
11
-
12
- export { BaseButton as default };
1
+ import { ComponentProps, ReactNode } from "react";
2
+ import { RenderProp } from "../../utils/render.js";
3
+ export type ButtonState = {
4
+ disabled: boolean;
5
+ };
6
+ type CommonProps = ComponentProps<"button"> & {
7
+ render?: RenderProp<"button", ButtonState>;
8
+ /**
9
+ * Set to `false` when `render` doesn't render a `<button>` (e.g. a link),
10
+ * so the button gets the attributes and keyboard handling a non-button element needs.
11
+ */
12
+ nativeButton?: boolean;
13
+ /** Keeps a disabled button focusable, so it stays in the tab order. */
14
+ focusableWhenDisabled?: boolean;
15
+ size?: "lg" | "md" | "sm" | "xs";
16
+ /**
17
+ * Shows the spinner, blocks clicks and keeps the button focusable.
18
+ * A submit button is also pending while its form is submitting.
19
+ */
20
+ pending?: boolean;
21
+ /**
22
+ * Shown while pending. Nothing is shown when it's missing; `data-pending` still marks the state.
23
+ */
24
+ spinner?: ReactNode;
25
+ };
26
+ type TextButtonProps = {
27
+ iconOnly?: false;
28
+ };
29
+ type IconOnlyButtonProps = {
30
+ /**
31
+ * A square button whose only content is an icon. It needs an `aria-label`,
32
+ * and the spinner replaces the icon while pending.
33
+ */
34
+ "iconOnly": true;
35
+ "aria-label": string;
36
+ };
37
+ type BaseButtonProps = CommonProps & (TextButtonProps | IconOnlyButtonProps);
38
+ declare const BaseButton: ({ size, pending: pendingProp, spinner, iconOnly, type, disabled, focusableWhenDisabled, onClick, className, children, ...otherProps }: BaseButtonProps) => import("react").JSX.Element;
39
+ export { BaseButton as default };
@@ -1,52 +1,58 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { faSpinner } from "@fortawesome/free-solid-svg-icons/faSpinner";
3
- import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4
- import {} from "react";
5
- import { cn } from "../../utils/cn.js";
6
- import PulseButton from "./PulseButton.js";
7
- const BaseButton = ({
8
- size = "md",
9
- pending = false,
10
- disabled,
11
- focusableWhenDisabled,
12
- className,
13
- children,
14
- ...otherProps
15
- }) => /* @__PURE__ */ jsxs(
16
- PulseButton,
17
- {
18
- className: (state) => cn({
19
- // Size
20
- "h-12 px-5 text-base leading-7 gap-3": size === "lg",
21
- "h-10 px-4 text-sm leading-6 gap-3": size === "md",
22
- "h-9 px-3 text-sm leading-5 gap-2": size === "sm",
23
- "h-8 px-2.5 text-xs leading-4 gap-2": size === "xs"
24
- }, [
25
- // Base
26
- "relative",
27
- "flex items-center justify-center",
28
- "rounded-md",
29
- "font-medium",
30
- "select-none",
31
- "outline-0",
32
- "transition-colors",
33
- // Focus
34
- "focus-visible:outline-2",
35
- "focus-visible:outline-offset-2",
36
- // Cursor
37
- "cursor-pointer",
38
- "data-disabled:cursor-default"
39
- ], typeof className === "function" ? className(state) : className),
40
- disabled,
41
- focusableWhenDisabled: pending || focusableWhenDisabled,
42
- ...otherProps,
43
- children: [
44
- pending && /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: faSpinner, size: "lg", className: "fa-spin-pulse" }),
45
- children
46
- ]
47
- }
48
- );
49
- var BaseButton_default = BaseButton;
50
- export {
51
- BaseButton_default as default
1
+ "use client";
2
+ import { Button } from "@base-ui/react/button";
3
+ import { cn } from "cn";
4
+ import { use } from "react";
5
+ import { useFormStatus } from "react-dom";
6
+ import { useRipples } from "../../hooks/useRipples.js";
7
+ import { FormContext } from "../form/FormContext.js";
8
+ import { jsxs } from "react/jsx-runtime";
9
+ // src/components/button/BaseButton.tsx
10
+ const BaseButton = ({ size = "md", pending: pendingProp = false, spinner, iconOnly = false, type, disabled = false, focusableWhenDisabled = false, onClick, className, children, ...otherProps }) => {
11
+ const { pending: nativeFormPending } = useFormStatus();
12
+ const { pending: baseFormPending } = use(FormContext);
13
+ const pending = pendingProp || type === "submit" && (nativeFormPending || baseFormPending);
14
+ const [triggerRippleEffect, ripples] = useRipples();
15
+ const handleClick = (e) => {
16
+ onClick?.(e);
17
+ if (!e.defaultPrevented) triggerRippleEffect(e);
18
+ };
19
+ return /* @__PURE__ */ jsxs(Button, {
20
+ ...otherProps,
21
+ type,
22
+ disabled: pending || disabled,
23
+ focusableWhenDisabled: pending || focusableWhenDisabled,
24
+ onClick: handleClick,
25
+ "aria-busy": pending || void 0,
26
+ "data-pending": pending ? "" : void 0,
27
+ "data-icon-only": iconOnly ? "" : void 0,
28
+ className: cn({
29
+ "h-12 text-base leading-7 gap-3": size === "lg",
30
+ "h-10 text-sm leading-6 gap-3": size === "md",
31
+ "h-9 text-sm leading-5 gap-2": size === "sm",
32
+ "h-8 text-xs leading-4 gap-2": size === "xs",
33
+ "px-5": size === "lg" && !iconOnly,
34
+ "px-4": size === "md" && !iconOnly,
35
+ "px-3": size === "sm" && !iconOnly,
36
+ "px-2.5": size === "xs" && !iconOnly,
37
+ "aspect-square px-0": iconOnly
38
+ }, [
39
+ "relative",
40
+ "flex items-center justify-center",
41
+ "rounded-md",
42
+ "font-medium",
43
+ "select-none",
44
+ "outline-0",
45
+ "transition-colors",
46
+ "focus-visible:outline-2",
47
+ "focus-visible:outline-offset-2",
48
+ "cursor-pointer",
49
+ "data-disabled:cursor-default"
50
+ ], className),
51
+ children: [
52
+ ripples,
53
+ pending && spinner,
54
+ !(pending && iconOnly && spinner) && children
55
+ ]
56
+ });
52
57
  };
58
+ export { BaseButton as default };
@@ -1,4 +1,2 @@
1
- export { default as BaseButton } from './BaseButton.js';
2
- import 'react/jsx-runtime';
3
- import 'react';
4
- import '@base-ui/react/button';
1
+ import BaseButton, { ButtonState } from "./BaseButton.js";
2
+ export { BaseButton, type ButtonState };
@@ -1,4 +1 @@
1
- import { default as default2 } from "./BaseButton.js";
2
- export {
3
- default2 as BaseButton
4
- };
1
+ export { default as BaseButton } from "./BaseButton.js";
@@ -1,6 +1,7 @@
1
- import * as react from 'react';
2
- import { useRender } from '@base-ui/react/use-render';
3
-
4
- declare const AnimatedPopup: ({ render, ...otherProps }: useRender.ComponentProps<"div">) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
-
6
- export { AnimatedPopup as default };
1
+ import { RenderProp } from "../../utils/render.js";
2
+ import { ComponentProps } from "react";
3
+ type AnimatedPopupProps = ComponentProps<"div"> & {
4
+ render?: RenderProp<"div">;
5
+ };
6
+ declare const AnimatedPopup: ({ render, className, ...otherProps }: AnimatedPopupProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
7
+ export { AnimatedPopup as default };