Skip to content

Commit

Permalink
Refactor radio group types
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Jul 31, 2024
1 parent 5274194 commit de807f6
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
Text,
} from '../../../component-library';

export type SnapUIRadioOption = { value: string; name: string };

export type SnapUIRadioProps = {
name: string;
label?: string;
error?: string;
options: { name: string; value: string }[];
options: SnapUIRadioOption[];
form?: string;
};

Expand All @@ -35,8 +37,6 @@ export const SnapUIRadioGroup: FunctionComponent<SnapUIRadioProps> = ({

const [value, setValue] = useState(initialValue ?? '');

type RadioOptions = [{ value: string; name: string }];

useEffect(() => {
if (initialValue && value !== initialValue) {
setValue(initialValue);
Expand All @@ -48,8 +48,8 @@ export const SnapUIRadioGroup: FunctionComponent<SnapUIRadioProps> = ({
handleInputChange(name, newValue, form);
};

const displayRadioOptions = (options: RadioOptions) => {
return options.map((option: { value: string; name: string }) => {
const displayRadioOptions = (options: SnapUIRadioOption[]) => {
return options.map((option: SnapUIRadioOption) => {
return (
<Box display={Display.Flex} alignItems={AlignItems.center}>
<input
Expand Down Expand Up @@ -80,7 +80,7 @@ export const SnapUIRadioGroup: FunctionComponent<SnapUIRadioProps> = ({
flexDirection={FlexDirection.Column}
>
{label && <Label htmlFor={name}>{label}</Label>}
{displayRadioOptions(props.options as RadioOptions)}
{displayRadioOptions(props.options)}
{error && (
<HelpText severity={HelpTextSeverity.Danger} marginTop={1}>
{error}
Expand Down

0 comments on commit de807f6

Please sign in to comment.