Skip to content

Commit ee4a017

Browse files
jawinnpfulton
authored andcommitted
docs(helptext): storybook fixes and addition
Clears up a couple issues: - An arg called "treatment" was named "variant" in the actual template and its usage. This has been renamed, so this control now works. - Icon is now hidden for the neutral Help text, to conform with the component guidelines. An issue originally noticed in Field group where neutral help text was showing an invalid icon when it shouldn't be allowing that combination. Adds a new story, so both negative and neutral variants are represented in VRTs. Also includes wrapping text as part of the new story.
1 parent ed92b42 commit ee4a017

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

components/helptext/stories/helptext.stories.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default {
1818
},
1919
control: { type: "text" },
2020
},
21-
treatment: {
22-
name: "Treatment",
21+
variant: {
22+
name: "Variant",
2323
type: { name: "string" },
2424
table: {
2525
type: { summary: "string" },
@@ -28,17 +28,27 @@ export default {
2828
options: ["neutral", "negative"],
2929
control: "inline-radio",
3030
},
31+
size: {
32+
name: "Size",
33+
type: { name: "string", required: true },
34+
table: {
35+
type: { summary: "string" },
36+
category: "Component",
37+
},
38+
options: ["s", "m", "l", "xl"],
39+
control: "select",
40+
},
3141
hideIcon: {
3242
name: "Hide icon",
3343
type: { name: "boolean" },
34-
description: "Only applicable if treatment is negative.",
44+
description: "Help text using the negative variant can have an optional icon.",
3545
table: {
3646
type: { summary: "boolean" },
3747
disable: false,
38-
category: "Advanced",
48+
category: "Component",
3949
},
4050
control: "boolean",
41-
if: { arg: "treatment", eq: "negative" },
51+
if: { arg: "variant", eq: "negative" },
4252
},
4353
isDisabled: {
4454
name: "Disabled",
@@ -49,13 +59,23 @@ export default {
4959
},
5060
control: "boolean",
5161
},
62+
customStyles: {
63+
name: "Custom styles",
64+
description: "Storybook only styles for testing the story, applied to the parent element.",
65+
table: {
66+
type: { summary: "object" },
67+
category: "Advanced",
68+
},
69+
if: { arg: 'customStyles' }
70+
}
5271
},
5372
args: {
5473
rootClass: "spectrum-HelpText",
5574
text: "Create a password with at least 8 characters.",
56-
treatment: "neutral",
75+
variant: "neutral",
5776
hideIcon: false,
5877
isDisabled: false,
78+
size: "m",
5979
},
6080
parameters: {
6181
actions: {
@@ -70,4 +90,13 @@ export default {
7090
};
7191

7292
export const Default = Template.bind({});
93+
Default.storyName = "Neutral";
7394
Default.args = {};
95+
96+
export const Negative = Template.bind({});
97+
Negative.storyName = "Negative";
98+
Negative.args = {
99+
variant: "negative",
100+
text: "This is an example with wrapping text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
101+
customStyles: {'max-width': '350px'},
102+
};

components/helptext/stories/template.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { html } from "lit";
22
import { classMap } from "lit/directives/class-map.js";
33
import { ifDefined } from "lit/directives/if-defined.js";
4+
import { styleMap } from "lit/directives/style-map.js";
45

56
import { Template as Icon } from "@spectrum-css/icon/stories/template.js";
67

@@ -16,6 +17,7 @@ export const Template = ({
1617
variant,
1718
id,
1819
customClasses = [],
20+
customStyles = {},
1921
...globals
2022
}) => {
2123
const { express } = globals;
@@ -37,13 +39,14 @@ export const Template = ({
3739
[`${rootClass}--${variant}`]: typeof variant !== "undefined",
3840
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
3941
})}
42+
style=${styleMap(customStyles)}
4043
id=${ifDefined(id)}
4144
>
42-
${!hideIcon
45+
${!hideIcon && variant == "negative"
4346
? Icon({
44-
iconName: "Alert",
45-
size,
46-
customClasses: [`${rootClass}-validationIcon`],
47+
iconName: "Alert",
48+
size,
49+
customClasses: [`${rootClass}-validationIcon`],
4750
})
4851
: ""}
4952
<div class=${`${rootClass}-text`}>${text}</div>

0 commit comments

Comments
 (0)