diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-30 19:39:20 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-31 23:15:11 +0200 |
| commit | ae384aec5084b9fb9f02166890686a37d1260ef2 (patch) | |
| tree | 59f2b2d53513e5d69bafa1323f64844dd00be28a /src/components/atoms/forms/fieldset.tsx | |
| parent | 782cc0a31a866519fb7c3e18a523b347d3e40238 (diff) | |
chore: add a Fieldset component
Diffstat (limited to 'src/components/atoms/forms/fieldset.tsx')
| -rw-r--r-- | src/components/atoms/forms/fieldset.tsx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/components/atoms/forms/fieldset.tsx b/src/components/atoms/forms/fieldset.tsx new file mode 100644 index 0000000..99d31e7 --- /dev/null +++ b/src/components/atoms/forms/fieldset.tsx @@ -0,0 +1,59 @@ +import { FC, ReactNode } from 'react'; +import styles from './fieldset.module.scss'; + +export type FieldsetProps = { + /** + * The fieldset body. + */ + children: ReactNode | ReactNode[]; + /** + * Set additional classnames to the fieldset wrapper. + */ + className?: string; + /** + * The fieldset legend. + */ + legend: string; + /** + * Set additional classnames to the legend. + */ + legendClassName?: string; + /** + * The legend position. Default: stacked. + */ + legendPosition?: 'inline' | 'stacked'; + /** + * An accessible role. Default: group. + */ + role?: 'group' | 'radiogroup' | 'presentation' | 'none'; +}; + +/** + * Fieldset component + * + * Render a fieldset with a legend. + */ +const Fieldset: FC<FieldsetProps> = ({ + children, + className = '', + legend, + legendClassName = '', + legendPosition = 'stacked', + ...props +}) => { + const wrapperModifier = `wrapper--${legendPosition}`; + + return ( + <fieldset + className={`${styles.wrapper} ${styles[wrapperModifier]} ${className}`} + {...props} + > + <legend className={`${styles.legend} ${legendClassName}`}> + {legend} + </legend> + {children} + </fieldset> + ); +}; + +export default Fieldset; |
