From 84d194016360729ace10bb5c72a85d8ae49046ec Mon Sep 17 00:00:00 2001 From: Josh Winn <965114+jawinn@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:08:04 -0400 Subject: [PATCH] docs(button): custom mdx docs page Create an MDX "Docs" page that works as a replacement for the YML docs pages, and covers the important Button options from there and the guidelines. Adds the tag "is-hidden-story" for excluding Storybook sidebar items. --- .storybook/main.js | 1 + .storybook/manager.js | 2 +- components/button/stories/button.mdx | 103 +++++ components/button/stories/button.stories.js | 469 +++++++++++++------- 4 files changed, 419 insertions(+), 156 deletions(-) create mode 100644 components/button/stories/button.mdx diff --git a/.storybook/main.js b/.storybook/main.js index 8a024ddafa8..d6e748a3330 100644 --- a/.storybook/main.js +++ b/.storybook/main.js @@ -10,6 +10,7 @@ const componentPkgs = readdirSync(componentsPath, { module.exports = { stories: [ + "../components/*/stories/*.mdx", "../components/*/stories/*.stories.js", "./guides/*.mdx", "./foundations/*/*.mdx", diff --git a/.storybook/manager.js b/.storybook/manager.js index fb843f695a3..791ceaca79f 100644 --- a/.storybook/manager.js +++ b/.storybook/manager.js @@ -50,7 +50,7 @@ addons.setConfig({ sidebar: { showRoots: false, filters: { - patterns: (item) => !(item.id.includes('forced-colors') || item.tags.includes('foundation')), + patterns: (item) => !item.id.includes('forced-colors') && ['foundation','is-hidden-story'].every((tag) => !item.tags.includes(tag)), } }, }); diff --git a/components/button/stories/button.mdx b/components/button/stories/button.mdx new file mode 100644 index 00000000000..16ba1132323 --- /dev/null +++ b/components/button/stories/button.mdx @@ -0,0 +1,103 @@ +import { Canvas, Meta, Subtitle } from '@storybook/blocks'; + +import * as ButtonStories from './button.stories'; + + + +# Button + +Buttons allow users to perform an action or to navigate to another page. They have +multiple styles forvarious needs, and are ideal forcalling attention to where a user needs to +do something in order to move forward in a flow. + +## Variants + +There are four available variants that are used for different levels of emphasis and different +types of actions. By default, a button uses the fill style with a solid background. The primary +and secondary variants also have an outline option. + +### Accent + +The call to action button communicates strong emphasis and is reserved for encouraging critical +actions. In general, only use the emphasized option for the most important action on the page. + + + +### Primary + +The primary button is for medium emphasis. Use it in place of a call to action button when the +action requires less prominence, or if there are multiple primary actions of the same importance +in the same view. Both the fill (default) and outline styles are demonstrated below: + + + +### Secondary + +The secondary button is for low emphasis. It’s paired with other button types to surface less +prominent actions, and should never be the only button in a group. Both the fill (default) and +outline styles are demonstrated below: + + + +### Negative + +The negative button is for emphasizing actions that can be destructive or have negative +consequences if taken. Use it sparingly. + + + +## Static color + +When a button needs to be placed on top of a color background or a visual, use the static color +option. Static color buttons do not change shades or values depending upon the color theme. + +### Static white - primary + + + +### Static white - secondary + + + +### Static black - primary + + + +### Static black - secondary + + + +## Sizing + +Buttons come in four different sizes: small, medium, large, and extra large. The medium size is +the default and most frequently used option. Use the other sizes sparingly; they should be used +to create a hierarchy of importance within the page. + + + +## Pending state + +The pending button is for indicating that a quick progress action is taking place. In this case, the +label and optional icon disappear and a progress circle appears. The progress circle always shows an +indeterminate progress. We recommend the use of the `.is-pending` class on the component’s parent +container, but there is also an option to use an attribute of `pending` instead. Buttons should have +the disabled attribute when the pending state is applied. + + + +## Disabled state + +A button in a disabled state shows that an action exists, but is not available in that circumstance. +This state can be used to maintain layout continuity and to communicate that an action may become +available later. + + + +## Text overflow behavior + +When the button text is too long for the horizontal space available, it wraps to form another line. +When there is no icon present, the text is aligned center. When there is an icon present, the text is +aligned `start` (left with a writing direction of left-to-right) and the icon remains vertically aligned +at the top. + + \ No newline at end of file diff --git a/components/button/stories/button.stories.js b/components/button/stories/button.stories.js index 3047ae884be..1bf61b2396b 100644 --- a/components/button/stories/button.stories.js +++ b/components/button/stories/button.stories.js @@ -1,5 +1,6 @@ import { html } from "lit"; import { styleMap } from "lit/directives/style-map.js"; +import { when } from "lit/directives/when.js"; import { withDownStateDimensionCapture } from "../../../.storybook/decorators"; import { default as IconStories } from "@spectrum-css/icon/stories/icon.stories.js"; @@ -13,7 +14,6 @@ import { Template } from "./template"; export default { title: "Components/Button", component: "Button", - decorators: [withDownStateDimensionCapture(".spectrum-Button:not(:disabled)")], argTypes: { size: { name: "Size", @@ -114,7 +114,7 @@ export default { type: { name: "string" }, table: { type: { summary: "string" }, - category: "Advanced", + category: "Component", }, options: ["white", "black"], @@ -145,6 +145,7 @@ export default { } }, decorators: [ + withDownStateDimensionCapture(".spectrum-Button:not(:disabled)"), (Story, context) => html`