import React, { useEffect, useState } from 'react'; import { ComponentMeta, ComponentStory } from '@storybook/react'; import { CheckIcon } from '@100mslive/react-icons'; import { Label } from '../Label'; import { Flex } from '../Layout'; import { Checkbox } from '.'; export default { title: 'UI Components/Checkbox', component: CheckboxWithLabelComponent, argTypes: { onCheckedChange: { action: { type: 'clicked' } }, checked: { control: { type: 'boolean' } }, label: { control: { type: 'text' } }, css: { control: { type: 'object' } }, }, args: { checked: true, label: 'Label', }, } as ComponentMeta; type CheckboxWithLabelComponentProps = { label?: string; checked?: boolean; } & React.ComponentProps; function CheckboxWithLabelComponent({ label, checked = true, css, onCheckedChange }: CheckboxWithLabelComponentProps) { const [internalChecked, setInternalChecked] = useState(checked); useEffect(() => { handleOnCheckedChange(checked); }, [checked]); //eslint-disable-line function handleOnCheckedChange(checked: boolean) { setInternalChecked(checked); if (onCheckedChange) { onCheckedChange(checked); } } return ( ); } const CheckboxWithLabelStory: ComponentStory = args => { return ; }; export const Example = CheckboxWithLabelStory.bind({}); Example.storyName = 'Checkbox';