Skip to content

Commit 239ef97

Browse files
marissahuysentruytcastastrophe
authored andcommitted
docs(fieldlabel): adds missing stories and cleans up test cases
- adds missing stories and corresponding documentation - removes duplicate test case for right-aligned - adds customStyles to default test to match all other test styles
1 parent 2d2738f commit 239ef97

File tree

2 files changed

+81
-7
lines changed

2 files changed

+81
-7
lines changed

components/fieldlabel/stories/fieldlabel.stories.js

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { disableDefaultModes } from "@spectrum-css/preview/modes";
22
import { isDisabled, isRequired, size } from "@spectrum-css/preview/types";
3+
import { Sizes } from "@spectrum-css/preview/decorators";
34
import pkgJson from "../package.json";
45
import { FieldLabelGroup } from "./fieldlabel.test.js";
6+
import { Template } from "./template.js";
57

68
/**
79
* The field label component is used along with inputs to display a label for that input.
@@ -39,15 +41,91 @@ export default {
3941
alignment: "left",
4042
isDisabled: false,
4143
isRequired: false,
44+
label: "Label",
4245
},
4346
parameters: {
4447
packageJson: pkgJson,
4548
},
4649
};
4750

51+
/**
52+
* By default, a field label has left-aligned text, and is a medium size. For field label text, use a short, catch-all description (1-3 words) of the information that a user needs to provide.
53+
*
54+
* The default position of a field label is above an input, but it can alternatively be positioned to the side. Visit the [form component](/docs/components-form--docs) to see examples of the field label with an input.
55+
56+
*/
4857
export const Default = FieldLabelGroup.bind({});
49-
Default.args = {
58+
Default.args = {};
59+
60+
// ********* DOCS ONLY ********* //
61+
/**
62+
* Field labels come in four different sizes: small, medium, large, and extra-large. The medium size is the default and most frequently used option with medium-sized inputs. Use the other sizes sparingly; they should be used to create a hierarchy of importance within the page.
63+
*
64+
* Both small and medium field labels have the same font size, but different paddings when used as side labels.
65+
*/
66+
export const Sizing = (args, context) => Sizes({
67+
Template,
68+
withBorder: false,
69+
withHeading: false,
70+
...args,
71+
}, context);
72+
Sizing.tags = ["!dev"];
73+
Sizing.parameters = {
74+
chromatic: { disableSnapshot: true },
75+
};
76+
77+
/**
78+
* To render right-aligned field label text, apply the `.spectrum-FieldLabel--right` class to the field label.
79+
*
80+
*/
81+
export const RightAligned = Template.bind({});
82+
RightAligned.args = {
5083
label: "Label",
84+
alignment: "right",
85+
customStyles: {
86+
width: "72px",
87+
},
88+
};
89+
RightAligned.tags = ["!dev"];
90+
RightAligned.parameters = {
91+
chromatic: { disableSnapshot: true },
92+
};
93+
RightAligned.storyName = "Right-aligned";
94+
95+
/**
96+
* Field labels for required inputs can be marked with an asterisk at the end of the label. Optional inputs would then be understood to not have the asterisk. If using the asterisk icon, do not leave any space between the label text and the start of the `<svg>` element in the markup. Extra space should not be added in addition to the inline margin.
97+
*/
98+
export const Required = Template.bind({});
99+
Required.args = {
100+
isRequired: true,
101+
};
102+
Required.tags = ["!dev"];
103+
Required.parameters = {
104+
chromatic: { disableSnapshot: true },
105+
};
106+
107+
/**
108+
* When the field label is too long for the available horizontal space, it wraps to form another line.
109+
*/
110+
export const WrappingAndRequired = Template.bind({});
111+
WrappingAndRequired.args = {
112+
label: "Label example with longer text that will wrap to the next line. And with an asterisk that marks it as required.",
113+
isRequired: true,
114+
customStyles: { width: "200px" },
115+
};
116+
WrappingAndRequired.tags = ["!dev"];
117+
WrappingAndRequired.parameters = {
118+
chromatic: { disableSnapshot: true },
119+
};
120+
WrappingAndRequired.storyName = "Wrapping and required";
121+
122+
export const Disabled = Template.bind({});
123+
Disabled.args = {
124+
isDisabled: true,
125+
};
126+
Disabled.tags = ["!dev"];
127+
Disabled.parameters = {
128+
chromatic: { disableSnapshot: true },
51129
};
52130

53131
// ********* VRT ONLY ********* //

components/fieldlabel/stories/fieldlabel.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ export const FieldLabelGroup = Variants({
55
Template,
66
testData: [
77
{
8-
testHeading: "Default"
9-
},
10-
{
11-
testHeading: "Right alignment",
12-
alignment: "right",
8+
testHeading: "Default",
139
customStyles: { width: "200px" },
1410
},
1511
{
@@ -20,7 +16,7 @@ export const FieldLabelGroup = Variants({
2016
{
2117
testHeading: "Wrapped",
2218
withStates: false,
23-
label: "Label example with longer text that will wrap to the next line. And with an asterisk that marks it as required.",
19+
label: "Label example with longer text that will wrap to the next line. Sometimes there is an asterisk that marks it as required.",
2420
customStyles: { width: "200px" },
2521
},
2622
],

0 commit comments

Comments
 (0)