@bento/radio 0.1.2 → 0.2.0

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 ADDED
@@ -0,0 +1,187 @@
1
+ import {
2
+ Meta,
3
+ ArgTypes,
4
+ Story,
5
+ Controls,
6
+ Source,
7
+ } from '@storybook/addon-docs/blocks';
8
+
9
+ # Radio
10
+
11
+ The `@bento/radio` package provides accessible, customizable radio controls. It exports the **RadioGroup** and **Radio** primitives, enabling you to build groups of radio options with consistent keyboard navigation, focus management, and ARIA support.
12
+
13
+ The `RadioGroup` allows a user to select a single item from a list of `Radio` components.
14
+
15
+ The `Radio` is a single radio option that can be selected by the user.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install --save @bento/radio
21
+ ```
22
+
23
+ ## Props
24
+
25
+ The following properties are available to be used on the `RadioGroup` and `Radio` primitives:
26
+
27
+ ### RadioGroup
28
+
29
+ | Prop | Type | Required | Description |
30
+ |------|------|----------|------------|
31
+ | `value` | `string` | No | The current value (controlled). |
32
+ | `defaultValue` | `string` | No | The default value (uncontrolled). |
33
+ | `isDisabled` | `boolean` | No | Whether the input is disabled. |
34
+ | `isReadOnly` | `boolean` | No | Whether the input can be selected but not changed by the user. |
35
+ | `isRequired` | `boolean` | No | Whether user input is required on the input before form submission. |
36
+ | `isInvalid` | `boolean` | No | Whether the input value is invalid. |
37
+ | `name` | `string` | No | The name of the input element, used when submitting an HTML form. |
38
+ | `form` | `string` | No | The `<form>` element to associate the input with.
39
+ The value of this attribute must be the id of a `<form>` in the same document. |
40
+ | `children` | `ReactNode` | Yes | Radio children. |
41
+ | `slot` | `string` | No | A named part of a component that can be customized. This is implemented by the consuming component.
42
+ The exposed slot names of a component are available in the components documentation. |
43
+ | `slots` | `Record<string, object \| Function>` | No | An object that contains the customizations for the slots.
44
+ The main way you interact with the slot system as a consumer. |
45
+ | `ref` | `Ref<HTMLDivElement> \| LegacyRef<Component<RadioGroupProps & Slots, any, any>>` | No | Allows getting a ref to the component instance.
46
+ Once the component unmounts, React will set `ref.current` to `null`
47
+ (or call the ref with `null` if you passed a callback ref).
48
+ @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
49
+ | `as` | `"div"` | No | |
50
+
51
+ ### Radio
52
+
53
+ | Prop | Type | Required | Description |
54
+ |------|------|----------|------------|
55
+ | `value` | `string` | Yes | The value of the radio button, used when submitting an HTML form. |
56
+ | `inputRef` | `Ref<HTMLInputElement>` | No | A ref for the HTML input element. |
57
+ | `children` | `ReactNode` | No | The label for the Radio. Accepts any renderable node. |
58
+ | `isDisabled` | `boolean` | No | Whether the radio button is disabled or not. Shows that a selection exists,
59
+ but is not available in that circumstance. |
60
+ | `autoFocus` | `boolean` | No | Whether the element should receive focus on render. |
61
+ | `slot` | `string` | No | A named part of a component that can be customized. This is implemented by the consuming component.
62
+ The exposed slot names of a component are available in the components documentation. |
63
+ | `slots` | `Record<string, object \| Function>` | No | An object that contains the customizations for the slots.
64
+ The main way you interact with the slot system as a consumer. |
65
+ | `ref` | `Ref<HTMLDivElement> \| LegacyRef<Component<RadioProps & Slots, any, any>>` | No | Allows getting a ref to the component instance.
66
+ Once the component unmounts, React will set `ref.current` to `null`
67
+ (or call the ref with `null` if you passed a callback ref).
68
+ @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} |
69
+ | `as` | `"div"` | No | |
70
+
71
+ ## Data Attributes, Slot Map and Props
72
+
73
+ The data attributes, slot map and props can be used to style and customize the `RadioGroup` and `Radio` primitives.
74
+
75
+ ### `RadioGroup` Data Attributes
76
+
77
+ | Attribute | Description | Example Values |
78
+ | ---------------- | ------------------------------- | -------------- |
79
+ | `data-disabled` | Indicates the group is disabled | "true" |
80
+ | `data-readonly` | Indicates the group is readonly | "true" |
81
+ | `data-required` | Indicates the group is required | "true" |
82
+ | `data-invalid` | Indicates the group is invalid | "true" |
83
+
84
+ ### `Radio` Data Attributes
85
+
86
+ | Attribute | Description | Example Values |
87
+ | -------------------- | ------------------------------------ | -------------- |
88
+ | `data-pressed` | Indicates the radio is being pressed | "true" |
89
+ | `data-hovered` | Indicates the radio is hovered | "true" |
90
+ | `data-focused` | Indicates the radio has focus | "true" |
91
+ | `data-focus-visible` | Indicates focus should be visible | "true" |
92
+ | `data-selected` | Indicates the radio is selected | "true" |
93
+ | `data-disabled` | Indicates the radio is disabled | "true" |
94
+ | `data-readonly` | Indicates the radio is readonly | "true" |
95
+ | `data-invalid` | Indicates the radio is invalid | "true" |
96
+ | `data-required` | Indicates the radio is required | "true" |
97
+
98
+ ### `RadioGroup` Slot Map
99
+
100
+ | Slot Name | Description |
101
+ | ------------- | --------------------------- |
102
+ | `label` | Label for radio group |
103
+ | `description` | Description for radio group |
104
+ | `error` | Error for radio group |
105
+
106
+ ### `Radio` Slot Map
107
+
108
+ | Slot Name | Description |
109
+ | ---------------- | ------------------------ |
110
+ | `icon-checked` | Icon for checked radio |
111
+ | `icon-unchecked` | Icon for unchecked radio |
112
+
113
+ ## Examples
114
+
115
+ ### Uncontrolled
116
+
117
+ The `RadioGroup` is uncontrolled by default.
118
+
119
+ ```tsx
120
+ import { Radio, RadioGroup } from '@bento/radio';
121
+ import { Text } from '@bento/text';
122
+ /* v8 ignore next */
123
+ import React from 'react';
124
+
125
+ export function UncontrolledExample() {
126
+ return (
127
+ <RadioGroup onChange={(value: string) => console.log('selected', value)}>
128
+ <Text slot="label">Favorite fruit</Text>
129
+ <Radio value="apple">Apple</Radio>
130
+ <Radio value="banana">Banana</Radio>
131
+ <Radio value="orange" isDisabled>
132
+ Orange
133
+ </Radio>
134
+ </RadioGroup>
135
+ );
136
+ }
137
+ ```
138
+
139
+ ### Controlled
140
+
141
+ The `RadioGroup` can be controlled by passing a `value` and `onChange` prop.
142
+
143
+ ```tsx
144
+ /* v8 ignore next */
145
+ import React, { useState } from 'react';
146
+ import { RadioGroup, Radio } from '@bento/radio';
147
+ import { Text } from '@bento/text';
148
+
149
+ export function ControlledExample() {
150
+ const [value, setValue] = useState<string>();
151
+ return (
152
+ <RadioGroup value={value} onChange={setValue}>
153
+ <Text slot="label">Favorite fruit</Text>
154
+ <Radio value="apple">Apple</Radio>
155
+ <Radio value="banana">Banana</Radio>
156
+ <Radio value="orange">Orange</Radio>
157
+ </RadioGroup>
158
+ );
159
+ }
160
+ ```
161
+
162
+ ### Single Radio
163
+
164
+ Even if you only have one radio option, it must always be placed inside a `RadioGroup`.
165
+
166
+ ```tsx
167
+ import { Radio, RadioGroup } from '@bento/radio';
168
+ import { Text } from '@bento/text';
169
+ /* v8 ignore next */
170
+ import React, { type ComponentProps } from 'react';
171
+
172
+ export function SingleRadioExample(props: {
173
+ groupProps?: Partial<ComponentProps<typeof RadioGroup>>;
174
+ radioProps?: Partial<ComponentProps<typeof Radio>>;
175
+ }) {
176
+ return (
177
+ // Radios are always required to be in a group
178
+ <RadioGroup name="fruit" {...props.groupProps}>
179
+ <Text slot="label">Favorite fruit (single radio)</Text>
180
+ <Radio value="apple" {...props.radioProps}>
181
+ Apple
182
+ </Radio>
183
+ <Text slot="description">This is the description</Text>
184
+ </RadioGroup>
185
+ );
186
+ }
187
+ ```
package/README.mdx CHANGED
@@ -1,4 +1,10 @@
1
- import { Meta, ArgTypes, Story, Controls, Source } from '@storybook/addon-docs/blocks';
1
+ import {
2
+ Meta,
3
+ ArgTypes,
4
+ Story,
5
+ Controls,
6
+ Source,
7
+ } from '@storybook/addon-docs/blocks';
2
8
  import * as Stories from './radio.stories.tsx';
3
9
  import Uncontrolled from './examples/uncontrolled.tsx?raw';
4
10
  import Controlled from './examples/controlled.tsx?raw';
@@ -22,18 +28,6 @@ npm install --save @bento/radio
22
28
 
23
29
  ## Props
24
30
 
25
- The `@bento/radio` package exports the `RadioGroup` and `Radio` primitives:
26
-
27
- ```jsx
28
- import { RadioGroup, Radio } from '@bento/radio';
29
-
30
- <RadioGroup label="Favorite fruit">
31
- <Radio value="apple">Apple</Radio>
32
- <Radio value="banana">Banana</Radio>
33
- <Radio value="orange">Orange</Radio>
34
- </RadioGroup>;
35
- ```
36
-
37
31
  The following properties are available to be used on the `RadioGroup` and `Radio` primitives:
38
32
 
39
33
  ### RadioGroup
@@ -50,42 +44,41 @@ The data attributes, slot map and props can be used to style and customize the `
50
44
 
51
45
  ### `RadioGroup` Data Attributes
52
46
 
53
- | Attribute | Description |
54
- | --------------- | ------------------------------- |
55
- | `data-disabled` | Indicates the group is disabled |
56
- | `data-readonly` | Indicates the group is readonly |
57
- | `data-required` | Indicates the group is required |
58
- | `data-invalid` | Indicates the group is invalid |
47
+ | Attribute | Description | Example Values |
48
+ | ---------------- | ------------------------------- | -------------- |
49
+ | `data-disabled` | Indicates the group is disabled | "true" |
50
+ | `data-readonly` | Indicates the group is readonly | "true" |
51
+ | `data-required` | Indicates the group is required | "true" |
52
+ | `data-invalid` | Indicates the group is invalid | "true" |
59
53
 
60
54
  ### `Radio` Data Attributes
61
55
 
62
- | Attribute | Description |
63
- | -------------------- | ------------------------------------ |
64
- | `data-pressed` | Indicates the radio is being pressed |
65
- | `data-hovered` | Indicates the radio is hovered |
66
- | `data-focused` | Indicates the radio has focus |
67
- | `data-focus-visible` | Indicates focus should be visible |
68
- | `data-selected` | Indicates the radio is selected |
69
- | `data-disabled` | Indicates the radio is disabled |
70
- | `data-readonly` | Indicates the radio is readonly |
71
- | `data-invalid` | Indicates the radio is invalid |
72
- | `data-required` | Indicates the radio is required |
56
+ | Attribute | Description | Example Values |
57
+ | -------------------- | ------------------------------------ | -------------- |
58
+ | `data-pressed` | Indicates the radio is being pressed | "true" |
59
+ | `data-hovered` | Indicates the radio is hovered | "true" |
60
+ | `data-focused` | Indicates the radio has focus | "true" |
61
+ | `data-focus-visible` | Indicates focus should be visible | "true" |
62
+ | `data-selected` | Indicates the radio is selected | "true" |
63
+ | `data-disabled` | Indicates the radio is disabled | "true" |
64
+ | `data-readonly` | Indicates the radio is readonly | "true" |
65
+ | `data-invalid` | Indicates the radio is invalid | "true" |
66
+ | `data-required` | Indicates the radio is required | "true" |
73
67
 
74
68
  ### `RadioGroup` Slot Map
75
69
 
76
- | Slot Name | Description |
77
- | ------------------- | ---------------------------- |
78
- | `group.label` | Label for radiogroup |
79
- | `group.description` | Description for radiogroup |
80
- | `group.error` | Error message for radiogroup |
70
+ | Slot Name | Description |
71
+ | ------------- | --------------------------- |
72
+ | `label` | Label for radio group |
73
+ | `description` | Description for radio group |
74
+ | `error` | Error for radio group |
81
75
 
82
76
  ### `Radio` Slot Map
83
77
 
84
- | Slot Name | Description |
85
- | ------------------------ | ------------------------ |
86
- | `control.icon-checked` | Icon for checked radio |
87
- | `control.icon-unchecked` | Icon for unchecked radio |
88
- | `control.label` | Text for radio |
78
+ | Slot Name | Description |
79
+ | ---------------- | ------------------------ |
80
+ | `icon-checked` | Icon for checked radio |
81
+ | `icon-unchecked` | Icon for unchecked radio |
89
82
 
90
83
  ## Examples
91
84
 
package/dist/index.cjs CHANGED
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var React2 = require('react');
4
- var control = require('@bento/control');
4
+ var container = require('@bento/container');
5
5
  var useDataAttributes = require('@bento/use-data-attributes');
6
6
  var icon = require('@bento/icon');
7
7
  var slots = require('@bento/slots');
8
8
  var useProps = require('@bento/use-props');
9
+ var visuallyHidden = require('@bento/visually-hidden');
9
10
  var utils = require('@react-aria/utils');
10
11
  var reactAria = require('react-aria');
11
12
  var reactStately = require('react-stately');
@@ -31,14 +32,10 @@ var Radio = slots.withSlots("BentoRadio", function Radio2(args) {
31
32
  isDisabled: interactionDisabled
32
33
  });
33
34
  return /* @__PURE__ */ React2__default.default.createElement(
34
- control.Control,
35
+ container.Container,
35
36
  {
36
- slot: "control",
37
- label: props.children,
38
- labelProps: utils.mergeProps(labelProps, hoverProps),
39
- inputRef,
40
- inputProps: utils.mergeProps(inputProps, focusProps),
41
- ...apply(props, ["isDisabled", "value", "autoFocus"]),
37
+ as: "label",
38
+ ...apply(utils.mergeProps(labelProps, hoverProps)),
42
39
  ...useDataAttributes.useDataAttributes({
43
40
  selected: isSelected,
44
41
  pressed: isPressed,
@@ -51,43 +48,37 @@ var Radio = slots.withSlots("BentoRadio", function Radio2(args) {
51
48
  required: state.isRequired
52
49
  })
53
50
  },
54
- isSelected ? /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-checked", icon: "radioChecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, /* @__PURE__ */ React2__default.default.createElement("circle", { cx: 12, cy: 12, r: 8 - 6 / 2, fill: "none", stroke: "orange", strokeWidth: 6 }))) : /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-unchecked", icon: "radioUnchecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, /* @__PURE__ */ React2__default.default.createElement("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "gray", strokeWidth: 2 })))
51
+ /* @__PURE__ */ React2__default.default.createElement(visuallyHidden.VisuallyHidden, null, /* @__PURE__ */ React2__default.default.createElement("input", { ...utils.mergeProps(inputProps, focusProps), ref: inputRef })),
52
+ isSelected ? /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-checked", icon: "radioChecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2__default.default.createElement("circle", { cx: 12, cy: 12, r: 8 - 6 / 2, fill: "none", stroke: "orange", strokeWidth: 6 }))) : /* @__PURE__ */ React2__default.default.createElement(icon.Icon, { slot: "icon-unchecked", icon: "radioUnchecked" }, /* @__PURE__ */ React2__default.default.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2__default.default.createElement("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "gray", strokeWidth: 2 }))),
53
+ props.children
55
54
  );
56
55
  });
57
56
  var RadioGroup = slots.withSlots("BentoRadioGroup", function RadioGroup2(args) {
58
- const { errorMessage, ...restArgs } = args;
59
- const { props, apply } = useProps.useProps(restArgs);
57
+ const { props, apply } = useProps.useProps(args);
60
58
  const state = reactStately.useRadioGroupState(props);
61
59
  const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = reactAria.useRadioGroup(
62
- props,
60
+ { ...props, label: props.label ?? "Radio Group", description: props.description ?? "Description" },
63
61
  state
64
62
  );
65
- const displayedErrorMessage = React2.useMemo(
66
- function getErrorMessage() {
67
- return typeof errorMessage === "function" ? errorMessage(validationResult) : errorMessage || validationResult.validationErrors.join(", ");
68
- },
69
- [errorMessage, validationResult]
70
- );
71
- return /* @__PURE__ */ React2__default.default.createElement(
72
- control.ControlGroup,
63
+ return /* @__PURE__ */ React2__default.default.createElement(RadioGroupStateContext.Provider, { value: state }, /* @__PURE__ */ React2__default.default.createElement(
64
+ container.Container,
73
65
  {
74
- slot: "group",
75
- labelProps,
76
- descriptionProps,
77
- errorMessage: displayedErrorMessage,
78
- errorMessageProps,
79
- ...radioGroupProps,
80
- ...apply(props, ["isInvalid", "isDisabled", "isReadOnly", "isRequired", "validationBehavior"]),
66
+ ...apply(radioGroupProps),
81
67
  ...useDataAttributes.useDataAttributes({
82
68
  orientation: props.orientation || "vertical",
83
69
  invalid: state.isInvalid,
84
70
  disabled: state.isDisabled,
85
71
  readonly: state.isReadOnly,
86
72
  required: state.isRequired
87
- })
73
+ }),
74
+ slots: {
75
+ label: labelProps,
76
+ description: descriptionProps,
77
+ error: reactAria.mergeProps(errorMessageProps, validationResult)
78
+ }
88
79
  },
89
- /* @__PURE__ */ React2__default.default.createElement(RadioGroupStateContext.Provider, { value: state }, props.children)
90
- );
80
+ props.children
81
+ ));
91
82
  });
92
83
 
93
84
  exports.Radio = Radio;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/radio-group-state.tsx","../src/radio.tsx","../src/radio-group.tsx"],"names":["React","withSlots","Radio","useProps","useObjectRef","useMemo","mergeRefs","useFocusRing","useRadio","useHover","Control","mergeProps","useDataAttributes","Icon","RadioGroup","useRadioGroupState","useRadioGroup","ControlGroup"],"mappings":";;;;;;;;;;;;;;;;;AAGO,IAAM,sBAAA,GAAyBA,uBAAA,CAAM,aAAA,CAAsC,IAAI,CAAA;;;AC8B/E,IAAM,KAAA,GAAQC,eAAA,CAAU,YAAA,EAAc,SAASC,OAAM,IAAA,EAAkB;AAC5E,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAIC,kBAAS,IAAI,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQH,uBAAAA,CAAM,UAAA,CAAW,sBAAsB,CAAA;AACrD,EAAA,MAAM,GAAA,GAAMA,uBAAAA,CAAM,MAAA,CAAyB,IAAI,CAAA;AAC/C,EAAA,MAAM,QAAA,GAAWI,kBAAA,CAAaC,cAAA,CAAQ,MAAMC,gBAAU,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAA;AAClG,EAAA,MAAM,EAAE,SAAA,EAAW,cAAA,EAAgB,UAAA,KAAeC,sBAAA,EAAa;AAC/D,EAAA,MAAM,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,WAAU,GAAIC,kBAAA,CAAS,KAAA,EAAqB,KAAA,EAAO,QAAQ,CAAA;AACvG,EAAA,MAAM,mBAAA,GAAsB,KAAA,CAAM,UAAA,IAAc,KAAA,CAAM,UAAA;AACtD,EAAA,MAAM,EAAE,UAAA,EAAY,SAAA,EAAU,GAAIC,kBAAA,CAAS;AAAA,IACzC,GAAG,KAAA;AAAA,IACH,UAAA,EAAY;AAAA,GACb,CAAA;AAED,EAAA,uBACET,uBAAAA,CAAA,aAAA;AAAA,IAACU,eAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAK,SAAA;AAAA,MACL,OAAO,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AAC,CAAA;AAAA,MAC7F,GAAGL,mCAAAA,CAAkB;AAAA,QACpB,WAAA,EAAa,MAAM,WAAA,IAAe,UAAA;AAAA,QAClC,SAAS,KAAA,CAAM,SAAA;AAAA,QACf,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM;AAAA,OACjB;AAAA,KAAA;AAAA,oBAEDZ,wBAAA,aAAA,CAAC,sBAAA,CAAuB,UAAvB,EAAgC,KAAA,EAAO,KAAA,EAAA,EAAQ,KAAA,CAAM,QAAS;AAAA,GACjE;AAEJ,CAAC","file":"index.cjs","sourcesContent":["import React from 'react';\nimport { RadioGroupState } from 'react-stately';\n\nexport const RadioGroupStateContext = React.createContext<RadioGroupState | null>(null);\n","import React, { useMemo } from 'react';\nimport { Control, type ControlProps } from '@bento/control';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useFocusRing, useHover, useRadio, type AriaRadioProps } from 'react-aria';\nimport { RadioGroupStateContext } from './radio-group-state';\n\nexport interface RadioProps extends AriaRadioProps, Partial<Omit<ControlProps, keyof AriaRadioProps>> {\n /** The value of the radio button, used when submitting an HTML form. */\n value: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the Radio. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /**\n * Whether the radio button is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n}\n\n/**\n * The `Radio` is a single radio option that can be selected by the user.\n */\nexport const Radio = withSlots('BentoRadio', function Radio(args: RadioProps) {\n const { props, apply } = useProps(args);\n const state = React.useContext(RadioGroupStateContext)!;\n const ref = React.useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n const { inputProps, labelProps, isSelected, isPressed } = useRadio(props as RadioProps, state, inputRef);\n const interactionDisabled = props.isDisabled || state.isReadOnly;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n\n return (\n <Control\n slot=\"control\"\n label={props.children}\n labelProps={mergeProps(labelProps, hoverProps)}\n inputRef={inputRef}\n inputProps={mergeProps(inputProps, focusProps)}\n {...apply(props, ['isDisabled', 'value', 'autoFocus'])}\n {...useDataAttributes({\n selected: isSelected,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: props.isDisabled,\n readonly: state.isReadOnly,\n invalid: state.isInvalid,\n required: state.isRequired\n })}\n >\n {isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"radioChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <circle cx={12} cy={12} r={8 - 6 / 2} fill=\"none\" stroke=\"orange\" strokeWidth={6} />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"radioUnchecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <circle cx={12} cy={12} r={8} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n </Control>\n );\n});\n","import React, { useMemo } from 'react';\nimport { ControlGroup, ControlGroupProps } from '@bento/control';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { useRadioGroup, type AriaRadioGroupProps } from 'react-aria';\nimport { useRadioGroupState } from 'react-stately';\nimport { RadioGroupStateContext } from './radio-group-state';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { type ValidationResult } from '@react-types/shared';\n\nexport interface RadioGroupProps\n extends AriaRadioGroupProps,\n Partial<Omit<ControlGroupProps, keyof AriaRadioGroupProps>> {\n /** The current value (controlled). */\n value?: string;\n\n /** The default value (uncontrolled). */\n defaultValue?: string;\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The <form> element to associate the input with.\n * The value of this attribute must be the id of a <form> in the same document.\n */\n form?: string;\n\n /** Radio children. */\n children: React.ReactNode;\n\n /** Error message for the radio group. */\n errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);\n}\n\n/**\n * The `RadioGroup` allows a user to select a single item from a list of `Radio` components.\n */\nexport const RadioGroup = withSlots('BentoRadioGroup', function RadioGroup(args: RadioGroupProps) {\n const { errorMessage, ...restArgs } = args;\n const { props, apply } = useProps(restArgs);\n const state = useRadioGroupState(props);\n const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useRadioGroup(\n props,\n state\n );\n\n const displayedErrorMessage = useMemo(\n function getErrorMessage() {\n return typeof errorMessage === 'function'\n ? errorMessage(validationResult)\n : errorMessage || validationResult.validationErrors.join(', ');\n },\n [errorMessage, validationResult]\n );\n\n return (\n <ControlGroup\n slot=\"group\"\n labelProps={labelProps}\n descriptionProps={descriptionProps}\n errorMessage={displayedErrorMessage}\n errorMessageProps={errorMessageProps}\n {...radioGroupProps}\n {...apply(props, ['isInvalid', 'isDisabled', 'isReadOnly', 'isRequired', 'validationBehavior'])}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n >\n <RadioGroupStateContext.Provider value={state}>{props.children}</RadioGroupStateContext.Provider>\n </ControlGroup>\n );\n});\n"]}
1
+ {"version":3,"sources":["../src/radio-group-state.tsx","../src/radio.tsx","../src/radio-group.tsx"],"names":["React","withSlots","Radio","useProps","useObjectRef","useMemo","mergeRefs","useFocusRing","useRadio","useHover","Container","mergeProps","useDataAttributes","VisuallyHidden","Icon","RadioGroup","useRadioGroupState","useRadioGroup"],"mappings":";;;;;;;;;;;;;;;;;;AAGO,IAAM,sBAAA,GAAyBA,uBAAA,CAAM,aAAA,CAAsC,IAAI,CAAA;;;AC+B/E,IAAM,KAAA,GAAQC,eAAA,CAAU,YAAA,EAAc,SAASC,OAAM,IAAA,EAAkB;AAC5E,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAIC,kBAAS,IAAI,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQH,uBAAAA,CAAM,UAAA,CAAW,sBAAsB,CAAA;AACrD,EAAA,MAAM,GAAA,GAAMA,uBAAAA,CAAM,MAAA,CAAyB,IAAI,CAAA;AAC/C,EAAA,MAAM,QAAA,GAAWI,kBAAA,CAAaC,cAAA,CAAQ,MAAMC,gBAAU,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAA;AAClG,EAAA,MAAM,EAAE,SAAA,EAAW,cAAA,EAAgB,UAAA,KAAeC,sBAAA,EAAa;AAC/D,EAAA,MAAM,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,WAAU,GAAIC,kBAAA,CAAS,KAAA,EAAqB,KAAA,EAAO,QAAQ,CAAA;AACvG,EAAA,MAAM,mBAAA,GAAsB,KAAA,CAAM,UAAA,IAAc,KAAA,CAAM,UAAA;AACtD,EAAA,MAAM,EAAE,UAAA,EAAY,SAAA,EAAU,GAAIC,kBAAA,CAAS;AAAA,IACzC,GAAG,KAAA;AAAA,IACH,UAAA,EAAY;AAAA,GACb,CAAA;AAED,EAAA,uBACET,uBAAAA,CAAA,aAAA;AAAA,IAACU,mBAAA;AAAA,IAAA;AAAA,MACC,EAAA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AAA,EAAOD,oBAAAA,CAAW,iBAAA,EAAmB,gBAAgB;AAAA;AACvD,KAAA;AAAA,IAEC,KAAA,CAAM;AAAA,GAEX,CAAA;AAEJ,CAAC","file":"index.cjs","sourcesContent":["import React from 'react';\nimport { RadioGroupState } from 'react-stately';\n\nexport const RadioGroupStateContext = React.createContext<RadioGroupState | null>(null);\n","import React, { useMemo } from 'react';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { VisuallyHidden } from '@bento/visually-hidden';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useFocusRing, useHover, useRadio, type AriaRadioProps } from 'react-aria';\nimport { RadioGroupStateContext } from './radio-group-state';\n\nexport interface RadioProps extends AriaRadioProps, Omit<ContainerProps, keyof AriaRadioProps> {\n /** The value of the radio button, used when submitting an HTML form. */\n value: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the Radio. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /**\n * Whether the radio button is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n}\n\n/**\n * The `Radio` is a single radio option that can be selected by the user.\n */\nexport const Radio = withSlots('BentoRadio', function Radio(args: RadioProps) {\n const { props, apply } = useProps(args);\n const state = React.useContext(RadioGroupStateContext)!;\n const ref = React.useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n const { inputProps, labelProps, isSelected, isPressed } = useRadio(props as RadioProps, state, inputRef);\n const interactionDisabled = props.isDisabled || state.isReadOnly;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n\n return (\n <Container\n as=\"label\"\n {...apply(mergeProps(labelProps, hoverProps))}\n {...useDataAttributes({\n selected: isSelected,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: props.isDisabled,\n readonly: state.isReadOnly,\n invalid: state.isInvalid,\n required: state.isRequired\n })}\n >\n <VisuallyHidden>\n <input {...mergeProps(inputProps, focusProps)} ref={inputRef} />\n </VisuallyHidden>\n\n {isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"radioChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx={12} cy={12} r={8 - 6 / 2} fill=\"none\" stroke=\"orange\" strokeWidth={6} />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"radioUnchecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx={12} cy={12} r={8} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n {props.children}\n </Container>\n );\n});\n","import React from 'react';\nimport { withSlots } from '@bento/slots';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useProps } from '@bento/use-props';\nimport { useRadioGroup, mergeProps, type AriaRadioGroupProps } from 'react-aria';\nimport { useRadioGroupState } from 'react-stately';\nimport { RadioGroupStateContext } from './radio-group-state';\nimport { useDataAttributes } from '@bento/use-data-attributes';\n\nexport interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyof AriaRadioGroupProps> {\n /** The current value (controlled). */\n value?: string;\n\n /** The default value (uncontrolled). */\n defaultValue?: string;\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n */\n form?: string;\n\n /** Radio children. */\n children: React.ReactNode;\n}\n\n/**\n * The `RadioGroup` allows a user to select a single item from a list of `Radio` components.\n */\nexport const RadioGroup = withSlots('BentoRadioGroup', function RadioGroup(args: RadioGroupProps) {\n const { props, apply } = useProps(args);\n const state = useRadioGroupState(props);\n const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useRadioGroup(\n { ...props, label: props.label ?? 'Radio Group', description: props.description ?? 'Description' },\n state\n );\n\n return (\n <RadioGroupStateContext.Provider value={state}>\n <Container\n {...apply(radioGroupProps)}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n slots={{\n label: labelProps,\n description: descriptionProps,\n error: mergeProps(errorMessageProps, validationResult)\n }}\n >\n {props.children}\n </Container>\n </RadioGroupStateContext.Provider>\n );\n});\n"]}
package/dist/index.d.cts CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as _bento_slots from '@bento/slots';
2
2
  import React from 'react';
3
- import { ControlProps, ControlGroupProps } from '@bento/control';
3
+ import { ContainerProps } from '@bento/container';
4
4
  import { AriaRadioProps, AriaRadioGroupProps } from 'react-aria';
5
- import { ValidationResult } from '@react-types/shared';
6
5
 
7
- interface RadioProps extends AriaRadioProps, Partial<Omit<ControlProps, keyof AriaRadioProps>> {
6
+ interface RadioProps extends AriaRadioProps, Omit<ContainerProps, keyof AriaRadioProps> {
8
7
  /** The value of the radio button, used when submitting an HTML form. */
9
8
  value: string;
10
9
  /** A ref for the HTML input element. */
@@ -22,9 +21,9 @@ interface RadioProps extends AriaRadioProps, Partial<Omit<ControlProps, keyof Ar
22
21
  /**
23
22
  * The `Radio` is a single radio option that can be selected by the user.
24
23
  */
25
- declare const Radio: React.NamedExoticComponent<RadioProps & _bento_slots.Slots>;
24
+ declare const Radio: React.MemoExoticComponent<React.ComponentType<RadioProps & _bento_slots.Slots>>;
26
25
 
27
- interface RadioGroupProps extends AriaRadioGroupProps, Partial<Omit<ControlGroupProps, keyof AriaRadioGroupProps>> {
26
+ interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyof AriaRadioGroupProps> {
28
27
  /** The current value (controlled). */
29
28
  value?: string;
30
29
  /** The default value (uncontrolled). */
@@ -40,18 +39,16 @@ interface RadioGroupProps extends AriaRadioGroupProps, Partial<Omit<ControlGroup
40
39
  /** The name of the input element, used when submitting an HTML form. */
41
40
  name?: string;
42
41
  /**
43
- * The <form> element to associate the input with.
44
- * The value of this attribute must be the id of a <form> in the same document.
42
+ * The `<form>` element to associate the input with.
43
+ * The value of this attribute must be the id of a `<form>` in the same document.
45
44
  */
46
45
  form?: string;
47
46
  /** Radio children. */
48
47
  children: React.ReactNode;
49
- /** Error message for the radio group. */
50
- errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);
51
48
  }
52
49
  /**
53
50
  * The `RadioGroup` allows a user to select a single item from a list of `Radio` components.
54
51
  */
55
- declare const RadioGroup: React.NamedExoticComponent<RadioGroupProps & _bento_slots.Slots>;
52
+ declare const RadioGroup: React.MemoExoticComponent<React.ComponentType<RadioGroupProps & _bento_slots.Slots>>;
56
53
 
57
54
  export { Radio, RadioGroup, type RadioGroupProps, type RadioProps };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as _bento_slots from '@bento/slots';
2
2
  import React from 'react';
3
- import { ControlProps, ControlGroupProps } from '@bento/control';
3
+ import { ContainerProps } from '@bento/container';
4
4
  import { AriaRadioProps, AriaRadioGroupProps } from 'react-aria';
5
- import { ValidationResult } from '@react-types/shared';
6
5
 
7
- interface RadioProps extends AriaRadioProps, Partial<Omit<ControlProps, keyof AriaRadioProps>> {
6
+ interface RadioProps extends AriaRadioProps, Omit<ContainerProps, keyof AriaRadioProps> {
8
7
  /** The value of the radio button, used when submitting an HTML form. */
9
8
  value: string;
10
9
  /** A ref for the HTML input element. */
@@ -22,9 +21,9 @@ interface RadioProps extends AriaRadioProps, Partial<Omit<ControlProps, keyof Ar
22
21
  /**
23
22
  * The `Radio` is a single radio option that can be selected by the user.
24
23
  */
25
- declare const Radio: React.NamedExoticComponent<RadioProps & _bento_slots.Slots>;
24
+ declare const Radio: React.MemoExoticComponent<React.ComponentType<RadioProps & _bento_slots.Slots>>;
26
25
 
27
- interface RadioGroupProps extends AriaRadioGroupProps, Partial<Omit<ControlGroupProps, keyof AriaRadioGroupProps>> {
26
+ interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyof AriaRadioGroupProps> {
28
27
  /** The current value (controlled). */
29
28
  value?: string;
30
29
  /** The default value (uncontrolled). */
@@ -40,18 +39,16 @@ interface RadioGroupProps extends AriaRadioGroupProps, Partial<Omit<ControlGroup
40
39
  /** The name of the input element, used when submitting an HTML form. */
41
40
  name?: string;
42
41
  /**
43
- * The <form> element to associate the input with.
44
- * The value of this attribute must be the id of a <form> in the same document.
42
+ * The `<form>` element to associate the input with.
43
+ * The value of this attribute must be the id of a `<form>` in the same document.
45
44
  */
46
45
  form?: string;
47
46
  /** Radio children. */
48
47
  children: React.ReactNode;
49
- /** Error message for the radio group. */
50
- errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);
51
48
  }
52
49
  /**
53
50
  * The `RadioGroup` allows a user to select a single item from a list of `Radio` components.
54
51
  */
55
- declare const RadioGroup: React.NamedExoticComponent<RadioGroupProps & _bento_slots.Slots>;
52
+ declare const RadioGroup: React.MemoExoticComponent<React.ComponentType<RadioGroupProps & _bento_slots.Slots>>;
56
53
 
57
54
  export { Radio, RadioGroup, type RadioGroupProps, type RadioProps };
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import React2, { useMemo } from 'react';
2
- import { Control, ControlGroup } from '@bento/control';
2
+ import { Container } from '@bento/container';
3
3
  import { useDataAttributes } from '@bento/use-data-attributes';
4
4
  import { Icon } from '@bento/icon';
5
5
  import { withSlots } from '@bento/slots';
6
6
  import { useProps } from '@bento/use-props';
7
+ import { VisuallyHidden } from '@bento/visually-hidden';
7
8
  import { useObjectRef, mergeRefs, mergeProps } from '@react-aria/utils';
8
- import { useFocusRing, useRadio, useHover, useRadioGroup } from 'react-aria';
9
+ import { useFocusRing, useRadio, useHover, useRadioGroup, mergeProps as mergeProps$1 } from 'react-aria';
9
10
  import { useRadioGroupState } from 'react-stately';
10
11
 
11
12
  // src/radio.tsx
@@ -25,14 +26,10 @@ var Radio = withSlots("BentoRadio", function Radio2(args) {
25
26
  isDisabled: interactionDisabled
26
27
  });
27
28
  return /* @__PURE__ */ React2.createElement(
28
- Control,
29
+ Container,
29
30
  {
30
- slot: "control",
31
- label: props.children,
32
- labelProps: mergeProps(labelProps, hoverProps),
33
- inputRef,
34
- inputProps: mergeProps(inputProps, focusProps),
35
- ...apply(props, ["isDisabled", "value", "autoFocus"]),
31
+ as: "label",
32
+ ...apply(mergeProps(labelProps, hoverProps)),
36
33
  ...useDataAttributes({
37
34
  selected: isSelected,
38
35
  pressed: isPressed,
@@ -45,43 +42,37 @@ var Radio = withSlots("BentoRadio", function Radio2(args) {
45
42
  required: state.isRequired
46
43
  })
47
44
  },
48
- isSelected ? /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-checked", icon: "radioChecked" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, /* @__PURE__ */ React2.createElement("circle", { cx: 12, cy: 12, r: 8 - 6 / 2, fill: "none", stroke: "orange", strokeWidth: 6 }))) : /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-unchecked", icon: "radioUnchecked" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, /* @__PURE__ */ React2.createElement("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "gray", strokeWidth: 2 })))
45
+ /* @__PURE__ */ React2.createElement(VisuallyHidden, null, /* @__PURE__ */ React2.createElement("input", { ...mergeProps(inputProps, focusProps), ref: inputRef })),
46
+ isSelected ? /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-checked", icon: "radioChecked" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2.createElement("circle", { cx: 12, cy: 12, r: 8 - 6 / 2, fill: "none", stroke: "orange", strokeWidth: 6 }))) : /* @__PURE__ */ React2.createElement(Icon, { slot: "icon-unchecked", icon: "radioUnchecked" }, /* @__PURE__ */ React2.createElement("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ React2.createElement("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "gray", strokeWidth: 2 }))),
47
+ props.children
49
48
  );
50
49
  });
51
50
  var RadioGroup = withSlots("BentoRadioGroup", function RadioGroup2(args) {
52
- const { errorMessage, ...restArgs } = args;
53
- const { props, apply } = useProps(restArgs);
51
+ const { props, apply } = useProps(args);
54
52
  const state = useRadioGroupState(props);
55
53
  const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useRadioGroup(
56
- props,
54
+ { ...props, label: props.label ?? "Radio Group", description: props.description ?? "Description" },
57
55
  state
58
56
  );
59
- const displayedErrorMessage = useMemo(
60
- function getErrorMessage() {
61
- return typeof errorMessage === "function" ? errorMessage(validationResult) : errorMessage || validationResult.validationErrors.join(", ");
62
- },
63
- [errorMessage, validationResult]
64
- );
65
- return /* @__PURE__ */ React2.createElement(
66
- ControlGroup,
57
+ return /* @__PURE__ */ React2.createElement(RadioGroupStateContext.Provider, { value: state }, /* @__PURE__ */ React2.createElement(
58
+ Container,
67
59
  {
68
- slot: "group",
69
- labelProps,
70
- descriptionProps,
71
- errorMessage: displayedErrorMessage,
72
- errorMessageProps,
73
- ...radioGroupProps,
74
- ...apply(props, ["isInvalid", "isDisabled", "isReadOnly", "isRequired", "validationBehavior"]),
60
+ ...apply(radioGroupProps),
75
61
  ...useDataAttributes({
76
62
  orientation: props.orientation || "vertical",
77
63
  invalid: state.isInvalid,
78
64
  disabled: state.isDisabled,
79
65
  readonly: state.isReadOnly,
80
66
  required: state.isRequired
81
- })
67
+ }),
68
+ slots: {
69
+ label: labelProps,
70
+ description: descriptionProps,
71
+ error: mergeProps$1(errorMessageProps, validationResult)
72
+ }
82
73
  },
83
- /* @__PURE__ */ React2.createElement(RadioGroupStateContext.Provider, { value: state }, props.children)
84
- );
74
+ props.children
75
+ ));
85
76
  });
86
77
 
87
78
  export { Radio, RadioGroup };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/radio-group-state.tsx","../src/radio.tsx","../src/radio-group.tsx"],"names":["React","Radio","withSlots","RadioGroup","useProps","useMemo","useDataAttributes"],"mappings":";;;;;;;;;;;AAGO,IAAM,sBAAA,GAAyBA,MAAA,CAAM,aAAA,CAAsC,IAAI,CAAA;;;AC8B/E,IAAM,KAAA,GAAQ,SAAA,CAAU,YAAA,EAAc,SAASC,OAAM,IAAA,EAAkB;AAC5E,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAI,SAAS,IAAI,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQD,MAAAA,CAAM,UAAA,CAAW,sBAAsB,CAAA;AACrD,EAAA,MAAM,GAAA,GAAMA,MAAAA,CAAM,MAAA,CAAyB,IAAI,CAAA;AAC/C,EAAA,MAAM,QAAA,GAAW,YAAA,CAAa,OAAA,CAAQ,MAAM,UAAU,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAA;AAClG,EAAA,MAAM,EAAE,SAAA,EAAW,cAAA,EAAgB,UAAA,KAAe,YAAA,EAAa;AAC/D,EAAA,MAAM,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,WAAU,GAAI,QAAA,CAAS,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ACA,CAAC,cAAc,gBAAgB;AAAA,GACjC;AAEA,EAAA,uBACEL,MAAAA,CAAA,aAAA;AAAA,IAAC,YAAA;AAAA,IAAA;AAAA,MACC,IAAA,EAAK,OAAA;AAAA,MACL,UAAA;AAAA,MACA,gBAAA;AAAA,MACA,YAAA,EAAc,qBAAA;AAAA,MACd,iBAAA;AAAA,MACC,GAAG,eAAA;AAAA,MACH,GAAG,MAAM,KAAA,EAAO,CAAC,aAAa,YAAA,EAAc,YAAA,EAAc,YAAA,EAAc,oBAAoB,CAAC,CAAA;AAAA,MAC7F,GAAGM,iBAAAA,CAAkB;AAAA,QACpB,WAAA,EAAa,MAAM,WAAA,IAAe,UAAA;AAAA,QAClC,SAAS,KAAA,CAAM,SAAA;AAAA,QACf,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM;AAAA,OACjB;AAAA,KAAA;AAAA,oBAEDN,OAAA,aAAA,CAAC,sBAAA,CAAuB,UAAvB,EAAgC,KAAA,EAAO,KAAA,EAAA,EAAQ,KAAA,CAAM,QAAS;AAAA,GACjE;AAEJ,CAAC","file":"index.js","sourcesContent":["import React from 'react';\nimport { RadioGroupState } from 'react-stately';\n\nexport const RadioGroupStateContext = React.createContext<RadioGroupState | null>(null);\n","import React, { useMemo } from 'react';\nimport { Control, type ControlProps } from '@bento/control';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useFocusRing, useHover, useRadio, type AriaRadioProps } from 'react-aria';\nimport { RadioGroupStateContext } from './radio-group-state';\n\nexport interface RadioProps extends AriaRadioProps, Partial<Omit<ControlProps, keyof AriaRadioProps>> {\n /** The value of the radio button, used when submitting an HTML form. */\n value: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the Radio. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /**\n * Whether the radio button is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n}\n\n/**\n * The `Radio` is a single radio option that can be selected by the user.\n */\nexport const Radio = withSlots('BentoRadio', function Radio(args: RadioProps) {\n const { props, apply } = useProps(args);\n const state = React.useContext(RadioGroupStateContext)!;\n const ref = React.useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n const { inputProps, labelProps, isSelected, isPressed } = useRadio(props as RadioProps, state, inputRef);\n const interactionDisabled = props.isDisabled || state.isReadOnly;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n\n return (\n <Control\n slot=\"control\"\n label={props.children}\n labelProps={mergeProps(labelProps, hoverProps)}\n inputRef={inputRef}\n inputProps={mergeProps(inputProps, focusProps)}\n {...apply(props, ['isDisabled', 'value', 'autoFocus'])}\n {...useDataAttributes({\n selected: isSelected,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: props.isDisabled,\n readonly: state.isReadOnly,\n invalid: state.isInvalid,\n required: state.isRequired\n })}\n >\n {isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"radioChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <circle cx={12} cy={12} r={8 - 6 / 2} fill=\"none\" stroke=\"orange\" strokeWidth={6} />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"radioUnchecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\" aria-hidden=\"true\">\n <circle cx={12} cy={12} r={8} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n </Control>\n );\n});\n","import React, { useMemo } from 'react';\nimport { ControlGroup, ControlGroupProps } from '@bento/control';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { useRadioGroup, type AriaRadioGroupProps } from 'react-aria';\nimport { useRadioGroupState } from 'react-stately';\nimport { RadioGroupStateContext } from './radio-group-state';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { type ValidationResult } from '@react-types/shared';\n\nexport interface RadioGroupProps\n extends AriaRadioGroupProps,\n Partial<Omit<ControlGroupProps, keyof AriaRadioGroupProps>> {\n /** The current value (controlled). */\n value?: string;\n\n /** The default value (uncontrolled). */\n defaultValue?: string;\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The <form> element to associate the input with.\n * The value of this attribute must be the id of a <form> in the same document.\n */\n form?: string;\n\n /** Radio children. */\n children: React.ReactNode;\n\n /** Error message for the radio group. */\n errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);\n}\n\n/**\n * The `RadioGroup` allows a user to select a single item from a list of `Radio` components.\n */\nexport const RadioGroup = withSlots('BentoRadioGroup', function RadioGroup(args: RadioGroupProps) {\n const { errorMessage, ...restArgs } = args;\n const { props, apply } = useProps(restArgs);\n const state = useRadioGroupState(props);\n const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useRadioGroup(\n props,\n state\n );\n\n const displayedErrorMessage = useMemo(\n function getErrorMessage() {\n return typeof errorMessage === 'function'\n ? errorMessage(validationResult)\n : errorMessage || validationResult.validationErrors.join(', ');\n },\n [errorMessage, validationResult]\n );\n\n return (\n <ControlGroup\n slot=\"group\"\n labelProps={labelProps}\n descriptionProps={descriptionProps}\n errorMessage={displayedErrorMessage}\n errorMessageProps={errorMessageProps}\n {...radioGroupProps}\n {...apply(props, ['isInvalid', 'isDisabled', 'isReadOnly', 'isRequired', 'validationBehavior'])}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n >\n <RadioGroupStateContext.Provider value={state}>{props.children}</RadioGroupStateContext.Provider>\n </ControlGroup>\n );\n});\n"]}
1
+ {"version":3,"sources":["../src/radio-group-state.tsx","../src/radio.tsx","../src/radio-group.tsx"],"names":["React","Radio","withSlots","RadioGroup","useProps","Container","useDataAttributes","mergeProps"],"mappings":";;;;;;;;;;;;AAGO,IAAM,sBAAA,GAAyBA,MAAA,CAAM,aAAA,CAAsC,IAAI,CAAA;;;AC+B/E,IAAM,KAAA,GAAQ,SAAA,CAAU,YAAA,EAAc,SAASC,OAAM,IAAA,EAAkB;AAC5E,EAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAM,GAAI,SAAS,IAAI,CAAA;AACtC,EAAA,MAAM,KAAA,GAAQD,MAAAA,CAAM,UAAA,CAAW,sBAAsB,CAAA;AACrD,EAAA,MAAM,GAAA,GAAMA,MAAAA,CAAM,MAAA,CAAyB,IAAI,CAAA;AAC/C,EAAA,MAAM,QAAA,GAAW,YAAA,CAAa,OAAA,CAAQ,MAAM,UAAU,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAA,EAAG,CAAC,GAAA,EAAK,KAAA,CAAM,QAAQ,CAAC,CAAC,CAAA;AAClG,EAAA,MAAM,EAAE,SAAA,EAAW,cAAA,EAAgB,UAAA,KAAe,YAAA,EAAa;AAC/D,EAAA,MAAM,EAAE,YAAY,UAAA,EAAY,UAAA,EAAY,WAAU,GAAI,QAAA,CAAS,KAAA,EAAqB,KAAA,EAAO,QAAQ,CAAA;AACvG,EAAA,MAAM,mBAAA,GAAsB,KAAA,CAAM,UAAA,IAAc,KAAA,CAA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A,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM,UAAA;AAAA,QAChB,UAAU,KAAA,CAAM;AAAA,OACjB,CAAA;AAAA,MACD,KAAA,EAAO;AAAA,QACL,KAAA,EAAO,UAAA;AAAA,QACP,WAAA,EAAa,gBAAA;AAAA,QACb,KAAA,EAAOC,YAAAA,CAAW,iBAAA,EAAmB,gBAAgB;AAAA;AACvD,KAAA;AAAA,IAEC,KAAA,CAAM;AAAA,GAEX,CAAA;AAEJ,CAAC","file":"index.js","sourcesContent":["import React from 'react';\nimport { RadioGroupState } from 'react-stately';\n\nexport const RadioGroupStateContext = React.createContext<RadioGroupState | null>(null);\n","import React, { useMemo } from 'react';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useDataAttributes } from '@bento/use-data-attributes';\nimport { Icon } from '@bento/icon';\nimport { withSlots } from '@bento/slots';\nimport { useProps } from '@bento/use-props';\nimport { VisuallyHidden } from '@bento/visually-hidden';\nimport { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';\nimport { useFocusRing, useHover, useRadio, type AriaRadioProps } from 'react-aria';\nimport { RadioGroupStateContext } from './radio-group-state';\n\nexport interface RadioProps extends AriaRadioProps, Omit<ContainerProps, keyof AriaRadioProps> {\n /** The value of the radio button, used when submitting an HTML form. */\n value: string;\n\n /** A ref for the HTML input element. */\n inputRef?: React.Ref<HTMLInputElement>;\n\n /** The label for the Radio. Accepts any renderable node. */\n children?: React.ReactNode;\n\n /**\n * Whether the radio button is disabled or not. Shows that a selection exists,\n * but is not available in that circumstance.\n */\n isDisabled?: boolean;\n\n /** Whether the element should receive focus on render. */\n autoFocus?: boolean;\n}\n\n/**\n * The `Radio` is a single radio option that can be selected by the user.\n */\nexport const Radio = withSlots('BentoRadio', function Radio(args: RadioProps) {\n const { props, apply } = useProps(args);\n const state = React.useContext(RadioGroupStateContext)!;\n const ref = React.useRef<HTMLInputElement>(null);\n const inputRef = useObjectRef(useMemo(() => mergeRefs(ref, props.inputRef), [ref, props.inputRef]));\n const { isFocused, isFocusVisible, focusProps } = useFocusRing();\n const { inputProps, labelProps, isSelected, isPressed } = useRadio(props as RadioProps, state, inputRef);\n const interactionDisabled = props.isDisabled || state.isReadOnly;\n const { hoverProps, isHovered } = useHover({\n ...props,\n isDisabled: interactionDisabled\n });\n\n return (\n <Container\n as=\"label\"\n {...apply(mergeProps(labelProps, hoverProps))}\n {...useDataAttributes({\n selected: isSelected,\n pressed: isPressed,\n hovered: isHovered,\n focused: isFocused,\n focusVisible: isFocusVisible,\n disabled: props.isDisabled,\n readonly: state.isReadOnly,\n invalid: state.isInvalid,\n required: state.isRequired\n })}\n >\n <VisuallyHidden>\n <input {...mergeProps(inputProps, focusProps)} ref={inputRef} />\n </VisuallyHidden>\n\n {isSelected ? (\n <Icon slot=\"icon-checked\" icon=\"radioChecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx={12} cy={12} r={8 - 6 / 2} fill=\"none\" stroke=\"orange\" strokeWidth={6} />\n </svg>\n </Icon>\n ) : (\n <Icon slot=\"icon-unchecked\" icon=\"radioUnchecked\">\n <svg viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx={12} cy={12} r={8} fill=\"none\" stroke=\"gray\" strokeWidth={2} />\n </svg>\n </Icon>\n )}\n {props.children}\n </Container>\n );\n});\n","import React from 'react';\nimport { withSlots } from '@bento/slots';\nimport { Container, type ContainerProps } from '@bento/container';\nimport { useProps } from '@bento/use-props';\nimport { useRadioGroup, mergeProps, type AriaRadioGroupProps } from 'react-aria';\nimport { useRadioGroupState } from 'react-stately';\nimport { RadioGroupStateContext } from './radio-group-state';\nimport { useDataAttributes } from '@bento/use-data-attributes';\n\nexport interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyof AriaRadioGroupProps> {\n /** The current value (controlled). */\n value?: string;\n\n /** The default value (uncontrolled). */\n defaultValue?: string;\n\n /** Whether the input is disabled. */\n isDisabled?: boolean;\n\n /** Whether the input can be selected but not changed by the user. */\n isReadOnly?: boolean;\n\n /** Whether user input is required on the input before form submission. */\n isRequired?: boolean;\n\n /** Whether the input value is invalid. */\n isInvalid?: boolean;\n\n /** The name of the input element, used when submitting an HTML form. */\n name?: string;\n\n /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n */\n form?: string;\n\n /** Radio children. */\n children: React.ReactNode;\n}\n\n/**\n * The `RadioGroup` allows a user to select a single item from a list of `Radio` components.\n */\nexport const RadioGroup = withSlots('BentoRadioGroup', function RadioGroup(args: RadioGroupProps) {\n const { props, apply } = useProps(args);\n const state = useRadioGroupState(props);\n const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useRadioGroup(\n { ...props, label: props.label ?? 'Radio Group', description: props.description ?? 'Description' },\n state\n );\n\n return (\n <RadioGroupStateContext.Provider value={state}>\n <Container\n {...apply(radioGroupProps)}\n {...useDataAttributes({\n orientation: props.orientation || 'vertical',\n invalid: state.isInvalid,\n disabled: state.isDisabled,\n readonly: state.isReadOnly,\n required: state.isRequired\n })}\n slots={{\n label: labelProps,\n description: descriptionProps,\n error: mergeProps(errorMessageProps, validationResult)\n }}\n >\n {props.children}\n </Container>\n </RadioGroupStateContext.Provider>\n );\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento/radio",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Radio component",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -9,6 +9,7 @@
9
9
  "build": "tsup-node",
10
10
  "lint": "biome lint && tsc",
11
11
  "posttest": "npm run lint",
12
+ "prepublishOnly": "node ../../scripts/compile-readme.ts",
12
13
  "pretest": "npm run build",
13
14
  "test": "vitest --run",
14
15
  "test:watch": "vitest"
@@ -39,11 +40,12 @@
39
40
  "package.json"
40
41
  ],
41
42
  "dependencies": {
42
- "@bento/control": "^0.1.1",
43
- "@bento/icon": "^0.1.1",
44
- "@bento/slots": "^0.1.2",
45
- "@bento/use-data-attributes": "^0.1.0",
46
- "@bento/use-props": "^0.1.0",
43
+ "@bento/container": "^0.2.0",
44
+ "@bento/icon": "^0.1.3",
45
+ "@bento/slots": "^0.2.0",
46
+ "@bento/use-data-attributes": "^0.1.1",
47
+ "@bento/use-props": "^0.2.0",
48
+ "@bento/visually-hidden": "^0.1.0",
47
49
  "@react-aria/utils": "^3.30.0",
48
50
  "react-aria": "^3.44.0",
49
51
  "react-stately": "^3.42.0"
@@ -1,16 +1,13 @@
1
- import React, { useMemo } from 'react';
2
- import { ControlGroup, ControlGroupProps } from '@bento/control';
1
+ import React from 'react';
3
2
  import { withSlots } from '@bento/slots';
3
+ import { Container, type ContainerProps } from '@bento/container';
4
4
  import { useProps } from '@bento/use-props';
5
- import { useRadioGroup, type AriaRadioGroupProps } from 'react-aria';
5
+ import { useRadioGroup, mergeProps, type AriaRadioGroupProps } from 'react-aria';
6
6
  import { useRadioGroupState } from 'react-stately';
7
7
  import { RadioGroupStateContext } from './radio-group-state';
8
8
  import { useDataAttributes } from '@bento/use-data-attributes';
9
- import { type ValidationResult } from '@react-types/shared';
10
9
 
11
- export interface RadioGroupProps
12
- extends AriaRadioGroupProps,
13
- Partial<Omit<ControlGroupProps, keyof AriaRadioGroupProps>> {
10
+ export interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyof AriaRadioGroupProps> {
14
11
  /** The current value (controlled). */
15
12
  value?: string;
16
13
 
@@ -33,57 +30,45 @@ export interface RadioGroupProps
33
30
  name?: string;
34
31
 
35
32
  /**
36
- * The <form> element to associate the input with.
37
- * The value of this attribute must be the id of a <form> in the same document.
33
+ * The `<form>` element to associate the input with.
34
+ * The value of this attribute must be the id of a `<form>` in the same document.
38
35
  */
39
36
  form?: string;
40
37
 
41
38
  /** Radio children. */
42
39
  children: React.ReactNode;
43
-
44
- /** Error message for the radio group. */
45
- errorMessage?: React.ReactNode | ((val: ValidationResult) => React.ReactNode);
46
40
  }
47
41
 
48
42
  /**
49
43
  * The `RadioGroup` allows a user to select a single item from a list of `Radio` components.
50
44
  */
51
45
  export const RadioGroup = withSlots('BentoRadioGroup', function RadioGroup(args: RadioGroupProps) {
52
- const { errorMessage, ...restArgs } = args;
53
- const { props, apply } = useProps(restArgs);
46
+ const { props, apply } = useProps(args);
54
47
  const state = useRadioGroupState(props);
55
48
  const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, ...validationResult } = useRadioGroup(
56
- props,
49
+ { ...props, label: props.label ?? 'Radio Group', description: props.description ?? 'Description' },
57
50
  state
58
51
  );
59
52
 
60
- const displayedErrorMessage = useMemo(
61
- function getErrorMessage() {
62
- return typeof errorMessage === 'function'
63
- ? errorMessage(validationResult)
64
- : errorMessage || validationResult.validationErrors.join(', ');
65
- },
66
- [errorMessage, validationResult]
67
- );
68
-
69
53
  return (
70
- <ControlGroup
71
- slot="group"
72
- labelProps={labelProps}
73
- descriptionProps={descriptionProps}
74
- errorMessage={displayedErrorMessage}
75
- errorMessageProps={errorMessageProps}
76
- {...radioGroupProps}
77
- {...apply(props, ['isInvalid', 'isDisabled', 'isReadOnly', 'isRequired', 'validationBehavior'])}
78
- {...useDataAttributes({
79
- orientation: props.orientation || 'vertical',
80
- invalid: state.isInvalid,
81
- disabled: state.isDisabled,
82
- readonly: state.isReadOnly,
83
- required: state.isRequired
84
- })}
85
- >
86
- <RadioGroupStateContext.Provider value={state}>{props.children}</RadioGroupStateContext.Provider>
87
- </ControlGroup>
54
+ <RadioGroupStateContext.Provider value={state}>
55
+ <Container
56
+ {...apply(radioGroupProps)}
57
+ {...useDataAttributes({
58
+ orientation: props.orientation || 'vertical',
59
+ invalid: state.isInvalid,
60
+ disabled: state.isDisabled,
61
+ readonly: state.isReadOnly,
62
+ required: state.isRequired
63
+ })}
64
+ slots={{
65
+ label: labelProps,
66
+ description: descriptionProps,
67
+ error: mergeProps(errorMessageProps, validationResult)
68
+ }}
69
+ >
70
+ {props.children}
71
+ </Container>
72
+ </RadioGroupStateContext.Provider>
88
73
  );
89
74
  });
package/src/radio.tsx CHANGED
@@ -1,14 +1,15 @@
1
1
  import React, { useMemo } from 'react';
2
- import { Control, type ControlProps } from '@bento/control';
2
+ import { Container, type ContainerProps } from '@bento/container';
3
3
  import { useDataAttributes } from '@bento/use-data-attributes';
4
4
  import { Icon } from '@bento/icon';
5
5
  import { withSlots } from '@bento/slots';
6
6
  import { useProps } from '@bento/use-props';
7
+ import { VisuallyHidden } from '@bento/visually-hidden';
7
8
  import { mergeProps, mergeRefs, useObjectRef } from '@react-aria/utils';
8
9
  import { useFocusRing, useHover, useRadio, type AriaRadioProps } from 'react-aria';
9
10
  import { RadioGroupStateContext } from './radio-group-state';
10
11
 
11
- export interface RadioProps extends AriaRadioProps, Partial<Omit<ControlProps, keyof AriaRadioProps>> {
12
+ export interface RadioProps extends AriaRadioProps, Omit<ContainerProps, keyof AriaRadioProps> {
12
13
  /** The value of the radio button, used when submitting an HTML form. */
13
14
  value: string;
14
15
 
@@ -45,13 +46,9 @@ export const Radio = withSlots('BentoRadio', function Radio(args: RadioProps) {
45
46
  });
46
47
 
47
48
  return (
48
- <Control
49
- slot="control"
50
- label={props.children}
51
- labelProps={mergeProps(labelProps, hoverProps)}
52
- inputRef={inputRef}
53
- inputProps={mergeProps(inputProps, focusProps)}
54
- {...apply(props, ['isDisabled', 'value', 'autoFocus'])}
49
+ <Container
50
+ as="label"
51
+ {...apply(mergeProps(labelProps, hoverProps))}
55
52
  {...useDataAttributes({
56
53
  selected: isSelected,
57
54
  pressed: isPressed,
@@ -64,19 +61,24 @@ export const Radio = withSlots('BentoRadio', function Radio(args: RadioProps) {
64
61
  required: state.isRequired
65
62
  })}
66
63
  >
64
+ <VisuallyHidden>
65
+ <input {...mergeProps(inputProps, focusProps)} ref={inputRef} />
66
+ </VisuallyHidden>
67
+
67
68
  {isSelected ? (
68
69
  <Icon slot="icon-checked" icon="radioChecked">
69
- <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
70
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
70
71
  <circle cx={12} cy={12} r={8 - 6 / 2} fill="none" stroke="orange" strokeWidth={6} />
71
72
  </svg>
72
73
  </Icon>
73
74
  ) : (
74
75
  <Icon slot="icon-unchecked" icon="radioUnchecked">
75
- <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
76
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
76
77
  <circle cx={12} cy={12} r={8} fill="none" stroke="gray" strokeWidth={2} />
77
78
  </svg>
78
79
  </Icon>
79
80
  )}
80
- </Control>
81
+ {props.children}
82
+ </Container>
81
83
  );
82
84
  });