|
| 1 | +import { useState } from 'preact/hooks'; |
| 2 | + |
| 3 | +import type { RichCheckboxProps } from '../../../../components/input/RichCheckbox'; |
| 4 | +import RichCheckbox from '../../../../components/input/RichCheckbox'; |
| 5 | +import Library from '../../Library'; |
| 6 | + |
| 7 | +function RichCheckbox_({ |
| 8 | + children, |
| 9 | + initialChecked = false, |
| 10 | + subtitle, |
| 11 | +}: Omit<RichCheckboxProps, 'checked' | 'onChange'> & { |
| 12 | + initialChecked?: boolean; |
| 13 | +}) { |
| 14 | + const [checked, setChecked] = useState(initialChecked); |
| 15 | + |
| 16 | + return ( |
| 17 | + <RichCheckbox checked={checked} onChange={setChecked} subtitle={subtitle}> |
| 18 | + {children} |
| 19 | + </RichCheckbox> |
| 20 | + ); |
| 21 | +} |
| 22 | + |
| 23 | +export default function CheckboxPage() { |
| 24 | + return ( |
| 25 | + <Library.Page |
| 26 | + title="RichCheckbox" |
| 27 | + intro={ |
| 28 | + <> |
| 29 | + <p> |
| 30 | + <code>RichCheckbox</code> is an opinionated controlled{' '} |
| 31 | + <code> |
| 32 | + [role={'"'}checkbox{'"'}] |
| 33 | + </code>{' '} |
| 34 | + component that includes a checkbox icon next to some content. |
| 35 | + </p> |
| 36 | + <p> |
| 37 | + It has predefined hover and checked styles, like the individual{' '} |
| 38 | + <code>Radio</code>s inside{' '} |
| 39 | + <Library.Link href="/input-radio-group"> |
| 40 | + <code>RadioGroup</code> |
| 41 | + </Library.Link> |
| 42 | + . |
| 43 | + </p> |
| 44 | + </> |
| 45 | + } |
| 46 | + > |
| 47 | + <Library.SectionL2> |
| 48 | + <Library.Usage symbolName="RichCheckbox" /> |
| 49 | + <Library.SectionL3> |
| 50 | + <Library.Demo title="Basic RichCheckbox" withSource> |
| 51 | + <div className="flex flex-col gap-y-2"> |
| 52 | + <RichCheckbox_>Click me</RichCheckbox_> |
| 53 | + <RichCheckbox_ subtitle="This one includes a subtitle"> |
| 54 | + Click me |
| 55 | + </RichCheckbox_> |
| 56 | + </div> |
| 57 | + </Library.Demo> |
| 58 | + </Library.SectionL3> |
| 59 | + </Library.SectionL2> |
| 60 | + |
| 61 | + <Library.SectionL2 title="Component API"> |
| 62 | + <Library.SectionL3 title="checked"> |
| 63 | + <Library.Info> |
| 64 | + <Library.InfoItem label="description"> |
| 65 | + Set whether the <code>RichCheckbox</code> is checked. |
| 66 | + </Library.InfoItem> |
| 67 | + <Library.InfoItem label="type"> |
| 68 | + <code>{`boolean`}</code> |
| 69 | + </Library.InfoItem> |
| 70 | + </Library.Info> |
| 71 | + </Library.SectionL3> |
| 72 | + <Library.SectionL3 title="children"> |
| 73 | + <Library.Info> |
| 74 | + <Library.InfoItem label="description"> |
| 75 | + Main content of the checkbox. Will be displayed next to check |
| 76 | + checkbox icon, and vertically aligned with it. |
| 77 | + </Library.InfoItem> |
| 78 | + <Library.InfoItem label="type"> |
| 79 | + <code>{`ComponentChildren`}</code> |
| 80 | + </Library.InfoItem> |
| 81 | + </Library.Info> |
| 82 | + </Library.SectionL3> |
| 83 | + <Library.SectionL3 title="onChange"> |
| 84 | + <Library.Info> |
| 85 | + <Library.InfoItem label="description"> |
| 86 | + Callback invoked check the <code>checked</code> value changes. |
| 87 | + </Library.InfoItem> |
| 88 | + <Library.InfoItem label="type"> |
| 89 | + <code>{`(checked: boolean) => void`}</code> |
| 90 | + </Library.InfoItem> |
| 91 | + </Library.Info> |
| 92 | + </Library.SectionL3> |
| 93 | + <Library.SectionL3 title="subtitle"> |
| 94 | + <Library.Info> |
| 95 | + <Library.InfoItem label="description"> |
| 96 | + If provided, it will show extra content in a lighter font color, |
| 97 | + right below the main content, and aligned to the left with it. |
| 98 | + </Library.InfoItem> |
| 99 | + <Library.InfoItem label="type"> |
| 100 | + <code>{`ComponentChildren`}</code> |
| 101 | + </Library.InfoItem> |
| 102 | + <Library.InfoItem label="default"> |
| 103 | + <code>{`undefined`}</code> |
| 104 | + </Library.InfoItem> |
| 105 | + </Library.Info> |
| 106 | + </Library.SectionL3> |
| 107 | + </Library.SectionL2> |
| 108 | + </Library.Page> |
| 109 | + ); |
| 110 | +} |
0 commit comments