From 68221bcab6bcd725b9b51afedcda1971db2c8f4c Mon Sep 17 00:00:00 2001 From: Bea Esguerra Date: Thu, 19 Dec 2024 14:49:39 -0700 Subject: [PATCH] Use LabeledField in other component stories (#2400) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: Use LabeledField in other component stories Issue: WB-1783 ## Test plan: Verify stories for the following components: - SingleSelect (`?path=/docs/packages-dropdown-singleselect--docs`) - MultiSelect (`?path=/docs/packages-dropdown-multiselect--docs`) - TextArea (`?path=/docs/packages-form-textarea--docs`) - TextArea Variants (`?path=/docs/packages-form-textarea-all-variants--docs`) - TextField (`?path=/docs/packages-form-textfield--docs`) - TextField Variants (`?path=/docs/packages-form-textfield-all-variants--docs`) - SearchField (`?path=/docs/packages-searchfield--docs`) - SearchField Variants (`?path=/docs/packages-searchfield-all-variants--docs`) Note: This addresses Storybook a11y issues related to form fields and labels. There are some stories that focus on the form field without the label so those warnings will need to be handled separately! Author: beaesguerra Reviewers: jandrade, beaesguerra Required Reviewers: Approved By: jandrade Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Lint / Lint (ubuntu-latest, 20.x), ✅ Test / Test (ubuntu-latest, 20.x, 2/2), ✅ Test / Test (ubuntu-latest, 20.x, 1/2), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Chromatic - Build on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ⏭️ Chromatic - Skip on Release PR (changesets), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ⏭️ dependabot Pull Request URL: https://github.com/Khan/wonder-blocks/pull/2400 --- .../multi-select.stories.tsx | 117 ++-- .../single-select.stories.tsx | 135 ++--- .../text-area-variants.stories.tsx | 23 +- .../wonder-blocks-form/text-area.stories.tsx | 195 ++++--- .../text-field-variants.stories.tsx | 23 +- .../wonder-blocks-form/text-field.stories.tsx | 505 +++++------------- .../search-field-variants.stories.tsx | 23 +- .../search-field.stories.tsx | 64 ++- 8 files changed, 433 insertions(+), 652 deletions(-) diff --git a/__docs__/wonder-blocks-dropdown/multi-select.stories.tsx b/__docs__/wonder-blocks-dropdown/multi-select.stories.tsx index db9426d7d..fcc46c63e 100644 --- a/__docs__/wonder-blocks-dropdown/multi-select.stories.tsx +++ b/__docs__/wonder-blocks-dropdown/multi-select.stories.tsx @@ -8,8 +8,8 @@ import {PropsFor, View} from "@khanacademy/wonder-blocks-core"; import Button from "@khanacademy/wonder-blocks-button"; import {Checkbox} from "@khanacademy/wonder-blocks-form"; import {OnePaneDialog, ModalLauncher} from "@khanacademy/wonder-blocks-modal"; -import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens"; -import {HeadingLarge, LabelMedium} from "@khanacademy/wonder-blocks-typography"; +import {color, spacing} from "@khanacademy/wonder-blocks-tokens"; +import {HeadingLarge} from "@khanacademy/wonder-blocks-typography"; import {MultiSelect, OptionItem} from "@khanacademy/wonder-blocks-dropdown"; import Pill from "@khanacademy/wonder-blocks-pill"; import type {Labels} from "@khanacademy/wonder-blocks-dropdown"; @@ -25,7 +25,7 @@ import { chatIcon, } from "./option-item-examples"; import {OpenerProps} from "../../packages/wonder-blocks-dropdown/src/util/types"; -import Strut from "../../packages/wonder-blocks-layout/src/components/strut"; +import {LabeledField} from "@khanacademy/wonder-blocks-labeled-field"; type StoryComponentType = StoryObj; @@ -271,7 +271,10 @@ export const CustomStylesOpened: StoryComponentType = { ], }; -const ControlledMultiSelect = (args: PropsFor) => { +const ControlledMultiSelect = ( + storyArgs: PropsFor & {label?: string}, +) => { + const {label, ...args} = storyArgs; const [opened, setOpened] = React.useState(false); const [selectedValues, setSelectedValues] = React.useState( args.selectedValues || [], @@ -280,31 +283,29 @@ const ControlledMultiSelect = (args: PropsFor) => { null | string | void >(null); return ( - - { - if (values.includes("jupiter")) { - return "Don't pick jupiter!"; - } - }} - onValidate={setErrorMessage} - > - {items} - - {(errorMessage || args.error) && ( - { + if (values.includes("jupiter")) { + return "Don't pick jupiter!"; + } + }} + onValidate={setErrorMessage} > - {errorMessage || "Error from error prop"} - - )} - + {items} + + } + /> ); }; @@ -378,20 +379,17 @@ export const Required: StoryComponentType = { export const ErrorFromValidation: StoryComponentType = { render: (args: PropsFor) => { return ( - - - Validation example (try picking jupiter) - - + + {items} - - Validation example (on mount) - {items} @@ -494,27 +492,30 @@ export const DropdownInModal: StoryComponentType = { */ export const Disabled: StoryComponentType = { render: () => ( - - - Disabled prop is set to true - - {}}> - - - - - - No items - - {}} /> - - - All items are disabled - - {}}> - - - + + {}}> + + + + } + /> + {}} />} + /> + + {}}> + + + + } + /> ), }; diff --git a/__docs__/wonder-blocks-dropdown/single-select.stories.tsx b/__docs__/wonder-blocks-dropdown/single-select.stories.tsx index 99760b932..77a74acba 100644 --- a/__docs__/wonder-blocks-dropdown/single-select.stories.tsx +++ b/__docs__/wonder-blocks-dropdown/single-select.stories.tsx @@ -7,19 +7,14 @@ import {action} from "@storybook/addon-actions"; import type {Meta, StoryObj} from "@storybook/react"; import Button from "@khanacademy/wonder-blocks-button"; -import {color, semanticColor, spacing} from "@khanacademy/wonder-blocks-tokens"; +import {color, spacing} from "@khanacademy/wonder-blocks-tokens"; import {PropsFor, View} from "@khanacademy/wonder-blocks-core"; import {TextField} from "@khanacademy/wonder-blocks-form"; import {PhosphorIcon} from "@khanacademy/wonder-blocks-icon"; import {Strut} from "@khanacademy/wonder-blocks-layout"; import {OnePaneDialog, ModalLauncher} from "@khanacademy/wonder-blocks-modal"; import Pill from "@khanacademy/wonder-blocks-pill"; -import { - Body, - HeadingLarge, - LabelMedium, - LabelSmall, -} from "@khanacademy/wonder-blocks-typography"; +import {Body, HeadingLarge} from "@khanacademy/wonder-blocks-typography"; import { SingleSelect, OptionItem, @@ -39,6 +34,7 @@ import { currencies, } from "./option-item-examples"; import {OpenerProps} from "../../packages/wonder-blocks-dropdown/src/util/types"; +import {LabeledField} from "@khanacademy/wonder-blocks-labeled-field"; type StoryComponentType = StoryObj; type SingleSelectArgs = Partial; @@ -353,36 +349,49 @@ export const LongOptionLabels: StoryComponentType = { */ export const Disabled: StoryComponentType = { render: () => ( - - - Disabled prop is set to true - - {}} - selectedValue="" - disabled={true} - > - {items} - - - - No items - - {}} /> - - - All items are disabled - - {}}> - - - + + {}} + selectedValue="" + disabled={true} + > + {items} + + } + /> + {}} + /> + } + /> + {}} + > + + + + } + /> ), }; -const ControlledSingleSelect = (args: PropsFor) => { +const ControlledSingleSelect = ( + storyArgs: PropsFor & {label?: string}, +) => { + const {label, ...args} = storyArgs; const [opened, setOpened] = React.useState(false); const [selectedValue, setSelectedValue] = React.useState( args.selectedValue, @@ -391,32 +400,30 @@ const ControlledSingleSelect = (args: PropsFor) => { null | string | void >(null); return ( - - { - if (value === "lemon") { - return "Pick another option!"; - } - }} - onValidate={setErrorMessage} - > - {items} - - {(errorMessage || args.error) && ( - { + if (value === "lemon") { + return "Pick another option!"; + } + }} + onValidate={setErrorMessage} > - {errorMessage || "Error from error prop"} - - )} - + {items} + + } + /> ); }; @@ -490,13 +497,10 @@ export const Required: StoryComponentType = { export const ErrorFromValidation: StoryComponentType = { render: (args: PropsFor) => { return ( - - - Validation example (try picking lemon to trigger an error) - + { if (value === "lemon") { return "Pick another option!"; @@ -505,12 +509,9 @@ export const ErrorFromValidation: StoryComponentType = { > {items} - - Validation example (on mount) - { if (value === "lemon") { return "Pick another option!"; diff --git a/__docs__/wonder-blocks-form/text-area-variants.stories.tsx b/__docs__/wonder-blocks-form/text-area-variants.stories.tsx index 93b95967b..9ea9b2db6 100644 --- a/__docs__/wonder-blocks-form/text-area-variants.stories.tsx +++ b/__docs__/wonder-blocks-form/text-area-variants.stories.tsx @@ -4,8 +4,9 @@ import type {Meta, StoryObj} from "@storybook/react"; import {View} from "@khanacademy/wonder-blocks-core"; import {color, spacing} from "@khanacademy/wonder-blocks-tokens"; -import {LabelLarge, LabelMedium} from "@khanacademy/wonder-blocks-typography"; +import {LabelLarge} from "@khanacademy/wonder-blocks-typography"; import {TextArea} from "@khanacademy/wonder-blocks-form"; +import {LabeledField} from "@khanacademy/wonder-blocks-labeled-field"; /** * The following stories are used to generate the pseudo states for the @@ -58,16 +59,16 @@ const States = (props: { {states.map((scenario) => { return ( - - {scenario.label} - -