@omer-x/tailwind-ui-kit 1.0.0-alpha.38 → 1.0.0-alpha.39

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
@@ -212,6 +212,67 @@ With `BaseForm`'s `onlyDirty`, give the group an array default (`defaultValues={
212
212
  </BaseCheckboxGroup>
213
213
  ```
214
214
 
215
+ #### `BaseRadioGroup`
216
+
217
+ A Base UI [`Radio Group`](https://base-ui.com/react/components/radio-group): shared state for the `BaseRadio`s inside it. Only one radio is selected at a time, and its `value` is submitted under the group's `name`. Arrow keys move the selection.
218
+
219
+ | Prop | Type | Default | Description |
220
+ |------|------|---------|-------------|
221
+ | `name` | `string` | | Submitted name of the group |
222
+ | `value` | `string` | | The `value` of the selected radio, when controlled |
223
+ | `defaultValue` | `string` | | The `value` of the radio selected at first |
224
+ | `onValueChange` | `(value: string, event: Event) => void` | | Called with the selected `value` and the DOM event that changed it |
225
+ | `disabled` | `boolean` | | Disables every radio in the group |
226
+ | `readOnly` | `boolean` | | Keeps the selection from changing |
227
+ | `required` | `boolean` | | A radio must be selected before the form submits |
228
+ | `form` | `string` | | The `id` of a `<form>` to submit with, when the group isn't inside it |
229
+ | `inputRef` | `Ref<HTMLInputElement>` | | The hidden `<input>` of the selected (or first enabled) radio |
230
+ | `className` | `string` | | Classes for the group `<div>` (default `flex flex-col gap-2`) |
231
+ | `render` | `RenderProp<"div", RadioGroupState>` | | Render another element for the group |
232
+ | …rest | | | `<div>` props. Give the group an accessible name with `aria-label` or `aria-labelledby` (inside `BaseFormField`, its `label` names the group) |
233
+
234
+ Render functions get `RadioGroupState`: `{ disabled, readOnly, required }`. The group sets `data-disabled`, `data-readonly` and `data-required`.
235
+
236
+ Inside `BaseForm`, use it alone with a `name`, or in `BaseFormField`'s `children` to get the field's name, label, `required` from the schema and server errors. With `onlyDirty`, give it a string default (`defaultValues={{ plan: "free" }}`). It is sent only when the selection differs from it.
237
+
238
+ ```tsx
239
+ <BaseFormField name="plan" label="Plan" schema={Schema.shape.plan}>
240
+ {constraints => (
241
+ <BaseRadioGroup required={constraints.required} defaultValue="free">
242
+ <BaseRadio value="free" label="Free" />
243
+ <BaseRadio value="pro" label="Pro" />
244
+ </BaseRadioGroup>
245
+ )}
246
+ </BaseFormField>
247
+ ```
248
+
249
+ #### `BaseRadio`
250
+
251
+ A Base UI [`Radio`](https://base-ui.com/react/components/radio-group) with its label, for use inside `BaseRadioGroup`.
252
+
253
+ | Prop | Type | Default | Description |
254
+ |------|------|---------|-------------|
255
+ | `label` | `ReactNode` | | Text next to the radio (required) |
256
+ | `value` | `string` | | Submitted under the group's `name` when selected (required) |
257
+ | `labelClassName` | `string` | | Classes for the `<label>` around the radio and its text (default `flex items-center gap-2 text-sm font-normal`) |
258
+ | `icon` | `ReactNode` | | Shown inside the radio when selected, e.g. a dot (`<span className="size-1.5 rounded-full bg-white" />`). The kit bundles none |
259
+ | `renderIndicator` | `RenderProp<"span", RadioState>` | | Style the indicator that holds the icon |
260
+ | `keepIndicatorMounted` | `boolean` | `false` | Keep the indicator in the DOM when not selected (e.g. to animate it out) |
261
+ | `className` | `string` | | Classes for the radio (default is a `size-4` `rounded-full` box with a focus ring offset) |
262
+ | `render` | `RenderProp<"span", RadioState>` | | Render another element for the radio |
263
+ | …rest | | | `disabled`, `readOnly`, `required`, `inputRef`, `nativeButton`, and `<span>` props |
264
+
265
+ Render functions get `RadioState`: `{ checked, disabled, readOnly, required }`. The radio and the indicator set `data-checked` / `data-unchecked`, `data-disabled`, `data-readonly` and `data-required`. The indicator also sets `data-starting-style` / `data-ending-style` while it enters and leaves. The `<label>` sets `data-disabled` when the radio itself is `disabled`.
266
+
267
+ ```tsx
268
+ <BaseRadio
269
+ value="pro"
270
+ label="Pro"
271
+ className="border border-neutral-400 data-checked:border-blue-600 data-checked:bg-blue-600"
272
+ icon={<span className="size-1.5 rounded-full bg-white" />}
273
+ />
274
+ ```
275
+
215
276
  #### `BaseFieldset`
216
277
 
217
278
  A Base UI [`Fieldset`](https://base-ui.com/react/components/fieldset): a native `<fieldset>` that groups related controls under a stylable legend. The legend is linked to the fieldset (`aria-labelledby`), so screen readers announce it as the group's name.
@@ -0,0 +1,30 @@
1
+ import { RenderProp } from "../../utils/render.js";
2
+ import { ComponentProps, ReactNode, Ref } from "react";
3
+ export type RadioState = {
4
+ checked: boolean;
5
+ disabled: boolean;
6
+ readOnly: boolean;
7
+ required: boolean;
8
+ };
9
+ type BaseRadioProps = Omit<ComponentProps<"span">, "onChange" | "defaultValue"> & {
10
+ label: ReactNode;
11
+ /** Submitted under the group's `name` when this radio is selected. */
12
+ value: string;
13
+ render?: RenderProp<"span", RadioState>;
14
+ /** Classes for the `<label>` around the radio and its text. */
15
+ labelClassName?: string;
16
+ /** Shown inside the radio when selected, e.g. a dot. */
17
+ icon?: ReactNode;
18
+ renderIndicator?: RenderProp<"span", RadioState>;
19
+ /** Keep the indicator in the DOM when not selected, e.g. to animate it out with CSS. */
20
+ keepIndicatorMounted?: boolean;
21
+ disabled?: boolean;
22
+ readOnly?: boolean;
23
+ required?: boolean;
24
+ /** A ref to the hidden `<input>` of this radio. */
25
+ inputRef?: Ref<HTMLInputElement>;
26
+ /** Set to `true` when `render` renders a `<button>`. */
27
+ nativeButton?: boolean;
28
+ };
29
+ declare const BaseRadio: ({ label, labelClassName, icon, renderIndicator, keepIndicatorMounted, className, ...otherProps }: BaseRadioProps) => import("react").JSX.Element;
30
+ export { BaseRadio as default };
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { Field } from "@base-ui/react/field";
3
+ import { Radio } from "@base-ui/react/radio";
4
+ import { cn } from "cn";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ // src/components/form/BaseRadio.tsx
7
+ const BaseRadio = ({ label, labelClassName, icon, renderIndicator, keepIndicatorMounted, className, ...otherProps }) => /* @__PURE__ */ jsxs(Field.Item, {
8
+ disabled: otherProps.disabled,
9
+ render: /* @__PURE__ */ jsx("label", {}),
10
+ className: cn("flex items-center gap-2 text-sm font-normal", labelClassName),
11
+ children: [/* @__PURE__ */ jsx(Radio.Root, {
12
+ ...otherProps,
13
+ className: cn("flex", "size-4", "shrink-0", "items-center", "justify-center", "rounded-full", "transition-colors", "duration-150", "ease-[ease]", "focus-visible:outline-2", "focus-visible:outline-offset-2", className),
14
+ children: /* @__PURE__ */ jsx(Radio.Indicator, {
15
+ keepMounted: keepIndicatorMounted,
16
+ className: "flex size-full items-center justify-center",
17
+ render: renderIndicator,
18
+ children: icon
19
+ })
20
+ }), label]
21
+ });
22
+ export { BaseRadio as default };
@@ -0,0 +1,28 @@
1
+ import { ComponentProps, Ref } from "react";
2
+ import { RenderProp } from "../../utils/render.js";
3
+ export type RadioGroupState = {
4
+ disabled: boolean;
5
+ readOnly: boolean;
6
+ required: boolean;
7
+ };
8
+ type BaseRadioGroupProps = Omit<ComponentProps<"div">, "onChange" | "defaultValue"> & {
9
+ render?: RenderProp<"div", RadioGroupState>;
10
+ /** Submitted name of the group. The selected radio's `value` is sent under it. */
11
+ name?: string;
12
+ /** The `value` of the selected radio, when controlled. */
13
+ value?: string;
14
+ /** The `value` of the radio selected at first. */
15
+ defaultValue?: string;
16
+ /** Called with the selected radio's `value` and the DOM event that changed it. */
17
+ onValueChange?: (value: string, event: Event) => void;
18
+ disabled?: boolean;
19
+ readOnly?: boolean;
20
+ /** The user must select a radio before the form submits. */
21
+ required?: boolean;
22
+ /** The `id` of a `<form>` to submit with, when the group isn't inside it. */
23
+ form?: string;
24
+ /** A ref to the hidden `<input>` of the selected (or first enabled) radio. */
25
+ inputRef?: Ref<HTMLInputElement>;
26
+ };
27
+ declare const BaseRadioGroup: ({ onValueChange, className, ...otherProps }: BaseRadioGroupProps) => import("react").JSX.Element;
28
+ export { BaseRadioGroup as default };
@@ -0,0 +1,21 @@
1
+ "use client";
2
+ import { Field } from "@base-ui/react/field";
3
+ import { RadioGroup } from "@base-ui/react/radio-group";
4
+ import { cn } from "cn";
5
+ import { use } from "react";
6
+ import { InsideFieldContext } from "./InsideFieldContext.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ // src/components/form/BaseRadioGroup.tsx
9
+ const BaseRadioGroup = ({ onValueChange, className, ...otherProps }) => {
10
+ const group = /* @__PURE__ */ jsx(RadioGroup, {
11
+ ...otherProps,
12
+ onValueChange: onValueChange && ((value, details) => onValueChange(value, details.event)),
13
+ className: cn("flex flex-col gap-2", className)
14
+ });
15
+ if (use(InsideFieldContext)) return group;
16
+ return /* @__PURE__ */ jsx(Field.Root, {
17
+ className: "contents",
18
+ children: group
19
+ });
20
+ };
21
+ export { BaseRadioGroup as default };
@@ -2,6 +2,7 @@
2
2
  import { Field } from "@base-ui/react/field";
3
3
  import { use, useEffect } from "react";
4
4
  import { FormContext } from "./FormContext.js";
5
+ import { InsideFieldContext } from "./InsideFieldContext.js";
5
6
  import { jsx } from "react/jsx-runtime";
6
7
  // src/components/form/FieldRoot.tsx
7
8
  const FieldRoot = ({ name, className, children }) => {
@@ -15,7 +16,10 @@ const FieldRoot = ({ name, className, children }) => {
15
16
  return /* @__PURE__ */ jsx(Field.Root, {
16
17
  name,
17
18
  className,
18
- children
19
+ children: /* @__PURE__ */ jsx(InsideFieldContext, {
20
+ value: true,
21
+ children
22
+ })
19
23
  });
20
24
  };
21
25
  export { FieldRoot as default };
@@ -0,0 +1,2 @@
1
+ /** `true` inside a `BaseFormField`, whose field wraps its controls. */
2
+ export declare const InsideFieldContext: import("react").Context<boolean>;
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+ // src/components/form/InsideFieldContext.ts
3
+ /** `true` inside a `BaseFormField`, whose field wraps its controls. */
4
+ const InsideFieldContext = createContext(false);
5
+ export { InsideFieldContext };
@@ -16,4 +16,6 @@ import { AutocompleteArrowState, AutocompleteBackdropState, AutocompleteCollisio
16
16
  import { AutocompleteSeparatorState } from "./BaseAutocompleteSeparator.js";
17
17
  import { InputSize } from "./inputSizes.js";
18
18
  import BaseFieldset, { FieldsetState } from "./BaseFieldset.js";
19
- export { type AutocompleteActions, type AutocompleteAlign, type AutocompleteArrowState, type AutocompleteBackdropState, type AutocompleteClearState, type AutocompleteCollisionAvoidance, type AutocompleteFilter, type AutocompleteFocusTarget, type AutocompleteHighlightReason, type AutocompleteInputState, type AutocompleteInteractionType, type AutocompleteItemGroup, type AutocompleteItemState, type AutocompleteListState, type AutocompleteOffsetFunction, type AutocompletePopupState, type AutocompletePositionerState, type AutocompleteSeparatorState, type AutocompleteSide, _default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseFieldset, BaseForm, BaseFormField, BaseInput, BaseSwitch, type CheckboxGroupState, type CheckboxState, type DisplayedFormMessage, type FieldConstraints, type FieldState, type FieldsetState, type InputSize, type MessageFormatter, type SwitchState, type UseAutocompleteFilterOptions, useAutocompleteFilter, useFormMessages };
19
+ import BaseRadioGroup, { RadioGroupState } from "./BaseRadioGroup.js";
20
+ import BaseRadio, { RadioState } from "./BaseRadio.js";
21
+ export { type AutocompleteActions, type AutocompleteAlign, type AutocompleteArrowState, type AutocompleteBackdropState, type AutocompleteClearState, type AutocompleteCollisionAvoidance, type AutocompleteFilter, type AutocompleteFocusTarget, type AutocompleteHighlightReason, type AutocompleteInputState, type AutocompleteInteractionType, type AutocompleteItemGroup, type AutocompleteItemState, type AutocompleteListState, type AutocompleteOffsetFunction, type AutocompletePopupState, type AutocompletePositionerState, type AutocompleteSeparatorState, type AutocompleteSide, _default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseFieldset, BaseForm, BaseFormField, BaseInput, BaseRadio, BaseRadioGroup, BaseSwitch, type CheckboxGroupState, type CheckboxState, type DisplayedFormMessage, type FieldConstraints, type FieldState, type FieldsetState, type InputSize, type MessageFormatter, type RadioGroupState, type RadioState, type SwitchState, type UseAutocompleteFilterOptions, useAutocompleteFilter, useFormMessages };
@@ -8,4 +8,6 @@ import useFormMessages from "./useFormMessages.js";
8
8
  import BaseAutocomplete_default from "./BaseAutocomplete.js";
9
9
  import useAutocompleteFilter from "./useAutocompleteFilter.js";
10
10
  import BaseFieldset from "./BaseFieldset.js";
11
- export { BaseAutocomplete_default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseFieldset, BaseForm, BaseFormField, BaseInput, BaseSwitch, useAutocompleteFilter, useFormMessages };
11
+ import BaseRadioGroup from "./BaseRadioGroup.js";
12
+ import BaseRadio from "./BaseRadio.js";
13
+ export { BaseAutocomplete_default as BaseAutocomplete, BaseCheckbox, BaseCheckboxGroup, BaseFieldset, BaseForm, BaseFormField, BaseInput, BaseRadio, BaseRadioGroup, BaseSwitch, useAutocompleteFilter, useFormMessages };
@@ -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" | "autoHighlight" | "locale" | "filterable" | "query" | "defaultQuery" | "onQueryChange">;
68
+ rootProps: Omit<Props, "filter" | "locale" | "autoHighlight" | "filterable" | "query" | "defaultQuery" | "onQueryChange">;
69
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/tailwind-ui-kit",
3
- "version": "1.0.0-alpha.38",
3
+ "version": "1.0.0-alpha.39",
4
4
  "description": "Tailwind CSS-based React component library for building user interfaces",
5
5
  "keywords": [
6
6
  "tailwind",