import React from "react"; import {ComponentStory, ComponentMeta} from "@storybook/react"; import {VisuallyHidden} from "@react-aria/visually-hidden"; import {radio, button} from "@nextui-org/theme"; import {clsx} from "@nextui-org/shared-utils"; import { RadioGroup, Radio, RadioProps, RadioGroupProps, useRadio, useRadioGroupContext, } from "../src"; export default { title: "Components/RadioGroup", component: RadioGroup, onChange: {action: "changed"}, argTypes: { color: { control: { type: "select", options: ["neutral", "primary", "secondary", "success", "warning", "danger"], }, }, radius: { control: { type: "select", options: ["none", "base", "sm", "md", "lg", "xl", "full"], }, }, size: { control: { type: "select", options: ["xs", "sm", "md", "lg", "xl"], }, }, isDisabled: { control: { type: "boolean", }, }, }, } as ComponentMeta; const defaultProps = { ...radio.defaultVariants, label: "Options", }; const Template: ComponentStory = (args: RadioGroupProps) => { const radioProps = args.description ? { a: { description: "Description for Option A", }, b: { description: "Description for Option B", }, c: { description: "Description for Option C", }, d: { description: "Description for Option D", }, } : { a: {}, b: {}, c: {}, d: {}, }; const items = ( <> Option A Option B Option C Option D ); return args.isRequired ? (
{ e.preventDefault(); alert("Submitted!"); }} > {items}
) : ( {items} ); }; const ControlledTemplate: ComponentStory = (args: RadioGroupProps) => { const [selectedItem, setSelectedItem] = React.useState("london"); React.useEffect(() => { // eslint-disable-next-line no-console console.log("isSelected:", selectedItem); }, [selectedItem]); return (
Buenos Aires Sydney London Tokyo

Selected: {selectedItem}

); }; export const Default = Template.bind({}); Default.args = { ...defaultProps, }; export const IsDisabled = Template.bind({}); IsDisabled.args = { ...defaultProps, isDisabled: true, }; export const DefaultChecked = Template.bind({}); DefaultChecked.args = { ...defaultProps, defaultValue: "C", }; export const IsRequired = Template.bind({}); IsRequired.args = { ...defaultProps, isRequired: true, }; export const WithDescription = Template.bind({}); WithDescription.args = { ...defaultProps, description: "for", }; export const Invalid = Template.bind({}); Invalid.args = { ...defaultProps, validationState: "invalid", description: "for", }; export const Row = Template.bind({}); Row.args = { ...defaultProps, orientation: "horizontal", description: "for", }; export const DisableAnimation = Template.bind({}); DisableAnimation.args = { ...defaultProps, disableAnimation: true, }; export const Controlled = ControlledTemplate.bind({}); Controlled.args = { ...defaultProps, }; const CustomRadio = (props: RadioProps) => { const {children, ...otherProps} = props; const {groupState} = useRadioGroupContext(); const isSelected = groupState.selectedValue === otherProps.value; return ( {children} ); }; export const CustomWithStyles = () => { return ( Free Pro Enterprise ); }; const RadioCard = (props: RadioProps) => { const { Component, children, isSelected, description, getBaseProps, getWrapperProps, getInputProps, getLabelProps, getLabelWrapperProps, getControlProps, } = useRadio(props); return (
{children && {children}} {description && ( {description} )}
); }; export const CustomWithHooks = () => { return ( Free Pro Enterprise ); };