import React, { useEffect, useState } from 'react' import { type Meta, type StoryObj } from '@storybook/react-vite' import { DocsTemplate } from '../../../.storybook' import CheckboxComponent from './Checkbox' const meta: Meta = { title: 'Components/FormComponents/Checkbox', component: CheckboxComponent, parameters: { design: { type: 'figma', url: 'https://www.figma.com/design/RvhKD82948FMQnh5MyCi0o/Web-Design-System?node-id=121-336&t=KUWdug3XS3dQ8hnl-0', }, docs: { page: () => ( The Checkbox component is a form element that allows users to select or deselect a single option from a set of choices. It consists of a small box that can be checked or unchecked, indicating the user's selection status. An optional label can be associated with the Checkbox to provide additional context or description for the option. } infoBullets={[ Utilize the Checkbox component in forms or settings sections where users need to make binary choices from a set of options. , Add a concise and descriptive label alongside the{' '} Checkbox to help users understand the purpose of the option. , A partial state can be used to indicate that some, but not all, of the options in a set are selected. This is most useful when the checkbox is part of a collection of checkboxes and some, but not all, of the subset options are selected. , ]} /> ), }, }, } export default meta type Story = StoryObj const Checkbox = (args) => { const [checked, setChecked] = useState(args.checked) const [partialChecked, setPartialChecked] = useState(args.partialChecked) const inputHandler = (check, partial?: boolean) => { if (typeof partial === 'boolean') { setPartialChecked((prev) => !prev) setChecked(true) } else { setChecked(check) setPartialChecked(false) } } useEffect(() => { typeof args.checked === 'boolean' && inputHandler(args.checked) }, [args.checked]) return ( inputHandler(check, partial)} /> ) } const Template: Story = { render: (args) => { return }, } export const Standard: Story = { ...Template, args: { checked: false, label: 'Checkbox Label', }, } export const Disabled: Story = { ...Template, args: { checked: true, label: 'Checkbox Label (disabled)', disabled: true, }, } Disabled.storyName = 'Checked (disabled)' export const Radio: Story = { ...Template, args: { checked: false, label: 'Radio Label', type: 'radio', }, } export const NoLabel: Story = { ...Template, args: { checked: false, label: 'No Label', hideLabel: true, }, } export const PartialState: Story = { ...Template, args: { partialChecked: true, label: 'Partial State', }, } export const PartialStateDisabled: Story = { ...Template, args: { partialChecked: true, label: 'Partial State (disabled)', disabled: true, }, } PartialStateDisabled.storyName = 'Partial State (disabled)'