@omer-x/tailwind-ui-kit 1.0.0-alpha.30 → 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 +59 -0
- package/dist/components/form/BaseCheckbox.d.ts +49 -0
- package/dist/components/form/BaseCheckbox.js +31 -0
- package/dist/components/form/BaseCheckboxGroup.d.ts +24 -0
- package/dist/components/form/BaseCheckboxGroup.js +20 -0
- package/dist/components/form/index.d.ts +3 -1
- package/dist/components/form/index.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -153,6 +153,65 @@ Render functions get `SwitchState`: `{ checked, disabled, readOnly, required }`.
|
|
|
153
153
|
/>
|
|
154
154
|
```
|
|
155
155
|
|
|
156
|
+
#### `BaseCheckbox`
|
|
157
|
+
|
|
158
|
+
A Base UI [`Checkbox`](https://base-ui.com/react/components/checkbox) with its label. Like `BaseSwitch`, it submits `"true"` / `"false"` by default, so its value always appears in form data, also inside `BaseForm`.
|
|
159
|
+
|
|
160
|
+
| Prop | Type | Default | Description |
|
|
161
|
+
|------|------|---------|-------------|
|
|
162
|
+
| `label` | `ReactNode` | | Text next to the checkbox (required) |
|
|
163
|
+
| `labelClassName` | `string` | | Classes for the `<label>` around the checkbox and its text (default `flex items-center gap-2 text-sm font-normal`) |
|
|
164
|
+
| `icon` | `ReactNode` | | Shown inside the box when checked. The kit bundles none |
|
|
165
|
+
| `indeterminateIcon` | `ReactNode` | `icon` | Shown inside the box when indeterminate |
|
|
166
|
+
| `renderIndicator` | `RenderProp<"span", CheckboxState>` | | Style the indicator that holds the icon |
|
|
167
|
+
| `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when unchecked (e.g. to animate it out) |
|
|
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 |
|
|
170
|
+
| `value` | `string` | `"true"` | Submitted when checked |
|
|
171
|
+
| `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
|
|
172
|
+
| `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
|
|
173
|
+
| `render` | `RenderProp<"span", CheckboxState>` | | Render another element for the box |
|
|
174
|
+
| …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
|
|
175
|
+
|
|
176
|
+
Render functions get `CheckboxState`: `{ checked, disabled, readOnly, required, indeterminate }`. The box and the indicator set `data-checked` / `data-unchecked`, `data-indeterminate`, `data-disabled`, `data-readonly` and `data-required`. The indicator also sets `data-starting-style` / `data-ending-style` while it enters and leaves.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
<BaseCheckbox
|
|
180
|
+
name="terms"
|
|
181
|
+
label="I accept the terms"
|
|
182
|
+
className="rounded border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
|
|
183
|
+
renderIndicator={<span className="text-white" />}
|
|
184
|
+
icon={<CheckIcon />}
|
|
185
|
+
/>
|
|
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
|
+
|
|
156
215
|
#### `BaseForm`
|
|
157
216
|
|
|
158
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:
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ComponentProps, ReactNode, Ref } from "react";
|
|
2
|
+
import { RenderProp } from "../../utils/render.js";
|
|
3
|
+
export type CheckboxState = {
|
|
4
|
+
checked: boolean;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
readOnly: boolean;
|
|
7
|
+
required: boolean;
|
|
8
|
+
indeterminate: boolean;
|
|
9
|
+
};
|
|
10
|
+
type BaseCheckboxProps = Omit<ComponentProps<"span">, "onChange" | "defaultChecked" | "defaultValue"> & {
|
|
11
|
+
label: ReactNode;
|
|
12
|
+
render?: RenderProp<"span", CheckboxState>;
|
|
13
|
+
/** Classes for the `<label>` around the checkbox and its text. */
|
|
14
|
+
labelClassName?: string;
|
|
15
|
+
/** Shown inside the box when checked. */
|
|
16
|
+
icon?: ReactNode;
|
|
17
|
+
/** Shown inside the box when indeterminate. Falls back to `icon`. */
|
|
18
|
+
indeterminateIcon?: ReactNode;
|
|
19
|
+
renderIndicator?: RenderProp<"span", CheckboxState>;
|
|
20
|
+
/** Keep the indicator in the DOM when unchecked, e.g. to animate it out with CSS. */
|
|
21
|
+
keepIndicatorMounted?: boolean;
|
|
22
|
+
name?: string;
|
|
23
|
+
/** Submitted when checked. */
|
|
24
|
+
value?: string;
|
|
25
|
+
/** Submitted when unchecked. */
|
|
26
|
+
uncheckedValue?: string;
|
|
27
|
+
checked?: boolean;
|
|
28
|
+
defaultChecked?: boolean;
|
|
29
|
+
/** Shows the mixed state. It doesn't change `checked`. */
|
|
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;
|
|
36
|
+
/** Called with the new state and the DOM event that changed it. */
|
|
37
|
+
onCheckedChange?: (checked: boolean, event: Event) => void;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
readOnly?: boolean;
|
|
40
|
+
required?: boolean;
|
|
41
|
+
/** The `id` of a `<form>` to submit with, when the checkbox isn't inside it. */
|
|
42
|
+
form?: string;
|
|
43
|
+
/** A ref to the hidden `<input>` that holds the value. */
|
|
44
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
45
|
+
/** Set to `true` when `render` renders a `<button>`. */
|
|
46
|
+
nativeButton?: boolean;
|
|
47
|
+
};
|
|
48
|
+
declare const BaseCheckbox: ({ label, labelClassName, icon, indeterminateIcon, renderIndicator, keepIndicatorMounted, onCheckedChange, value, uncheckedValue, indeterminate, parent, className, ...otherProps }: BaseCheckboxProps) => import("react").JSX.Element;
|
|
49
|
+
export { BaseCheckbox as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Checkbox } from "@base-ui/react/checkbox";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/components/form/BaseCheckbox.tsx
|
|
7
|
+
const BaseCheckbox = ({ label, labelClassName, icon, indeterminateIcon, renderIndicator, keepIndicatorMounted, onCheckedChange, value = "true", uncheckedValue = "false", indeterminate, parent, className, ...otherProps }) => /* @__PURE__ */ jsxs("label", {
|
|
8
|
+
className: cn("flex items-center gap-2 text-sm font-normal", labelClassName),
|
|
9
|
+
children: [/* @__PURE__ */ jsx(Checkbox.Root, {
|
|
10
|
+
...otherProps,
|
|
11
|
+
value,
|
|
12
|
+
uncheckedValue,
|
|
13
|
+
indeterminate,
|
|
14
|
+
parent,
|
|
15
|
+
onCheckedChange: onCheckedChange && ((checked, details) => onCheckedChange(checked, details.event)),
|
|
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),
|
|
17
|
+
children: /* @__PURE__ */ jsx(Checkbox.Indicator, {
|
|
18
|
+
keepMounted: keepIndicatorMounted,
|
|
19
|
+
className: "flex size-full items-center justify-center",
|
|
20
|
+
render: renderIndicator,
|
|
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
|
|
28
|
+
})
|
|
29
|
+
}), label]
|
|
30
|
+
});
|
|
31
|
+
export { BaseCheckbox as default };
|
|
@@ -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,7 +1,9 @@
|
|
|
1
1
|
import BaseInput from "./BaseInput.js";
|
|
2
2
|
import BaseSwitch, { SwitchState } from "./BaseSwitch.js";
|
|
3
|
+
import BaseCheckbox, { CheckboxState } from "./BaseCheckbox.js";
|
|
4
|
+
import BaseCheckboxGroup, { CheckboxGroupState } from "./BaseCheckboxGroup.js";
|
|
3
5
|
import BaseForm from "./BaseForm.js";
|
|
4
6
|
import BaseFormField, { FieldState } from "./BaseFormField.js";
|
|
5
7
|
import useFormMessages from "./useFormMessages.js";
|
|
6
8
|
import { DisplayedFormMessage, MessageFormatter } from "./FormContext.js";
|
|
7
|
-
export { BaseForm, BaseFormField, BaseInput, BaseSwitch, 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,6 +1,8 @@
|
|
|
1
1
|
import BaseInput from "./BaseInput.js";
|
|
2
2
|
import BaseSwitch from "./BaseSwitch.js";
|
|
3
|
+
import BaseCheckbox from "./BaseCheckbox.js";
|
|
4
|
+
import BaseCheckboxGroup from "./BaseCheckboxGroup.js";
|
|
3
5
|
import BaseForm from "./BaseForm.js";
|
|
4
6
|
import BaseFormField from "./BaseFormField.js";
|
|
5
7
|
import useFormMessages from "./useFormMessages.js";
|
|
6
|
-
export { BaseForm, BaseFormField, BaseInput, BaseSwitch, useFormMessages };
|
|
8
|
+
export { BaseCheckbox, BaseCheckboxGroup, BaseForm, BaseFormField, BaseInput, BaseSwitch, useFormMessages };
|