@omer-x/tailwind-ui-kit 1.0.0-alpha.20 → 1.0.0-alpha.22
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.
- package/MIGRATION.md +73 -0
- package/README.md +142 -32
- package/dist/components/button/BaseButton.d.ts +13 -2
- package/dist/components/button/index.d.ts +2 -2
- package/dist/components/dialog/BaseDialog.d.ts +58 -0
- package/dist/components/dialog/BaseDialog.js +24 -0
- package/dist/components/dialog/BaseDialogClose.d.ts +13 -0
- package/dist/components/dialog/BaseDialogClose.js +7 -0
- package/dist/components/dialog/BaseDialogDescription.d.ts +8 -0
- package/dist/components/dialog/BaseDialogDescription.js +7 -0
- package/dist/components/dialog/BaseDialogPopup.d.ts +40 -0
- package/dist/components/dialog/BaseDialogPopup.js +24 -0
- package/dist/components/dialog/BaseDialogTitle.d.ts +8 -0
- package/dist/components/dialog/BaseDialogTitle.js +11 -0
- package/dist/components/dialog/BaseDialogTrigger.d.ts +20 -0
- package/dist/components/dialog/BaseDialogTrigger.js +11 -0
- package/dist/components/dialog/createDialogHandle.d.ts +26 -0
- package/dist/components/dialog/createDialogHandle.js +28 -0
- package/dist/components/dialog/index.d.ts +6 -4
- package/dist/components/dialog/index.js +3 -4
- package/dist/components/elements/JustAnchor.d.ts +6 -2
- package/dist/components/elements/JustAnchor.js +1 -1
- package/dist/components/elements/JustButton.d.ts +6 -2
- package/dist/components/elements/JustButton.js +1 -1
- package/dist/components/elements/JustDiv.d.ts +6 -2
- package/dist/components/elements/JustDiv.js +1 -1
- package/dist/components/elements/JustInput.d.ts +6 -2
- package/dist/components/elements/JustInput.js +1 -1
- package/dist/components/elements/JustSpan.d.ts +6 -2
- package/dist/components/elements/JustSpan.js +1 -1
- package/dist/components/form/BaseFormField.d.ts +15 -5
- package/dist/components/form/BaseSwitch.d.ts +30 -5
- package/dist/components/form/BaseSwitch.js +2 -1
- package/dist/components/form/ClientSideError.d.ts +3 -3
- package/dist/components/form/ServerSideError.d.ts +3 -3
- package/dist/components/form/index.d.ts +3 -3
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/render.d.ts +31 -0
- package/dist/utils/render.js +24 -0
- package/package.json +2 -1
- package/dist/components/dialog/AnimatedPopup.d.ts +0 -3
- package/dist/components/dialog/AnimatedPopup.js +0 -10
- package/dist/components/dialog/DialogBackdrop.d.ts +0 -3
- package/dist/components/dialog/DialogBackdrop.js +0 -10
- package/dist/components/dialog/DialogTitle.d.ts +0 -3
- package/dist/components/dialog/DialogTitle.js +0 -10
package/MIGRATION.md
CHANGED
|
@@ -5,6 +5,32 @@ Each breaking change has its own section with before / after code and the reason
|
|
|
5
5
|
- **Mechanical:** a rename or a type change. The compiler points you to every place to fix.
|
|
6
6
|
- **Check manually:** behavior changed. Code still compiles, but may act differently.
|
|
7
7
|
|
|
8
|
+
## Types
|
|
9
|
+
|
|
10
|
+
### Props no longer name Base UI types (mechanical, #55)
|
|
11
|
+
|
|
12
|
+
Component props are now native element props plus the kit's own props, and `render` / `render*` props use the kit's `RenderProp` type. This changes three things:
|
|
13
|
+
|
|
14
|
+
- `className` and `style` on `BaseButton` and `BaseSwitch` no longer take a function of the state. Use data attributes instead:
|
|
15
|
+
|
|
16
|
+
```diff
|
|
17
|
+
- className={state => (state.disabled ? "opacity-50" : "")}
|
|
18
|
+
+ className="data-disabled:opacity-50"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- Event handlers get React's event types, so `event.preventBaseUIHandler()` is no longer typed.
|
|
22
|
+
- Types like `ComponentProps<typeof Button>` or `useRender.ComponentProps<"div">` from `@base-ui/react` are replaced by the kit's types: `RenderProp`, `ButtonState`, `SwitchState` and `FieldState`. To build your own component with a `render` prop, use `useRender` and `mergeProps` from `@omer-x/tailwind-ui-kit/utils`:
|
|
23
|
+
|
|
24
|
+
```diff
|
|
25
|
+
- import { useRender } from "@base-ui/react/use-render";
|
|
26
|
+
- import { mergeProps } from "@base-ui/react/merge-props";
|
|
27
|
+
+ import { mergeProps, type RenderProp, useRender } from "@omer-x/tailwind-ui-kit/utils";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The kit's `useRender` takes `defaultTagName`, `render`, `props` and `state`.
|
|
31
|
+
|
|
32
|
+
**Why:** Base UI is an implementation detail. Types that named it tied apps to it, and replacing it would have broken them.
|
|
33
|
+
|
|
8
34
|
## Button
|
|
9
35
|
|
|
10
36
|
### Font Awesome is removed: pass a `spinner` (mechanical, #5, #8)
|
|
@@ -76,8 +102,55 @@ Remove any `pending={isSubmitting}` you wired up by hand for submit buttons of `
|
|
|
76
102
|
|
|
77
103
|
**Why:** screen readers announced a plain group of buttons and links, with no current page and unnamed arrows.
|
|
78
104
|
|
|
105
|
+
## Dialog
|
|
106
|
+
|
|
107
|
+
### `AnimatedPopup`, `DialogBackdrop` and `DialogTitle` are replaced by `BaseDialog` (mechanical, #52)
|
|
108
|
+
|
|
109
|
+
The dialog entry point now wraps every part, so apps no longer import `@base-ui/react/dialog`. `BaseDialog.Popup` brings its portal and the backdrop that `DialogBackdrop` used to style, and `BaseDialog.Title` has `DialogTitle`'s typography:
|
|
110
|
+
|
|
111
|
+
```diff
|
|
112
|
+
- import { Dialog } from "@base-ui/react/dialog";
|
|
113
|
+
- import { AnimatedPopup, DialogBackdrop, DialogTitle } from "@omer-x/tailwind-ui-kit/dialog";
|
|
114
|
+
+ import { BaseDialog } from "@omer-x/tailwind-ui-kit/dialog";
|
|
115
|
+
|
|
116
|
+
- <Dialog.Root>
|
|
117
|
+
- <Dialog.Trigger render={<Button />}>Open</Dialog.Trigger>
|
|
118
|
+
- <Dialog.Portal>
|
|
119
|
+
- <Dialog.Backdrop render={<DialogBackdrop />} />
|
|
120
|
+
- <Dialog.Popup render={<AnimatedPopup className="rounded-lg bg-white p-6 shadow-lg" />}>
|
|
121
|
+
- <Dialog.Title render={<DialogTitle />}>Delete item?</Dialog.Title>
|
|
122
|
+
- <Dialog.Close render={<Button />}>Cancel</Dialog.Close>
|
|
123
|
+
- </Dialog.Popup>
|
|
124
|
+
- </Dialog.Portal>
|
|
125
|
+
- </Dialog.Root>
|
|
126
|
+
+ <BaseDialog>
|
|
127
|
+
+ <BaseDialog.Trigger render={<Button />}>Open</BaseDialog.Trigger>
|
|
128
|
+
+ <BaseDialog.Popup className="rounded-lg bg-white p-6 shadow-lg">
|
|
129
|
+
+ <BaseDialog.Title>Delete item?</BaseDialog.Title>
|
|
130
|
+
+ <BaseDialog.Close render={<Button />}>Cancel</BaseDialog.Close>
|
|
131
|
+
+ </BaseDialog.Popup>
|
|
132
|
+
+ </BaseDialog>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
- `Dialog.createHandle()` becomes `createDialogHandle()`. Its `open()` no longer needs an argument.
|
|
136
|
+
- `onOpenChange` gets the DOM event instead of Base UI's event details.
|
|
137
|
+
- Portal props (`container`, `keepMounted`) move to `BaseDialog.Popup`. Style the backdrop with its `renderBackdrop` prop, or turn it off with `backdrop={false}`.
|
|
138
|
+
|
|
139
|
+
**Why:** apps had to import Base UI to build a dialog, which tied them to it.
|
|
140
|
+
|
|
79
141
|
## Form
|
|
80
142
|
|
|
143
|
+
### `BaseSwitch`: `onCheckedChange` gets the DOM event (mechanical, #55)
|
|
144
|
+
|
|
145
|
+
The second argument of `onCheckedChange` is now the DOM `Event`, not Base UI's event details. `eventDetails.cancel()` is gone: to refuse a change, control the switch with `checked`.
|
|
146
|
+
|
|
147
|
+
```diff
|
|
148
|
+
- onCheckedChange={(checked, details) => track(details.event)}
|
|
149
|
+
+ onCheckedChange={(checked, event) => track(event)}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Why:** the event details were a Base UI type (#55).
|
|
153
|
+
|
|
81
154
|
### Fields are validated in the browser (check manually, #65)
|
|
82
155
|
|
|
83
156
|
`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.
|
package/README.md
CHANGED
|
@@ -9,12 +9,12 @@ Colorless React components built on [Base UI](https://base-ui.com) and [Tailwind
|
|
|
9
9
|
Read these before using or changing any component.
|
|
10
10
|
|
|
11
11
|
1. **Colorless bases.** Components ship without colors, background colors, border colors or any theme. You give them your look by wrapping them once in your app and using the wrapper everywhere.
|
|
12
|
-
2. **Everything is styleable.** Each component accepts `className`, and sub-parts are exposed through `render*` props (`renderLabel`, `renderErrors`, `renderThumb`, …). A `render` prop accepts an element or a function,
|
|
13
|
-
3. **Style states with data attributes.**
|
|
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
14
|
4. **Naming.** `Base*` components are meant to be wrapped and themed. `Just*` components are bare elements that only add a `render` prop. Unprefixed components are layout and composition helpers.
|
|
15
15
|
5. **Client components.** All components are client components.
|
|
16
16
|
6. **Short for the common case, without losing power.** Each component is designed on its own: parts that always go together are combined, and Base UI's full capabilities stay available through props or optional parts.
|
|
17
|
-
7. **Never import Base UI in apps.** Base UI is an implementation detail and may be replaced someday. Apps use the kit's components only. If something you need isn't covered yet, add it to the kit instead of importing `@base-ui/react` (progress is tracked in #56).
|
|
17
|
+
7. **Never import Base UI in apps.** Base UI is an implementation detail and may be replaced someday. Apps use the kit's components only, and the kit's types never name Base UI types. To build your own component with a `render` prop, use the kit's [`useRender`](#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
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
@@ -44,7 +44,7 @@ Tailwind v4 does not scan `node_modules`, so the classes used inside the compone
|
|
|
44
44
|
@source "../../node_modules/@omer-x/tailwind-ui-kit";
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
Some components use the `dark:` variant (e.g. `
|
|
47
|
+
Some components use the `dark:` variant (e.g. the backdrop of `BaseDialog.Popup`). They follow whatever `dark` variant your app defines.
|
|
48
48
|
|
|
49
49
|
### 2. Your bundler must support CSS modules
|
|
50
50
|
|
|
@@ -96,7 +96,10 @@ A Base UI [`Button`](https://base-ui.com/react/components/button) with sizes, a
|
|
|
96
96
|
| `pending` | `boolean` | `false` | Shows the spinner, blocks clicks and keeps the button focusable |
|
|
97
97
|
| `spinner` | `ReactNode` | | Shown while pending. Without it nothing is shown, and `data-pending` still marks the state |
|
|
98
98
|
| `iconOnly` | `boolean` | `false` | A square button for a single icon. Requires `aria-label`. While pending, the spinner replaces the icon |
|
|
99
|
-
|
|
|
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`, … |
|
|
100
103
|
|
|
101
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`.
|
|
102
105
|
- Children are laid out with flex and a size-based gap, so icons and text line up without extra markup.
|
|
@@ -108,7 +111,7 @@ A Base UI [`Button`](https://base-ui.com/react/components/button) with sizes, a
|
|
|
108
111
|
<Button iconOnly aria-label="Delete"><TrashIcon /></Button>
|
|
109
112
|
```
|
|
110
113
|
|
|
111
|
-
**Links that look like buttons:** render your app's own link (so typed routes keep working) and
|
|
114
|
+
**Links that look like buttons:** render your app's own link (so typed routes keep working) and set `nativeButton={false}`:
|
|
112
115
|
|
|
113
116
|
```tsx
|
|
114
117
|
<Button render={<Link href="/products/new" />} nativeButton={false}>New product</Button>
|
|
@@ -135,10 +138,14 @@ A Base UI [`Switch`](https://base-ui.com/react/components/switch) with its label
|
|
|
135
138
|
| Prop | Type | Default | Description |
|
|
136
139
|
|------|------|---------|-------------|
|
|
137
140
|
| `label` | `ReactNode` | | Text next to the switch (required) |
|
|
138
|
-
| `renderThumb` |
|
|
141
|
+
| `renderThumb` | `RenderProp<"span", SwitchState>` | | Style the thumb |
|
|
139
142
|
| `value` | `string` | `"true"` | Submitted when checked |
|
|
140
143
|
| `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
|
|
141
|
-
|
|
|
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 }`.
|
|
142
149
|
|
|
143
150
|
```tsx
|
|
144
151
|
<BaseSwitch
|
|
@@ -273,12 +280,12 @@ A Base UI [`Field`](https://base-ui.com/react/components/field) made of a label,
|
|
|
273
280
|
| `name` | `string` | Field name. It also links the server errors in `fieldErrors[name]` |
|
|
274
281
|
| `schema` | `ZodType` | Source of the HTML constraints applied to the control |
|
|
275
282
|
| `label` | `string` | Label text. No label is rendered when omitted |
|
|
276
|
-
| `control` |
|
|
277
|
-
| `renderLabel` |
|
|
278
|
-
| `renderErrors` |
|
|
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 |
|
|
279
286
|
| `className` | `string` | Classes for the field root (a flex column by default) |
|
|
280
287
|
|
|
281
|
-
Error texts come from `BaseForm`'s `formatMessage`.
|
|
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).
|
|
282
289
|
|
|
283
290
|
```tsx
|
|
284
291
|
<BaseFormField
|
|
@@ -292,32 +299,96 @@ Error texts come from `BaseForm`'s `formatMessage`.
|
|
|
292
299
|
|
|
293
300
|
### `@omer-x/tailwind-ui-kit/dialog`
|
|
294
301
|
|
|
295
|
-
|
|
302
|
+
#### `BaseDialog`
|
|
303
|
+
|
|
304
|
+
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:
|
|
305
|
+
|
|
306
|
+
```tsx
|
|
307
|
+
import { BaseDialog } from "@omer-x/tailwind-ui-kit/dialog";
|
|
308
|
+
|
|
309
|
+
<BaseDialog>
|
|
310
|
+
<BaseDialog.Trigger render={<Button />}>Delete</BaseDialog.Trigger>
|
|
311
|
+
<BaseDialog.Popup className="rounded-lg bg-white p-6 shadow-lg">
|
|
312
|
+
<BaseDialog.Title>Delete item?</BaseDialog.Title>
|
|
313
|
+
<BaseDialog.Description>This can't be undone.</BaseDialog.Description>
|
|
314
|
+
<BaseDialog.Close render={<Button />}>Cancel</BaseDialog.Close>
|
|
315
|
+
</BaseDialog.Popup>
|
|
316
|
+
</BaseDialog>
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
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.
|
|
320
|
+
|
|
321
|
+
| Part | Renders | Description |
|
|
322
|
+
|------|---------|-------------|
|
|
323
|
+
| `BaseDialog` | nothing | Groups the parts and holds the open state |
|
|
324
|
+
| `BaseDialog.Trigger` | `<button>` | Opens the dialog. `data-popup-open` while its dialog is open |
|
|
325
|
+
| `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 |
|
|
326
|
+
| `BaseDialog.Title` | `<h2>` | The heading that names the dialog (`text-xl font-semibold`) |
|
|
327
|
+
| `BaseDialog.Description` | `<p>` | Describes the dialog to assistive technology |
|
|
328
|
+
| `BaseDialog.Close` | `<button>` | Closes the dialog |
|
|
329
|
+
|
|
330
|
+
Every part takes `className` and `render`. `Trigger` and `Close` also take `nativeButton` (set it to `false` when `render` doesn't render a `<button>`).
|
|
331
|
+
|
|
332
|
+
`BaseDialog` props:
|
|
333
|
+
|
|
334
|
+
| Prop | Type | Default | Description |
|
|
335
|
+
|------|------|---------|-------------|
|
|
336
|
+
| `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
|
|
337
|
+
| `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
|
|
338
|
+
| `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
|
|
339
|
+
| `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 |
|
|
340
|
+
| `disablePointerDismissal` | `boolean` | `false` | Keeps the dialog open on outside presses |
|
|
341
|
+
| `handle` | `DialogHandle<Payload>` | | Connects triggers outside the dialog and opens it from code (see below) |
|
|
342
|
+
| `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open dialog belongs to |
|
|
343
|
+
| `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the dialog |
|
|
344
|
+
|
|
345
|
+
`BaseDialog.Popup` props:
|
|
346
|
+
|
|
347
|
+
| Prop | Type | Default | Description |
|
|
348
|
+
|------|------|---------|-------------|
|
|
349
|
+
| `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` |
|
|
350
|
+
| `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"`) |
|
|
351
|
+
| `finalFocus` | `DialogFocusTarget` | `true` | The element focused on close. `true` is the trigger |
|
|
352
|
+
| `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the popup is portaled to |
|
|
353
|
+
| `keepMounted` | `boolean` | `false` | Keeps the popup in the DOM while closed |
|
|
354
|
+
| `backdrop` | `boolean` | `true` | Set to `false` for no backdrop. Nested dialogs never render one |
|
|
355
|
+
| `renderBackdrop` | `RenderProp<"div", DialogBackdropState>` | | Style or replace the backdrop: a fixed full-screen black overlay (lighter in light mode, darker in dark mode) with a fade transition |
|
|
356
|
+
| `render` | `RenderProp<"div", DialogPopupState>` | | The state is `{ open, nested, nestedDialogOpen }` |
|
|
357
|
+
|
|
358
|
+
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).
|
|
296
359
|
|
|
297
|
-
|
|
360
|
+
**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.
|
|
298
361
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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`) |
|
|
362
|
+
#### `createDialogHandle`
|
|
363
|
+
|
|
364
|
+
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:
|
|
304
365
|
|
|
305
366
|
```tsx
|
|
306
|
-
import {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
</
|
|
367
|
+
import { BaseDialog, createDialogHandle } from "@omer-x/tailwind-ui-kit/dialog";
|
|
368
|
+
|
|
369
|
+
const deleteDialog = createDialogHandle<{ id: string, name: string }>();
|
|
370
|
+
|
|
371
|
+
// triggers anywhere on the page
|
|
372
|
+
<BaseDialog.Trigger handle={deleteDialog} payload={{ id: p.id, name: p.name }} render={<Button />}>Delete</BaseDialog.Trigger>
|
|
373
|
+
|
|
374
|
+
// one dialog on the page
|
|
375
|
+
<BaseDialog handle={deleteDialog}>
|
|
376
|
+
{({ payload }) => payload && (
|
|
377
|
+
<BaseDialog.Popup size="sm">
|
|
378
|
+
<BaseDialog.Title>Delete {payload.name}?</BaseDialog.Title>
|
|
379
|
+
</BaseDialog.Popup>
|
|
380
|
+
)}
|
|
381
|
+
</BaseDialog>
|
|
382
|
+
|
|
383
|
+
// from code
|
|
384
|
+
deleteDialog.openWithPayload({ id, name });
|
|
319
385
|
```
|
|
320
386
|
|
|
387
|
+
A `DialogHandle<Payload>` has `open(triggerId?)`, `openWithPayload(payload)`, `close()` and `isOpen`.
|
|
388
|
+
|
|
389
|
+
- Calls are **ignored while the dialog isn't mounted**. Keep the `BaseDialog` with the handle rendered.
|
|
390
|
+
- Call them **from event handlers or effects, never during render**.
|
|
391
|
+
|
|
321
392
|
### `@omer-x/tailwind-ui-kit/layout`
|
|
322
393
|
|
|
323
394
|
#### `Container`
|
|
@@ -390,6 +461,45 @@ A `<td>` whose content is cut to a single line with an ellipsis instead of widen
|
|
|
390
461
|
|
|
391
462
|
### `@omer-x/tailwind-ui-kit/utils`
|
|
392
463
|
|
|
464
|
+
Helpers for building your own components on the kit, so you never import Base UI.
|
|
465
|
+
|
|
466
|
+
#### `RenderProp`
|
|
467
|
+
|
|
468
|
+
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).
|
|
469
|
+
|
|
470
|
+
#### `useRender`
|
|
471
|
+
|
|
472
|
+
Renders an element that can be replaced through a `render` prop, with your props merged into it.
|
|
473
|
+
|
|
474
|
+
| Option | Type | Description |
|
|
475
|
+
|--------|------|-------------|
|
|
476
|
+
| `defaultTagName` | `keyof JSX.IntrinsicElements` | The element rendered when `render` is missing |
|
|
477
|
+
| `render` | `RenderProp<Tag, State>` | The `render` prop of your component |
|
|
478
|
+
| `props` | props of `Tag` | Merged into the rendered element |
|
|
479
|
+
| `state` | `State` | Passed to a `render` function, and set as data attributes (`{ active: true }` becomes `data-active`) |
|
|
480
|
+
|
|
481
|
+
```tsx
|
|
482
|
+
import { type RenderProp, useRender } from "@omer-x/tailwind-ui-kit/utils";
|
|
483
|
+
|
|
484
|
+
type BadgeProps = ComponentProps<"span"> & {
|
|
485
|
+
render?: RenderProp<"span">,
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
const Badge = ({ render, className, ...props }: BadgeProps) => useRender({
|
|
489
|
+
defaultTagName: "span",
|
|
490
|
+
render,
|
|
491
|
+
props: { ...props, className: cn("rounded px-2 text-xs", className) },
|
|
492
|
+
});
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
#### `mergeProps`
|
|
496
|
+
|
|
497
|
+
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.
|
|
498
|
+
|
|
499
|
+
```tsx
|
|
500
|
+
useRender({ defaultTagName: "div", render, props: mergeProps<"div">({ className: "p-4", onClick: track }, props) });
|
|
501
|
+
```
|
|
502
|
+
|
|
393
503
|
#### `cn` (deprecated)
|
|
394
504
|
|
|
395
505
|
Kept for backward compatibility. Import from the [`cn`](https://www.npmjs.com/package/cn) package directly instead:
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { Button } from "@base-ui/react/button";
|
|
2
1
|
import { ComponentProps, ReactNode } from "react";
|
|
3
|
-
|
|
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;
|
|
4
15
|
size?: "lg" | "md" | "sm" | "xs";
|
|
5
16
|
/**
|
|
6
17
|
* Shows the spinner, blocks clicks and keeps the button focusable.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import BaseButton from "./BaseButton.js";
|
|
2
|
-
export { BaseButton };
|
|
1
|
+
import BaseButton, { ButtonState } from "./BaseButton.js";
|
|
2
|
+
export { BaseButton, type ButtonState };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { BaseDialogTriggerProps } from "./BaseDialogTrigger.js";
|
|
3
|
+
import { DialogBackdropState, DialogFocusTarget, DialogPopupState } from "./BaseDialogPopup.js";
|
|
4
|
+
import "../../utils/index.js";
|
|
5
|
+
import { DialogCloseState } from "./BaseDialogClose.js";
|
|
6
|
+
import { DialogHandle } from "./createDialogHandle.js";
|
|
7
|
+
import { ReactNode } from "react";
|
|
8
|
+
type BaseDialogProps<Payload = unknown> = {
|
|
9
|
+
open?: boolean;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
/** Called with the new state and the DOM event that changed it (none when it was changed from code). */
|
|
12
|
+
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
13
|
+
/** Called after the open or close transition ends. */
|
|
14
|
+
onOpenChangeComplete?: (open: boolean) => void;
|
|
15
|
+
/**
|
|
16
|
+
* - `true`: focus is trapped, page scroll is locked and the rest of the page ignores the pointer.
|
|
17
|
+
* - `false`: the rest of the page stays usable.
|
|
18
|
+
* - `"trap-focus"`: focus is trapped, but the page scrolls and takes pointer input.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
modal?: boolean | "trap-focus";
|
|
22
|
+
/** Keeps the dialog open on outside presses. */
|
|
23
|
+
disablePointerDismissal?: boolean;
|
|
24
|
+
/** Connects triggers placed outside the dialog, and opens it from code. Create one with `createDialogHandle()`. */
|
|
25
|
+
handle?: DialogHandle<Payload>;
|
|
26
|
+
/** The `id` of the trigger the dialog belongs to, for a controlled dialog with several triggers. */
|
|
27
|
+
triggerId?: string | null;
|
|
28
|
+
/** The `id` of the trigger an initially open dialog belongs to. */
|
|
29
|
+
defaultTriggerId?: string | null;
|
|
30
|
+
/** The dialog's parts, or a function that gets the payload of the trigger that opened it. */
|
|
31
|
+
children?: ReactNode | ((context: {
|
|
32
|
+
payload: Payload | undefined;
|
|
33
|
+
}) => ReactNode);
|
|
34
|
+
};
|
|
35
|
+
declare const _default: (<Payload>({ handle, onOpenChange, ...otherProps }: BaseDialogProps<Payload>) => import("react").JSX.Element) & {
|
|
36
|
+
Trigger: <Payload>({ handle, ...otherProps }: BaseDialogTriggerProps<Payload>) => import("react").JSX.Element;
|
|
37
|
+
Popup: ({ size, container, keepMounted, backdrop, renderBackdrop, className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
38
|
+
size?: "lg" | "md" | "sm" | "xs";
|
|
39
|
+
render?: RenderProp<"div", DialogPopupState>;
|
|
40
|
+
initialFocus?: DialogFocusTarget;
|
|
41
|
+
finalFocus?: DialogFocusTarget;
|
|
42
|
+
container?: HTMLElement | ShadowRoot | import("react").RefObject<HTMLElement | ShadowRoot | null> | null;
|
|
43
|
+
keepMounted?: boolean;
|
|
44
|
+
backdrop?: boolean;
|
|
45
|
+
renderBackdrop?: RenderProp<"div", DialogBackdropState>;
|
|
46
|
+
}) => import("react").JSX.Element;
|
|
47
|
+
Title: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLHeadingElement> & import("react").HTMLAttributes<HTMLHeadingElement> & {
|
|
48
|
+
render?: RenderProp<"h2">;
|
|
49
|
+
}) => import("react").JSX.Element;
|
|
50
|
+
Description: (props: import("react").ClassAttributes<HTMLParagraphElement> & import("react").HTMLAttributes<HTMLParagraphElement> & {
|
|
51
|
+
render?: RenderProp<"p">;
|
|
52
|
+
}) => import("react").JSX.Element;
|
|
53
|
+
Close: (props: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
54
|
+
render?: RenderProp<"button", DialogCloseState>;
|
|
55
|
+
nativeButton?: boolean;
|
|
56
|
+
}) => import("react").JSX.Element;
|
|
57
|
+
};
|
|
58
|
+
export { _default as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
3
|
+
import BaseDialogClose from "./BaseDialogClose.js";
|
|
4
|
+
import BaseDialogDescription from "./BaseDialogDescription.js";
|
|
5
|
+
import BaseDialogPopup from "./BaseDialogPopup.js";
|
|
6
|
+
import BaseDialogTitle from "./BaseDialogTitle.js";
|
|
7
|
+
import BaseDialogTrigger from "./BaseDialogTrigger.js";
|
|
8
|
+
import { toBaseUIHandle } from "./createDialogHandle.js";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
// src/components/dialog/BaseDialog.tsx
|
|
11
|
+
/** Groups the parts of a dialog. Renders no element. */
|
|
12
|
+
const BaseDialog = ({ handle, onOpenChange, ...otherProps }) => /* @__PURE__ */ jsx(Dialog.Root, {
|
|
13
|
+
...otherProps,
|
|
14
|
+
handle: handle && toBaseUIHandle(handle),
|
|
15
|
+
onOpenChange: onOpenChange && ((open, details) => onOpenChange(open, details.event))
|
|
16
|
+
});
|
|
17
|
+
var BaseDialog_default = Object.assign(BaseDialog, {
|
|
18
|
+
Trigger: BaseDialogTrigger,
|
|
19
|
+
Popup: BaseDialogPopup,
|
|
20
|
+
Title: BaseDialogTitle,
|
|
21
|
+
Description: BaseDialogDescription,
|
|
22
|
+
Close: BaseDialogClose
|
|
23
|
+
});
|
|
24
|
+
export { BaseDialog_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type DialogCloseState = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
};
|
|
6
|
+
type BaseDialogCloseProps = ComponentProps<"button"> & {
|
|
7
|
+
render?: RenderProp<"button", DialogCloseState>;
|
|
8
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
9
|
+
nativeButton?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/** A button that closes the dialog. Renders a `<button>`. */
|
|
12
|
+
declare const BaseDialogClose: (props: BaseDialogCloseProps) => import("react").JSX.Element;
|
|
13
|
+
export { BaseDialogClose as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/dialog/BaseDialogClose.tsx
|
|
5
|
+
/** A button that closes the dialog. Renders a `<button>`. */
|
|
6
|
+
const BaseDialogClose = (props) => /* @__PURE__ */ jsx(Dialog.Close, { ...props });
|
|
7
|
+
export { BaseDialogClose as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseDialogDescriptionProps = ComponentProps<"p"> & {
|
|
4
|
+
render?: RenderProp<"p">;
|
|
5
|
+
};
|
|
6
|
+
/** A paragraph that describes the dialog to assistive technology. Renders a `<p>`. */
|
|
7
|
+
declare const BaseDialogDescription: (props: BaseDialogDescriptionProps) => import("react").JSX.Element;
|
|
8
|
+
export { BaseDialogDescription as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/dialog/BaseDialogDescription.tsx
|
|
5
|
+
/** A paragraph that describes the dialog to assistive technology. Renders a `<p>`. */
|
|
6
|
+
const BaseDialogDescription = (props) => /* @__PURE__ */ jsx(Dialog.Description, { ...props });
|
|
7
|
+
export { BaseDialogDescription as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps, RefObject } from "react";
|
|
3
|
+
export type DialogPopupState = {
|
|
4
|
+
open: boolean;
|
|
5
|
+
/** Whether the dialog is inside another dialog. */
|
|
6
|
+
nested: boolean;
|
|
7
|
+
/** Whether a dialog inside this one is open. */
|
|
8
|
+
nestedDialogOpen: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type DialogBackdropState = {
|
|
11
|
+
open: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** How the dialog was opened or closed. Empty when it's unknown (e.g. opened from code). */
|
|
14
|
+
export type DialogInteractionType = "mouse" | "touch" | "pen" | "keyboard" | "";
|
|
15
|
+
/**
|
|
16
|
+
* - `true`: the default (the first tabbable element when opening, the trigger when closing).
|
|
17
|
+
* - `false`: don't move focus.
|
|
18
|
+
* - a ref: focus that element.
|
|
19
|
+
* - a function: return an element, `true` / `null` for the default, or `false` / `undefined` to not move focus.
|
|
20
|
+
*/
|
|
21
|
+
export type DialogFocusTarget = boolean | RefObject<HTMLElement | null> | ((interactionType: DialogInteractionType) => boolean | HTMLElement | null | void);
|
|
22
|
+
type BaseDialogPopupProps = ComponentProps<"div"> & {
|
|
23
|
+
/** The popup's width: `xs` 288px, `sm` 320px, `md` 384px, `lg` 512px. Never wider than the viewport. */
|
|
24
|
+
size?: "lg" | "md" | "sm" | "xs";
|
|
25
|
+
render?: RenderProp<"div", DialogPopupState>;
|
|
26
|
+
/** The element focused when the dialog opens. */
|
|
27
|
+
initialFocus?: DialogFocusTarget;
|
|
28
|
+
/** The element focused when the dialog closes. */
|
|
29
|
+
finalFocus?: DialogFocusTarget;
|
|
30
|
+
/** Where the popup is portaled to. Defaults to `<body>`. */
|
|
31
|
+
container?: HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null;
|
|
32
|
+
/** Keeps the popup in the DOM while the dialog is closed. */
|
|
33
|
+
keepMounted?: boolean;
|
|
34
|
+
/** Set to `false` to render no backdrop. Nested dialogs render none either way. */
|
|
35
|
+
backdrop?: boolean;
|
|
36
|
+
renderBackdrop?: RenderProp<"div", DialogBackdropState>;
|
|
37
|
+
};
|
|
38
|
+
/** The dialog's window, with its portal and backdrop. Renders a `<div>`. */
|
|
39
|
+
declare const BaseDialogPopup: ({ size, container, keepMounted, backdrop, renderBackdrop, className, ...otherProps }: BaseDialogPopupProps) => import("react").JSX.Element;
|
|
40
|
+
export { BaseDialogPopup as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/components/dialog/BaseDialogPopup.tsx
|
|
6
|
+
const sizes = {
|
|
7
|
+
xs: "w-72",
|
|
8
|
+
sm: "w-80",
|
|
9
|
+
md: "w-96",
|
|
10
|
+
lg: "w-lg"
|
|
11
|
+
};
|
|
12
|
+
/** The dialog's window, with its portal and backdrop. Renders a `<div>`. */
|
|
13
|
+
const BaseDialogPopup = ({ size = "md", container, keepMounted, backdrop = true, renderBackdrop, className, ...otherProps }) => /* @__PURE__ */ jsxs(Dialog.Portal, {
|
|
14
|
+
container,
|
|
15
|
+
keepMounted,
|
|
16
|
+
children: [backdrop && /* @__PURE__ */ jsx(Dialog.Backdrop, {
|
|
17
|
+
render: renderBackdrop,
|
|
18
|
+
className: cn("fixed", "inset-0", "min-h-dvh", "bg-black", "opacity-20", "transition-all", "duration-150", "data-ending-style:opacity-0", "data-starting-style:opacity-0", "dark:opacity-70", "supports-[-webkit-touch-callout:none]:absolute")
|
|
19
|
+
}), /* @__PURE__ */ jsx(Dialog.Popup, {
|
|
20
|
+
...otherProps,
|
|
21
|
+
className: cn("fixed", "top-[calc(50%+1.25rem*var(--nested-dialogs))]", "left-1/2", "-mt-8", sizes[size], "max-w-[calc(100vw-3rem)]", "-translate-x-1/2", "-translate-y-1/2", "scale-[calc(1-0.1*var(--nested-dialogs))]", "transition-all", "duration-150", "data-ending-style:scale-90", "data-ending-style:opacity-0", "data-nested-dialog-open:after:absolute", "data-nested-dialog-open:after:inset-0", "data-nested-dialog-open:after:rounded-[inherit]", "data-nested-dialog-open:after:bg-black/5", "data-starting-style:scale-90", "data-starting-style:opacity-0", className)
|
|
22
|
+
})]
|
|
23
|
+
});
|
|
24
|
+
export { BaseDialogPopup as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type BaseDialogTitleProps = ComponentProps<"h2"> & {
|
|
4
|
+
render?: RenderProp<"h2">;
|
|
5
|
+
};
|
|
6
|
+
/** The dialog's heading, which also names the dialog. Renders an `<h2>`. */
|
|
7
|
+
declare const BaseDialogTitle: ({ className, ...otherProps }: BaseDialogTitleProps) => import("react").JSX.Element;
|
|
8
|
+
export { BaseDialogTitle as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/dialog/BaseDialogTitle.tsx
|
|
6
|
+
/** The dialog's heading, which also names the dialog. Renders an `<h2>`. */
|
|
7
|
+
const BaseDialogTitle = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Dialog.Title, {
|
|
8
|
+
...otherProps,
|
|
9
|
+
className: cn("-mt-1.5", "mb-1", "text-xl", "font-semibold", className)
|
|
10
|
+
});
|
|
11
|
+
export { BaseDialogTitle as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DialogHandle } from "./createDialogHandle.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
export type DialogTriggerState = {
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
/** Whether the dialog is open and was opened by this trigger. */
|
|
7
|
+
open: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type BaseDialogTriggerProps<Payload = unknown> = ComponentProps<"button"> & {
|
|
10
|
+
render?: RenderProp<"button", DialogTriggerState>;
|
|
11
|
+
/** Connects a trigger placed outside its `BaseDialog`. Create one with `createDialogHandle()`. */
|
|
12
|
+
handle?: DialogHandle<Payload>;
|
|
13
|
+
/** Passed to the dialog's function children when this trigger opens it. */
|
|
14
|
+
payload?: Payload;
|
|
15
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
16
|
+
nativeButton?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/** A button that opens the dialog. Renders a `<button>`, with `data-popup-open` while its dialog is open. */
|
|
19
|
+
declare const BaseDialogTrigger: <Payload>({ handle, ...otherProps }: BaseDialogTriggerProps<Payload>) => import("react").JSX.Element;
|
|
20
|
+
export { BaseDialogTrigger as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
3
|
+
import { toBaseUIHandle } from "./createDialogHandle.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/components/dialog/BaseDialogTrigger.tsx
|
|
6
|
+
/** A button that opens the dialog. Renders a `<button>`, with `data-popup-open` while its dialog is open. */
|
|
7
|
+
const BaseDialogTrigger = ({ handle, ...otherProps }) => /* @__PURE__ */ jsx(Dialog.Trigger, {
|
|
8
|
+
...otherProps,
|
|
9
|
+
handle: handle && toBaseUIHandle(handle)
|
|
10
|
+
});
|
|
11
|
+
export { BaseDialogTrigger as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opens and closes a dialog from anywhere: from triggers outside the dialog and from code.
|
|
3
|
+
* Create one with `createDialogHandle()` and pass it to `BaseDialog` and its triggers.
|
|
4
|
+
*
|
|
5
|
+
* Calls are ignored while no `BaseDialog` with this handle is mounted.
|
|
6
|
+
* Call the methods from event handlers or effects, never during render.
|
|
7
|
+
*/
|
|
8
|
+
export type DialogHandle<Payload = unknown> = {
|
|
9
|
+
/** Opens the dialog. Give a trigger's `id` to open it as if that trigger was pressed. */
|
|
10
|
+
open: (triggerId?: string | null) => void;
|
|
11
|
+
/** Opens the dialog with a payload, which `BaseDialog`'s function children receive. */
|
|
12
|
+
openWithPayload: (payload: Payload) => void;
|
|
13
|
+
close: () => void;
|
|
14
|
+
/** Whether the dialog is open. `false` while no `BaseDialog` with this handle is mounted. */
|
|
15
|
+
readonly isOpen: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Returns the Base UI handle behind a kit handle. Internal: not exported to apps.
|
|
19
|
+
* Its return type doesn't name Base UI so the declaration files don't either. Callers cast it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function toBaseUIHandle(handle: DialogHandle<never>): object | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a handle to open a dialog from triggers outside it, or from code.
|
|
24
|
+
* Pass the payload type to type the payload of triggers and `openWithPayload`.
|
|
25
|
+
*/
|
|
26
|
+
export default function createDialogHandle<Payload = unknown>(): DialogHandle<Payload>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
2
|
+
// src/components/dialog/createDialogHandle.ts
|
|
3
|
+
const baseUIHandles = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* Returns the Base UI handle behind a kit handle. Internal: not exported to apps.
|
|
6
|
+
* Its return type doesn't name Base UI so the declaration files don't either. Callers cast it.
|
|
7
|
+
*/
|
|
8
|
+
function toBaseUIHandle(handle) {
|
|
9
|
+
return baseUIHandles.get(handle);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a handle to open a dialog from triggers outside it, or from code.
|
|
13
|
+
* Pass the payload type to type the payload of triggers and `openWithPayload`.
|
|
14
|
+
*/
|
|
15
|
+
function createDialogHandle() {
|
|
16
|
+
const baseUIHandle = Dialog.createHandle();
|
|
17
|
+
const handle = {
|
|
18
|
+
open: (triggerId = null) => baseUIHandle.open(triggerId),
|
|
19
|
+
openWithPayload: (payload) => baseUIHandle.openWithPayload(payload),
|
|
20
|
+
close: () => baseUIHandle.close(),
|
|
21
|
+
get isOpen() {
|
|
22
|
+
return baseUIHandle.isOpen;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
baseUIHandles.set(handle, baseUIHandle);
|
|
26
|
+
return handle;
|
|
27
|
+
}
|
|
28
|
+
export { createDialogHandle as default, toBaseUIHandle };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import _default from "./BaseDialog.js";
|
|
2
|
+
import createDialogHandle, { DialogHandle } from "./createDialogHandle.js";
|
|
3
|
+
import { DialogBackdropState, DialogFocusTarget, DialogInteractionType, DialogPopupState } from "./BaseDialogPopup.js";
|
|
4
|
+
import { DialogCloseState } from "./BaseDialogClose.js";
|
|
5
|
+
import { DialogTriggerState } from "./BaseDialogTrigger.js";
|
|
6
|
+
export { _default as BaseDialog, type DialogBackdropState, type DialogCloseState, type DialogFocusTarget, type DialogHandle, type DialogInteractionType, type DialogPopupState, type DialogTriggerState, createDialogHandle };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export { AnimatedPopup, DialogBackdrop, DialogTitle };
|
|
1
|
+
import BaseDialog_default from "./BaseDialog.js";
|
|
2
|
+
import createDialogHandle from "./createDialogHandle.js";
|
|
3
|
+
export { BaseDialog_default as BaseDialog, createDialogHandle };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustAnchorProps = ComponentProps<"a"> & {
|
|
4
|
+
render?: RenderProp<"a">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustAnchor: ({ render, ...props }: JustAnchorProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
7
|
export { JustAnchor as default };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustButtonProps = ComponentProps<"button"> & {
|
|
4
|
+
render?: RenderProp<"button">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustButton: ({ render, ...props }: JustButtonProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
7
|
export { JustButton as default };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustDivProps = ComponentProps<"div"> & {
|
|
4
|
+
render?: RenderProp<"div">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustDiv: ({ render, ...props }: JustDivProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
7
|
export { JustDiv as default };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustInputProps = ComponentProps<"input"> & {
|
|
4
|
+
render?: RenderProp<"input">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustInput: ({ render, ...props }: JustInputProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
7
|
export { JustInput as default };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
type JustSpanProps = ComponentProps<"span"> & {
|
|
4
|
+
render?: RenderProp<"span">;
|
|
5
|
+
};
|
|
6
|
+
declare const JustSpan: ({ render, ...props }: JustSpanProps) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
7
|
export { JustSpan as default };
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentProps } from "react";
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
2
|
import { ZodType } from "zod";
|
|
3
|
+
export type FieldState = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
/** The control has lost focus at least once. */
|
|
6
|
+
touched: boolean;
|
|
7
|
+
/** The value differs from the initial one. */
|
|
8
|
+
dirty: boolean;
|
|
9
|
+
/** `null` until the field is validated. */
|
|
10
|
+
valid: boolean | null;
|
|
11
|
+
filled: boolean;
|
|
12
|
+
focused: boolean;
|
|
13
|
+
};
|
|
4
14
|
type BaseFormFieldProps = {
|
|
5
15
|
schema: ZodType;
|
|
6
16
|
name: string;
|
|
7
17
|
label?: string;
|
|
8
|
-
control?:
|
|
9
|
-
renderLabel?:
|
|
10
|
-
renderErrors?:
|
|
18
|
+
control?: RenderProp<"input", FieldState>;
|
|
19
|
+
renderLabel?: RenderProp<"label", FieldState>;
|
|
20
|
+
renderErrors?: RenderProp<"div", FieldState>;
|
|
11
21
|
className?: string;
|
|
12
22
|
};
|
|
13
23
|
declare const BaseFormField: ({ schema, name, label, control, renderLabel, renderErrors, className }: BaseFormFieldProps) => import("react").JSX.Element;
|
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
type
|
|
1
|
+
import { ComponentProps, ReactNode, Ref } from "react";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
export type SwitchState = {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
required: boolean;
|
|
8
|
+
};
|
|
9
|
+
type BaseSwitchProps = Omit<ComponentProps<"span">, "onChange" | "defaultChecked" | "defaultValue"> & {
|
|
4
10
|
label: ReactNode;
|
|
5
|
-
|
|
11
|
+
render?: RenderProp<"span", SwitchState>;
|
|
12
|
+
renderThumb?: RenderProp<"span", SwitchState>;
|
|
13
|
+
name?: string;
|
|
14
|
+
/** Submitted when checked. */
|
|
15
|
+
value?: string;
|
|
16
|
+
/** Submitted when unchecked. */
|
|
17
|
+
uncheckedValue?: string;
|
|
18
|
+
checked?: boolean;
|
|
19
|
+
defaultChecked?: boolean;
|
|
20
|
+
/** Called with the new state and the DOM event that changed it. */
|
|
21
|
+
onCheckedChange?: (checked: boolean, event: Event) => void;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
readOnly?: boolean;
|
|
24
|
+
required?: boolean;
|
|
25
|
+
/** The `id` of a `<form>` to submit with, when the switch isn't inside it. */
|
|
26
|
+
form?: string;
|
|
27
|
+
/** A ref to the hidden `<input>` that holds the value. */
|
|
28
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
29
|
+
/** Set to `true` when `render` renders a `<button>`. */
|
|
30
|
+
nativeButton?: boolean;
|
|
6
31
|
};
|
|
7
|
-
declare const BaseSwitch: ({ label, renderThumb, value, uncheckedValue, className, ...otherProps }: BaseSwitchProps) => import("react").JSX.Element;
|
|
32
|
+
declare const BaseSwitch: ({ label, renderThumb, onCheckedChange, value, uncheckedValue, className, ...otherProps }: BaseSwitchProps) => import("react").JSX.Element;
|
|
8
33
|
export { BaseSwitch as default };
|
|
@@ -3,12 +3,13 @@ import { cn } from "cn";
|
|
|
3
3
|
import "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/components/form/BaseSwitch.tsx
|
|
6
|
-
const BaseSwitch = ({ label, renderThumb, value = "true", uncheckedValue = "false", className, ...otherProps }) => /* @__PURE__ */ jsxs("label", {
|
|
6
|
+
const BaseSwitch = ({ label, renderThumb, onCheckedChange, value = "true", uncheckedValue = "false", className, ...otherProps }) => /* @__PURE__ */ jsxs("label", {
|
|
7
7
|
className: "flex items-center gap-2 text-sm font-normal",
|
|
8
8
|
children: [/* @__PURE__ */ jsx(Switch.Root, {
|
|
9
9
|
...otherProps,
|
|
10
10
|
value,
|
|
11
11
|
uncheckedValue,
|
|
12
|
+
onCheckedChange: onCheckedChange && ((checked, details) => onCheckedChange(checked, details.event)),
|
|
12
13
|
className: cn("flex", "h-5", "w-9", "shrink-0", "p-0.5", "transition-colors", "duration-150", "ease-[ease]", "focus-visible:outline-2", "focus-visible:outline-offset-2", className),
|
|
13
14
|
children: /* @__PURE__ */ jsx(Switch.Thumb, {
|
|
14
15
|
className: cn("size-3.5", "transition-[translate,background-color]", "duration-150", "ease-[ease]", "data-checked:translate-x-4"),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FieldState } from "./BaseFormField.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
3
|
import { ZodType } from "zod";
|
|
4
4
|
type ClientSideErrorProps = {
|
|
5
5
|
schema: ZodType;
|
|
6
|
-
render?:
|
|
6
|
+
render?: RenderProp<"div", FieldState>;
|
|
7
7
|
};
|
|
8
8
|
declare const ClientSideError: ({ schema, render }: ClientSideErrorProps) => import("react").JSX.Element[];
|
|
9
9
|
export { ClientSideError as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FieldState } from "./BaseFormField.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
3
|
type ServerSideErrorProps = {
|
|
4
4
|
name: string;
|
|
5
|
-
render?:
|
|
5
|
+
render?: RenderProp<"div", FieldState>;
|
|
6
6
|
};
|
|
7
7
|
declare const ServerSideError: ({ name, render }: ServerSideErrorProps) => import("react").JSX.Element[];
|
|
8
8
|
export { ServerSideError as default };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BaseInput from "./BaseInput.js";
|
|
2
|
-
import BaseSwitch from "./BaseSwitch.js";
|
|
2
|
+
import BaseSwitch, { SwitchState } from "./BaseSwitch.js";
|
|
3
3
|
import BaseForm from "./BaseForm.js";
|
|
4
|
-
import BaseFormField from "./BaseFormField.js";
|
|
4
|
+
import BaseFormField, { FieldState } from "./BaseFormField.js";
|
|
5
5
|
import useFormMessages from "./useFormMessages.js";
|
|
6
6
|
import { DisplayedFormMessage, MessageFormatter } from "./FormContext.js";
|
|
7
|
-
export { BaseForm, BaseFormField, BaseInput, BaseSwitch, type DisplayedFormMessage, type MessageFormatter, useFormMessages };
|
|
7
|
+
export { BaseForm, BaseFormField, BaseInput, BaseSwitch, type DisplayedFormMessage, type FieldState, type MessageFormatter, type SwitchState, useFormMessages };
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, JSX, ReactElement } from "react";
|
|
2
|
+
export type IntrinsicTag = keyof JSX.IntrinsicElements;
|
|
3
|
+
type RenderFunction<Tag extends IntrinsicTag, State> = (props: ComponentPropsWithRef<Tag>, state: State) => ReactElement;
|
|
4
|
+
/**
|
|
5
|
+
* Replaces the element a component renders.
|
|
6
|
+
* An element is rendered with the component's props merged into it.
|
|
7
|
+
* A function gets those props (spread them onto your element) and the component's state.
|
|
8
|
+
*/
|
|
9
|
+
export type RenderProp<Tag extends IntrinsicTag, State = object> = ReactElement | RenderFunction<Tag, State>;
|
|
10
|
+
export type UseRenderOptions<Tag extends IntrinsicTag, State extends object> = {
|
|
11
|
+
/** The element rendered when `render` is missing. */
|
|
12
|
+
defaultTagName: Tag;
|
|
13
|
+
render?: RenderProp<Tag, State>;
|
|
14
|
+
/** Props of the rendered element. They are merged into the `render` element's own props. */
|
|
15
|
+
props?: ComponentPropsWithRef<Tag>;
|
|
16
|
+
/** Passed to a `render` function, and set as data attributes (`{ checked: true }` → `data-checked`). */
|
|
17
|
+
state?: State;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Renders `defaultTagName`, or the element given by `render`, with `props` merged into it.
|
|
21
|
+
* Build a component that takes a `render` prop with it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useRender<Tag extends IntrinsicTag, State extends object = object>({ defaultTagName, render, props, state }: UseRenderOptions<Tag, State>): ReactElement;
|
|
24
|
+
type Props<Tag extends IntrinsicTag> = ComponentPropsWithRef<Tag>;
|
|
25
|
+
/**
|
|
26
|
+
* Merges props for one element, later ones winning.
|
|
27
|
+
* Event handlers are chained (later ones run first), `className`s are joined and `style`s are merged.
|
|
28
|
+
* `ref` is not merged.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mergeProps<Tag extends IntrinsicTag>(...props: (Props<Tag> | undefined)[]): Props<Tag>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { mergePropsN } from "@base-ui/react/merge-props";
|
|
2
|
+
import { useRender as useRender$1 } from "@base-ui/react/use-render";
|
|
3
|
+
// src/utils/render.ts
|
|
4
|
+
/**
|
|
5
|
+
* Renders `defaultTagName`, or the element given by `render`, with `props` merged into it.
|
|
6
|
+
* Build a component that takes a `render` prop with it.
|
|
7
|
+
*/
|
|
8
|
+
function useRender({ defaultTagName, render, props, state }) {
|
|
9
|
+
return useRender$1({
|
|
10
|
+
defaultTagName,
|
|
11
|
+
render,
|
|
12
|
+
props,
|
|
13
|
+
state
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Merges props for one element, later ones winning.
|
|
18
|
+
* Event handlers are chained (later ones run first), `className`s are joined and `style`s are merged.
|
|
19
|
+
* `ref` is not merged.
|
|
20
|
+
*/
|
|
21
|
+
function mergeProps(...props) {
|
|
22
|
+
return mergePropsN(props);
|
|
23
|
+
}
|
|
24
|
+
export { mergeProps, useRender };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omer-x/tailwind-ui-kit",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
4
4
|
"description": "Tailwind CSS-based React component library for building user interfaces",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tailwind",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"test:watch": "vitest --coverage",
|
|
70
70
|
"dev": "storybook dev -p 3000",
|
|
71
71
|
"build": "tsdown",
|
|
72
|
+
"postbuild": "node scripts/check-public-types.ts",
|
|
72
73
|
"build-storybook": "storybook build"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
-
declare const AnimatedPopup: ({ render, className, ...otherProps }: useRender.ComponentProps<"div">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
-
export { AnimatedPopup as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
-
import { cn } from "cn";
|
|
4
|
-
// src/components/dialog/AnimatedPopup.tsx
|
|
5
|
-
const AnimatedPopup = ({ render, className, ...otherProps }) => useRender({
|
|
6
|
-
defaultTagName: "div",
|
|
7
|
-
render,
|
|
8
|
-
props: mergeProps({ className: cn("fixed", "top-[calc(50%+1.25rem*var(--nested-dialogs))]", "left-1/2", "-mt-8", "w-96", "max-w-[calc(100vw-3rem)]", "-translate-x-1/2", "-translate-y-1/2", "scale-[calc(1-0.1*var(--nested-dialogs))]", "transition-all", "duration-150", "data-[ending-style]:scale-90", "data-[ending-style]:opacity-0", "data-[nested-dialog-open]:after:absolute", "data-[nested-dialog-open]:after:inset-0", "data-[nested-dialog-open]:after:rounded-[inherit]", "data-[nested-dialog-open]:after:bg-black/5", "data-[starting-style]:scale-90", "data-[starting-style]:opacity-0", className) }, otherProps)
|
|
9
|
-
});
|
|
10
|
-
export { AnimatedPopup as default };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
2
|
-
declare const DialogBackdrop: ({ render, ...otherProps }: useRender.ComponentProps<"div">) => import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
3
|
-
export { DialogBackdrop as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
-
import { cn } from "cn";
|
|
4
|
-
// src/components/dialog/DialogBackdrop.tsx
|
|
5
|
-
const DialogBackdrop = ({ render, ...otherProps }) => useRender({
|
|
6
|
-
defaultTagName: "div",
|
|
7
|
-
render,
|
|
8
|
-
props: mergeProps({ className: cn("fixed", "inset-0", "min-h-dvh", "bg-black", "opacity-20", "transition-all", "duration-150", "data-[ending-style]:opacity-0", "data-[starting-style]:opacity-0", "dark:opacity-70", "supports-[-webkit-touch-callout:none]:absolute") }, otherProps)
|
|
9
|
-
});
|
|
10
|
-
export { DialogBackdrop as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { mergeProps } from "@base-ui/react/merge-props";
|
|
2
|
-
import { useRender } from "@base-ui/react/use-render";
|
|
3
|
-
import { cn } from "cn";
|
|
4
|
-
// src/components/dialog/DialogTitle.tsx
|
|
5
|
-
const DialogTitle = ({ render, ...otherProps }) => useRender({
|
|
6
|
-
defaultTagName: "h2",
|
|
7
|
-
render,
|
|
8
|
-
props: mergeProps({ className: cn("-mt-1.5", "mb-1", "text-xl", "font-semibold") }, otherProps)
|
|
9
|
-
});
|
|
10
|
-
export { DialogTitle as default };
|