diff --git a/src/components/form-field/form-field.tsx b/src/components/form-field/form-field.tsx index 1cfc8c17..27d9dfe9 100644 --- a/src/components/form-field/form-field.tsx +++ b/src/components/form-field/form-field.tsx @@ -12,6 +12,7 @@ import { MultiCombobox } from "./multi-combobox/multi-combobox"; import { SingleCombobox } from "./single-combobox/single-combobox"; import { FormFieldGroup } from "./form-field-group"; import { SearchInput } from "./search-input/search-input"; +import { RadioBox } from "./radio-box/radio-box"; interface FormFieldProps { children: React.ReactNode; @@ -34,5 +35,6 @@ FormField.MultiCombobox = MultiCombobox; FormField.SingleCombobox = SingleCombobox; FormField.Group = FormFieldGroup; FormField.SearchInput = SearchInput; +FormField.RadioBox = RadioBox; export { FormField }; diff --git a/src/components/form-field/radio-box/radio-box-option.tsx b/src/components/form-field/radio-box/radio-box-option.tsx new file mode 100644 index 00000000..0c5d67e5 --- /dev/null +++ b/src/components/form-field/radio-box/radio-box-option.tsx @@ -0,0 +1,73 @@ +import { RadioGroup } from "@headlessui/react"; +import React from "react"; +import { classNames } from "../../../util/class-names"; + +export interface RadioBoxOptionProps { + children: React.ReactNode; + value: string; + disabled?: boolean; + highlightText?: string; +} + +export const RadioBoxOption = ({ + children, + value, + disabled, + highlightText, +}: RadioBoxOptionProps) => { + return ( + + {({ checked, disabled: optionDisabled }) => ( +
+ {highlightText && ( + + {highlightText} + + )} + + + {checked && ( + + )} + + +

+ {children} +

+
+ )} +
+ ); +}; diff --git a/src/components/form-field/radio-box/radio-box.stories.tsx b/src/components/form-field/radio-box/radio-box.stories.tsx new file mode 100644 index 00000000..6026d684 --- /dev/null +++ b/src/components/form-field/radio-box/radio-box.stories.tsx @@ -0,0 +1,61 @@ +import type { Meta, StoryObj } from "@storybook/react"; +import React, { useState } from "react"; +import { FormField } from "../form-field"; +import { RadioBox } from "./radio-box"; + +const meta: Meta = { + title: "Input/RadioBox", + component: RadioBox, +}; + +export default meta; + +type Story = StoryObj; + +const RadioBoxWithHooks = () => { + const [value, setValue] = useState("value_1"); + + return ( + + + +
+

Option 1

+

+ To be, or not to be, that is the question: Whether ’tis nobler in the + mind to suffer The slings and arrows of outrageous fortune, … +

+
+
+ + +
+

Option 2

+

+ To be, or not to be, that is the question: Whether ’tis nobler in the + mind to suffer The slings and arrows of outrageous fortune, … +

+
+
+ + +
+

Option 3

+

+ To be, or not to be, that is the question: Whether ’tis nobler in the + mind to suffer The slings and arrows of outrageous fortune, … +

+
+
+
+
+ ); +}; + +export const Default: Story = { + render: () => ( +
+ +
+ ), +}; diff --git a/src/components/form-field/radio-box/radio-box.tsx b/src/components/form-field/radio-box/radio-box.tsx new file mode 100644 index 00000000..ac81b133 --- /dev/null +++ b/src/components/form-field/radio-box/radio-box.tsx @@ -0,0 +1,20 @@ +import React from "react"; +import { RadioGroup } from "@headlessui/react"; +import { RadioBoxOption } from "./radio-box-option"; + +export interface RadioBoxProps { + id: string; + children: React.ReactNode; + value: string; + onChange: (value: string) => void; +} + +export const RadioBox = ({ id, value, children, onChange }: RadioBoxProps) => { + return ( + + {children} + + ); +}; + +RadioBox.Option = RadioBoxOption;