@omer-x/tailwind-ui-kit 1.0.0-alpha.31 → 1.0.0-alpha.32
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 +28 -0
- package/dist/components/form/BaseCheckbox.d.ts +6 -1
- package/dist/components/form/BaseCheckbox.js +10 -3
- package/dist/components/form/BaseCheckboxGroup.d.ts +24 -0
- package/dist/components/form/BaseCheckboxGroup.js +20 -0
- package/dist/components/form/index.d.ts +2 -1
- package/dist/components/form/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -166,6 +166,7 @@ A Base UI [`Checkbox`](https://base-ui.com/react/components/checkbox) with its l
|
|
|
166
166
|
| `renderIndicator` | `RenderProp<"span", CheckboxState>` | | Style the indicator that holds the icon |
|
|
167
167
|
| `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when unchecked (e.g. to animate it out) |
|
|
168
168
|
| `indeterminate` | `boolean` | `false` | Show the mixed state (`aria-checked="mixed"`). It doesn't change `checked` |
|
|
169
|
+
| `parent` | `boolean` | `false` | Make it the "select all" checkbox of a `BaseCheckboxGroup` with `allValues`. It checks or clears the whole group, is indeterminate when only some are checked, and isn't submitted |
|
|
169
170
|
| `value` | `string` | `"true"` | Submitted when checked |
|
|
170
171
|
| `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
|
|
171
172
|
| `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
|
|
@@ -184,6 +185,33 @@ Render functions get `CheckboxState`: `{ checked, disabled, readOnly, required,
|
|
|
184
185
|
/>
|
|
185
186
|
```
|
|
186
187
|
|
|
188
|
+
#### `BaseCheckboxGroup`
|
|
189
|
+
|
|
190
|
+
A Base UI [`Checkbox Group`](https://base-ui.com/react/components/checkbox-group): shared state for the checkboxes inside it. Its `name` is passed to every checkbox in the group, and each checked box submits its own `value` under that name, so the server reads them all with `formData.getAll(name)`. Checkboxes in a group never submit an unchecked value.
|
|
191
|
+
|
|
192
|
+
| Prop | Type | Default | Description |
|
|
193
|
+
|------|------|---------|-------------|
|
|
194
|
+
| `name` | `string` | | Submitted name of every checkbox in the group |
|
|
195
|
+
| `value` | `string[]` | | The `value`s of the checked boxes, when controlled |
|
|
196
|
+
| `defaultValue` | `string[]` | | The `value`s of the boxes checked at first |
|
|
197
|
+
| `onValueChange` | `(value: string[], event: Event) => void` | | Called with the new checked `value`s and the DOM event that changed it |
|
|
198
|
+
| `allValues` | `string[]` | | Every child `value`. Needed by a `BaseCheckbox` with `parent` ("select all") |
|
|
199
|
+
| `disabled` | `boolean` | | Disables every checkbox in the group |
|
|
200
|
+
| `className` | `string` | | Classes for the group `<div>` (default `flex flex-col gap-2`) |
|
|
201
|
+
| `render` | `RenderProp<"div", CheckboxGroupState>` | | Render another element for the group |
|
|
202
|
+
| …rest | | | `<div>` props. Give the group an accessible name with `aria-label` or `aria-labelledby` |
|
|
203
|
+
|
|
204
|
+
Render functions get `CheckboxGroupState`: `{ disabled }`. The group sets `data-disabled` when disabled.
|
|
205
|
+
|
|
206
|
+
With `BaseForm`'s `onlyDirty`, give the group an array default (`defaultValues={{ channels: ["email"] }}`). It is sent only when the set of checked values changed, and as an empty value when everything was unchecked.
|
|
207
|
+
|
|
208
|
+
```tsx
|
|
209
|
+
<BaseCheckboxGroup name="channels" aria-label="Channels" defaultValue={["email"]}>
|
|
210
|
+
<BaseCheckbox value="email" label="Email" />
|
|
211
|
+
<BaseCheckbox value="sms" label="SMS" />
|
|
212
|
+
</BaseCheckboxGroup>
|
|
213
|
+
```
|
|
214
|
+
|
|
187
215
|
#### `BaseForm`
|
|
188
216
|
|
|
189
217
|
A Base UI [`Form`](https://base-ui.com/react/components/form) connected to an action through React's `useActionState`. Actions are made with [`@omer-x/next-form-actions`](https://github.com/omermecitoglu/next-form-actions) (v2), which defines the result shape. Install it next to the kit:
|
|
@@ -28,6 +28,11 @@ type BaseCheckboxProps = Omit<ComponentProps<"span">, "onChange" | "defaultCheck
|
|
|
28
28
|
defaultChecked?: boolean;
|
|
29
29
|
/** Shows the mixed state. It doesn't change `checked`. */
|
|
30
30
|
indeterminate?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Makes this the "select all" checkbox of a `BaseCheckboxGroup` with `allValues`.
|
|
33
|
+
* It checks or clears the whole group, is indeterminate when only some boxes are checked, and isn't submitted.
|
|
34
|
+
*/
|
|
35
|
+
parent?: boolean;
|
|
31
36
|
/** Called with the new state and the DOM event that changed it. */
|
|
32
37
|
onCheckedChange?: (checked: boolean, event: Event) => void;
|
|
33
38
|
disabled?: boolean;
|
|
@@ -40,5 +45,5 @@ type BaseCheckboxProps = Omit<ComponentProps<"span">, "onChange" | "defaultCheck
|
|
|
40
45
|
/** Set to `true` when `render` renders a `<button>`. */
|
|
41
46
|
nativeButton?: boolean;
|
|
42
47
|
};
|
|
43
|
-
declare const BaseCheckbox: ({ label, labelClassName, icon, indeterminateIcon, renderIndicator, keepIndicatorMounted, onCheckedChange, value, uncheckedValue, indeterminate, className, ...otherProps }: BaseCheckboxProps) => import("react").JSX.Element;
|
|
48
|
+
declare const BaseCheckbox: ({ label, labelClassName, icon, indeterminateIcon, renderIndicator, keepIndicatorMounted, onCheckedChange, value, uncheckedValue, indeterminate, parent, className, ...otherProps }: BaseCheckboxProps) => import("react").JSX.Element;
|
|
44
49
|
export { BaseCheckbox as default };
|
|
@@ -2,22 +2,29 @@
|
|
|
2
2
|
import { Checkbox } from "@base-ui/react/checkbox";
|
|
3
3
|
import { cn } from "cn";
|
|
4
4
|
import "react";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
6
|
// src/components/form/BaseCheckbox.tsx
|
|
7
|
-
const BaseCheckbox = ({ label, labelClassName, icon, indeterminateIcon, renderIndicator, keepIndicatorMounted, onCheckedChange, value = "true", uncheckedValue = "false", indeterminate, className, ...otherProps }) => /* @__PURE__ */ jsxs("label", {
|
|
7
|
+
const BaseCheckbox = ({ label, labelClassName, icon, indeterminateIcon, renderIndicator, keepIndicatorMounted, onCheckedChange, value = "true", uncheckedValue = "false", indeterminate, parent, className, ...otherProps }) => /* @__PURE__ */ jsxs("label", {
|
|
8
8
|
className: cn("flex items-center gap-2 text-sm font-normal", labelClassName),
|
|
9
9
|
children: [/* @__PURE__ */ jsx(Checkbox.Root, {
|
|
10
10
|
...otherProps,
|
|
11
11
|
value,
|
|
12
12
|
uncheckedValue,
|
|
13
13
|
indeterminate,
|
|
14
|
+
parent,
|
|
14
15
|
onCheckedChange: onCheckedChange && ((checked, details) => onCheckedChange(checked, details.event)),
|
|
15
16
|
className: cn("flex", "size-4", "shrink-0", "items-center", "justify-center", "transition-colors", "duration-150", "ease-[ease]", "focus-visible:outline-2", "focus-visible:outline-offset-2", className),
|
|
16
17
|
children: /* @__PURE__ */ jsx(Checkbox.Indicator, {
|
|
17
18
|
keepMounted: keepIndicatorMounted,
|
|
18
19
|
className: "flex size-full items-center justify-center",
|
|
19
20
|
render: renderIndicator,
|
|
20
|
-
children:
|
|
21
|
+
children: parent ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
22
|
+
className: "contents in-data-indeterminate:hidden",
|
|
23
|
+
children: icon
|
|
24
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
25
|
+
className: "hidden in-data-indeterminate:contents",
|
|
26
|
+
children: indeterminateIcon ?? icon
|
|
27
|
+
})] }) : indeterminate ? indeterminateIcon ?? icon : icon
|
|
21
28
|
})
|
|
22
29
|
}), label]
|
|
23
30
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RenderProp } from "../../utils/render.js";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
export type CheckboxGroupState = {
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
};
|
|
6
|
+
type BaseCheckboxGroupProps = Omit<ComponentProps<"div">, "onChange" | "defaultValue"> & {
|
|
7
|
+
render?: RenderProp<"div", CheckboxGroupState>;
|
|
8
|
+
/**
|
|
9
|
+
* Submitted name of every checkbox in the group.
|
|
10
|
+
* Each checked box adds its own `value` under this name, so the server gets them all with `formData.getAll(name)`.
|
|
11
|
+
*/
|
|
12
|
+
name?: string;
|
|
13
|
+
/** The `value`s of the checked boxes, when controlled. */
|
|
14
|
+
value?: string[];
|
|
15
|
+
/** The `value`s of the boxes checked at first. */
|
|
16
|
+
defaultValue?: string[];
|
|
17
|
+
/** Called with the new list of checked `value`s and the DOM event that changed it. */
|
|
18
|
+
onValueChange?: (value: string[], event: Event) => void;
|
|
19
|
+
/** Every child `value`. Needed by a parent ("select all") checkbox. */
|
|
20
|
+
allValues?: string[];
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
};
|
|
23
|
+
declare const BaseCheckboxGroup: ({ name, onValueChange, className, ...otherProps }: BaseCheckboxGroupProps) => import("react").JSX.Element;
|
|
24
|
+
export { BaseCheckboxGroup as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { CheckboxGroup } from "@base-ui/react/checkbox-group";
|
|
3
|
+
import { Field } from "@base-ui/react/field";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
// src/components/form/BaseCheckboxGroup.tsx
|
|
7
|
+
const BaseCheckboxGroup = ({ name, onValueChange, className, ...otherProps }) => {
|
|
8
|
+
const group = /* @__PURE__ */ jsx(CheckboxGroup, {
|
|
9
|
+
...otherProps,
|
|
10
|
+
onValueChange: onValueChange && ((value, details) => onValueChange(value, details.event)),
|
|
11
|
+
className: cn("flex flex-col gap-2", className)
|
|
12
|
+
});
|
|
13
|
+
if (!name) return group;
|
|
14
|
+
return /* @__PURE__ */ jsx(Field.Root, {
|
|
15
|
+
name,
|
|
16
|
+
className: "contents",
|
|
17
|
+
children: group
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export { BaseCheckboxGroup as default };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import BaseInput from "./BaseInput.js";
|
|
2
2
|
import BaseSwitch, { SwitchState } from "./BaseSwitch.js";
|
|
3
3
|
import BaseCheckbox, { CheckboxState } from "./BaseCheckbox.js";
|
|
4
|
+
import BaseCheckboxGroup, { CheckboxGroupState } from "./BaseCheckboxGroup.js";
|
|
4
5
|
import BaseForm from "./BaseForm.js";
|
|
5
6
|
import BaseFormField, { FieldState } from "./BaseFormField.js";
|
|
6
7
|
import useFormMessages from "./useFormMessages.js";
|
|
7
8
|
import { DisplayedFormMessage, MessageFormatter } from "./FormContext.js";
|
|
8
|
-
export { BaseCheckbox, BaseForm, BaseFormField, BaseInput, BaseSwitch, type CheckboxState, type DisplayedFormMessage, type FieldState, type MessageFormatter, type SwitchState, useFormMessages };
|
|
9
|
+
export { BaseCheckbox, BaseCheckboxGroup, BaseForm, BaseFormField, BaseInput, BaseSwitch, type CheckboxGroupState, type CheckboxState, type DisplayedFormMessage, type FieldState, type MessageFormatter, type SwitchState, useFormMessages };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import BaseInput from "./BaseInput.js";
|
|
2
2
|
import BaseSwitch from "./BaseSwitch.js";
|
|
3
3
|
import BaseCheckbox from "./BaseCheckbox.js";
|
|
4
|
+
import BaseCheckboxGroup from "./BaseCheckboxGroup.js";
|
|
4
5
|
import BaseForm from "./BaseForm.js";
|
|
5
6
|
import BaseFormField from "./BaseFormField.js";
|
|
6
7
|
import useFormMessages from "./useFormMessages.js";
|
|
7
|
-
export { BaseCheckbox, BaseForm, BaseFormField, BaseInput, BaseSwitch, useFormMessages };
|
|
8
|
+
export { BaseCheckbox, BaseCheckboxGroup, BaseForm, BaseFormField, BaseInput, BaseSwitch, useFormMessages };
|