feat(frontend): added label to toggle button group

pull/85/head
Samuel Rowe 3 years ago
parent 4859d14422
commit bc1de05d7f

@ -19,6 +19,20 @@ interface IToggleButtonProps {
} }
const Root = styled("div")` const Root = styled("div")`
display: flex;
flex-direction: column;
row-gap: ${({ theme }) => theme.spacing(0.4)};
`;
const Label = styled("label")`
color: #374151;
font-size: 12px;
font-weight: 500;
padding: 0;
margin: 0;
`;
const Buttons = styled("div")`
display: flex; display: flex;
flex-direction: row; flex-direction: row;
`; `;
@ -30,7 +44,8 @@ const ToggleButton = styled(Button)<IToggleButtonProps>(({ index, total }) => ({
${index === total - 1 ? "8px" : "0px"} ${index === total - 1 ? "8px" : "0px"}
${index === 0 ? "8px" : "0px"} ${index === 0 ? "8px" : "0px"}
`, `,
fontSize: 11 fontSize: 11,
minWidth: 120
})); }));
const ButtonBorder = styled("div")` const ButtonBorder = styled("div")`
@ -40,10 +55,8 @@ const ButtonBorder = styled("div")`
const Toggle: FunctionComponent<IToggleProps> = ( const Toggle: FunctionComponent<IToggleProps> = (
props: IToggleProps props: IToggleProps
): ReactElement => { ): ReactElement => {
const { name, help, options } = props; const { label, name, options } = props;
const formik = useFormikContext(); const formik = useFormikContext();
const error =
lodash.get(formik.touched, name) && lodash.get(formik.errors, name);
const value = lodash.get(formik.values, name); const value = lodash.get(formik.values, name);
const handleChange = (newValue: string) => () => { const handleChange = (newValue: string) => () => {
@ -52,6 +65,8 @@ const Toggle: FunctionComponent<IToggleProps> = (
return ( return (
<Root> <Root>
<Label>{label}</Label>
<Buttons>
{options.map((option, index) => ( {options.map((option, index) => (
<Fragment key={option.value}> <Fragment key={option.value}>
<ToggleButton <ToggleButton
@ -67,11 +82,7 @@ const Toggle: FunctionComponent<IToggleProps> = (
{index + 1 < options.length && <ButtonBorder />} {index + 1 < options.length && <ButtonBorder />}
</Fragment> </Fragment>
))} ))}
</Buttons>
<div className="mt-1 text-xs text-red-600">
{error && <span className="caption">{error}</span>}
{!error && help}
</div>
</Root> </Root>
); );
}; };

Loading…
Cancel
Save