StyleGuide.jsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { h } from 'preact';
  2. import ArrowDropdown from '../icons/ArrowDropdown';
  3. import ArrowDropup from '../icons/ArrowDropup';
  4. import Button from '../components/Button';
  5. import Dialog from '../components/Dialog';
  6. import Heading from '../components/Heading';
  7. import Select from '../components/Select';
  8. import Switch from '../components/Switch';
  9. import TextField from '../components/TextField';
  10. import { useCallback, useState } from 'preact/hooks';
  11. export default function StyleGuide() {
  12. const [switches, setSwitches] = useState({ 0: false, 1: true, 2: false, 3: false });
  13. const [showDialog, setShowDialog] = useState(false);
  14. const handleSwitch = useCallback(
  15. (id, checked) => {
  16. setSwitches({ ...switches, [id]: checked });
  17. },
  18. [switches]
  19. );
  20. const handleDismissDialog = () => {
  21. setShowDialog(false);
  22. };
  23. return (
  24. <div>
  25. <Heading size="md">Button</Heading>
  26. <div className="flex space-x-4 mb-4">
  27. <Button>Default</Button>
  28. <Button color="red">Danger</Button>
  29. <Button color="green">Save</Button>
  30. <Button color="gray">Gray</Button>
  31. <Button disabled>Disabled</Button>
  32. </div>
  33. <div className="flex space-x-4 mb-4">
  34. <Button type="text">Default</Button>
  35. <Button color="red" type="text">
  36. Danger
  37. </Button>
  38. <Button color="green" type="text">
  39. Save
  40. </Button>
  41. <Button color="gray" type="text">
  42. Gray
  43. </Button>
  44. <Button disabled type="text">
  45. Disabled
  46. </Button>
  47. </div>
  48. <div className="flex space-x-4 mb-4">
  49. <Button type="outlined">Default</Button>
  50. <Button color="red" type="outlined">
  51. Danger
  52. </Button>
  53. <Button color="green" type="outlined">
  54. Save
  55. </Button>
  56. <Button color="gray" type="outlined">
  57. Gray
  58. </Button>
  59. <Button disabled type="outlined">
  60. Disabled
  61. </Button>
  62. </div>
  63. <Heading size="md">Dialog</Heading>
  64. <Button
  65. onClick={() => {
  66. setShowDialog(true);
  67. }}
  68. >
  69. Show Dialog
  70. </Button>
  71. {showDialog ? (
  72. <Dialog
  73. onDismiss={handleDismissDialog}
  74. title="This is a dialog"
  75. text="Would you like to see more?"
  76. actions={[
  77. { text: 'Yes', color: 'red', onClick: handleDismissDialog },
  78. { text: 'No', onClick: handleDismissDialog },
  79. ]}
  80. />
  81. ) : null}
  82. <Heading size="md">Switch</Heading>
  83. <div className="flex-col space-y-4 max-w-4xl">
  84. <Switch label="Disabled, off" labelPosition="after" />
  85. <Switch label="Disabled, on" labelPosition="after" checked />
  86. <Switch
  87. label="Enabled, (off initial)"
  88. labelPosition="after"
  89. checked={switches[0]}
  90. id={0}
  91. onChange={handleSwitch}
  92. />
  93. <Switch
  94. label="Enabled, (on initial)"
  95. labelPosition="after"
  96. checked={switches[1]}
  97. id={1}
  98. onChange={handleSwitch}
  99. />
  100. <Switch checked={switches[2]} id={2} label="Label before" onChange={handleSwitch} />
  101. <Switch checked={switches[3]} id={3} label="Label after" labelPosition="after" onChange={handleSwitch} />
  102. </div>
  103. <Heading size="md">Select</Heading>
  104. <div className="flex space-x-4 mb-4 max-w-4xl">
  105. <Select label="Basic select box" options={['All', 'None', 'Other']} selected="None" />
  106. </div>
  107. <Heading size="md">TextField</Heading>
  108. <div className="flex-col space-y-4 max-w-4xl">
  109. <TextField label="Default text field" />
  110. <TextField label="Pre-filled" value="This is my pre-filled value" />
  111. <TextField label="With help" helpText="This is some help text" />
  112. <TextField label="Leading icon" leadingIcon={ArrowDropdown} />
  113. <TextField label="Trailing icon" trailingIcon={ArrowDropup} />
  114. </div>
  115. </div>
  116. );
  117. }