demo.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. import type { Component } from "solid-js"
  2. import { createSignal } from "solid-js"
  3. import {
  4. Accordion,
  5. Button,
  6. Checkbox,
  7. Select,
  8. Tabs,
  9. Tooltip,
  10. Fonts,
  11. List,
  12. Dialog,
  13. Icon,
  14. IconButton,
  15. Input,
  16. SelectDialog,
  17. Collapsible,
  18. } from "./components"
  19. import "./index.css"
  20. const Demo: Component = () => {
  21. const [dialogOpen, setDialogOpen] = createSignal(false)
  22. const [selectDialogOpen, setSelectDialogOpen] = createSignal(false)
  23. const [inputValue, setInputValue] = createSignal("")
  24. const [checked, setChecked] = createSignal(false)
  25. const [termsAccepted, setTermsAccepted] = createSignal(false)
  26. const Content = (props: { dark?: boolean }) => (
  27. <div class={`${props.dark ? "dark" : ""}`}>
  28. <h3>Buttons</h3>
  29. <section>
  30. <Button variant="primary" size="normal">
  31. Normal Primary
  32. </Button>
  33. <Button variant="secondary" size="normal">
  34. Normal Secondary
  35. </Button>
  36. <Button variant="ghost" size="normal">
  37. Normal Ghost
  38. </Button>
  39. <Button variant="secondary" size="normal" disabled>
  40. Normal Disabled
  41. </Button>
  42. <Button variant="primary" size="large">
  43. Large Primary
  44. </Button>
  45. <Button variant="secondary" size="large">
  46. Large Secondary
  47. </Button>
  48. <Button variant="ghost" size="large">
  49. Large Ghost
  50. </Button>
  51. <Button variant="secondary" size="large" disabled>
  52. Large Disabled
  53. </Button>
  54. </section>
  55. <h3>Select</h3>
  56. <section>
  57. <Select
  58. class={props.dark ? "dark" : ""}
  59. variant="primary"
  60. options={["Option 1", "Option 2", "Option 3"]}
  61. placeholder="Select Primary"
  62. />
  63. <Select
  64. variant="secondary"
  65. class={props.dark ? "dark" : ""}
  66. options={["Option 1", "Option 2", "Option 3"]}
  67. placeholder="Select Secondary"
  68. />
  69. <Select
  70. variant="ghost"
  71. class={props.dark ? "dark" : ""}
  72. options={["Option 1", "Option 2", "Option 3"]}
  73. placeholder="Select Ghost"
  74. />
  75. </section>
  76. <h3>Tabs</h3>
  77. <section>
  78. <Tabs defaultValue="tab1" style={{ width: "100%" }}>
  79. <Tabs.List>
  80. <Tabs.Trigger value="tab1">Tab 1</Tabs.Trigger>
  81. <Tabs.Trigger value="tab2">Tab 2</Tabs.Trigger>
  82. <Tabs.Trigger value="tab3">Tab 3</Tabs.Trigger>
  83. <Tabs.Trigger value="tab4" disabled>
  84. Disabled Tab
  85. </Tabs.Trigger>
  86. </Tabs.List>
  87. <Tabs.Content value="tab1">
  88. <div style={{ padding: "16px" }}>
  89. <h4>Tab 1 Content</h4>
  90. <p>This is the content for the first tab.</p>
  91. </div>
  92. </Tabs.Content>
  93. <Tabs.Content value="tab2">
  94. <div style={{ padding: "16px" }}>
  95. <h4>Tab 2 Content</h4>
  96. <p>This is the content for the second tab.</p>
  97. </div>
  98. </Tabs.Content>
  99. <Tabs.Content value="tab3">
  100. <div style={{ padding: "16px" }}>
  101. <h4>Tab 3 Content</h4>
  102. <p>This is the content for the third tab.</p>
  103. </div>
  104. </Tabs.Content>
  105. <Tabs.Content value="tab4">
  106. <div style={{ padding: "16px" }}>
  107. <h4>Tab 4 Content</h4>
  108. <p>This tab should be disabled.</p>
  109. </div>
  110. </Tabs.Content>
  111. </Tabs>
  112. </section>
  113. <h3>Tooltips</h3>
  114. <section>
  115. <Tooltip value="This is a top tooltip" placement="top">
  116. <Button variant="secondary">Top Tooltip</Button>
  117. </Tooltip>
  118. <Tooltip value="This is a bottom tooltip" placement="bottom">
  119. <Button variant="secondary">Bottom Tooltip</Button>
  120. </Tooltip>
  121. <Tooltip value="This is a left tooltip" placement="left">
  122. <Button variant="secondary">Left Tooltip</Button>
  123. </Tooltip>
  124. <Tooltip value="This is a right tooltip" placement="right">
  125. <Button variant="secondary">Right Tooltip</Button>
  126. </Tooltip>
  127. <Tooltip value={`Dynamic tooltip: ${new Date().toLocaleTimeString()}`} placement="top">
  128. <Button variant="primary">Dynamic Tooltip</Button>
  129. </Tooltip>
  130. </section>
  131. <h3>List</h3>
  132. <section style={{ height: "300px" }}>
  133. <List data={["Item 1", "Item 2", "Item 3"]} key={(x) => x}>
  134. {(x) => <div>{x}</div>}
  135. </List>
  136. </section>
  137. <h3>Input</h3>
  138. <section>
  139. <Input
  140. placeholder="Enter text..."
  141. value={inputValue()}
  142. onInput={(e: InputEvent & { currentTarget: HTMLInputElement }) => setInputValue(e.currentTarget.value)}
  143. />
  144. <Input placeholder="Disabled input" disabled />
  145. <Input type="password" placeholder="Password input" />
  146. </section>
  147. <h3>Checkbox</h3>
  148. <section style={{ "flex-direction": "column", "align-items": "flex-start", gap: "12px" }}>
  149. <Checkbox label="Simple checkbox" />
  150. <Checkbox label="Checked by default" defaultChecked />
  151. <Checkbox label="Disabled checkbox" disabled />
  152. <Checkbox label="Disabled & checked" disabled checked />
  153. <Checkbox
  154. label="Controlled checkbox"
  155. description="This checkbox is controlled by state"
  156. checked={checked()}
  157. onChange={setChecked}
  158. />
  159. <Checkbox label="With description" description="This is a helpful description for the checkbox" />
  160. <Checkbox label="Indeterminate state" description="Useful for nested checkbox lists" indeterminate />
  161. <Checkbox
  162. label="I agree to the Terms and Conditions"
  163. description="You must agree to continue"
  164. checked={termsAccepted()}
  165. onChange={setTermsAccepted}
  166. validationState={!termsAccepted() ? "invalid" : "valid"}
  167. />
  168. </section>
  169. <h3>Icons</h3>
  170. <section>
  171. <Icon name="close" />
  172. <Icon name="checkmark" />
  173. <Icon name="chevron-down" />
  174. <Icon name="chevron-up" />
  175. <Icon name="chevron-left" />
  176. <Icon name="chevron-right" />
  177. <Icon name="search" />
  178. <Icon name="loading" />
  179. </section>
  180. <h3>Icon Buttons</h3>
  181. <section>
  182. <IconButton icon="close" onClick={() => console.log("Close clicked")} />
  183. <IconButton icon="checkmark" onClick={() => console.log("Check clicked")} />
  184. <IconButton icon="search" onClick={() => console.log("Search clicked")} disabled />
  185. </section>
  186. <h3>Dialog</h3>
  187. <section>
  188. <Button onClick={() => setDialogOpen(true)}>Open Dialog</Button>
  189. <Dialog open={dialogOpen()} onOpenChange={setDialogOpen}>
  190. <Dialog.Title>Example Dialog</Dialog.Title>
  191. <Dialog.Description>This is an example dialog with a title and description.</Dialog.Description>
  192. <div
  193. style={{
  194. "margin-top": "16px",
  195. display: "flex",
  196. gap: "8px",
  197. "justify-content": "flex-end",
  198. }}
  199. >
  200. <Button variant="ghost" onClick={() => setDialogOpen(false)}>
  201. Cancel
  202. </Button>
  203. <Button variant="primary" onClick={() => setDialogOpen(false)}>
  204. Confirm
  205. </Button>
  206. </div>
  207. </Dialog>
  208. </section>
  209. <h3>Select Dialog</h3>
  210. <section>
  211. <Button onClick={() => setSelectDialogOpen(true)}>Open Select Dialog</Button>
  212. <SelectDialog
  213. title="Select an Option"
  214. defaultOpen={selectDialogOpen()}
  215. onOpenChange={setSelectDialogOpen}
  216. items={["Option 1", "Option 2", "Option 3", "Option 4", "Option 5"]}
  217. key={(x) => x}
  218. onSelect={(option) => {
  219. console.log("Selected:", option)
  220. setSelectDialogOpen(false)
  221. }}
  222. placeholder="Search options..."
  223. >
  224. {(item) => <div>{item}</div>}
  225. </SelectDialog>
  226. </section>
  227. <h3>Collapsible</h3>
  228. <section>
  229. <Collapsible>
  230. <Collapsible.Trigger>
  231. <Button variant="secondary">Toggle Content</Button>
  232. </Collapsible.Trigger>
  233. <Collapsible.Content>
  234. <div
  235. style={{
  236. padding: "16px",
  237. "background-color": "var(--surface-base)",
  238. "border-radius": "8px",
  239. "margin-top": "8px",
  240. }}
  241. >
  242. <p>This is collapsible content that can be toggled open and closed.</p>
  243. <p>It animates smoothly using CSS animations.</p>
  244. </div>
  245. </Collapsible.Content>
  246. </Collapsible>
  247. </section>
  248. <h3>Accordion</h3>
  249. <section>
  250. <Accordion collapsible>
  251. <Accordion.Item value="item-1">
  252. <Accordion.Header>
  253. <Accordion.Trigger>What is Kobalte?</Accordion.Trigger>
  254. </Accordion.Header>
  255. <Accordion.Content>
  256. <div style={{ padding: "16px" }}>
  257. <p>Kobalte is a UI toolkit for building accessible web apps and design systems with SolidJS.</p>
  258. </div>
  259. </Accordion.Content>
  260. </Accordion.Item>
  261. <Accordion.Item value="item-2">
  262. <Accordion.Header>
  263. <Accordion.Trigger>Is it accessible?</Accordion.Trigger>
  264. </Accordion.Header>
  265. <Accordion.Content>
  266. <div style={{ padding: "16px" }}>
  267. <p>Yes. It adheres to the WAI-ARIA design patterns.</p>
  268. </div>
  269. </Accordion.Content>
  270. </Accordion.Item>
  271. <Accordion.Item value="item-3">
  272. <Accordion.Header>
  273. <Accordion.Trigger>Can it be animated?</Accordion.Trigger>
  274. </Accordion.Header>
  275. <Accordion.Content>
  276. <div style={{ padding: "16px" }}>
  277. <p>Yes! You can animate the content height using CSS animations.</p>
  278. </div>
  279. </Accordion.Content>
  280. </Accordion.Item>
  281. </Accordion>
  282. </section>
  283. </div>
  284. )
  285. return (
  286. <>
  287. <Fonts />
  288. <main>
  289. <Content />
  290. <Content dark />
  291. </main>
  292. </>
  293. )
  294. }
  295. export default Demo