Skip to content

Commit 131fded

Browse files
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 bccce81 commit 131fded

File tree

2 files changed

+85
-7
lines changed

2 files changed

+85
-7
lines changed

components/fieldlabel/stories/fieldlabel.stories.js

Lines changed: 83 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,95 @@ 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 is left-aligned, 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 [text field component](/story/components-text-field--default) or [form documentation](/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+
* A right-aligned 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+
* Inputs can be marked as required or optional, depending on the situation, using a necessity indicator. There are two styles for the necessity indicator: icon or text. In a single form, mark only the required fields or only the optional fields, depending on whichever is less frequent in the entire form.
97+
*
98+
* Field labels for required inputs are shown with a default asterisk marked at the end of the label. 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.
99+
*
100+
* Alternatively, the necessity indicator can be show with text, appended to the end of the label that reads "(required)".
101+
*/
102+
export const Required = Template.bind({});
103+
Required.args = {
104+
isRequired: true,
105+
};
106+
Required.tags = ["!dev"];
107+
Required.parameters = {
108+
chromatic: { disableSnapshot: true },
109+
};
110+
111+
/**
112+
* When the field label is too long for the available horizontal space, it wraps to form another line.
113+
*/
114+
export const WrappingAndRequired = Template.bind({});
115+
WrappingAndRequired.args = {
116+
label: "Label example with longer text that will wrap to the next line. And with an asterisk that marks it as required.",
117+
isRequired: true,
118+
customStyles: { width: "200px" },
119+
};
120+
WrappingAndRequired.tags = ["!dev"];
121+
WrappingAndRequired.parameters = {
122+
chromatic: { disableSnapshot: true },
123+
};
124+
WrappingAndRequired.storyName = "Wrapping and required";
125+
126+
export const Disabled = Template.bind({});
127+
Disabled.args = {
128+
isDisabled: true,
129+
};
130+
Disabled.tags = ["!dev"];
131+
Disabled.parameters = {
132+
chromatic: { disableSnapshot: true },
51133
};
52134

53135
// ********* 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)