@omer-x/tailwind-ui-kit 1.0.0-alpha.28 → 1.0.0-alpha.29
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/README.md +68 -0
- package/dist/components/disclosure/BaseAccordion.d.ts +48 -0
- package/dist/components/disclosure/BaseAccordion.js +18 -0
- package/dist/components/disclosure/BaseAccordionItem.d.ts +20 -0
- package/dist/components/disclosure/BaseAccordionItem.js +10 -0
- package/dist/components/disclosure/BaseAccordionPanel.d.ts +20 -0
- package/dist/components/disclosure/BaseAccordionPanel.js +15 -0
- package/dist/components/disclosure/BaseAccordionTrigger.d.ts +22 -0
- package/dist/components/disclosure/BaseAccordionTrigger.js +23 -0
- package/dist/components/disclosure/index.d.ts +4 -0
- package/dist/components/disclosure/index.js +1 -0
- package/dist/components/disclosure/panelTransition.d.ts +7 -0
- package/dist/components/disclosure/panelTransition.js +9 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -405,6 +405,74 @@ A `DialogHandle<Payload>` has `open(triggerId?)`, `openWithPayload(payload)`, `c
|
|
|
405
405
|
- Calls are **ignored while the dialog isn't mounted**. Keep the `BaseDialog` with the handle rendered.
|
|
406
406
|
- Call them **from event handlers or effects, never during render**.
|
|
407
407
|
|
|
408
|
+
### `@omer-x/tailwind-ui-kit/disclosure`
|
|
409
|
+
|
|
410
|
+
#### `BaseAccordion`
|
|
411
|
+
|
|
412
|
+
A Base UI [`Accordion`](https://base-ui.com/react/components/accordion): collapsible panels with headings. `Trigger` brings the heading around it, so each item needs three parts:
|
|
413
|
+
|
|
414
|
+
```tsx
|
|
415
|
+
import { BaseAccordion } from "@omer-x/tailwind-ui-kit/disclosure";
|
|
416
|
+
|
|
417
|
+
<BaseAccordion className="rounded-md border">
|
|
418
|
+
<BaseAccordion.Item value="shipping" className="border-b last:border-b-0">
|
|
419
|
+
<BaseAccordion.Trigger className="px-5 py-4 data-panel-open:bg-blue-50" icon={<ChevronDown />} iconClassName="in-data-panel-open:rotate-180">
|
|
420
|
+
Shipping
|
|
421
|
+
</BaseAccordion.Trigger>
|
|
422
|
+
<BaseAccordion.Panel>
|
|
423
|
+
<div className="px-5 py-4">Orders ship within two days.</div>
|
|
424
|
+
</BaseAccordion.Panel>
|
|
425
|
+
</BaseAccordion.Item>
|
|
426
|
+
</BaseAccordion>
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
The parts are reached with dot notation (`BaseAccordion.Item`), which only works in client components. Build accordions in a `"use client"` file, e.g. your app's themed wrapper.
|
|
430
|
+
|
|
431
|
+
| Part | Renders | Description |
|
|
432
|
+
|------|---------|-------------|
|
|
433
|
+
| `BaseAccordion` | `<div>` | Groups the items and holds which ones are open |
|
|
434
|
+
| `BaseAccordion.Item` | `<div>` | Groups a trigger with its panel |
|
|
435
|
+
| `BaseAccordion.Trigger` | `<h3>` around a `<button>` | The heading that labels the panel, and the button that opens and closes it. A full-width flex row (`justify-between`) with a focus outline |
|
|
436
|
+
| `BaseAccordion.Panel` | `<div>` | The item's content, with a height transition (shared with Collapsible). **Put padding on an element inside it**, so it can shrink to zero |
|
|
437
|
+
|
|
438
|
+
Every part takes `className` and `render`.
|
|
439
|
+
|
|
440
|
+
`BaseAccordion` props:
|
|
441
|
+
|
|
442
|
+
| Prop | Type | Default | Description |
|
|
443
|
+
|------|------|---------|-------------|
|
|
444
|
+
| `value` / `defaultValue` | `Value[]` | `[]` | Controlled / initial values of the open items |
|
|
445
|
+
| `onValueChange` | `(value, event) => void` | | Called with the open items' values and the DOM event that changed them (`undefined` when changed from code) |
|
|
446
|
+
| `multiple` | `boolean` | `false` | Lets several items be open at once |
|
|
447
|
+
| `disabled` | `boolean` | `false` | Ignores user interaction on every item |
|
|
448
|
+
| `keepMounted` | `boolean` | `false` | Keeps closed panels in the DOM |
|
|
449
|
+
| `hiddenUntilFound` | `boolean` | `false` | Keeps closed panels hidden with `hidden="until-found"`, so the browser's page search finds and opens them. Overrides `keepMounted` |
|
|
450
|
+
| `render` | `RenderProp<"div", AccordionState>` | | The state is `{ value, disabled }` |
|
|
451
|
+
|
|
452
|
+
`BaseAccordion.Item` props:
|
|
453
|
+
|
|
454
|
+
| Prop | Type | Default | Description |
|
|
455
|
+
|------|------|---------|-------------|
|
|
456
|
+
| `value` | `unknown` | generated | Identifies the item in the accordion's `value` |
|
|
457
|
+
| `disabled` | `boolean` | `false` | Ignores user interaction on this item |
|
|
458
|
+
| `onOpenChange` | `(open, event) => void` | | Called with the item's new state and the DOM event |
|
|
459
|
+
| `render` | `RenderProp<"div", AccordionItemState>` | | The state is `{ open, disabled, index }` |
|
|
460
|
+
|
|
461
|
+
`BaseAccordion.Trigger` props:
|
|
462
|
+
|
|
463
|
+
| Prop | Type | Default | Description |
|
|
464
|
+
|------|------|---------|-------------|
|
|
465
|
+
| `icon` | `ReactNode` | | Shown after the text, in a `<span>` with a transform transition. Nothing is rendered without it |
|
|
466
|
+
| `iconClassName` | `string` | | Classes for the icon's `<span>`, e.g. `in-data-panel-open:rotate-180` |
|
|
467
|
+
| `headerClassName` | `string` | | Classes for the heading |
|
|
468
|
+
| `renderHeader` | `RenderProp<"h3", AccordionItemState>` | | Replaces the heading, e.g. `<h2 />` for another level |
|
|
469
|
+
| `render` | `RenderProp<"button", AccordionItemState>` | | Replaces the button |
|
|
470
|
+
| `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
|
|
471
|
+
|
|
472
|
+
`BaseAccordion.Panel` takes `keepMounted` and `hiddenUntilFound` (overriding the accordion's) and `render` (`RenderProp<"div", AccordionPanelState>`, the item's state plus `transitionStatus`).
|
|
473
|
+
|
|
474
|
+
Data attributes: the item, heading and panel have `data-open` and `data-index`. The trigger has `data-panel-open`. Disabled parts have `data-disabled`. The panel has `data-starting-style` / `data-ending-style` during its transition.
|
|
475
|
+
|
|
408
476
|
### `@omer-x/tailwind-ui-kit/layout`
|
|
409
477
|
|
|
410
478
|
#### `Container`
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AccordionItemState } from "./BaseAccordionItem.js";
|
|
2
|
+
import { AccordionPanelState } from "./BaseAccordionPanel.js";
|
|
3
|
+
import { RenderProp } from "../../utils/render.js";
|
|
4
|
+
import { ComponentProps } from "react";
|
|
5
|
+
export type AccordionState<Value = unknown> = {
|
|
6
|
+
/** The values of the open items. */
|
|
7
|
+
value: Value[];
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
};
|
|
10
|
+
type BaseAccordionProps<Value = unknown> = Omit<ComponentProps<"div">, "defaultValue"> & {
|
|
11
|
+
render?: RenderProp<"div", AccordionState<Value>>;
|
|
12
|
+
/** The values of the open items (controlled). */
|
|
13
|
+
value?: Value[];
|
|
14
|
+
/** The values of the items open at first. */
|
|
15
|
+
defaultValue?: Value[];
|
|
16
|
+
/** Called with the values of the open items and the DOM event that changed them (none when changed from code). */
|
|
17
|
+
onValueChange?: (value: Value[], event: Event | undefined) => void;
|
|
18
|
+
/** Lets several items be open at once. */
|
|
19
|
+
multiple?: boolean;
|
|
20
|
+
/** Ignores user interaction on every item. */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** Keeps closed panels in the DOM. */
|
|
23
|
+
keepMounted?: boolean;
|
|
24
|
+
/** Lets the browser's page search find and open closed panels. Overrides `keepMounted`. */
|
|
25
|
+
hiddenUntilFound?: boolean;
|
|
26
|
+
};
|
|
27
|
+
declare const _default: (<Value>({ onValueChange, ...otherProps }: BaseAccordionProps<Value>) => import("react").JSX.Element) & {
|
|
28
|
+
Item: ({ onOpenChange, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
29
|
+
render?: RenderProp<"div", AccordionItemState>;
|
|
30
|
+
value?: unknown;
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
33
|
+
}) => import("react").JSX.Element;
|
|
34
|
+
Trigger: ({ icon, iconClassName, headerClassName, renderHeader, className, children, ...otherProps }: import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
35
|
+
render?: RenderProp<"button", AccordionItemState>;
|
|
36
|
+
icon?: import("react").ReactNode;
|
|
37
|
+
iconClassName?: string;
|
|
38
|
+
headerClassName?: string;
|
|
39
|
+
renderHeader?: RenderProp<"h3", AccordionItemState>;
|
|
40
|
+
nativeButton?: boolean;
|
|
41
|
+
}) => import("react").JSX.Element;
|
|
42
|
+
Panel: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
43
|
+
render?: RenderProp<"div", AccordionPanelState>;
|
|
44
|
+
keepMounted?: boolean;
|
|
45
|
+
hiddenUntilFound?: boolean;
|
|
46
|
+
}) => import("react").JSX.Element;
|
|
47
|
+
};
|
|
48
|
+
export { _default as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Accordion } from "@base-ui/react/accordion";
|
|
3
|
+
import BaseAccordionItem from "./BaseAccordionItem.js";
|
|
4
|
+
import BaseAccordionPanel from "./BaseAccordionPanel.js";
|
|
5
|
+
import BaseAccordionTrigger from "./BaseAccordionTrigger.js";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
// src/components/disclosure/BaseAccordion.tsx
|
|
8
|
+
/** Groups the items of an accordion. Renders a `<div>`. */
|
|
9
|
+
const BaseAccordion = ({ onValueChange, ...otherProps }) => /* @__PURE__ */ jsx(Accordion.Root, {
|
|
10
|
+
...otherProps,
|
|
11
|
+
onValueChange: onValueChange && ((value, details) => onValueChange(value, details.event))
|
|
12
|
+
});
|
|
13
|
+
var BaseAccordion_default = Object.assign(BaseAccordion, {
|
|
14
|
+
Item: BaseAccordionItem,
|
|
15
|
+
Trigger: BaseAccordionTrigger,
|
|
16
|
+
Panel: BaseAccordionPanel
|
|
17
|
+
});
|
|
18
|
+
export { BaseAccordion_default as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type AccordionItemState = {
|
|
4
|
+
/** Whether the item's panel is open. */
|
|
5
|
+
open: boolean;
|
|
6
|
+
disabled: boolean;
|
|
7
|
+
/** The item's position in the accordion. */
|
|
8
|
+
index: number;
|
|
9
|
+
};
|
|
10
|
+
type BaseAccordionItemProps = ComponentProps<"div"> & {
|
|
11
|
+
render?: RenderProp<"div", AccordionItemState>;
|
|
12
|
+
/** Identifies the item in the accordion's `value`. Generated when missing. */
|
|
13
|
+
value?: unknown;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Called with the new state and the DOM event that changed it (none when changed from code). */
|
|
16
|
+
onOpenChange?: (open: boolean, event: Event | undefined) => void;
|
|
17
|
+
};
|
|
18
|
+
/** Groups a trigger with its panel. Renders a `<div>`, with `data-open` while its panel is open. */
|
|
19
|
+
declare const BaseAccordionItem: ({ onOpenChange, ...otherProps }: BaseAccordionItemProps) => import("react").JSX.Element;
|
|
20
|
+
export { BaseAccordionItem as default };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Accordion } from "@base-ui/react/accordion";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/components/disclosure/BaseAccordionItem.tsx
|
|
5
|
+
/** Groups a trigger with its panel. Renders a `<div>`, with `data-open` while its panel is open. */
|
|
6
|
+
const BaseAccordionItem = ({ onOpenChange, ...otherProps }) => /* @__PURE__ */ jsx(Accordion.Item, {
|
|
7
|
+
...otherProps,
|
|
8
|
+
onOpenChange: onOpenChange && ((open, details) => onOpenChange(open, details.event))
|
|
9
|
+
});
|
|
10
|
+
export { BaseAccordionItem as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AccordionItemState } from "./BaseAccordionItem.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps } from "react";
|
|
4
|
+
export type AccordionPanelState = AccordionItemState & {
|
|
5
|
+
/** `"starting"` while opening, `"ending"` while closing. */
|
|
6
|
+
transitionStatus: "starting" | "ending" | "idle" | undefined;
|
|
7
|
+
};
|
|
8
|
+
type BaseAccordionPanelProps = ComponentProps<"div"> & {
|
|
9
|
+
render?: RenderProp<"div", AccordionPanelState>;
|
|
10
|
+
/** Keeps the panel in the DOM while closed. */
|
|
11
|
+
keepMounted?: boolean;
|
|
12
|
+
/** Lets the browser's page search find and open the panel. Overrides `keepMounted`. */
|
|
13
|
+
hiddenUntilFound?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The item's collapsible content, with a height transition. Renders a `<div>`.
|
|
17
|
+
* Put padding on an element inside it, so the panel can shrink to zero.
|
|
18
|
+
*/
|
|
19
|
+
declare const BaseAccordionPanel: ({ className, ...otherProps }: BaseAccordionPanelProps) => import("react").JSX.Element;
|
|
20
|
+
export { BaseAccordionPanel as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Accordion } from "@base-ui/react/accordion";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import panelTransition from "./panelTransition.js";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/components/disclosure/BaseAccordionPanel.tsx
|
|
7
|
+
/**
|
|
8
|
+
* The item's collapsible content, with a height transition. Renders a `<div>`.
|
|
9
|
+
* Put padding on an element inside it, so the panel can shrink to zero.
|
|
10
|
+
*/
|
|
11
|
+
const BaseAccordionPanel = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Accordion.Panel, {
|
|
12
|
+
...otherProps,
|
|
13
|
+
className: cn("[--disclosure-panel-height:var(--accordion-panel-height)]", panelTransition, className)
|
|
14
|
+
});
|
|
15
|
+
export { BaseAccordionPanel as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AccordionItemState } from "./BaseAccordionItem.js";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
import { ComponentProps, ReactNode } from "react";
|
|
4
|
+
type BaseAccordionTriggerProps = ComponentProps<"button"> & {
|
|
5
|
+
render?: RenderProp<"button", AccordionItemState>;
|
|
6
|
+
/** Shown after the text, e.g. a chevron. Rotate it with `iconClassName="in-data-panel-open:rotate-180"`. */
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
/** Classes for the `<span>` around the icon. */
|
|
9
|
+
iconClassName?: string;
|
|
10
|
+
/** Classes for the heading around the trigger. */
|
|
11
|
+
headerClassName?: string;
|
|
12
|
+
/** Replaces the heading around the trigger, e.g. `<h2 />` for another level. */
|
|
13
|
+
renderHeader?: RenderProp<"h3", AccordionItemState>;
|
|
14
|
+
/** Set to `false` when `render` doesn't render a `<button>`. */
|
|
15
|
+
nativeButton?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A button that opens and closes its item's panel, inside the heading that labels the panel.
|
|
19
|
+
* Renders an `<h3>` around a `<button>`, with `data-panel-open` while the panel is open.
|
|
20
|
+
*/
|
|
21
|
+
declare const BaseAccordionTrigger: ({ icon, iconClassName, headerClassName, renderHeader, className, children, ...otherProps }: BaseAccordionTriggerProps) => import("react").JSX.Element;
|
|
22
|
+
export { BaseAccordionTrigger as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Accordion } from "@base-ui/react/accordion";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
// src/components/disclosure/BaseAccordionTrigger.tsx
|
|
6
|
+
/**
|
|
7
|
+
* A button that opens and closes its item's panel, inside the heading that labels the panel.
|
|
8
|
+
* Renders an `<h3>` around a `<button>`, with `data-panel-open` while the panel is open.
|
|
9
|
+
*/
|
|
10
|
+
const BaseAccordionTrigger = ({ icon, iconClassName, headerClassName, renderHeader, className, children, ...otherProps }) => /* @__PURE__ */ jsx(Accordion.Header, {
|
|
11
|
+
className: headerClassName,
|
|
12
|
+
render: renderHeader,
|
|
13
|
+
children: /* @__PURE__ */ jsxs(Accordion.Trigger, {
|
|
14
|
+
...otherProps,
|
|
15
|
+
className: cn("flex", "w-full", "items-center", "justify-between", "gap-2", "text-left", "focus-visible:outline-2", "focus-visible:outline-offset-2", "data-disabled:cursor-not-allowed", className),
|
|
16
|
+
children: [children, icon && /* @__PURE__ */ jsx("span", {
|
|
17
|
+
"aria-hidden": "true",
|
|
18
|
+
className: cn("flex", "shrink-0", "transition-transform", "duration-150", iconClassName),
|
|
19
|
+
children: icon
|
|
20
|
+
})]
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
export { BaseAccordionTrigger as default };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import _default, { AccordionState } from "./BaseAccordion.js";
|
|
2
|
+
import { AccordionItemState } from "./BaseAccordionItem.js";
|
|
3
|
+
import { AccordionPanelState } from "./BaseAccordionPanel.js";
|
|
4
|
+
export { type AccordionItemState, type AccordionPanelState, type AccordionState, _default as BaseAccordion };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BaseAccordion } from "./BaseAccordion.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The open/close transition shared by the disclosure panels (Accordion, Collapsible).
|
|
3
|
+
* Each panel maps Base UI's own height variable onto `--disclosure-panel-height`.
|
|
4
|
+
* The panel animates its height, so padding belongs on an element inside it.
|
|
5
|
+
*/
|
|
6
|
+
declare const panelTransition: string;
|
|
7
|
+
export { panelTransition as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { cn } from "cn";
|
|
2
|
+
// src/components/disclosure/panelTransition.ts
|
|
3
|
+
/**
|
|
4
|
+
* The open/close transition shared by the disclosure panels (Accordion, Collapsible).
|
|
5
|
+
* Each panel maps Base UI's own height variable onto `--disclosure-panel-height`.
|
|
6
|
+
* The panel animates its height, so padding belongs on an element inside it.
|
|
7
|
+
*/
|
|
8
|
+
const panelTransition = cn("h-(--disclosure-panel-height)", "overflow-hidden", "transition-[height]", "duration-150", "ease-out", "data-ending-style:h-0", "data-starting-style:h-0", "[&[hidden]:not([hidden=until-found])]:hidden");
|
|
9
|
+
export { panelTransition as default };
|
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.29",
|
|
4
4
|
"description": "Tailwind CSS-based React component library for building user interfaces",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tailwind",
|
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
"types": "./dist/components/dialog/index.d.ts",
|
|
47
47
|
"import": "./dist/components/dialog/index.js"
|
|
48
48
|
},
|
|
49
|
+
"./disclosure": {
|
|
50
|
+
"types": "./dist/components/disclosure/index.d.ts",
|
|
51
|
+
"import": "./dist/components/disclosure/index.js"
|
|
52
|
+
},
|
|
49
53
|
"./form": {
|
|
50
54
|
"types": "./dist/components/form/index.d.ts",
|
|
51
55
|
"import": "./dist/components/form/index.js"
|