From b0342289b729506db88e55f16f93e89fc3bd9840 Mon Sep 17 00:00:00 2001 From: Josh Winn <965114+jawinn@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:15:05 -0400 Subject: [PATCH] docs(picker): migrate docs to storybook Migrates docs site information to Storybook for the Picker component. Creates several docs-only stories to represent the missing examples. Adds a control for value (currentValue), and separates the concept of value and placeholder, which are different things with different classes. Adds a control for displaying the thumbnail variant (with a workflow icon) from the docs site. This icon has a class associated with it that was not previously represented in Storybook. Renames "content" to "popoverContent" and refactors some of the iconName code in the Picker template for clarity. Updates the variants test.js data to add coverage for missing states and variants. --- components/picker/CHANGELOG.md | 54 +++- components/picker/stories/picker.stories.js | 302 +++++++++++++++++++- components/picker/stories/picker.test.js | 81 +++++- components/picker/stories/template.js | 145 +++++++--- components/tabs/stories/template.js | 2 +- 5 files changed, 520 insertions(+), 64 deletions(-) diff --git a/components/picker/CHANGELOG.md b/components/picker/CHANGELOG.md index 52c9d82f9bd..eb124fdaf9c 100644 --- a/components/picker/CHANGELOG.md +++ b/components/picker/CHANGELOG.md @@ -383,11 +383,11 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline \*refactor(picker)!: remove focus-ring([e37b430](https://github.com/adobe/spectrum-css/commit/e37b430)) - ### - 🛑 BREAKING CHANGES +### 🛑 BREAKING CHANGES - * - Remove focus-ring pseudo class in favor of focus-visible +#### Remove `focus-ring` class + +We've migrated away from the `focus-ring` class in favor of the native `:focus-visible` pseudo-class due to changes in browser support. @@ -1379,6 +1379,52 @@ Co-authored-by: castastrophe - correct icononly Picker width ([b165e11](https://github.com/adobe/spectrum-css/commit/b165e11)) - updated icon sizes for picker examples ([ad054f6](https://github.com/adobe/spectrum-css/commit/ad054f6)) +### Migration guide + +#### Component renamed + +Dropdown is now known as Picker. Replace all `.spectrum-Dropdown*` classnames with `.spectrum-Picker*`. + +#### Markup change + +The outer `
` is now gone and `.spectrum-FieldButton` is no longer used. Instead, the outer tag is now ` `; }; +/** + * Picker template including adjacent popover and help text. + */ export const Template = ({ rootClass = "spectrum-Picker", size = "m", label, labelPosition = "top", - placeholder, - helpText, + placeholder = "", + currentValue = "", + helpText = "", isQuiet = false, isKeyboardFocused = false, + showWorkflowIcon = false, isOpen = false, isInvalid = false, isLoading = false, isDisabled = false, isReadOnly = false, + isHovered = false, + isActive = false, withSwitch = false, fieldLabelStyle = {}, customClasses = [], customStyles = {}, - content = [], + popoverContent = [], id = getRandomId("picker"), } = {}, context = {}) => { const { updateArgs } = context; - let iconName = "ChevronDown200"; - switch (size) { - case "s": - iconName = "ChevronDown75"; - break; - case "m": - iconName = "ChevronDown100"; - break; - case "xl": - iconName = "ChevronDown300"; - break; - default: - iconName = "ChevronDown200"; - } - return html` ${when(label, () => FieldLabel({ @@ -117,7 +136,7 @@ export const Template = ({ label, isDisabled, customStyles: fieldLabelStyle, - alignment: labelPosition, + alignment: labelPosition === "side" ? "left" : undefined, }, context) )} ${Popover({ @@ -129,27 +148,26 @@ export const Template = ({ rootClass, size, placeholder, + currentValue, isQuiet, + showWorkflowIcon, isKeyboardFocused, isOpen, isInvalid, isLoading, isDisabled, isReadOnly, + isHovered, + isActive, customClasses, - customStyles: { - "display": labelPosition == "left" ? "inline-block" : undefined, - ...customStyles, - }, - content, - iconName, + customStyles, labelPosition, id, onclick: function() { updateArgs({ isOpen: !isOpen }); }, }, context), - content, + content: popoverContent, }, context)} ${when(helpText, () => HelpText({ @@ -158,12 +176,65 @@ export const Template = ({ hideIcon: true, }, context) )} - ${when(withSwitch, () => Switch({ - size, - label: "Toggle switch", - customStyles: { - "padding-inline-start": "15px" - } - }, context))} + ${when(withSwitch, () => + Switch({ + size, + label: "Toggle switch", + customStyles: { + "padding-inline-start": "15px" + } + }, context) + )} `; }; + +/** + * Template showing both closed and open versions of the Picker. + */ +export const ClosedAndOpenTemplate = (args, context) => Container({ + withBorder: false, + content: html`${[false, true].map((isOpen) => + Container({ + withBorder: false, + direction: "column", + heading: isOpen ? "Open" : "Closed", + containerStyles: { + rowGap: "8px", + }, + // Make sure container flex layout does not misalign sibling elements such as field label in Template() + wrapperStyles: { + display: "block", + }, + content: Template({ + ...args, + isOpen, + }, context), + }) + )}`, +}); + +/** + * Template for the Disabled docs story. + */ +export const DisabledTemplate = (args, context) => Container({ + withBorder: false, + content: html`${[false, true].map((isInvalid) => + Container({ + withBorder: false, + direction: "column", + heading: isInvalid ? "Invalid" : "Default", + containerStyles: { + rowGap: "8px", + overflow: "hidden", + }, + // Make sure container flex layout does not misalign sibling elements such as field label in Template() + wrapperStyles: { + display: "block", + }, + content: Template({ + ...args, + isInvalid, + }, context), + }) + )}`, +}); \ No newline at end of file diff --git a/components/tabs/stories/template.js b/components/tabs/stories/template.js index 17c6a3e2585..2e5c4ee6d45 100644 --- a/components/tabs/stories/template.js +++ b/components/tabs/stories/template.js @@ -124,7 +124,7 @@ export const Template = ({ customPopoverStyles: { insetBlockStart: "24px", }, - content: [ + popoverContent: [ () => Menu({ selectionMode: "none", size,