pleroma/src/components/radio.tsx

41 lines
970 B
TypeScript
Raw Normal View History

2022-12-17 12:53:02 -08:00
import React from 'react';
import List, { ListItem } from './list';
interface IRadioGroup {
onChange: React.ChangeEventHandler;
children: React.ReactElement<{ onChange: React.ChangeEventHandler }>[];
2022-12-17 12:53:02 -08:00
}
const RadioGroup = ({ onChange, children }: IRadioGroup) => {
const childrenWithProps = React.Children.map(children, child =>
React.cloneElement(child, { onChange }),
);
return <List>{childrenWithProps}</List>;
};
interface IRadioItem {
label: React.ReactNode;
hint?: React.ReactNode;
value: string;
checked: boolean;
onChange?: React.ChangeEventHandler;
2022-12-17 12:53:02 -08:00
}
const RadioItem: React.FC<IRadioItem> = ({ label, hint, checked = false, onChange, value }) => (
<ListItem label={label} hint={hint}>
<input
type='radio'
checked={checked}
onChange={onChange}
value={value}
className='h-4 w-4 border-gray-300 text-primary-600 focus:ring-primary-500'
/>
</ListItem>
);
2022-12-17 12:53:02 -08:00
export {
RadioGroup,
RadioItem,
};