@arbor-education/design-system.components 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gather/skills/write-stories/SKILL.md +207 -271
- package/.storybook/preview.ts +5 -0
- package/CHANGELOG.md +23 -0
- package/README.md +8 -0
- package/component-library.md +144 -13
- package/dist/components/articleCard/ArticleCard.stories.d.ts +137 -11
- package/dist/components/articleCard/ArticleCard.stories.d.ts.map +1 -1
- package/dist/components/articleCard/ArticleCard.stories.js +358 -91
- package/dist/components/articleCard/ArticleCard.stories.js.map +1 -1
- package/dist/components/avatar/Avatar.stories.d.ts +6 -6
- package/dist/components/avatar/Avatar.stories.d.ts.map +1 -1
- package/dist/components/avatar/Avatar.stories.js +393 -49
- package/dist/components/avatar/Avatar.stories.js.map +1 -1
- package/dist/components/avatarGroup/AvatarGroup.stories.d.ts +9 -7
- package/dist/components/avatarGroup/AvatarGroup.stories.d.ts.map +1 -1
- package/dist/components/avatarGroup/AvatarGroup.stories.js +688 -65
- package/dist/components/avatarGroup/AvatarGroup.stories.js.map +1 -1
- package/dist/components/banner/Banner.stories.d.ts.map +1 -1
- package/dist/components/banner/Banner.stories.js +7 -3
- package/dist/components/banner/Banner.stories.js.map +1 -1
- package/dist/components/card/Card.stories.d.ts +105 -4
- package/dist/components/card/Card.stories.d.ts.map +1 -1
- package/dist/components/card/Card.stories.js +336 -18
- package/dist/components/card/Card.stories.js.map +1 -1
- package/dist/components/combobox/Combobox.stories.d.ts +134 -21
- package/dist/components/combobox/Combobox.stories.d.ts.map +1 -1
- package/dist/components/combobox/Combobox.stories.js +676 -175
- package/dist/components/combobox/Combobox.stories.js.map +1 -1
- package/dist/components/datePicker/DatePicker.stories.d.ts +119 -27
- package/dist/components/datePicker/DatePicker.stories.d.ts.map +1 -1
- package/dist/components/datePicker/DatePicker.stories.js +575 -47
- package/dist/components/datePicker/DatePicker.stories.js.map +1 -1
- package/dist/components/dateTimePicker/DateTimePicker.stories.d.ts +155 -39
- package/dist/components/dateTimePicker/DateTimePicker.stories.d.ts.map +1 -1
- package/dist/components/dateTimePicker/DateTimePicker.stories.js +674 -103
- package/dist/components/dateTimePicker/DateTimePicker.stories.js.map +1 -1
- package/dist/components/editableText/EditableText.stories.d.ts +53 -12
- package/dist/components/editableText/EditableText.stories.d.ts.map +1 -1
- package/dist/components/editableText/EditableText.stories.js +401 -64
- package/dist/components/editableText/EditableText.stories.js.map +1 -1
- package/dist/components/formField/FormField.d.ts +4 -0
- package/dist/components/formField/FormField.d.ts.map +1 -1
- package/dist/components/formField/FormField.js +2 -1
- package/dist/components/formField/FormField.js.map +1 -1
- package/dist/components/formField/FormField.test.js +5 -0
- package/dist/components/formField/FormField.test.js.map +1 -1
- package/dist/components/formField/fieldset/Fieldset.stories.d.ts +56 -4
- package/dist/components/formField/fieldset/Fieldset.stories.d.ts.map +1 -1
- package/dist/components/formField/fieldset/Fieldset.stories.js +534 -28
- package/dist/components/formField/fieldset/Fieldset.stories.js.map +1 -1
- package/dist/components/formField/inputs/checkbox/CheckboxGroup.d.ts +3 -1
- package/dist/components/formField/inputs/checkbox/CheckboxGroup.d.ts.map +1 -1
- package/dist/components/formField/inputs/checkbox/CheckboxInput.js +1 -1
- package/dist/components/formField/inputs/checkbox/CheckboxInput.js.map +1 -1
- package/dist/components/formField/inputs/colourPickerDropdown/ColourPickerDropdown.stories.d.ts +95 -1
- package/dist/components/formField/inputs/colourPickerDropdown/ColourPickerDropdown.stories.d.ts.map +1 -1
- package/dist/components/formField/inputs/colourPickerDropdown/ColourPickerDropdown.stories.js +386 -9
- package/dist/components/formField/inputs/colourPickerDropdown/ColourPickerDropdown.stories.js.map +1 -1
- package/dist/components/formField/inputs/radio/RadioButtonGroup.d.ts +6 -2
- package/dist/components/formField/inputs/radio/RadioButtonGroup.d.ts.map +1 -1
- package/dist/components/formField/inputs/radio/RadioButtonGroup.js.map +1 -1
- package/dist/components/formField/inputs/radio/RadioButtonInput.stories.d.ts.map +1 -1
- package/dist/components/formField/inputs/radio/RadioButtonInput.stories.js +61 -49
- package/dist/components/formField/inputs/radio/RadioButtonInput.stories.js.map +1 -1
- package/dist/components/formField/inputs/selectDropdown/SelectDropdown.stories.d.ts +188 -166
- package/dist/components/formField/inputs/selectDropdown/SelectDropdown.stories.d.ts.map +1 -1
- package/dist/components/formField/inputs/selectDropdown/SelectDropdown.stories.js +821 -160
- package/dist/components/formField/inputs/selectDropdown/SelectDropdown.stories.js.map +1 -1
- package/dist/components/formField/inputs/time/TimeInput.stories.d.ts +176 -22
- package/dist/components/formField/inputs/time/TimeInput.stories.d.ts.map +1 -1
- package/dist/components/formField/inputs/time/TimeInput.stories.js +851 -92
- package/dist/components/formField/inputs/time/TimeInput.stories.js.map +1 -1
- package/dist/components/formField/label/Label.stories.d.ts +54 -5
- package/dist/components/formField/label/Label.stories.d.ts.map +1 -1
- package/dist/components/formField/label/Label.stories.js +238 -4
- package/dist/components/formField/label/Label.stories.js.map +1 -1
- package/dist/components/icoText/IcoText.stories.d.ts +32 -6
- package/dist/components/icoText/IcoText.stories.d.ts.map +1 -1
- package/dist/components/icoText/IcoText.stories.js +309 -14
- package/dist/components/icoText/IcoText.stories.js.map +1 -1
- package/dist/components/kpiCard/KPICard.stories.d.ts +100 -2
- package/dist/components/kpiCard/KPICard.stories.d.ts.map +1 -1
- package/dist/components/kpiCard/KPICard.stories.js +354 -10
- package/dist/components/kpiCard/KPICard.stories.js.map +1 -1
- package/dist/components/kvpList/KVPList.stories.d.ts +57 -4
- package/dist/components/kvpList/KVPList.stories.d.ts.map +1 -1
- package/dist/components/kvpList/KVPList.stories.js +403 -10
- package/dist/components/kvpList/KVPList.stories.js.map +1 -1
- package/dist/components/modal/Modal.stories.d.ts +113 -9
- package/dist/components/modal/Modal.stories.d.ts.map +1 -1
- package/dist/components/modal/Modal.stories.js +633 -13
- package/dist/components/modal/Modal.stories.js.map +1 -1
- package/dist/components/modal/modalManager/ModalManager.stories.d.ts +34 -10
- package/dist/components/modal/modalManager/ModalManager.stories.d.ts.map +1 -1
- package/dist/components/modal/modalManager/ModalManager.stories.js +463 -85
- package/dist/components/modal/modalManager/ModalManager.stories.js.map +1 -1
- package/dist/components/pill/Pill.d.ts.map +1 -1
- package/dist/components/pill/Pill.js +1 -1
- package/dist/components/pill/Pill.js.map +1 -1
- package/dist/components/pill/Pill.stories.d.ts.map +1 -1
- package/dist/components/pill/Pill.stories.js +11 -13
- package/dist/components/pill/Pill.stories.js.map +1 -1
- package/dist/components/row/Row.stories.d.ts +1 -2
- package/dist/components/row/Row.stories.d.ts.map +1 -1
- package/dist/components/row/Row.stories.js +360 -50
- package/dist/components/row/Row.stories.js.map +1 -1
- package/dist/components/searchBar/SearchBar.stories.d.ts +52 -4
- package/dist/components/searchBar/SearchBar.stories.d.ts.map +1 -1
- package/dist/components/searchBar/SearchBar.stories.js +428 -36
- package/dist/components/searchBar/SearchBar.stories.js.map +1 -1
- package/dist/components/section/Section.stories.d.ts +11 -41
- package/dist/components/section/Section.stories.d.ts.map +1 -1
- package/dist/components/section/Section.stories.js +494 -56
- package/dist/components/section/Section.stories.js.map +1 -1
- package/dist/components/singleUser/SingleUser.stories.d.ts +5 -4
- package/dist/components/singleUser/SingleUser.stories.d.ts.map +1 -1
- package/dist/components/singleUser/SingleUser.stories.js +303 -31
- package/dist/components/singleUser/SingleUser.stories.js.map +1 -1
- package/dist/components/slideoverManager/SlideoverManager.stories.d.ts +32 -11
- package/dist/components/slideoverManager/SlideoverManager.stories.d.ts.map +1 -1
- package/dist/components/slideoverManager/SlideoverManager.stories.js +380 -84
- package/dist/components/slideoverManager/SlideoverManager.stories.js.map +1 -1
- package/dist/components/table/DSDefaultColDef.d.ts.map +1 -1
- package/dist/components/table/DSDefaultColDef.js +4 -3
- package/dist/components/table/DSDefaultColDef.js.map +1 -1
- package/dist/components/table/Table.d.ts +6 -1
- package/dist/components/table/Table.d.ts.map +1 -1
- package/dist/components/table/Table.js +8 -3
- package/dist/components/table/Table.js.map +1 -1
- package/dist/components/table/Table.stories.d.ts +3 -0
- package/dist/components/table/Table.stories.d.ts.map +1 -1
- package/dist/components/table/Table.stories.js +384 -5
- package/dist/components/table/Table.stories.js.map +1 -1
- package/dist/components/table/Table.test.js +30 -0
- package/dist/components/table/Table.test.js.map +1 -1
- package/dist/components/table/TableFooter.stories.d.ts +49 -0
- package/dist/components/table/TableFooter.stories.d.ts.map +1 -0
- package/dist/components/table/TableFooter.stories.js +137 -0
- package/dist/components/table/TableFooter.stories.js.map +1 -0
- package/dist/components/table/TableHeader.stories.d.ts +93 -0
- package/dist/components/table/TableHeader.stories.d.ts.map +1 -0
- package/dist/components/table/TableHeader.stories.js +176 -0
- package/dist/components/table/TableHeader.stories.js.map +1 -0
- package/dist/components/table/cellEditors/DateCellEditor.stories.d.ts +44 -0
- package/dist/components/table/cellEditors/DateCellEditor.stories.d.ts.map +1 -0
- package/dist/components/table/cellEditors/DateCellEditor.stories.js +186 -0
- package/dist/components/table/cellEditors/DateCellEditor.stories.js.map +1 -0
- package/dist/components/table/cellRenderers/BooleanCellRenderer.stories.d.ts +40 -0
- package/dist/components/table/cellRenderers/BooleanCellRenderer.stories.d.ts.map +1 -0
- package/dist/components/table/cellRenderers/BooleanCellRenderer.stories.js +209 -0
- package/dist/components/table/cellRenderers/BooleanCellRenderer.stories.js.map +1 -0
- package/dist/components/table/cellRenderers/ButtonCellRenderer.stories.d.ts +48 -0
- package/dist/components/table/cellRenderers/ButtonCellRenderer.stories.d.ts.map +1 -0
- package/dist/components/table/cellRenderers/ButtonCellRenderer.stories.js +244 -0
- package/dist/components/table/cellRenderers/ButtonCellRenderer.stories.js.map +1 -0
- package/dist/components/table/cellRenderers/CheckboxCellRenderer.d.ts.map +1 -1
- package/dist/components/table/cellRenderers/CheckboxCellRenderer.js +3 -1
- package/dist/components/table/cellRenderers/CheckboxCellRenderer.js.map +1 -1
- package/dist/components/table/cellRenderers/CheckboxCellRenderer.stories.d.ts +64 -0
- package/dist/components/table/cellRenderers/CheckboxCellRenderer.stories.d.ts.map +1 -0
- package/dist/components/table/cellRenderers/CheckboxCellRenderer.stories.js +241 -0
- package/dist/components/table/cellRenderers/CheckboxCellRenderer.stories.js.map +1 -0
- package/dist/components/table/cellRenderers/DefaultCellRenderer.stories.d.ts +55 -0
- package/dist/components/table/cellRenderers/DefaultCellRenderer.stories.d.ts.map +1 -0
- package/dist/components/table/cellRenderers/DefaultCellRenderer.stories.js +245 -0
- package/dist/components/table/cellRenderers/DefaultCellRenderer.stories.js.map +1 -0
- package/dist/components/table/cellRenderers/InlineTextCellRenderer.stories.d.ts +67 -0
- package/dist/components/table/cellRenderers/InlineTextCellRenderer.stories.d.ts.map +1 -0
- package/dist/components/table/cellRenderers/InlineTextCellRenderer.stories.js +221 -0
- package/dist/components/table/cellRenderers/InlineTextCellRenderer.stories.js.map +1 -0
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.stories.d.ts +75 -0
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.stories.d.ts.map +1 -0
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.stories.js +270 -0
- package/dist/components/table/cellRenderers/SelectDropdownCellRenderer.stories.js.map +1 -0
- package/dist/components/table/columnFilters/BooleanFilter.stories.d.ts +57 -0
- package/dist/components/table/columnFilters/BooleanFilter.stories.d.ts.map +1 -0
- package/dist/components/table/columnFilters/BooleanFilter.stories.js +198 -0
- package/dist/components/table/columnFilters/BooleanFilter.stories.js.map +1 -0
- package/dist/components/table/columnFilters/TimeFilter.stories.d.ts +58 -0
- package/dist/components/table/columnFilters/TimeFilter.stories.d.ts.map +1 -0
- package/dist/components/table/columnFilters/TimeFilter.stories.js +207 -0
- package/dist/components/table/columnFilters/TimeFilter.stories.js.map +1 -0
- package/dist/components/table/pagination/PaginationPanel.stories.d.ts +113 -0
- package/dist/components/table/pagination/PaginationPanel.stories.d.ts.map +1 -0
- package/dist/components/table/pagination/PaginationPanel.stories.js +272 -0
- package/dist/components/table/pagination/PaginationPanel.stories.js.map +1 -0
- package/dist/components/table/tableControls/HideColumnsDropdown.d.ts.map +1 -1
- package/dist/components/table/tableControls/HideColumnsDropdown.js +9 -3
- package/dist/components/table/tableControls/HideColumnsDropdown.js.map +1 -1
- package/dist/components/table/tableControls/TableControls.stories.d.ts +151 -0
- package/dist/components/table/tableControls/TableControls.stories.d.ts.map +1 -0
- package/dist/components/table/tableControls/TableControls.stories.js +356 -0
- package/dist/components/table/tableControls/TableControls.stories.js.map +1 -0
- package/dist/components/table/tableControls/TableSettingsDropdown.d.ts +27 -1
- package/dist/components/table/tableControls/TableSettingsDropdown.d.ts.map +1 -1
- package/dist/components/table/tableControls/TableSettingsDropdown.js +53 -26
- package/dist/components/table/tableControls/TableSettingsDropdown.js.map +1 -1
- package/dist/components/table/tableControls/TableSettingsDropdown.test.d.ts +2 -0
- package/dist/components/table/tableControls/TableSettingsDropdown.test.d.ts.map +1 -0
- package/dist/components/table/tableControls/TableSettingsDropdown.test.js +178 -0
- package/dist/components/table/tableControls/TableSettingsDropdown.test.js.map +1 -0
- package/dist/components/tabs/Tabs.stories.d.ts +22 -4
- package/dist/components/tabs/Tabs.stories.d.ts.map +1 -1
- package/dist/components/tabs/Tabs.stories.js +398 -22
- package/dist/components/tabs/Tabs.stories.js.map +1 -1
- package/dist/components/tabs/TabsItem.stories.d.ts +54 -1
- package/dist/components/tabs/TabsItem.stories.d.ts.map +1 -1
- package/dist/components/tabs/TabsItem.stories.js +61 -9
- package/dist/components/tabs/TabsItem.stories.js.map +1 -1
- package/dist/components/toast/Toast.stories.d.ts +103 -10
- package/dist/components/toast/Toast.stories.d.ts.map +1 -1
- package/dist/components/toast/Toast.stories.js +409 -47
- package/dist/components/toast/Toast.stories.js.map +1 -1
- package/dist/components/toggle/Toggle.stories.d.ts +61 -46
- package/dist/components/toggle/Toggle.stories.d.ts.map +1 -1
- package/dist/components/toggle/Toggle.stories.js +311 -122
- package/dist/components/toggle/Toggle.stories.js.map +1 -1
- package/dist/components/tooltip/Tooltip.stories.d.ts +78 -6
- package/dist/components/tooltip/Tooltip.stories.d.ts.map +1 -1
- package/dist/components/tooltip/Tooltip.stories.js +413 -7
- package/dist/components/tooltip/Tooltip.stories.js.map +1 -1
- package/dist/components/tooltip/TooltipWrapper.stories.d.ts +71 -7
- package/dist/components/tooltip/TooltipWrapper.stories.d.ts.map +1 -1
- package/dist/components/tooltip/TooltipWrapper.stories.js +238 -10
- package/dist/components/tooltip/TooltipWrapper.stories.js.map +1 -1
- package/dist/index.css +8 -0
- package/dist/index.css.map +1 -1
- package/dist/utils/PopupParentContext.stories.d.ts +17 -0
- package/dist/utils/PopupParentContext.stories.d.ts.map +1 -0
- package/dist/utils/PopupParentContext.stories.js +266 -0
- package/dist/utils/PopupParentContext.stories.js.map +1 -0
- package/dist/utils/getDefaultPopupParent.d.ts.map +1 -1
- package/dist/utils/getDefaultPopupParent.js +6 -0
- package/dist/utils/getDefaultPopupParent.js.map +1 -1
- package/package.json +1 -1
- package/src/components/articleCard/ArticleCard.stories.tsx +524 -111
- package/src/components/avatar/Avatar.stories.tsx +504 -59
- package/src/components/avatarGroup/AvatarGroup.stories.tsx +977 -175
- package/src/components/banner/Banner.stories.tsx +7 -3
- package/src/components/card/Card.stories.tsx +466 -36
- package/src/components/combobox/Combobox.stories.tsx +867 -260
- package/src/components/datePicker/DatePicker.stories.tsx +777 -60
- package/src/components/dateTimePicker/DateTimePicker.stories.tsx +910 -132
- package/src/components/editableText/EditableText.stories.tsx +567 -91
- package/src/components/formField/FormField.test.tsx +6 -0
- package/src/components/formField/FormField.tsx +5 -0
- package/src/components/formField/fieldset/Fieldset.stories.tsx +761 -51
- package/src/components/formField/inputs/checkbox/CheckboxGroup.tsx +1 -1
- package/src/components/formField/inputs/checkbox/CheckboxInput.tsx +1 -1
- package/src/components/formField/inputs/colourPickerDropdown/ColourPickerDropdown.stories.tsx +504 -11
- package/src/components/formField/inputs/radio/RadioButtonGroup.tsx +17 -4
- package/src/components/formField/inputs/radio/RadioButtonInput.stories.tsx +71 -59
- package/src/components/formField/inputs/selectDropdown/SelectDropdown.stories.tsx +1079 -168
- package/src/components/formField/inputs/time/TimeInput.stories.tsx +1140 -104
- package/src/components/formField/label/Label.stories.tsx +317 -8
- package/src/components/icoText/IcoText.stories.tsx +442 -31
- package/src/components/kpiCard/KPICard.stories.tsx +475 -30
- package/src/components/kvpList/KVPList.stories.tsx +593 -26
- package/src/components/modal/Modal.stories.tsx +963 -26
- package/src/components/modal/modalManager/ModalManager.stories.tsx +612 -454
- package/src/components/pill/Pill.stories.tsx +11 -13
- package/src/components/pill/Pill.tsx +1 -0
- package/src/components/row/Row.stories.tsx +474 -58
- package/src/components/searchBar/SearchBar.stories.tsx +570 -38
- package/src/components/section/Section.stories.tsx +723 -70
- package/src/components/singleUser/SingleUser.stories.tsx +393 -34
- package/src/components/slideoverManager/SlideoverManager.stories.tsx +572 -342
- package/src/components/table/DSDefaultColDef.ts +25 -5
- package/src/components/table/Table.stories.tsx +460 -5
- package/src/components/table/Table.test.tsx +53 -0
- package/src/components/table/Table.tsx +9 -2
- package/src/components/table/TableFooter.stories.tsx +196 -0
- package/src/components/table/TableHeader.stories.tsx +251 -0
- package/src/components/table/cellEditors/DateCellEditor.stories.tsx +245 -0
- package/src/components/table/cellRenderers/BooleanCellRenderer.stories.tsx +278 -0
- package/src/components/table/cellRenderers/ButtonCellRenderer.stories.tsx +333 -0
- package/src/components/table/cellRenderers/CheckboxCellRenderer.stories.tsx +337 -0
- package/src/components/table/cellRenderers/CheckboxCellRenderer.tsx +5 -1
- package/src/components/table/cellRenderers/DefaultCellRenderer.stories.tsx +342 -0
- package/src/components/table/cellRenderers/InlineTextCellRenderer.stories.tsx +292 -0
- package/src/components/table/cellRenderers/SelectDropdownCellRenderer.stories.tsx +369 -0
- package/src/components/table/columnFilters/BooleanFilter.stories.tsx +268 -0
- package/src/components/table/columnFilters/TimeFilter.stories.tsx +281 -0
- package/src/components/table/pagination/PaginationPanel.stories.tsx +327 -0
- package/src/components/table/tableControls/HideColumnsDropdown.tsx +11 -2
- package/src/components/table/tableControls/TableControls.stories.tsx +415 -0
- package/src/components/table/tableControls/TableSettingsDropdown.test.tsx +207 -0
- package/src/components/table/tableControls/TableSettingsDropdown.tsx +103 -39
- package/src/components/tabs/Tabs.stories.tsx +540 -60
- package/src/components/tabs/TabsItem.stories.tsx +82 -8
- package/src/components/toast/Toast.stories.tsx +539 -77
- package/src/components/toggle/Toggle.stories.tsx +371 -135
- package/src/components/tooltip/Tooltip.stories.tsx +606 -15
- package/src/components/tooltip/TooltipWrapper.stories.tsx +348 -12
- package/src/docs/Contributing.mdx +241 -0
- package/src/docs/UsingComponents.mdx +93 -0
- package/src/docs/Welcome.mdx +68 -0
- package/src/global.scss +7 -0
- package/src/utils/PopupParentContext.stories.tsx +367 -0
- package/src/utils/getDefaultPopupParent.ts +6 -0
- package/.ralph/storybook-upgrade/knowledge.md +0 -308
- package/.ralph/storybook-upgrade/prd.json +0 -777
- package/.ralph/storybook-upgrade/progress.md +0 -342
- package/src/components/table/TableWIP.mdx +0 -3
|
@@ -1,35 +1,13 @@
|
|
|
1
1
|
import type { StoryObj } from '@storybook/react-vite';
|
|
2
|
-
|
|
3
|
-
* The Toggle component is a binary on/off switch, built on top of Radix UI's
|
|
4
|
-
* Switch primitive. Think of it like the light switch in the St. Olaf town
|
|
5
|
-
* hall — everyone in town knows exactly whether the lights are on or off,
|
|
6
|
-
* and there is never any confusion about which state you are in.
|
|
7
|
-
*
|
|
8
|
-
* Toggling is the right choice when you need an immediate, binary setting
|
|
9
|
-
* change — "dark mode on", "notifications off", "feature enabled". Unlike a
|
|
10
|
-
* checkbox, a toggle implies the change takes effect right away, without
|
|
11
|
-
* needing a form submission.
|
|
12
|
-
*
|
|
13
|
-
* **Accessibility**
|
|
14
|
-
* - Rendered as a `<button role="switch">` — screen readers announce the
|
|
15
|
-
* current state ("checked" / "not checked") automatically.
|
|
16
|
-
* - Fully keyboard accessible: `Space` or `Enter` toggles the state.
|
|
17
|
-
* - Associate a visible label with the toggle using a `<label htmlFor={id}>`
|
|
18
|
-
* so users of all abilities know what they are toggling.
|
|
19
|
-
* - The `disabled` prop renders the element as non-interactive and applies
|
|
20
|
-
* correct ARIA semantics.
|
|
21
|
-
*
|
|
22
|
-
* **CSS classes**
|
|
23
|
-
* - Root element: `ds-toggle`
|
|
24
|
-
* - Thumb (the sliding dot): `ds-toggle__thumb`
|
|
25
|
-
* - Checked state is driven by Radix's `data-state="checked"` attribute,
|
|
26
|
-
* which the SCSS uses to apply brand colours and shift the thumb position.
|
|
27
|
-
*/
|
|
2
|
+
declare function ToggleDocsPage(): import("react/jsx-runtime").JSX.Element;
|
|
28
3
|
declare const meta: {
|
|
29
4
|
title: string;
|
|
30
5
|
component: (props: import("@radix-ui/react-switch").SwitchProps) => import("react/jsx-runtime").JSX.Element;
|
|
31
6
|
parameters: {
|
|
32
7
|
layout: string;
|
|
8
|
+
docs: {
|
|
9
|
+
page: typeof ToggleDocsPage;
|
|
10
|
+
};
|
|
33
11
|
};
|
|
34
12
|
tags: string[];
|
|
35
13
|
args: {
|
|
@@ -39,58 +17,95 @@ declare const meta: {
|
|
|
39
17
|
checked: {
|
|
40
18
|
control: "boolean";
|
|
41
19
|
description: string;
|
|
20
|
+
table: {
|
|
21
|
+
type: {
|
|
22
|
+
summary: string;
|
|
23
|
+
};
|
|
24
|
+
defaultValue: {
|
|
25
|
+
summary: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
42
28
|
};
|
|
43
29
|
defaultChecked: {
|
|
44
30
|
control: "boolean";
|
|
45
31
|
description: string;
|
|
32
|
+
table: {
|
|
33
|
+
type: {
|
|
34
|
+
summary: string;
|
|
35
|
+
};
|
|
36
|
+
defaultValue: {
|
|
37
|
+
summary: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
46
40
|
};
|
|
47
41
|
disabled: {
|
|
48
42
|
control: "boolean";
|
|
49
43
|
description: string;
|
|
44
|
+
table: {
|
|
45
|
+
type: {
|
|
46
|
+
summary: string;
|
|
47
|
+
};
|
|
48
|
+
defaultValue: {
|
|
49
|
+
summary: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
50
52
|
};
|
|
51
53
|
required: {
|
|
52
54
|
control: "boolean";
|
|
53
55
|
description: string;
|
|
56
|
+
table: {
|
|
57
|
+
type: {
|
|
58
|
+
summary: string;
|
|
59
|
+
};
|
|
60
|
+
defaultValue: {
|
|
61
|
+
summary: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
54
64
|
};
|
|
55
65
|
name: {
|
|
56
66
|
control: "text";
|
|
57
67
|
description: string;
|
|
68
|
+
table: {
|
|
69
|
+
type: {
|
|
70
|
+
summary: string;
|
|
71
|
+
};
|
|
72
|
+
defaultValue: {
|
|
73
|
+
summary: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
58
76
|
};
|
|
59
77
|
value: {
|
|
60
78
|
control: "text";
|
|
61
79
|
description: string;
|
|
80
|
+
table: {
|
|
81
|
+
type: {
|
|
82
|
+
summary: string;
|
|
83
|
+
};
|
|
84
|
+
defaultValue: {
|
|
85
|
+
summary: string;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
62
88
|
};
|
|
63
89
|
onCheckedChange: {
|
|
64
90
|
action: string;
|
|
91
|
+
control: false;
|
|
65
92
|
description: string;
|
|
93
|
+
table: {
|
|
94
|
+
type: {
|
|
95
|
+
summary: string;
|
|
96
|
+
};
|
|
97
|
+
defaultValue: {
|
|
98
|
+
summary: string;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
66
101
|
};
|
|
67
102
|
};
|
|
68
103
|
};
|
|
69
104
|
export default meta;
|
|
70
105
|
type Story = StoryObj<typeof meta>;
|
|
71
|
-
/** The toggle in its default, unchecked (off) state. */
|
|
72
106
|
export declare const Default: Story;
|
|
73
|
-
/**
|
|
74
|
-
* The toggle in its checked (on) state.
|
|
75
|
-
*
|
|
76
|
-
* Uses `defaultChecked` so the component manages its own state — perfect for
|
|
77
|
-
* uncontrolled usage where you just need a sensible starting position.
|
|
78
|
-
*/
|
|
79
107
|
export declare const Checked: Story;
|
|
80
|
-
/**
|
|
81
|
-
* A disabled toggle that is currently off.
|
|
82
|
-
*
|
|
83
|
-
* Use this when a setting exists but cannot be changed in the current context
|
|
84
|
-
* — for example, a feature that requires a higher subscription tier.
|
|
85
|
-
*/
|
|
86
108
|
export declare const Disabled: Story;
|
|
87
|
-
/**
|
|
88
|
-
* A disabled toggle that is currently on.
|
|
89
|
-
*
|
|
90
|
-
* This communicates "this setting is enabled, but you cannot change it right
|
|
91
|
-
* now." Always pair a disabled toggle with a tooltip or helper text that
|
|
92
|
-
* explains why it cannot be interacted with.
|
|
93
|
-
*/
|
|
94
109
|
export declare const DisabledChecked: Story;
|
|
95
110
|
export declare const Controlled: Story;
|
|
96
111
|
export declare const WithLabel: Story;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toggle.stories.d.ts","sourceRoot":"","sources":["../../../src/components/toggle/Toggle.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"Toggle.stories.d.ts","sourceRoot":"","sources":["../../../src/components/toggle/Toggle.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AA4F5D,iBAAS,cAAc,4CAmBtB;AAMD,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8FqB,CAAC;AAEhC,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AA8FnC,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,KAuBrB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,KAuBtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAwB7B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,KAsCxB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KA0CvB,CAAC"}
|
|
@@ -1,38 +1,94 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { fn } from 'storybook/test';
|
|
4
|
+
import { Controls, Heading as DocHeading, Markdown, Primary as DocPrimary, Stories, Subtitle, Title, } from '@storybook/addon-docs/blocks';
|
|
4
5
|
import { Toggle } from './Toggle';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Docs page content
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
const DESCRIPTION_INTRO = [
|
|
10
|
+
'Toggle is an immediate binary on/off switch built on',
|
|
11
|
+
'[Radix UI Switch](https://www.radix-ui.com/primitives/docs/components/switch).',
|
|
12
|
+
'It communicates that a change takes effect instantly — without a form submission — making it the right',
|
|
13
|
+
'choice for settings toggles, feature flags, and preference switches.',
|
|
14
|
+
].join(' ');
|
|
15
|
+
const USAGE_GUIDANCE = [
|
|
16
|
+
'### When to use',
|
|
17
|
+
'',
|
|
18
|
+
'- **Immediate settings** — when flipping a switch takes effect right now (dark mode, notifications, feature enabled)',
|
|
19
|
+
'- **Binary state** — exactly two options: on and off, enabled and disabled',
|
|
20
|
+
'- **Standalone settings pages** — outside a form, where pressing Submit before seeing the effect would be jarring',
|
|
21
|
+
'',
|
|
22
|
+
'---',
|
|
23
|
+
'',
|
|
24
|
+
'### When NOT to use',
|
|
25
|
+
'',
|
|
26
|
+
'| Situation | Use instead |',
|
|
27
|
+
'|---|---|',
|
|
28
|
+
'| Choice requires confirmation before taking effect | [`CheckboxInput`](?path=/docs/components-formfield-inputs-checkbox--docs) inside a form |',
|
|
29
|
+
'| Multiple related on/off items in a list | `CheckboxInput` group — clearer visual grouping |',
|
|
30
|
+
'| Part of a multi-field form submission | `CheckboxInput` — toggle implies instant action, not deferred submission |',
|
|
31
|
+
].join('\n');
|
|
32
|
+
const DEVELOPER_NOTES = [
|
|
33
|
+
'### Critical usage patterns',
|
|
34
|
+
'',
|
|
35
|
+
'**Always provide a visible label.** Toggle renders as a styled button with no visible text. Without a',
|
|
36
|
+
'`<label htmlFor={id}>`, sighted users see a switch with no explanation of what it controls. Screen',
|
|
37
|
+
'readers announce the state ("checked" / "not checked") but cannot convey the meaning without a label.',
|
|
38
|
+
'',
|
|
39
|
+
'**`checked` vs `defaultChecked`.** Use `defaultChecked` for uncontrolled usage where the component',
|
|
40
|
+
'manages its own state after mount. Use `checked` + `onCheckedChange` for controlled mode when you need',
|
|
41
|
+
'to read the value elsewhere in the UI or sync with external state.',
|
|
42
|
+
'',
|
|
43
|
+
'**`onCheckedChange` receives a boolean — not an event.** Unlike native checkbox `onChange`, this',
|
|
44
|
+
'callback receives the new boolean value directly: `(checked: boolean) => void`. No `event.target.checked`',
|
|
45
|
+
'unwrapping needed.',
|
|
46
|
+
'',
|
|
47
|
+
'---',
|
|
48
|
+
'',
|
|
49
|
+
'### Accessibility',
|
|
50
|
+
'',
|
|
51
|
+
'- Rendered as `<button role="switch">` — screen readers announce "checked" / "not checked" automatically',
|
|
52
|
+
'- Fully keyboard accessible: `Space` or `Enter` toggles the state',
|
|
53
|
+
'- Associate with `<label htmlFor={id}>` — clicking the label also toggles the switch (larger tap target)',
|
|
54
|
+
'- The `disabled` prop renders the element as truly non-interactive with correct ARIA semantics',
|
|
55
|
+
'',
|
|
56
|
+
'---',
|
|
57
|
+
'',
|
|
58
|
+
'### Design tokens used',
|
|
59
|
+
'',
|
|
60
|
+
'| Token | Usage |',
|
|
61
|
+
'|---|---|',
|
|
62
|
+
'| `--toggle-off-default-color-background` | Track background (unchecked) |',
|
|
63
|
+
'| `--toggle-on-default-color-background` | Track background (checked — brand colour) |',
|
|
64
|
+
'| `--toggle-off-disabled-color-background` | Track background (disabled) |',
|
|
65
|
+
'| `--toggle-radius` | Track border radius |',
|
|
66
|
+
'| `--toggle-weight-border` | Track border weight |',
|
|
67
|
+
'| `--border-radius-round` | Thumb shape (circular) |',
|
|
68
|
+
].join('\n');
|
|
69
|
+
const RELATED_COMPONENTS = [
|
|
70
|
+
'## Related components',
|
|
71
|
+
'',
|
|
72
|
+
'[CheckboxInput](?path=/docs/components-formfield-inputs-checkbox--docs) · [FormField](?path=/docs/components-formfield--docs) · [RadioButtonInput](?path=/docs/components-formfield-inputs-radio--docs)',
|
|
73
|
+
].join('\n');
|
|
74
|
+
const PROPS_INTRO = 'The preview below is wired to the **Controls** panel — tweak any prop to see the story update in real time.';
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Docs page
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
function ToggleDocsPage() {
|
|
79
|
+
return (_jsxs(_Fragment, { children: [_jsx(Title, {}), _jsx(Subtitle, {}), _jsx(Markdown, { children: DESCRIPTION_INTRO }), _jsx(DocHeading, { children: "Interactive example" }), _jsx(Markdown, { children: PROPS_INTRO }), _jsx(DocPrimary, {}), _jsx(Controls, {}), _jsx(DocHeading, { children: "Usage guidance" }), _jsx(Markdown, { children: USAGE_GUIDANCE }), _jsx(DocHeading, { children: "Developer notes" }), _jsx(Markdown, { children: DEVELOPER_NOTES }), _jsx(DocHeading, { children: "Examples" }), _jsx(Stories, { title: "" }), _jsx(Markdown, { children: RELATED_COMPONENTS })] }));
|
|
80
|
+
}
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
// Meta
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
31
84
|
const meta = {
|
|
32
85
|
title: 'Components/Toggle',
|
|
33
86
|
component: Toggle,
|
|
34
87
|
parameters: {
|
|
35
88
|
layout: 'centered',
|
|
89
|
+
docs: {
|
|
90
|
+
page: ToggleDocsPage,
|
|
91
|
+
},
|
|
36
92
|
},
|
|
37
93
|
tags: ['autodocs'],
|
|
38
94
|
args: {
|
|
@@ -41,146 +97,279 @@ const meta = {
|
|
|
41
97
|
argTypes: {
|
|
42
98
|
checked: {
|
|
43
99
|
control: 'boolean',
|
|
44
|
-
description:
|
|
45
|
-
|
|
100
|
+
description: [
|
|
101
|
+
'Controls the checked state when used as a controlled component.',
|
|
102
|
+
'Pair with `onCheckedChange` to keep your state in sync.',
|
|
103
|
+
].join(' '),
|
|
104
|
+
table: {
|
|
105
|
+
type: { summary: 'boolean' },
|
|
106
|
+
defaultValue: { summary: 'undefined' },
|
|
107
|
+
},
|
|
46
108
|
},
|
|
47
109
|
defaultChecked: {
|
|
48
110
|
control: 'boolean',
|
|
49
|
-
description:
|
|
50
|
-
|
|
111
|
+
description: [
|
|
112
|
+
'Sets the initial checked state for an uncontrolled toggle.',
|
|
113
|
+
'The component manages its own state after mount.',
|
|
114
|
+
].join(' '),
|
|
115
|
+
table: {
|
|
116
|
+
type: { summary: 'boolean' },
|
|
117
|
+
defaultValue: { summary: 'undefined' },
|
|
118
|
+
},
|
|
51
119
|
},
|
|
52
120
|
disabled: {
|
|
53
121
|
control: 'boolean',
|
|
54
|
-
description:
|
|
55
|
-
|
|
122
|
+
description: [
|
|
123
|
+
'Disables the toggle. The toggle becomes non-interactive and is visually dimmed.',
|
|
124
|
+
'Useful for read-only settings or permission-gated features.',
|
|
125
|
+
].join(' '),
|
|
126
|
+
table: {
|
|
127
|
+
type: { summary: 'boolean' },
|
|
128
|
+
defaultValue: { summary: 'undefined' },
|
|
129
|
+
},
|
|
56
130
|
},
|
|
57
131
|
required: {
|
|
58
132
|
control: 'boolean',
|
|
59
|
-
description:
|
|
60
|
-
|
|
133
|
+
description: [
|
|
134
|
+
'Marks the toggle as required when used inside a `<form>`.',
|
|
135
|
+
'Prevents form submission if the toggle is unchecked.',
|
|
136
|
+
].join(' '),
|
|
137
|
+
table: {
|
|
138
|
+
type: { summary: 'boolean' },
|
|
139
|
+
defaultValue: { summary: 'undefined' },
|
|
140
|
+
},
|
|
61
141
|
},
|
|
62
142
|
name: {
|
|
63
143
|
control: 'text',
|
|
64
|
-
description:
|
|
65
|
-
|
|
144
|
+
description: [
|
|
145
|
+
'The name of the toggle as submitted with form data.',
|
|
146
|
+
'Works the same as the `name` attribute on a native `<input>`.',
|
|
147
|
+
].join(' '),
|
|
148
|
+
table: {
|
|
149
|
+
type: { summary: 'string' },
|
|
150
|
+
defaultValue: { summary: 'undefined' },
|
|
151
|
+
},
|
|
66
152
|
},
|
|
67
153
|
value: {
|
|
68
154
|
control: 'text',
|
|
69
|
-
description:
|
|
70
|
-
|
|
155
|
+
description: [
|
|
156
|
+
'The value submitted with form data when the toggle is checked.',
|
|
157
|
+
'Defaults to `"on"` (matching native checkbox behaviour).',
|
|
158
|
+
].join(' '),
|
|
159
|
+
table: {
|
|
160
|
+
type: { summary: 'string' },
|
|
161
|
+
defaultValue: { summary: '"on"' },
|
|
162
|
+
},
|
|
71
163
|
},
|
|
72
164
|
onCheckedChange: {
|
|
73
165
|
action: 'checkedChange',
|
|
74
|
-
|
|
75
|
-
|
|
166
|
+
control: false,
|
|
167
|
+
description: [
|
|
168
|
+
'Callback fired whenever the checked state changes.',
|
|
169
|
+
'Receives the new boolean value directly: `(checked: boolean) => void`.',
|
|
170
|
+
'Unlike native checkbox `onChange`, there is no event object to unwrap.',
|
|
171
|
+
].join(' '),
|
|
172
|
+
table: {
|
|
173
|
+
type: { summary: '(checked: boolean) => void' },
|
|
174
|
+
defaultValue: { summary: 'undefined' },
|
|
175
|
+
},
|
|
76
176
|
},
|
|
77
177
|
},
|
|
78
178
|
};
|
|
79
179
|
export default meta;
|
|
80
180
|
// ---------------------------------------------------------------------------
|
|
81
|
-
//
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
/** The toggle in its default, unchecked (off) state. */
|
|
84
|
-
export const Default = {};
|
|
85
|
-
/**
|
|
86
|
-
* The toggle in its checked (on) state.
|
|
87
|
-
*
|
|
88
|
-
* Uses `defaultChecked` so the component manages its own state — perfect for
|
|
89
|
-
* uncontrolled usage where you just need a sensible starting position.
|
|
90
|
-
*/
|
|
91
|
-
export const Checked = {
|
|
92
|
-
args: {
|
|
93
|
-
defaultChecked: true,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
181
|
+
// Helper
|
|
96
182
|
// ---------------------------------------------------------------------------
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
disabled: true,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* A disabled toggle that is currently on.
|
|
112
|
-
*
|
|
113
|
-
* This communicates "this setting is enabled, but you cannot change it right
|
|
114
|
-
* now." Always pair a disabled toggle with a tooltip or helper text that
|
|
115
|
-
* explains why it cannot be interacted with.
|
|
116
|
-
*/
|
|
117
|
-
export const DisabledChecked = {
|
|
118
|
-
args: {
|
|
119
|
-
defaultChecked: true,
|
|
120
|
-
disabled: true,
|
|
183
|
+
const withDescription = (story, description) => ({
|
|
184
|
+
...story,
|
|
185
|
+
parameters: {
|
|
186
|
+
...story.parameters,
|
|
187
|
+
docs: {
|
|
188
|
+
...story.parameters?.docs,
|
|
189
|
+
description: {
|
|
190
|
+
story: description,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
121
193
|
},
|
|
122
|
-
};
|
|
194
|
+
});
|
|
123
195
|
// ---------------------------------------------------------------------------
|
|
124
|
-
//
|
|
196
|
+
// Templates
|
|
125
197
|
// ---------------------------------------------------------------------------
|
|
126
|
-
/**
|
|
127
|
-
* A fully controlled toggle backed by React state.
|
|
128
|
-
*
|
|
129
|
-
* Back in St. Olaf, my neighbour Hildegard Bjornsson kept a hand-written
|
|
130
|
-
* ledger of every switch in her house — she never trusted a switch to remember
|
|
131
|
-
* its own state! A controlled toggle is just like that ledger: your component
|
|
132
|
-
* owns the truth, and the toggle simply displays what you tell it to.
|
|
133
|
-
*
|
|
134
|
-
* Use the controlled pattern when:
|
|
135
|
-
* - You need to read the toggle state elsewhere in the UI.
|
|
136
|
-
* - You want to conditionally show/hide other elements based on the state.
|
|
137
|
-
* - You are submitting state as part of a larger form payload.
|
|
138
|
-
*/
|
|
139
198
|
const ControlledTemplate = (args) => {
|
|
140
199
|
const [enabled, setEnabled] = useState(false);
|
|
141
200
|
return (_jsxs("div", { style: {
|
|
142
201
|
display: 'flex',
|
|
143
202
|
flexDirection: 'column',
|
|
144
203
|
alignItems: 'center',
|
|
145
|
-
gap: '
|
|
204
|
+
gap: 'var(--spacing-small)',
|
|
146
205
|
}, children: [_jsx(Toggle, { ...args, checked: enabled, onCheckedChange: (checked) => {
|
|
147
206
|
setEnabled(checked);
|
|
148
207
|
args.onCheckedChange?.(checked);
|
|
149
208
|
} }), _jsx("p", { style: {
|
|
150
209
|
margin: 0,
|
|
151
|
-
fontSize: '
|
|
210
|
+
fontSize: 'var(--font-size-2-13)',
|
|
152
211
|
color: enabled ? 'var(--color-brand-700)' : 'var(--color-grey-500)',
|
|
153
212
|
}, children: enabled ? 'Feature enabled' : 'Feature disabled' })] }));
|
|
154
213
|
};
|
|
155
|
-
export const Controlled = {
|
|
156
|
-
render: ControlledTemplate,
|
|
157
|
-
};
|
|
158
|
-
// ---------------------------------------------------------------------------
|
|
159
|
-
// With label (accessible usage)
|
|
160
|
-
// ---------------------------------------------------------------------------
|
|
161
|
-
/**
|
|
162
|
-
* A toggle paired with a visible `<label>` element for full accessibility.
|
|
163
|
-
*
|
|
164
|
-
* This is the pattern you should reach for in almost every real-world use
|
|
165
|
-
* case. By wiring the label's `htmlFor` to the toggle's `id`, you get:
|
|
166
|
-
*
|
|
167
|
-
* - Screen readers announce both the label text and the toggle state.
|
|
168
|
-
* - Clicking the label text also toggles the switch (larger click target).
|
|
169
|
-
* - Visual users see a clear description of what the toggle controls.
|
|
170
|
-
*
|
|
171
|
-
* You know, this is a lot like what we learned in St. Olaf Home Economics
|
|
172
|
-
* class — always label your preserves. An unlabelled jar of lingonberry jam
|
|
173
|
-
* looks just like an unlabelled jar of beet relish, and nobody wants that
|
|
174
|
-
* confusion at the dinner table. Or on a settings page!
|
|
175
|
-
*/
|
|
176
214
|
const WithLabelTemplate = (args) => {
|
|
177
215
|
const [enabled, setEnabled] = useState(false);
|
|
178
|
-
return (_jsxs("div", { style: {
|
|
216
|
+
return (_jsxs("div", { style: {
|
|
217
|
+
display: 'flex',
|
|
218
|
+
alignItems: 'center',
|
|
219
|
+
gap: 'var(--spacing-xsmall)',
|
|
220
|
+
}, children: [_jsx(Toggle, { ...args, id: "email-notifications-toggle", checked: enabled, onCheckedChange: (checked) => {
|
|
179
221
|
setEnabled(checked);
|
|
180
222
|
args.onCheckedChange?.(checked);
|
|
181
|
-
} }), _jsx("label", { htmlFor: "email-notifications-toggle", style: {
|
|
223
|
+
} }), _jsx("label", { htmlFor: "email-notifications-toggle", style: {
|
|
224
|
+
fontSize: 'var(--font-size-2-13)',
|
|
225
|
+
cursor: 'pointer',
|
|
226
|
+
userSelect: 'none',
|
|
227
|
+
}, children: "Email notifications" })] }));
|
|
182
228
|
};
|
|
183
|
-
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
// Stories
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
export const Default = withDescription({
|
|
233
|
+
render: args => _jsx(Toggle, { ...args }),
|
|
234
|
+
}, 'The toggle in its default, unchecked (off) state. Use the Controls panel to flip `checked`, `defaultChecked`, `disabled`, and other props.');
|
|
235
|
+
export const Checked = withDescription({
|
|
236
|
+
args: {
|
|
237
|
+
defaultChecked: true,
|
|
238
|
+
},
|
|
239
|
+
parameters: {
|
|
240
|
+
controls: { disable: true },
|
|
241
|
+
docs: {
|
|
242
|
+
source: {
|
|
243
|
+
language: 'tsx',
|
|
244
|
+
code: `
|
|
245
|
+
import { Toggle } from '@arbor-education/design-system.components';
|
|
246
|
+
|
|
247
|
+
function EnabledByDefaultToggle() {
|
|
248
|
+
return <Toggle defaultChecked />;
|
|
249
|
+
}
|
|
250
|
+
export default EnabledByDefaultToggle;
|
|
251
|
+
`.trim(),
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
}, 'The toggle in its checked (on) state. Uses `defaultChecked` for uncontrolled usage — the component manages its own state after mount.');
|
|
256
|
+
export const Disabled = withDescription({
|
|
257
|
+
args: {
|
|
258
|
+
disabled: true,
|
|
259
|
+
},
|
|
260
|
+
parameters: {
|
|
261
|
+
controls: { disable: true },
|
|
262
|
+
docs: {
|
|
263
|
+
source: {
|
|
264
|
+
language: 'tsx',
|
|
265
|
+
code: `
|
|
266
|
+
import { Toggle } from '@arbor-education/design-system.components';
|
|
267
|
+
|
|
268
|
+
function DisabledToggle() {
|
|
269
|
+
return <Toggle disabled />;
|
|
270
|
+
}
|
|
271
|
+
export default DisabledToggle;
|
|
272
|
+
`.trim(),
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
}, 'A disabled toggle in the off state. Use when a setting exists but cannot currently be changed — for example, a feature that requires a higher subscription tier.');
|
|
277
|
+
export const DisabledChecked = withDescription({
|
|
278
|
+
args: {
|
|
279
|
+
defaultChecked: true,
|
|
280
|
+
disabled: true,
|
|
281
|
+
},
|
|
282
|
+
parameters: {
|
|
283
|
+
controls: { disable: true },
|
|
284
|
+
docs: {
|
|
285
|
+
source: {
|
|
286
|
+
language: 'tsx',
|
|
287
|
+
code: `
|
|
288
|
+
import { Toggle } from '@arbor-education/design-system.components';
|
|
289
|
+
|
|
290
|
+
function DisabledCheckedToggle() {
|
|
291
|
+
return <Toggle defaultChecked disabled />;
|
|
292
|
+
}
|
|
293
|
+
export default DisabledCheckedToggle;
|
|
294
|
+
`.trim(),
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
}, 'A disabled toggle in the on state. This communicates "this setting is enabled, but you cannot change it right now." Always pair a disabled toggle with a tooltip or helper text explaining why it is locked.');
|
|
299
|
+
export const Controlled = withDescription({
|
|
300
|
+
render: ControlledTemplate,
|
|
301
|
+
parameters: {
|
|
302
|
+
controls: { disable: true },
|
|
303
|
+
docs: {
|
|
304
|
+
source: {
|
|
305
|
+
language: 'tsx',
|
|
306
|
+
code: `
|
|
307
|
+
import { useState } from 'react';
|
|
308
|
+
import { Toggle } from '@arbor-education/design-system.components';
|
|
309
|
+
|
|
310
|
+
function ControlledToggle() {
|
|
311
|
+
const [enabled, setEnabled] = useState(false);
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 'var(--spacing-small)' }}>
|
|
315
|
+
<Toggle
|
|
316
|
+
checked={enabled}
|
|
317
|
+
onCheckedChange={setEnabled}
|
|
318
|
+
/>
|
|
319
|
+
<p style={{ margin: 0 }}>
|
|
320
|
+
{enabled ? 'Feature enabled' : 'Feature disabled'}
|
|
321
|
+
</p>
|
|
322
|
+
</div>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
export default ControlledToggle;
|
|
326
|
+
`.trim(),
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
}, [
|
|
331
|
+
'A fully controlled toggle backed by React state.',
|
|
332
|
+
'Use the controlled pattern when you need to read the toggle state elsewhere in the UI, conditionally',
|
|
333
|
+
'show or hide other elements, or include the state in a larger form payload.',
|
|
334
|
+
].join(' '));
|
|
335
|
+
export const WithLabel = withDescription({
|
|
184
336
|
render: WithLabelTemplate,
|
|
185
|
-
|
|
337
|
+
parameters: {
|
|
338
|
+
controls: { disable: true },
|
|
339
|
+
docs: {
|
|
340
|
+
source: {
|
|
341
|
+
language: 'tsx',
|
|
342
|
+
code: `
|
|
343
|
+
import { useState } from 'react';
|
|
344
|
+
import { Toggle } from '@arbor-education/design-system.components';
|
|
345
|
+
|
|
346
|
+
function ToggleWithLabel() {
|
|
347
|
+
const [enabled, setEnabled] = useState(false);
|
|
348
|
+
|
|
349
|
+
return (
|
|
350
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: 'var(--spacing-xsmall)' }}>
|
|
351
|
+
<Toggle
|
|
352
|
+
id="email-notifications-toggle"
|
|
353
|
+
checked={enabled}
|
|
354
|
+
onCheckedChange={setEnabled}
|
|
355
|
+
/>
|
|
356
|
+
<label
|
|
357
|
+
htmlFor="email-notifications-toggle"
|
|
358
|
+
style={{ cursor: 'pointer', userSelect: 'none' }}
|
|
359
|
+
>
|
|
360
|
+
Email notifications
|
|
361
|
+
</label>
|
|
362
|
+
</div>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
export default ToggleWithLabel;
|
|
366
|
+
`.trim(),
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
}, [
|
|
371
|
+
'A toggle paired with a visible `<label>` element for full accessibility.',
|
|
372
|
+
'Wiring `htmlFor` on the label to the toggle\'s `id` means screen readers announce both the label text and',
|
|
373
|
+
'the toggle state, and clicking the label also toggles the switch — giving a larger tap target for all users.',
|
|
374
|
+
].join(' '));
|
|
186
375
|
//# sourceMappingURL=Toggle.stories.js.map
|