@omer-x/tailwind-ui-kit 1.0.0-alpha.45 → 1.0.0-alpha.46

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 (65) hide show
  1. package/README.md +52 -1799
  2. package/dist/components/menu/menuTypes.d.ts +1 -1
  3. package/dist/components/navigation/BaseTabs.d.ts +44 -0
  4. package/dist/components/navigation/BaseTabs.js +24 -0
  5. package/dist/components/navigation/BaseTabsIndicator.d.ts +30 -0
  6. package/dist/components/navigation/BaseTabsIndicator.js +16 -0
  7. package/dist/components/navigation/BaseTabsList.d.ts +19 -0
  8. package/dist/components/navigation/BaseTabsList.js +14 -0
  9. package/dist/components/navigation/BaseTabsPanel.d.ts +19 -0
  10. package/dist/components/navigation/BaseTabsPanel.js +11 -0
  11. package/dist/components/navigation/BaseTabsTab.d.ts +20 -0
  12. package/dist/components/navigation/BaseTabsTab.js +11 -0
  13. package/dist/components/navigation/index.d.ts +6 -0
  14. package/dist/components/navigation/index.js +1 -0
  15. package/dist/components/navigation/tabsTypes.d.ts +8 -0
  16. package/dist/components/navigation/tabsTypes.js +1 -0
  17. package/docs/button/BaseButton.md +32 -0
  18. package/docs/button/BaseToggle.md +29 -0
  19. package/docs/button/BaseToggleGroup.md +28 -0
  20. package/docs/dialog/BaseAlertDialog.md +36 -0
  21. package/docs/dialog/BaseDialog.md +61 -0
  22. package/docs/dialog/createAlertDialogHandle.md +21 -0
  23. package/docs/dialog/createDialogHandle.md +31 -0
  24. package/docs/disclosure/BaseAccordion.md +67 -0
  25. package/docs/disclosure/BaseCollapsible.md +56 -0
  26. package/docs/display/BaseAvatar.md +48 -0
  27. package/docs/display/BaseMeter.md +62 -0
  28. package/docs/elements/README.md +9 -0
  29. package/docs/feedback/BaseToast.md +91 -0
  30. package/docs/feedback/createToastManager.md +19 -0
  31. package/docs/feedback/useToast.md +37 -0
  32. package/docs/form/BaseAutocomplete.md +110 -0
  33. package/docs/form/BaseCheckbox.md +33 -0
  34. package/docs/form/BaseCheckboxGroup.md +28 -0
  35. package/docs/form/BaseFieldset.md +24 -0
  36. package/docs/form/BaseForm.md +89 -0
  37. package/docs/form/BaseFormField.md +47 -0
  38. package/docs/form/BaseInput.md +13 -0
  39. package/docs/form/BaseRadio.md +28 -0
  40. package/docs/form/BaseRadioGroup.md +35 -0
  41. package/docs/form/BaseSelect.md +109 -0
  42. package/docs/form/BaseSlider.md +93 -0
  43. package/docs/form/BaseSwitch.md +27 -0
  44. package/docs/form/useFormMessages.md +29 -0
  45. package/docs/hooks/useRipples.md +26 -0
  46. package/docs/layout/BaseSeparator.md +24 -0
  47. package/docs/layout/Container.md +5 -0
  48. package/docs/menu/BaseContextMenu.md +96 -0
  49. package/docs/menu/BaseMenu.md +84 -0
  50. package/docs/menu/BaseMenubar.md +45 -0
  51. package/docs/menu/createMenuHandle.md +31 -0
  52. package/docs/navigation/BaseTabs.md +69 -0
  53. package/docs/overlay/BaseTooltip.md +74 -0
  54. package/docs/overlay/createTooltipHandle.md +29 -0
  55. package/docs/page/Pagination.md +37 -0
  56. package/docs/page/usePagination.md +17 -0
  57. package/docs/providers/ToastProvider.md +11 -0
  58. package/docs/providers/TooltipProvider.md +17 -0
  59. package/docs/table/TableCell.md +16 -0
  60. package/docs/table/Tdx.md +5 -0
  61. package/docs/utils/RenderProp.md +5 -0
  62. package/docs/utils/cn.md +9 -0
  63. package/docs/utils/mergeProps.md +9 -0
  64. package/docs/utils/useRender.md +26 -0
  65. package/package.json +6 -1
@@ -65,5 +65,5 @@ export declare function splitFilterProps<Props extends MenuRootSharedProps>({ fi
65
65
  event: Event | undefined;
66
66
  }) => void) | undefined;
67
67
  } | null;
68
- rootProps: Omit<Props, "filter" | "locale" | "autoHighlight" | "filterable" | "query" | "defaultQuery" | "onQueryChange">;
68
+ rootProps: Omit<Props, "filter" | "locale" | "filterable" | "autoHighlight" | "query" | "defaultQuery" | "onQueryChange">;
69
69
  };
@@ -0,0 +1,44 @@
1
+ import { TabsTabState } from "./BaseTabsTab.js";
2
+ import { TabsIndicatorState } from "./BaseTabsIndicator.js";
3
+ import { TabsPanelState } from "./BaseTabsPanel.js";
4
+ import { TabsOrientation, TabsState } from "./tabsTypes.js";
5
+ import { RenderProp } from "../../utils/render.js";
6
+ import { ComponentProps } from "react";
7
+ type BaseTabsProps<Value = unknown> = Omit<ComponentProps<"div">, "defaultValue"> & {
8
+ render?: RenderProp<"div", TabsState>;
9
+ /** The value of the active tab (controlled). `null` activates none. */
10
+ value?: Value | null;
11
+ /** The value of the tab active at first. `null` activates none. Defaults to the first enabled tab. */
12
+ defaultValue?: Value | null;
13
+ /**
14
+ * Called with the value of the newly active tab and the DOM event that activated it.
15
+ * Uncontrolled tabs also call it when they pick a tab themselves (at first, or when the active tab is disabled or removed),
16
+ * with no event and possibly `null` when no enabled tab is left.
17
+ */
18
+ onValueChange?: (value: Value | null, event: Event | undefined) => void;
19
+ /** The direction of the tab list, and of the arrow keys that move between tabs. @default "horizontal" */
20
+ orientation?: TabsOrientation;
21
+ };
22
+ declare const _default: (<Value>({ onValueChange, className, ...otherProps }: BaseTabsProps<Value>) => import("react").JSX.Element) & {
23
+ List: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
24
+ render?: RenderProp<"div", TabsState>;
25
+ activateOnFocus?: boolean;
26
+ loopFocus?: boolean;
27
+ }) => import("react").JSX.Element;
28
+ Tab: ({ className, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "value"> & {
29
+ render?: RenderProp<"button", TabsTabState>;
30
+ value: unknown;
31
+ disabled?: boolean;
32
+ nativeButton?: boolean;
33
+ }) => import("react").JSX.Element;
34
+ Indicator: ({ className, ...otherProps }: import("react").ClassAttributes<HTMLSpanElement> & import("react").HTMLAttributes<HTMLSpanElement> & {
35
+ render?: RenderProp<"span", TabsIndicatorState>;
36
+ renderBeforeHydration?: boolean;
37
+ }) => import("react").JSX.Element;
38
+ Panel: ({ className, ...otherProps }: Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "value"> & {
39
+ render?: RenderProp<"div", TabsPanelState>;
40
+ value: unknown;
41
+ keepMounted?: boolean;
42
+ }) => import("react").JSX.Element;
43
+ };
44
+ export { _default as default };
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { Tabs } from "@base-ui/react/tabs";
3
+ import { cn } from "cn";
4
+ import BaseTabsIndicator from "./BaseTabsIndicator.js";
5
+ import BaseTabsList from "./BaseTabsList.js";
6
+ import BaseTabsPanel from "./BaseTabsPanel.js";
7
+ import BaseTabsTab from "./BaseTabsTab.js";
8
+ import { jsx } from "react/jsx-runtime";
9
+ // src/components/navigation/BaseTabs.tsx
10
+ /** Groups the tab list and its panels. Renders a `<div>`, a flex row while vertical. */
11
+ const BaseTabs = ({ onValueChange, className, ...otherProps }) => /* @__PURE__ */ jsx(Tabs.Root, {
12
+ ...otherProps,
13
+ className: cn("data-[orientation=vertical]:flex", className),
14
+ onValueChange: onValueChange && ((value, details) => {
15
+ onValueChange(value, details.reason === "none" ? details.event : void 0);
16
+ })
17
+ });
18
+ var BaseTabs_default = Object.assign(BaseTabs, {
19
+ List: BaseTabsList,
20
+ Tab: BaseTabsTab,
21
+ Indicator: BaseTabsIndicator,
22
+ Panel: BaseTabsPanel
23
+ });
24
+ export { BaseTabs_default as default };
@@ -0,0 +1,30 @@
1
+ import { TabsState } from "./tabsTypes.js";
2
+ import { RenderProp } from "../../utils/render.js";
3
+ import { ComponentProps } from "react";
4
+ export type TabsIndicatorState = TabsState & {
5
+ /** The active tab's offsets inside the list, in pixels. `null` while no tab is active. */
6
+ activeTabPosition: {
7
+ left: number;
8
+ right: number;
9
+ top: number;
10
+ bottom: number;
11
+ } | null;
12
+ /** The active tab's size, in pixels. `null` while no tab is active. */
13
+ activeTabSize: {
14
+ width: number;
15
+ height: number;
16
+ } | null;
17
+ };
18
+ type BaseTabsIndicatorProps = ComponentProps<"span"> & {
19
+ render?: RenderProp<"span", TabsIndicatorState>;
20
+ /** Renders the indicator before React hydrates, so it shows sooner after server rendering. @default false */
21
+ renderBeforeHydration?: boolean;
22
+ };
23
+ /**
24
+ * Follows the active tab. Put it inside `BaseTabs.List`. Renders a `<span>`.
25
+ * It covers the active tab and sits behind the tabs, with a transition. Turn it into an underline with
26
+ * e.g. `top-auto bottom-0 h-0.5`. The active tab's box is also in `--active-tab-left`, `-right`, `-top`,
27
+ * `-bottom`, `-width` and `-height`.
28
+ */
29
+ declare const BaseTabsIndicator: ({ className, ...otherProps }: BaseTabsIndicatorProps) => import("react").JSX.Element;
30
+ export { BaseTabsIndicator as default };
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { Tabs } from "@base-ui/react/tabs";
3
+ import { cn } from "cn";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/components/navigation/BaseTabsIndicator.tsx
6
+ /**
7
+ * Follows the active tab. Put it inside `BaseTabs.List`. Renders a `<span>`.
8
+ * It covers the active tab and sits behind the tabs, with a transition. Turn it into an underline with
9
+ * e.g. `top-auto bottom-0 h-0.5`. The active tab's box is also in `--active-tab-left`, `-right`, `-top`,
10
+ * `-bottom`, `-width` and `-height`.
11
+ */
12
+ const BaseTabsIndicator = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Tabs.Indicator, {
13
+ ...otherProps,
14
+ className: cn("absolute", "-z-10", "top-(--active-tab-top)", "left-(--active-tab-left)", "h-(--active-tab-height)", "w-(--active-tab-width)", "transition-all", "duration-200", "ease-in-out", className)
15
+ });
16
+ export { BaseTabsIndicator as default };
@@ -0,0 +1,19 @@
1
+ import { TabsState } from "./tabsTypes.js";
2
+ import { RenderProp } from "../../utils/render.js";
3
+ import { ComponentProps } from "react";
4
+ type BaseTabsListProps = ComponentProps<"div"> & {
5
+ render?: RenderProp<"div", TabsState>;
6
+ /**
7
+ * Activates a tab as soon as the arrow keys move focus to it. Otherwise <kbd>Enter</kbd> or <kbd>Space</kbd> activates it.
8
+ * @default false
9
+ */
10
+ activateOnFocus?: boolean;
11
+ /** Moves focus from the last tab back to the first with the arrow keys (and the other way). @default true */
12
+ loopFocus?: boolean;
13
+ };
14
+ /**
15
+ * Groups the tabs and positions the indicator. Renders a `<div>` with `role="tablist"`:
16
+ * a flex row (a column while vertical) that is `relative`, with its own stacking context.
17
+ */
18
+ declare const BaseTabsList: ({ className, ...otherProps }: BaseTabsListProps) => import("react").JSX.Element;
19
+ export { BaseTabsList as default };
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { Tabs } from "@base-ui/react/tabs";
3
+ import { cn } from "cn";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/components/navigation/BaseTabsList.tsx
6
+ /**
7
+ * Groups the tabs and positions the indicator. Renders a `<div>` with `role="tablist"`:
8
+ * a flex row (a column while vertical) that is `relative`, with its own stacking context.
9
+ */
10
+ const BaseTabsList = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Tabs.List, {
11
+ ...otherProps,
12
+ className: cn("relative", "isolate", "flex", "data-[orientation=vertical]:flex-col", className)
13
+ });
14
+ export { BaseTabsList as default };
@@ -0,0 +1,19 @@
1
+ import { TabsState } from "./tabsTypes.js";
2
+ import { RenderProp } from "../../utils/render.js";
3
+ import { ComponentProps } from "react";
4
+ export type TabsPanelState = TabsState & {
5
+ /** Whether the panel's tab is inactive. */
6
+ hidden: boolean;
7
+ /** `"starting"` while showing, `"ending"` while hiding. */
8
+ transitionStatus: "starting" | "ending" | "idle" | undefined;
9
+ };
10
+ type BaseTabsPanelProps = Omit<ComponentProps<"div">, "value"> & {
11
+ render?: RenderProp<"div", TabsPanelState>;
12
+ /** Shows the panel while the tab with the same `value` is active. */
13
+ value: unknown;
14
+ /** Keeps the panel in the DOM (hidden) while its tab is inactive. @default false */
15
+ keepMounted?: boolean;
16
+ };
17
+ /** The content of a tab. Renders a `<div>` with `role="tabpanel"`, with `data-hidden` while its tab is inactive. */
18
+ declare const BaseTabsPanel: ({ className, ...otherProps }: BaseTabsPanelProps) => import("react").JSX.Element;
19
+ export { BaseTabsPanel as default };
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { Tabs } from "@base-ui/react/tabs";
3
+ import { cn } from "cn";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/components/navigation/BaseTabsPanel.tsx
6
+ /** The content of a tab. Renders a `<div>` with `role="tabpanel"`, with `data-hidden` while its tab is inactive. */
7
+ const BaseTabsPanel = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Tabs.Panel, {
8
+ ...otherProps,
9
+ className: cn("focus-visible:outline-2", "focus-visible:outline-offset-2", className)
10
+ });
11
+ export { BaseTabsPanel as default };
@@ -0,0 +1,20 @@
1
+ import { TabsState } from "./tabsTypes.js";
2
+ import { RenderProp } from "../../utils/render.js";
3
+ import { ComponentProps } from "react";
4
+ export type TabsTabState = TabsState & {
5
+ /** Whether the tab is the active one. */
6
+ active: boolean;
7
+ disabled: boolean;
8
+ };
9
+ type BaseTabsTabProps = Omit<ComponentProps<"button">, "value"> & {
10
+ render?: RenderProp<"button", TabsTabState>;
11
+ /** Identifies the tab in the tabs' `value`, and links it to the panel with the same `value`. */
12
+ value: unknown;
13
+ /** Ignores user interaction. A disabled first tab isn't picked when the tabs have no `defaultValue`. */
14
+ disabled?: boolean;
15
+ /** Set to `false` when `render` doesn't render a `<button>`. */
16
+ nativeButton?: boolean;
17
+ };
18
+ /** A button that activates its panel. Renders a `<button>` with `role="tab"`, with `data-active` while active. */
19
+ declare const BaseTabsTab: ({ className, ...otherProps }: BaseTabsTabProps) => import("react").JSX.Element;
20
+ export { BaseTabsTab as default };
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { Tabs } from "@base-ui/react/tabs";
3
+ import { cn } from "cn";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/components/navigation/BaseTabsTab.tsx
6
+ /** A button that activates its panel. Renders a `<button>` with `role="tab"`, with `data-active` while active. */
7
+ const BaseTabsTab = ({ className, ...otherProps }) => /* @__PURE__ */ jsx(Tabs.Tab, {
8
+ ...otherProps,
9
+ className: cn("inline-flex", "items-center", "justify-center", "gap-2", "whitespace-nowrap", "cursor-pointer", "focus-visible:outline-2", "focus-visible:outline-offset-2", "data-disabled:cursor-not-allowed", className)
10
+ });
11
+ export { BaseTabsTab as default };
@@ -0,0 +1,6 @@
1
+ import _default from "./BaseTabs.js";
2
+ import { TabsActivationDirection, TabsOrientation, TabsState } from "./tabsTypes.js";
3
+ import { TabsTabState } from "./BaseTabsTab.js";
4
+ import { TabsIndicatorState } from "./BaseTabsIndicator.js";
5
+ import { TabsPanelState } from "./BaseTabsPanel.js";
6
+ export { _default as BaseTabs, type TabsActivationDirection, type TabsIndicatorState, type TabsOrientation, type TabsPanelState, type TabsState, type TabsTabState };
@@ -0,0 +1 @@
1
+ export { default as BaseTabs } from "./BaseTabs.js";
@@ -0,0 +1,8 @@
1
+ export type TabsOrientation = "horizontal" | "vertical";
2
+ /** Where the newly active tab is, relative to the one active before it. */
3
+ export type TabsActivationDirection = "left" | "right" | "up" | "down" | "none";
4
+ export type TabsState = {
5
+ orientation: TabsOrientation;
6
+ /** Where the active tab moved, also set as `data-activation-direction`. */
7
+ tabActivationDirection: TabsActivationDirection;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ # `BaseButton`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/button`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ A Base UI [`Button`](https://base-ui.com/react/components/button) with sizes, a pending state and a ripple effect on click.
6
+
7
+ | Prop | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | Height, padding, font size and gap |
10
+ | `pending` | `boolean` | `false` | Shows the spinner, blocks clicks and keeps the button focusable |
11
+ | `spinner` | `ReactNode` | | Shown while pending. Without it nothing is shown, and `data-pending` still marks the state |
12
+ | `iconOnly` | `boolean` | `false` | A square button for a single icon. Requires `aria-label`. While pending, the spinner replaces the icon |
13
+ | `render` | `RenderProp<"button", ButtonState>` | | Render another element, e.g. your app's link. The state is `{ disabled }` |
14
+ | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
15
+ | `focusableWhenDisabled` | `boolean` | `false` | Keeps a disabled button in the tab order |
16
+ | …rest | `<button>` props | | `disabled`, `type`, `onClick`, … |
17
+
18
+ - **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`.
19
+ - Children are laid out with flex and a size-based gap, so icons and text line up without extra markup.
20
+ - 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.
21
+ - The kit bundles no icons. Pass your own `spinner` (and icons as children), usually once in your themed wrapper.
22
+
23
+ ```tsx
24
+ <Button size="sm" pending={isSaving}>Save</Button>
25
+ <Button iconOnly aria-label="Delete"><TrashIcon /></Button>
26
+ ```
27
+
28
+ **Links that look like buttons:** render your app's own link (so typed routes keep working) and set `nativeButton={false}`:
29
+
30
+ ```tsx
31
+ <Button render={<Link href="/products/new" />} nativeButton={false}>New product</Button>
32
+ ```
@@ -0,0 +1,29 @@
1
+ # `BaseToggle`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/button`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ A Base UI [`Toggle`](https://base-ui.com/react/components/toggle): a two-state button that is pressed or not. It shares `BaseButton`'s sizes and ripple effect.
6
+
7
+ | Prop | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `pressed` | `boolean` | | Whether it's pressed, when controlled |
10
+ | `defaultPressed` | `boolean` | `false` | Whether it's pressed at first |
11
+ | `onPressedChange` | `(pressed: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
12
+ | `value` | `string` | | Identifies the toggle inside a `BaseToggleGroup` |
13
+ | `size` | `"lg" \| "md" \| "sm" \| "xs"` | `"md"` | Same heights, padding, font sizes and gaps as `BaseButton` |
14
+ | `iconOnly` | `boolean` | `false` | A square toggle for a single icon. Requires `aria-label` |
15
+ | `render` | `RenderProp<"button", ToggleState>` | | Render another element. The state is `{ pressed, disabled }` |
16
+ | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
17
+ | …rest | `<button>` props | | `disabled`, `onClick`, `aria-label`, … (`type` is always `"button"`) |
18
+
19
+ It sets `aria-pressed`, plus `data-pressed` while pressed, `data-disabled` and `data-icon-only`. Style the pressed look with `data-pressed:`. The ripple is skipped when `onClick` calls `preventDefault()`.
20
+
21
+ ```tsx
22
+ <BaseToggle
23
+ iconOnly
24
+ aria-label="Favorite"
25
+ className="border border-neutral-400 data-pressed:bg-neutral-700 data-pressed:text-white"
26
+ >
27
+ <StarIcon />
28
+ </BaseToggle>
29
+ ```
@@ -0,0 +1,28 @@
1
+ # `BaseToggleGroup`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/button`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ A Base UI [`Toggle Group`](https://base-ui.com/react/components/toggle-group): shared state for the `BaseToggle`s inside it. Give every toggle a `value`. By default pressing one releases the others; arrow keys move focus between them.
6
+
7
+ | Prop | Type | Default | Description |
8
+ |------|------|---------|-------------|
9
+ | `value` | `readonly string[]` | | The `value`s of the pressed toggles, when controlled |
10
+ | `defaultValue` | `readonly string[]` | | The `value`s of the toggles pressed at first |
11
+ | `onValueChange` | `(value: string[], event: Event) => void` | | Called with the pressed `value`s and the DOM event that changed them |
12
+ | `multiple` | `boolean` | `false` | Lets several toggles be pressed at once |
13
+ | `disabled` | `boolean` | `false` | Disables every toggle in the group |
14
+ | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Arrow-key direction, and the layout direction |
15
+ | `loopFocus` | `boolean` | `true` | Moves focus from the last toggle back to the first with the arrow keys |
16
+ | `className` | `string` | | Classes for the group `<div>` (default `flex`, `flex-col` when vertical) |
17
+ | `render` | `RenderProp<"div", ToggleGroupState>` | | Render another element for the group |
18
+ | …rest | `<div>` props | | Name the group with `aria-label` or `aria-labelledby` |
19
+
20
+ Render functions get `ToggleGroupState`: `{ disabled, multiple, orientation }`. The group has `role="group"` and sets `data-orientation`, `data-disabled` and `data-multiple`. Each toggle keeps its own `data-pressed` / `data-disabled`.
21
+
22
+ ```tsx
23
+ <BaseToggleGroup aria-label="Text alignment" defaultValue={["left"]} className="gap-1">
24
+ <Toggle value="left">Left</Toggle>
25
+ <Toggle value="center">Center</Toggle>
26
+ <Toggle value="right">Right</Toggle>
27
+ </BaseToggleGroup>
28
+ ```
@@ -0,0 +1,36 @@
1
+ # `BaseAlertDialog`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/dialog`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ A Base UI [`Alert Dialog`](https://base-ui.com/react/components/alert-dialog): a modal dialog the user has to respond to. It works like `BaseDialog`, with these differences:
6
+
7
+ - The popup has `role="alertdialog"`.
8
+ - It is always modal, and outside presses don't close it. Escape and `Close` buttons still do. There are no `modal` or `disablePointerDismissal` props.
9
+ - `Popup`, `Title`, `Description` and `Close` are `BaseDialog`'s parts, so they look the same and take the same props (`size`, `initialFocus`, `renderBackdrop`, …).
10
+
11
+ ```tsx
12
+ import { BaseAlertDialog } from "@omer-x/tailwind-ui-kit/dialog";
13
+
14
+ <BaseAlertDialog>
15
+ <BaseAlertDialog.Trigger render={<Button />}>Discard draft</BaseAlertDialog.Trigger>
16
+ <BaseAlertDialog.Popup size="sm" className="rounded-lg bg-white p-6 shadow-lg">
17
+ <BaseAlertDialog.Title>Discard draft?</BaseAlertDialog.Title>
18
+ <BaseAlertDialog.Description>You can't undo this action.</BaseAlertDialog.Description>
19
+ <BaseAlertDialog.Close render={<Button />}>Cancel</BaseAlertDialog.Close>
20
+ <BaseAlertDialog.Close render={<Button />} onClick={discard}>Discard</BaseAlertDialog.Close>
21
+ </BaseAlertDialog.Popup>
22
+ </BaseAlertDialog>
23
+ ```
24
+
25
+ | Part | Renders | Description |
26
+ |------|---------|-------------|
27
+ | `BaseAlertDialog` | nothing | Groups the parts and holds the open state |
28
+ | `BaseAlertDialog.Trigger` | `<button>` | Opens the alert dialog. `data-popup-open` while its alert dialog is open |
29
+ | `BaseAlertDialog.Popup` | `<div>` | Same as `BaseDialog.Popup` |
30
+ | `BaseAlertDialog.Title` | `<h2>` | Same as `BaseDialog.Title` |
31
+ | `BaseAlertDialog.Description` | `<p>` | Same as `BaseDialog.Description` |
32
+ | `BaseAlertDialog.Close` | `<button>` | Same as `BaseDialog.Close` |
33
+
34
+ `BaseAlertDialog` takes `BaseDialog`'s props except `modal` and `disablePointerDismissal`: `open`, `defaultOpen`, `onOpenChange`, `onOpenChangeComplete`, `handle` (an `AlertDialogHandle<Payload>`), `triggerId`, `defaultTriggerId` and `children` (parts, or a function of `{ payload }`).
35
+
36
+ Put it inside a `BaseDialog.Popup` to confirm something from a dialog: it stacks on top like a nested dialog.
@@ -0,0 +1,61 @@
1
+ # `BaseDialog`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/dialog`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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:
6
+
7
+ ```tsx
8
+ import { BaseDialog } from "@omer-x/tailwind-ui-kit/dialog";
9
+
10
+ <BaseDialog>
11
+ <BaseDialog.Trigger render={<Button />}>Delete</BaseDialog.Trigger>
12
+ <BaseDialog.Popup className="rounded-lg bg-white p-6 shadow-lg">
13
+ <BaseDialog.Title>Delete item?</BaseDialog.Title>
14
+ <BaseDialog.Description>This can't be undone.</BaseDialog.Description>
15
+ <BaseDialog.Close render={<Button />}>Cancel</BaseDialog.Close>
16
+ </BaseDialog.Popup>
17
+ </BaseDialog>
18
+ ```
19
+
20
+ 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.
21
+
22
+ | Part | Renders | Description |
23
+ |------|---------|-------------|
24
+ | `BaseDialog` | nothing | Groups the parts and holds the open state |
25
+ | `BaseDialog.Trigger` | `<button>` | Opens the dialog. `data-popup-open` while its dialog is open |
26
+ | `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 |
27
+ | `BaseDialog.Title` | `<h2>` | The heading that names the dialog (`text-xl font-semibold`) |
28
+ | `BaseDialog.Description` | `<p>` | Describes the dialog to assistive technology |
29
+ | `BaseDialog.Close` | `<button>` | Closes the dialog |
30
+
31
+ Every part takes `className` and `render`. `Trigger` and `Close` also take `nativeButton` (set it to `false` when `render` doesn't render a `<button>`).
32
+
33
+ `BaseDialog` props:
34
+
35
+ | Prop | Type | Default | Description |
36
+ |------|------|---------|-------------|
37
+ | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial open state |
38
+ | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
39
+ | `onOpenChangeComplete` | `(open) => void` | | Called after the open or close transition ends |
40
+ | `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 |
41
+ | `disablePointerDismissal` | `boolean` | `false` | Keeps the dialog open on outside presses |
42
+ | `handle` | `DialogHandle<Payload>` | | Connects triggers outside the dialog and opens it from code (see below) |
43
+ | `triggerId` / `defaultTriggerId` | `string \| null` | | The trigger a controlled / initially open dialog belongs to |
44
+ | `children` | `ReactNode \| ({ payload }) => ReactNode` | | The parts, or a function that gets the payload of the trigger that opened the dialog |
45
+
46
+ `BaseDialog.Popup` props:
47
+
48
+ | Prop | Type | Default | Description |
49
+ |------|------|---------|-------------|
50
+ | `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` |
51
+ | `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"`) |
52
+ | `finalFocus` | `DialogFocusTarget` | `true` | The element focused on close. `true` is the trigger |
53
+ | `container` | `HTMLElement \| ShadowRoot \| RefObject \| null` | `<body>` | Where the popup is portaled to |
54
+ | `keepMounted` | `boolean` | `false` | Keeps the popup in the DOM while closed |
55
+ | `backdrop` | `boolean` | `true` | Set to `false` for no backdrop. Nested dialogs never render one |
56
+ | `renderBackdrop` | `RenderProp<"div", DialogBackdropState>` | | Style or replace the backdrop: a fixed full-screen black overlay (`opacity-20`, `dark:opacity-70`) with a fade transition. A `className` on the element wins over the kit's conflicting classes (`<div className="opacity-50" />`). A function gets the kit's classes in `props.className` |
57
+ | `render` | `RenderProp<"div", DialogPopupState>` | | The state is `{ open, nested, nestedDialogOpen }` |
58
+
59
+ 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).
60
+
61
+ **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.
@@ -0,0 +1,21 @@
1
+ # `createAlertDialogHandle`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/dialog`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ `createDialogHandle` for alert dialogs. It returns an `AlertDialogHandle<Payload>` with the same methods (`open`, `openWithPayload`, `close`, `isOpen`) and the same rules. Pass it to `BaseAlertDialog` and `BaseAlertDialog.Trigger`:
6
+
7
+ ```tsx
8
+ import { BaseAlertDialog, createAlertDialogHandle } from "@omer-x/tailwind-ui-kit/dialog";
9
+
10
+ const removeAlert = createAlertDialogHandle<{ id: string, name: string }>();
11
+
12
+ <BaseAlertDialog.Trigger handle={removeAlert} payload={member} render={<Button />}>Remove</BaseAlertDialog.Trigger>
13
+
14
+ <BaseAlertDialog handle={removeAlert}>
15
+ {({ payload }) => payload && (
16
+ <BaseAlertDialog.Popup size="sm">
17
+ <BaseAlertDialog.Title>Remove {payload.name}?</BaseAlertDialog.Title>
18
+ </BaseAlertDialog.Popup>
19
+ )}
20
+ </BaseAlertDialog>
21
+ ```
@@ -0,0 +1,31 @@
1
+ # `createDialogHandle`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/dialog`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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:
6
+
7
+ ```tsx
8
+ import { BaseDialog, createDialogHandle } from "@omer-x/tailwind-ui-kit/dialog";
9
+
10
+ const deleteDialog = createDialogHandle<{ id: string, name: string }>();
11
+
12
+ // triggers anywhere on the page
13
+ <BaseDialog.Trigger handle={deleteDialog} payload={{ id: p.id, name: p.name }} render={<Button />}>Delete</BaseDialog.Trigger>
14
+
15
+ // one dialog on the page
16
+ <BaseDialog handle={deleteDialog}>
17
+ {({ payload }) => payload && (
18
+ <BaseDialog.Popup size="sm">
19
+ <BaseDialog.Title>Delete {payload.name}?</BaseDialog.Title>
20
+ </BaseDialog.Popup>
21
+ )}
22
+ </BaseDialog>
23
+
24
+ // from code
25
+ deleteDialog.openWithPayload({ id, name });
26
+ ```
27
+
28
+ A `DialogHandle<Payload>` has `open(triggerId?)`, `openWithPayload(payload)`, `close()` and `isOpen`.
29
+
30
+ - Calls are **ignored while the dialog isn't mounted**. Keep the `BaseDialog` with the handle rendered.
31
+ - Call them **from event handlers or effects, never during render**.
@@ -0,0 +1,67 @@
1
+ # `BaseAccordion`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/disclosure`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ 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:
6
+
7
+ ```tsx
8
+ import { BaseAccordion } from "@omer-x/tailwind-ui-kit/disclosure";
9
+
10
+ <BaseAccordion className="rounded-md border">
11
+ <BaseAccordion.Item value="shipping" className="border-b last:border-b-0">
12
+ <BaseAccordion.Trigger className="px-5 py-4 data-panel-open:bg-blue-50" icon={<ChevronDown />} iconClassName="in-data-panel-open:rotate-180">
13
+ Shipping
14
+ </BaseAccordion.Trigger>
15
+ <BaseAccordion.Panel>
16
+ <div className="px-5 py-4">Orders ship within two days.</div>
17
+ </BaseAccordion.Panel>
18
+ </BaseAccordion.Item>
19
+ </BaseAccordion>
20
+ ```
21
+
22
+ 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.
23
+
24
+ | Part | Renders | Description |
25
+ |------|---------|-------------|
26
+ | `BaseAccordion` | `<div>` | Groups the items and holds which ones are open |
27
+ | `BaseAccordion.Item` | `<div>` | Groups a trigger with its panel |
28
+ | `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 |
29
+ | `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 |
30
+
31
+ Every part takes `className` and `render`.
32
+
33
+ `BaseAccordion` props:
34
+
35
+ | Prop | Type | Default | Description |
36
+ |------|------|---------|-------------|
37
+ | `value` / `defaultValue` | `Value[]` | `[]` | Controlled / initial values of the open items |
38
+ | `onValueChange` | `(value, event) => void` | | Called with the open items' values and the DOM event that changed them (`undefined` when changed from code) |
39
+ | `multiple` | `boolean` | `false` | Lets several items be open at once |
40
+ | `disabled` | `boolean` | `false` | Ignores user interaction on every item |
41
+ | `keepMounted` | `boolean` | `false` | Keeps closed panels in the DOM |
42
+ | `hiddenUntilFound` | `boolean` | `false` | Keeps closed panels hidden with `hidden="until-found"`, so the browser's page search finds and opens them. Overrides `keepMounted` |
43
+ | `render` | `RenderProp<"div", AccordionState>` | | The state is `{ value, disabled }` |
44
+
45
+ `BaseAccordion.Item` props:
46
+
47
+ | Prop | Type | Default | Description |
48
+ |------|------|---------|-------------|
49
+ | `value` | `unknown` | generated | Identifies the item in the accordion's `value` |
50
+ | `disabled` | `boolean` | `false` | Ignores user interaction on this item |
51
+ | `onOpenChange` | `(open, event) => void` | | Called with the item's new state and the DOM event |
52
+ | `render` | `RenderProp<"div", AccordionItemState>` | | The state is `{ open, disabled, index }` |
53
+
54
+ `BaseAccordion.Trigger` props:
55
+
56
+ | Prop | Type | Default | Description |
57
+ |------|------|---------|-------------|
58
+ | `icon` | `ReactNode` | | Shown after the text, in a `<span>` with a transform transition. Nothing is rendered without it |
59
+ | `iconClassName` | `string` | | Classes for the icon's `<span>`, e.g. `in-data-panel-open:rotate-180` |
60
+ | `headerClassName` | `string` | | Classes for the heading |
61
+ | `renderHeader` | `RenderProp<"h3", AccordionItemState>` | | Replaces the heading, e.g. `<h2 />` for another level |
62
+ | `render` | `RenderProp<"button", AccordionItemState>` | | Replaces the button |
63
+ | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
64
+
65
+ `BaseAccordion.Panel` takes `keepMounted` and `hiddenUntilFound` (overriding the accordion's) and `render` (`RenderProp<"div", AccordionPanelState>`, the item's state plus `transitionStatus`).
66
+
67
+ 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.
@@ -0,0 +1,56 @@
1
+ # `BaseCollapsible`
2
+
3
+ Import from `@omer-x/tailwind-ui-kit/disclosure`. See the [README](../../README.md) for setup, theming and the other components.
4
+
5
+ A Base UI [`Collapsible`](https://base-ui.com/react/components/collapsible): a panel shown or hidden by a button.
6
+
7
+ ```tsx
8
+ import { BaseCollapsible } from "@omer-x/tailwind-ui-kit/disclosure";
9
+
10
+ <BaseCollapsible>
11
+ <BaseCollapsible.Trigger className="rounded-md px-3 py-1.5" icon={<ChevronDown />} iconClassName="in-data-panel-open:rotate-180">
12
+ Recovery keys
13
+ </BaseCollapsible.Trigger>
14
+ <BaseCollapsible.Panel>
15
+ <div className="p-4">alien-bean-pasta</div>
16
+ </BaseCollapsible.Panel>
17
+ </BaseCollapsible>
18
+ ```
19
+
20
+ Like `BaseAccordion`, the parts use dot notation, so build collapsibles in a `"use client"` file.
21
+
22
+ | Part | Renders | Description |
23
+ |------|---------|-------------|
24
+ | `BaseCollapsible` | `<div>` | Groups the trigger with the panel and holds whether it is open |
25
+ | `BaseCollapsible.Trigger` | `<button>` | Opens and closes the panel. An inline flex row with a focus outline |
26
+ | `BaseCollapsible.Panel` | `<div>` | The content, with a height transition (shared with Accordion). **Put padding on an element inside it**, so it can shrink to zero |
27
+
28
+ Every part takes `className` and `render`.
29
+
30
+ `BaseCollapsible` props:
31
+
32
+ | Prop | Type | Default | Description |
33
+ |------|------|---------|-------------|
34
+ | `open` / `defaultOpen` | `boolean` | `false` | Controlled / initial state of the panel |
35
+ | `onOpenChange` | `(open, event) => void` | | Called with the new state and the DOM event that changed it (`undefined` when changed from code) |
36
+ | `disabled` | `boolean` | `false` | Ignores user interaction |
37
+ | `render` | `RenderProp<"div", CollapsibleState>` | | The state is `{ open, disabled }` |
38
+
39
+ `BaseCollapsible.Trigger` props:
40
+
41
+ | Prop | Type | Default | Description |
42
+ |------|------|---------|-------------|
43
+ | `icon` | `ReactNode` | | Shown after the text, in a `<span>` with a transform transition. Nothing is rendered without it |
44
+ | `iconClassName` | `string` | | Classes for the icon's `<span>`, e.g. `in-data-panel-open:rotate-180` |
45
+ | `render` | `RenderProp<"button", CollapsibleState>` | | Replaces the button |
46
+ | `nativeButton` | `boolean` | `true` | Set to `false` when `render` doesn't render a `<button>` |
47
+
48
+ `BaseCollapsible.Panel` props:
49
+
50
+ | Prop | Type | Default | Description |
51
+ |------|------|---------|-------------|
52
+ | `keepMounted` | `boolean` | `false` | Keeps the closed panel in the DOM |
53
+ | `hiddenUntilFound` | `boolean` | `false` | Keeps the closed panel hidden with `hidden="until-found"`, so the browser's page search finds and opens it. Overrides `keepMounted` |
54
+ | `render` | `RenderProp<"div", CollapsiblePanelState>` | | The state is `{ open, disabled, transitionStatus }` |
55
+
56
+ Data attributes: the root and panel have `data-open` / `data-closed`. The trigger has `data-panel-open`. Disabled parts have `data-disabled`. The panel has `data-starting-style` / `data-ending-style` during its transition.