import { action } from 'storybook/actions'; import { Meta, StoryObj } from '@storybook/react-webpack5'; import React, { ComponentProps, useEffect, useRef } from 'react'; import { Checkbox, Props, } from '../../src/lib/components/checkbox/Checkbox.component'; import { Tooltip } from '../../src/lib/components/tooltip/Tooltip.component'; import { Column } from '../../src/lib/components/tablev2/Tablev2.component'; import { Box, Input, Table } from '../../src/lib/next'; import { Form, FormGroup, FormSection } from '../../src/lib'; import { Stack } from '../../src/lib/spacing'; type CheckboxStory = StoryObj; const meta: Meta = { title: 'Components/Inputs/Checkbox', component: Checkbox, args: { label: 'interested ?', onChange: action('Checkbox clicked'), }, argTypes: { onChange: { description: 'Function to be called when the checkbox is clicked, optional', }, label: { control: 'text', description: 'Label of the checkbox, optional' }, checked: { control: 'boolean', description: 'Control if the checkbox is checked, optional', }, disabled: { control: 'boolean', description: 'Control if the checkbox is disabled, optional', }, value: { control: 'text' }, }, }; export default meta; export const Playground: CheckboxStory = {}; export const ChoiceCheckbox: CheckboxStory = { render: () => { return ( <> What are you interested in ? ); }, }; export const OptionCheckbox: CheckboxStory = { render: () => { return (
} >
); }, }; export const IndeterminateCheckbox: StoryObj< ComponentProps & { 'data-cy': string } > = { render: (args) => { const checkboxRef = useRef(null); useEffect(() => { if (checkboxRef.current) { checkboxRef.current.indeterminate = true; } }, [checkboxRef]); return ; }, args: { 'data-cy': 'checked_checkbox', }, }; export const CheckedCheckbox: StoryObj< ComponentProps & { 'data-cy': string } > = { args: { checked: true, 'data-cy': 'checked_checkbox', }, }; export const UncheckedCheckbox: CheckboxStory = { args: { checked: false, }, }; export const DisabledCheckboxes: CheckboxStory = { render: () => { return ( <> ); }, }; export const DisabledWithReason: CheckboxStory = { render: () => ( ), }; export const DisabledCheckedCheckbox: CheckboxStory = { args: { checked: true, disabled: true, }, }; export const DisabledUncheckedCheckbox: CheckboxStory = { args: { checked: false, disabled: true, }, }; export const AllStates: CheckboxStory = { render: () => { const indeterminateRef = useRef(null); useEffect(() => { if (indeterminateRef.current) { indeterminateRef.current.indeterminate = true; } }, []); return (
{}} /> {}} /> {}} /> {}} /> {}} />
); }, }; export const IndeterminateUseCase = { render: ({}) => { const data = [ { name: 'test 1', volume: 1, capacity: '1Gi', }, { name: 'test 2', volume: 1, capacity: '1Gi', }, { name: 'test 2', volume: 1, capacity: '1Gi', }, ]; const columns: Column<(typeof data)[number]>[] = [ { Header: 'Name', accessor: 'name', }, { Header: 'Volume', accessor: 'volume', }, { Header: 'Capacity', accessor: 'capacity', }, ]; return (
); }, };