@omer-x/tailwind-ui-kit 1.0.0-alpha.30 → 1.0.0-alpha.31

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 CHANGED
@@ -153,6 +153,37 @@ 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
+ | `value` | `string` | `"true"` | Submitted when checked |
170
+ | `uncheckedValue` | `string` | `"false"` | Submitted when unchecked |
171
+ | `onCheckedChange` | `(checked: boolean, event: Event) => void` | | Called with the new state and the DOM event that changed it |
172
+ | `render` | `RenderProp<"span", CheckboxState>` | | Render another element for the box |
173
+ | …rest | | | `name`, `checked`, `defaultChecked`, `disabled`, `readOnly`, `required`, `form`, `inputRef`, `nativeButton`, and `<span>` props |
174
+
175
+ 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.
176
+
177
+ ```tsx
178
+ <BaseCheckbox
179
+ name="terms"
180
+ label="I accept the terms"
181
+ className="rounded border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
182
+ renderIndicator={<span className="text-white" />}
183
+ icon={<CheckIcon />}
184
+ />
185
+ ```
186
+
156
187
  #### `BaseForm`
157
188
 
158
189
  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,44 @@
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
+ /** Called with the new state and the DOM event that changed it. */
32
+ onCheckedChange?: (checked: boolean, event: Event) => void;
33
+ disabled?: boolean;
34
+ readOnly?: boolean;
35
+ required?: boolean;
36
+ /** The `id` of a `<form>` to submit with, when the checkbox isn't inside it. */
37
+ form?: string;
38
+ /** A ref to the hidden `<input>` that holds the value. */
39
+ inputRef?: Ref<HTMLInputElement>;
40
+ /** Set to `true` when `render` renders a `<button>`. */
41
+ nativeButton?: boolean;
42
+ };
43
+ declare const BaseCheckbox: ({ label, labelClassName, icon, indeterminateIcon, renderIndicator, keepIndicatorMounted, onCheckedChange, value, uncheckedValue, indeterminate, className, ...otherProps }: BaseCheckboxProps) => import("react").JSX.Element;
44
+ export { BaseCheckbox as default };
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { Checkbox } from "@base-ui/react/checkbox";
3
+ import { cn } from "cn";
4
+ import "react";
5
+ import { 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, 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
+ onCheckedChange: onCheckedChange && ((checked, details) => onCheckedChange(checked, details.event)),
15
+ 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
+ children: /* @__PURE__ */ jsx(Checkbox.Indicator, {
17
+ keepMounted: keepIndicatorMounted,
18
+ className: "flex size-full items-center justify-center",
19
+ render: renderIndicator,
20
+ children: indeterminate ? indeterminateIcon ?? icon : icon
21
+ })
22
+ }), label]
23
+ });
24
+ export { BaseCheckbox as default };
@@ -1,7 +1,8 @@
1
1
  import BaseInput from "./BaseInput.js";
2
2
  import BaseSwitch, { SwitchState } from "./BaseSwitch.js";
3
+ import BaseCheckbox, { CheckboxState } from "./BaseCheckbox.js";
3
4
  import BaseForm from "./BaseForm.js";
4
5
  import BaseFormField, { FieldState } from "./BaseFormField.js";
5
6
  import useFormMessages from "./useFormMessages.js";
6
7
  import { DisplayedFormMessage, MessageFormatter } from "./FormContext.js";
7
- export { BaseForm, BaseFormField, BaseInput, BaseSwitch, type DisplayedFormMessage, type FieldState, type MessageFormatter, type SwitchState, useFormMessages };
8
+ export { BaseCheckbox, BaseForm, BaseFormField, BaseInput, BaseSwitch, type CheckboxState, type DisplayedFormMessage, type FieldState, type MessageFormatter, type SwitchState, useFormMessages };
@@ -1,6 +1,7 @@
1
1
  import BaseInput from "./BaseInput.js";
2
2
  import BaseSwitch from "./BaseSwitch.js";
3
+ import BaseCheckbox from "./BaseCheckbox.js";
3
4
  import BaseForm from "./BaseForm.js";
4
5
  import BaseFormField from "./BaseFormField.js";
5
6
  import useFormMessages from "./useFormMessages.js";
6
- export { BaseForm, BaseFormField, BaseInput, BaseSwitch, useFormMessages };
7
+ export { BaseCheckbox, BaseForm, BaseFormField, BaseInput, BaseSwitch, useFormMessages };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/tailwind-ui-kit",
3
- "version": "1.0.0-alpha.30",
3
+ "version": "1.0.0-alpha.31",
4
4
  "description": "Tailwind CSS-based React component library for building user interfaces",
5
5
  "keywords": [
6
6
  "tailwind",