import { Meta } from "@storybook/react-vite"; import { useState } from "react"; import { Checkbox, CheckboxButton } from "./Checkbox"; const meta = { title: "Components/fields/Checkbox", component: Checkbox, decorators: [(Story) => ], } satisfies Meta; export default meta; const variants = ["contained", "light", "outlined", "text", "ghost"] as const; export const Basic = () => (
I agree I agree I agree I agree I agree I agree

Checkbox button

Attention pour les variantes contained et light le comportement n'est pas intuitif lorsqu'on décoche le bouton il parait toujours coché car le curseur est sur le bouton. on ne peut pas changer facilement le comportement car on importe les classes de bouton.

{[false, true].map((showInput) => { return ( <>

Show Input : {showInput ? "true" : "false"}

{variants.map((variant) => (
I agree I agree I agree I agree I agree I agree I agree I agree
))} ); })}
); export const Controlled = () => { const [checked, setChecked] = useState(false); return ( setChecked(e.target.checked)}> Checkbox value : {checked ? "True" : "False"} ); }; export const WithIndeterminate = () => { const [checked, setChecked] = useState(false); const [indeterminate, setIndeterminate] = useState(false); function handleChange() { if (checked && !indeterminate) { setIndeterminate(true); setChecked(false); } else if (!checked && indeterminate) { setIndeterminate(false); } else { setChecked((checked) => !checked); } } return ( Checkbox value : {checked ? "True" : "False"}, Indeterminate value :{" "} {indeterminate ? "True" : "False"} ); };