| 
 | 1 | +import React, { useRef, useState } from 'react';  | 
 | 2 | +import CheckboxButton, { CHECKED_STATES } from 'src/CheckboxButton';  | 
 | 3 | + | 
 | 4 | +import mdx from './CheckboxButton.mdx';  | 
 | 5 | + | 
 | 6 | +export default {  | 
 | 7 | +  title: 'Design System/CheckboxButton',  | 
 | 8 | +  component: CheckboxButton,  | 
 | 9 | +  parameters: {  | 
 | 10 | +    docs: {  | 
 | 11 | +      page: mdx,  | 
 | 12 | +    },  | 
 | 13 | +  },  | 
 | 14 | +};  | 
 | 15 | + | 
 | 16 | +export const Default = () => {  | 
 | 17 | +  const [isChecked, setIsChecked] = useState(CHECKED_STATES.CHECKED);  | 
 | 18 | + | 
 | 19 | +  const handleChange = () => {  | 
 | 20 | +    setIsChecked((prev) => !prev);  | 
 | 21 | +  };  | 
 | 22 | + | 
 | 23 | +  return (  | 
 | 24 | +    <CheckboxButton  | 
 | 25 | +      checked={isChecked}  | 
 | 26 | +      className="checkbox"  | 
 | 27 | +      disabled={false}  | 
 | 28 | +      id="1"  | 
 | 29 | +      type="checkbox"  | 
 | 30 | +      value={1}  | 
 | 31 | +      onChange={handleChange}  | 
 | 32 | +    />  | 
 | 33 | +  );  | 
 | 34 | +};  | 
 | 35 | + | 
 | 36 | +export const Indeterminate = () => {  | 
 | 37 | +  const inputEl = useRef(null);  | 
 | 38 | +  const [checked, setChecked] = useState([]);  | 
 | 39 | +  const checkboxes = ['1', '2', '3'];  | 
 | 40 | + | 
 | 41 | +  const onCheckAll = (event) => {  | 
 | 42 | +    if (event.target.checked) {  | 
 | 43 | +      setChecked(checkboxes);  | 
 | 44 | +    } else {  | 
 | 45 | +      setChecked([]);  | 
 | 46 | +    }  | 
 | 47 | +  };  | 
 | 48 | + | 
 | 49 | +  const onCheck = (event, value) => {  | 
 | 50 | +    if (event.target.checked) {  | 
 | 51 | +      setChecked([...checked, value]);  | 
 | 52 | +    } else {  | 
 | 53 | +      setChecked(checked.filter((item) => item !== value));  | 
 | 54 | +    }  | 
 | 55 | +  };  | 
 | 56 | + | 
 | 57 | +  return (  | 
 | 58 | +    <div style={{ display: 'flex', flexDirection: 'column', rowGap: '1rem' }}>  | 
 | 59 | +      <CheckboxButton  | 
 | 60 | +        checked={checked.length === 3}  | 
 | 61 | +        id="select-all"  | 
 | 62 | +        indeterminate={checked.length > 0 && checked.length < 3}  | 
 | 63 | +        ref={inputEl}  | 
 | 64 | +        onChange={onCheckAll}  | 
 | 65 | +      />  | 
 | 66 | +      {checkboxes.map((item) => (  | 
 | 67 | +        <CheckboxButton  | 
 | 68 | +          checked={checked.includes(item)}  | 
 | 69 | +          id={item}  | 
 | 70 | +          key={item}  | 
 | 71 | +          value={item}  | 
 | 72 | +          onChange={(e) => onCheck(e, item)}  | 
 | 73 | +        />  | 
 | 74 | +      ))}  | 
 | 75 | +    </div>  | 
 | 76 | +  );  | 
 | 77 | +};  | 
0 commit comments