Skip to content

Commit 1adb2f4

Browse files
authored
docs(helptext): migrate docs to storybook (#3151)
Migrates the help text component's docs page information to Storybook. Creates additional docs-only stories and some supporting templates. Brings over some helpful info from help text's guidelines for the descriptions.
1 parent 99ad67a commit 1adb2f4

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

components/helptext/stories/helptext.stories.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { Sizes } from "@spectrum-css/preview/decorators";
12
import { disableDefaultModes } from "@spectrum-css/preview/modes";
23
import { isDisabled, size } from "@spectrum-css/preview/types";
34
import pkgJson from "../package.json";
45
import { HelpTextGroup } from "./helptext.test.js";
6+
import { NegativeTemplate, Template, VariantsTemplate } from "./template.js";
57

68
/**
79
* Help text provides either an informative description or an error message that gives more context about what a user needs to input. It's commonly used in forms.
@@ -34,7 +36,7 @@ export default {
3436
hideIcon: {
3537
name: "Hide icon",
3638
type: { name: "boolean" },
37-
description: "Help text using the negative variant can have an optional icon.",
39+
description: "Hides the optional icon used with the negative variant.",
3840
table: {
3941
type: { summary: "boolean" },
4042
disable: false,
@@ -58,6 +60,9 @@ export default {
5860
},
5961
};
6062

63+
/**
64+
* The default neutral variant is used to convey informative messages.
65+
*/
6166
export const Default = HelpTextGroup.bind({});
6267
Default.args = {};
6368

@@ -71,3 +76,69 @@ WithForcedColors.parameters = {
7176
modes: disableDefaultModes
7277
},
7378
};
79+
80+
// ********* DOCS ONLY ********* //
81+
82+
/**
83+
* Help text comes in four different sizes: small, medium, large, and extra-large. The medium size is the default.
84+
*/
85+
export const Sizing = (args, context) => Sizes({
86+
Template,
87+
withHeading: false,
88+
withBorder: false,
89+
...args,
90+
}, context);
91+
Sizing.storyName = "Sizing";
92+
Sizing.args = {
93+
variant: "negative",
94+
};
95+
Sizing.tags = ["!dev"];
96+
Sizing.parameters = {
97+
chromatic: { disableSnapshot: true },
98+
};
99+
100+
/**
101+
* Help text using the neutral variant can be displayed in a disabled state. The text appears with a lighter gray that matches
102+
* the style of other components in a disabled state. Help text using the negative variant cannot be displayed in a disabled
103+
* state because it communicates an error, and error messages should not be visible when the component is disabled.
104+
*/
105+
export const Disabled = Template.bind({});
106+
Disabled.args = {
107+
isDisabled: true,
108+
};
109+
Disabled.tags = ["!dev"];
110+
Disabled.parameters = {
111+
chromatic: { disableSnapshot: true },
112+
};
113+
114+
/**
115+
* The negative variant is used to convey error messages and can have an optional icon.
116+
*
117+
* In most cases, help text is used with a component that already displays an icon communicating an error (e.g.,
118+
* [text field](?path=/docs/components-text-field--docs),
119+
* [picker](?path=/docs/components-picker--docs),
120+
* [combo box](?path=/docs/components-combobox--docs#standard---invalid)),
121+
* so it’s not necessary to include another icon. In other cases, help text that is used with a component that does not display an icon
122+
* communicating an error (e.g., [field group](?path=/docs/components-field-group--docs#invalid)) needs to display an icon.
123+
*/
124+
export const Negative = NegativeTemplate.bind({});
125+
Negative.args = {
126+
variant: "negative",
127+
};
128+
Negative.tags = ["!dev"];
129+
Negative.parameters = {
130+
chromatic: { disableSnapshot: true },
131+
};
132+
133+
/**
134+
* When the text is too long for the available horizontal space, it wraps to form another line.
135+
*/
136+
export const TextOverflow = VariantsTemplate.bind({});
137+
TextOverflow.args = {
138+
variant: "negative",
139+
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
140+
};
141+
TextOverflow.tags = ["!dev"];
142+
TextOverflow.parameters = {
143+
chromatic: { disableSnapshot: true },
144+
};

components/helptext/stories/template.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
2-
import { getRandomId } from "@spectrum-css/preview/decorators";
2+
import { Container, getRandomId } from "@spectrum-css/preview/decorators";
33
import { html } from "lit";
44
import { classMap } from "lit/directives/class-map.js";
55
import { ifDefined } from "lit/directives/if-defined.js";
@@ -45,3 +45,47 @@ export const Template = ({
4545
</div>
4646
`;
4747
};
48+
49+
/**
50+
* Displays both variants.
51+
*/
52+
export const VariantsTemplate = (args, context) => Container({
53+
withBorder: false,
54+
direction: "column",
55+
content: html`${["neutral", "negative"].map((variant) =>
56+
Container({
57+
withBorder: false,
58+
direction: "column",
59+
heading: `Variant: ${variant}`,
60+
containerStyles: {
61+
rowGap: "8px",
62+
},
63+
content: Template({
64+
...args,
65+
variant
66+
}, context),
67+
})
68+
)}`,
69+
});
70+
71+
/**
72+
* Displays options for the negative variant; with and without an icon.
73+
*/
74+
export const NegativeTemplate = (args, context) => Container({
75+
withBorder: false,
76+
direction: "column",
77+
content: html`${[true, false].map((hideIcon) =>
78+
Container({
79+
withBorder: false,
80+
direction: "column",
81+
heading: hideIcon ? "Without icon" : "With icon",
82+
containerStyles: {
83+
rowGap: "8px",
84+
},
85+
content: Template({
86+
...args,
87+
hideIcon
88+
}, context),
89+
})
90+
)}`,
91+
});

0 commit comments

Comments
 (0)