checkbox.stories.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import Checkbox from 'sentry/components/checkbox';
  4. export default {
  5. title: 'Components/Forms/Controls/Checkbox',
  6. component: Checkbox,
  7. args: {
  8. size: 'sm',
  9. disabled: false,
  10. checked: true,
  11. },
  12. argTypes: {
  13. size: {
  14. options: ['xs', 'sm', 'md'],
  15. control: {type: 'radio'},
  16. },
  17. disabled: {
  18. control: {type: 'boolean'},
  19. },
  20. },
  21. };
  22. export const Default = props => {
  23. const [checked, setChecked] = useState(true);
  24. return (
  25. <div>
  26. <Checkbox
  27. {...props}
  28. checked={checked}
  29. onChange={e => setChecked(e.target.checked)}
  30. />
  31. </div>
  32. );
  33. };
  34. export const WithLabel = props => {
  35. const [check1, setCheck1] = useState(true);
  36. const [check2, setCheck2] = useState(false);
  37. return (
  38. <div>
  39. <Label>
  40. Label to left
  41. <Checkbox
  42. {...props}
  43. checked={check1}
  44. onChange={e => setCheck1(e.target.checked)}
  45. />
  46. </Label>
  47. <Label>
  48. <Checkbox
  49. {...props}
  50. checked={check2}
  51. onChange={e => setCheck2(e.target.checked)}
  52. />
  53. Label to right
  54. </Label>
  55. </div>
  56. );
  57. };
  58. const Label = styled('label')`
  59. display: flex;
  60. align-items: center;
  61. gap: 1rem;
  62. margin-bottom: 2rem;
  63. `;