@bento/radio 0.2.1 → 0.2.2
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 +0 -40
- package/dist/index.cjs +14 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/package.json +16 -10
package/README.md
CHANGED
|
@@ -26,48 +26,8 @@ The following properties are available to be used on the `RadioGroup` and `Radio
|
|
|
26
26
|
|
|
27
27
|
### RadioGroup
|
|
28
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
29
|
### Radio
|
|
52
30
|
|
|
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
31
|
## Data Attributes, Slot Map and Props
|
|
72
32
|
|
|
73
33
|
The data attributes, slot map and props can be used to style and customize the `RadioGroup` and `Radio` primitives.
|
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,7 @@ var useProps = require('@bento/use-props');
|
|
|
10
10
|
var visuallyHidden = require('@bento/visually-hidden');
|
|
11
11
|
var utils = require('@react-aria/utils');
|
|
12
12
|
var reactAria = require('react-aria');
|
|
13
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
13
14
|
var reactStately = require('react-stately');
|
|
14
15
|
|
|
15
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -18,8 +19,6 @@ var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
|
18
19
|
|
|
19
20
|
// src/radio.tsx
|
|
20
21
|
var RadioGroupStateContext = React2__default.default.createContext(null);
|
|
21
|
-
|
|
22
|
-
// src/radio.tsx
|
|
23
22
|
var Radio = slots.withSlots("BentoRadio", function Radio2(args) {
|
|
24
23
|
const { props, apply } = useProps.useProps(args);
|
|
25
24
|
const state = React2__default.default.useContext(RadioGroupStateContext);
|
|
@@ -32,7 +31,7 @@ var Radio = slots.withSlots("BentoRadio", function Radio2(args) {
|
|
|
32
31
|
...props,
|
|
33
32
|
isDisabled: interactionDisabled
|
|
34
33
|
});
|
|
35
|
-
return /* @__PURE__ */
|
|
34
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
36
35
|
container.Container,
|
|
37
36
|
{
|
|
38
37
|
as: "label",
|
|
@@ -47,11 +46,13 @@ var Radio = slots.withSlots("BentoRadio", function Radio2(args) {
|
|
|
47
46
|
readonly: state.isReadOnly,
|
|
48
47
|
invalid: state.isInvalid,
|
|
49
48
|
required: state.isRequired
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
}),
|
|
50
|
+
children: [
|
|
51
|
+
/* @__PURE__ */ jsxRuntime.jsx(visuallyHidden.VisuallyHidden, { children: /* @__PURE__ */ jsxRuntime.jsx(input.Input, { ...utils.mergeProps(inputProps, focusProps), ref: inputRef }) }),
|
|
52
|
+
isSelected ? /* @__PURE__ */ jsxRuntime.jsx(icon.Icon, { slot: "icon-checked", icon: "radioChecked", children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: 12, cy: 12, r: 8 - 6 / 2, fill: "none", stroke: "orange", strokeWidth: 6 }) }) }) : /* @__PURE__ */ jsxRuntime.jsx(icon.Icon, { slot: "icon-unchecked", icon: "radioUnchecked", children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "gray", strokeWidth: 2 }) }) }),
|
|
53
|
+
props.children
|
|
54
|
+
]
|
|
55
|
+
}
|
|
55
56
|
);
|
|
56
57
|
});
|
|
57
58
|
var RadioGroup = slots.withSlots("BentoRadioGroup", function RadioGroup2(args) {
|
|
@@ -61,7 +62,7 @@ var RadioGroup = slots.withSlots("BentoRadioGroup", function RadioGroup2(args) {
|
|
|
61
62
|
{ ...props, label: props.label ?? "Radio Group", description: props.description ?? "Description" },
|
|
62
63
|
state
|
|
63
64
|
);
|
|
64
|
-
return /* @__PURE__ */
|
|
65
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RadioGroupStateContext.Provider, { value: state, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
65
66
|
container.Container,
|
|
66
67
|
{
|
|
67
68
|
...apply(radioGroupProps),
|
|
@@ -76,10 +77,10 @@ var RadioGroup = slots.withSlots("BentoRadioGroup", function RadioGroup2(args) {
|
|
|
76
77
|
label: labelProps,
|
|
77
78
|
description: descriptionProps,
|
|
78
79
|
error: reactAria.mergeProps(errorMessageProps, validationResult)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
));
|
|
80
|
+
},
|
|
81
|
+
children: props.children
|
|
82
|
+
}
|
|
83
|
+
) });
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
exports.Radio = Radio;
|
package/dist/index.cjs.map
CHANGED
|
@@ -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","Container","mergeProps","useDataAttributes","VisuallyHidden","Input","Icon","RadioGroup","useRadioGroupState","useRadioGroup"],"mappings":"
|
|
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","jsxs","Container","mergeProps","useDataAttributes","jsx","VisuallyHidden","Input","Icon","RadioGroup","useRadioGroupState","useRadioGroup"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGO,IAAM,sBAAA,GAAyBA,uBAAA,CAAM,aAAA,CAAsC,IAAI,CAAA;ACgC/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,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,QACf,UAAU,KAAA,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,EAAOD,oBAAAA,CAAW,iBAAA,EAAmB,gBAAgB;AAAA,OACvD;AAAA,MAEC,QAAA,EAAA,KAAA,CAAM;AAAA;AAAA,GACT,EACF,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 { Input } from '@bento/input';\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,4 +1,3 @@
|
|
|
1
|
-
import * as _bento_slots from '@bento/slots';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { ContainerProps } from '@bento/container';
|
|
4
3
|
import { AriaRadioProps, AriaRadioGroupProps } from 'react-aria';
|
|
@@ -21,7 +20,7 @@ interface RadioProps extends AriaRadioProps, Omit<ContainerProps, keyof AriaRadi
|
|
|
21
20
|
/**
|
|
22
21
|
* The `Radio` is a single radio option that can be selected by the user.
|
|
23
22
|
*/
|
|
24
|
-
declare const Radio: React.MemoExoticComponent<React.ComponentType<
|
|
23
|
+
declare const Radio: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
25
24
|
|
|
26
25
|
interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyof AriaRadioGroupProps> {
|
|
27
26
|
/** The current value (controlled). */
|
|
@@ -49,6 +48,6 @@ interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyo
|
|
|
49
48
|
/**
|
|
50
49
|
* The `RadioGroup` allows a user to select a single item from a list of `Radio` components.
|
|
51
50
|
*/
|
|
52
|
-
declare const RadioGroup: React.MemoExoticComponent<React.ComponentType<
|
|
51
|
+
declare const RadioGroup: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
53
52
|
|
|
54
53
|
export { Radio, RadioGroup, type RadioGroupProps, type RadioProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as _bento_slots from '@bento/slots';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import { ContainerProps } from '@bento/container';
|
|
4
3
|
import { AriaRadioProps, AriaRadioGroupProps } from 'react-aria';
|
|
@@ -21,7 +20,7 @@ interface RadioProps extends AriaRadioProps, Omit<ContainerProps, keyof AriaRadi
|
|
|
21
20
|
/**
|
|
22
21
|
* The `Radio` is a single radio option that can be selected by the user.
|
|
23
22
|
*/
|
|
24
|
-
declare const Radio: React.MemoExoticComponent<React.ComponentType<
|
|
23
|
+
declare const Radio: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
25
24
|
|
|
26
25
|
interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyof AriaRadioGroupProps> {
|
|
27
26
|
/** The current value (controlled). */
|
|
@@ -49,6 +48,6 @@ interface RadioGroupProps extends AriaRadioGroupProps, Omit<ContainerProps, keyo
|
|
|
49
48
|
/**
|
|
50
49
|
* The `RadioGroup` allows a user to select a single item from a list of `Radio` components.
|
|
51
50
|
*/
|
|
52
|
-
declare const RadioGroup: React.MemoExoticComponent<React.ComponentType<
|
|
51
|
+
declare const RadioGroup: React.MemoExoticComponent<React.ComponentType<any>>;
|
|
53
52
|
|
|
54
53
|
export { Radio, RadioGroup, type RadioGroupProps, type RadioProps };
|
package/dist/index.js
CHANGED
|
@@ -8,12 +8,11 @@ import { useProps } from '@bento/use-props';
|
|
|
8
8
|
import { VisuallyHidden } from '@bento/visually-hidden';
|
|
9
9
|
import { useObjectRef, mergeRefs, mergeProps } from '@react-aria/utils';
|
|
10
10
|
import { useFocusRing, useRadio, useHover, useRadioGroup, mergeProps as mergeProps$1 } from 'react-aria';
|
|
11
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
11
12
|
import { useRadioGroupState } from 'react-stately';
|
|
12
13
|
|
|
13
14
|
// src/radio.tsx
|
|
14
15
|
var RadioGroupStateContext = React2.createContext(null);
|
|
15
|
-
|
|
16
|
-
// src/radio.tsx
|
|
17
16
|
var Radio = withSlots("BentoRadio", function Radio2(args) {
|
|
18
17
|
const { props, apply } = useProps(args);
|
|
19
18
|
const state = React2.useContext(RadioGroupStateContext);
|
|
@@ -26,7 +25,7 @@ var Radio = withSlots("BentoRadio", function Radio2(args) {
|
|
|
26
25
|
...props,
|
|
27
26
|
isDisabled: interactionDisabled
|
|
28
27
|
});
|
|
29
|
-
return /* @__PURE__ */
|
|
28
|
+
return /* @__PURE__ */ jsxs(
|
|
30
29
|
Container,
|
|
31
30
|
{
|
|
32
31
|
as: "label",
|
|
@@ -41,11 +40,13 @@ var Radio = withSlots("BentoRadio", function Radio2(args) {
|
|
|
41
40
|
readonly: state.isReadOnly,
|
|
42
41
|
invalid: state.isInvalid,
|
|
43
42
|
required: state.isRequired
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
}),
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx(Input, { ...mergeProps(inputProps, focusProps), ref: inputRef }) }),
|
|
46
|
+
isSelected ? /* @__PURE__ */ jsx(Icon, { slot: "icon-checked", icon: "radioChecked", children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("circle", { cx: 12, cy: 12, r: 8 - 6 / 2, fill: "none", stroke: "orange", strokeWidth: 6 }) }) }) : /* @__PURE__ */ jsx(Icon, { slot: "icon-unchecked", icon: "radioUnchecked", children: /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("circle", { cx: 12, cy: 12, r: 8, fill: "none", stroke: "gray", strokeWidth: 2 }) }) }),
|
|
47
|
+
props.children
|
|
48
|
+
]
|
|
49
|
+
}
|
|
49
50
|
);
|
|
50
51
|
});
|
|
51
52
|
var RadioGroup = withSlots("BentoRadioGroup", function RadioGroup2(args) {
|
|
@@ -55,7 +56,7 @@ var RadioGroup = withSlots("BentoRadioGroup", function RadioGroup2(args) {
|
|
|
55
56
|
{ ...props, label: props.label ?? "Radio Group", description: props.description ?? "Description" },
|
|
56
57
|
state
|
|
57
58
|
);
|
|
58
|
-
return /* @__PURE__ */
|
|
59
|
+
return /* @__PURE__ */ jsx(RadioGroupStateContext.Provider, { value: state, children: /* @__PURE__ */ jsx(
|
|
59
60
|
Container,
|
|
60
61
|
{
|
|
61
62
|
...apply(radioGroupProps),
|
|
@@ -70,10 +71,10 @@ var RadioGroup = withSlots("BentoRadioGroup", function RadioGroup2(args) {
|
|
|
70
71
|
label: labelProps,
|
|
71
72
|
description: descriptionProps,
|
|
72
73
|
error: mergeProps$1(errorMessageProps, validationResult)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
));
|
|
74
|
+
},
|
|
75
|
+
children: props.children
|
|
76
|
+
}
|
|
77
|
+
) });
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
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","Container","useDataAttributes","mergeProps"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/radio-group-state.tsx","../src/radio.tsx","../src/radio-group.tsx"],"names":["React","Radio","withSlots","RadioGroup","useProps","jsx","Container","useDataAttributes","mergeProps"],"mappings":";;;;;;;;;;;;;;AAGO,IAAM,sBAAA,GAAyBA,MAAA,CAAM,aAAA,CAAsC,IAAI,CAAA;ACgC/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,CAAM,UAAA;AACtD,EAAA,MAAM,EAAE,UAAA,EAAY,SAAA,EAAU,GAAI,QAAA,CAAS;AAAA,IACzC,GAAG,KAAA;AAAA,IACH,UAAA,EAAY;AAAA,GACb,CAAA;AAED,EAAA,uBACE,IAAA;AA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AAAA,QACP,WAAA,EAAa,gBAAA;AAAA,QACb,KAAA,EAAOC,YAAAA,CAAW,iBAAA,EAAmB,gBAAgB;AAAA,OACvD;AAAA,MAEC,QAAA,EAAA,KAAA,CAAM;AAAA;AAAA,GACT,EACF,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 { Input } from '@bento/input';\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.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Radio component",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -8,15 +8,13 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsup-node",
|
|
10
10
|
"lint": "biome lint && tsc",
|
|
11
|
-
"
|
|
12
|
-
"prepublishOnly": "node ../../scripts/compile-readme.ts",
|
|
13
|
-
"pretest": "npm run build",
|
|
11
|
+
"prepublishOnly": "node ../../../scripts/compile-readme.ts",
|
|
14
12
|
"test": "vitest --run",
|
|
15
13
|
"test:watch": "vitest"
|
|
16
14
|
},
|
|
17
15
|
"repository": {
|
|
18
16
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/godaddy/
|
|
17
|
+
"url": "git+https://github.com/godaddy/antares.git"
|
|
20
18
|
},
|
|
21
19
|
"keywords": [
|
|
22
20
|
"accessibility",
|
|
@@ -31,9 +29,9 @@
|
|
|
31
29
|
"author": "GoDaddy Operating Company, LLC",
|
|
32
30
|
"license": "MIT",
|
|
33
31
|
"bugs": {
|
|
34
|
-
"url": "https://github.com/godaddy/
|
|
32
|
+
"url": "https://github.com/godaddy/antares/issues"
|
|
35
33
|
},
|
|
36
|
-
"homepage": "https://github.com/godaddy/
|
|
34
|
+
"homepage": "https://github.com/godaddy/antares#readme",
|
|
37
35
|
"files": [
|
|
38
36
|
"dist",
|
|
39
37
|
"src",
|
|
@@ -41,15 +39,23 @@
|
|
|
41
39
|
],
|
|
42
40
|
"dependencies": {
|
|
43
41
|
"@bento/container": "^0.2.1",
|
|
44
|
-
"@bento/icon": "^0.
|
|
42
|
+
"@bento/icon": "^0.2.0",
|
|
45
43
|
"@bento/input": "^0.1.0",
|
|
46
44
|
"@bento/slots": "^0.3.0",
|
|
47
45
|
"@bento/use-data-attributes": "^0.1.1",
|
|
48
46
|
"@bento/use-props": "^0.2.1",
|
|
49
47
|
"@bento/visually-hidden": "^0.1.1",
|
|
50
48
|
"@react-aria/utils": "^3.30.0",
|
|
51
|
-
"react-aria": "^3.
|
|
52
|
-
"react-stately": "^3.
|
|
49
|
+
"react-aria": "^3.45.0",
|
|
50
|
+
"react-stately": "^3.43.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/react": "^19.2.14",
|
|
54
|
+
"@types/react-dom": "^19.2.3",
|
|
55
|
+
"tsup": "^8.5.1",
|
|
56
|
+
"typescript": "^5.9.3",
|
|
57
|
+
"vitest": "^4.0.18",
|
|
58
|
+
"vitest-browser-react": "^2.1.0"
|
|
53
59
|
},
|
|
54
60
|
"peerDependencies": {
|
|
55
61
|
"react": "18.x || 19.x",
|