Skip to content

Commit cd82d6b

Browse files
committed
docs(fieldlabel): form - add stories
Add stories for the "Form" component that exists as its own entry in the docs (the CSS actually exists within the fieldlabel component).
1 parent 64169f0 commit cd82d6b

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { html } from "lit";
2+
import { classMap } from "lit/directives/class-map.js";
3+
import { styleMap } from "lit/directives/style-map.js";
4+
import { ifDefined } from "lit/directives/if-defined.js";
5+
6+
import { Template as FieldLabel } from "@spectrum-css/fieldlabel/stories/template.js";
7+
import { Template as TextField } from "@spectrum-css/textfield/stories/template.js";
8+
import { Template as Picker } from "@spectrum-css/picker/stories/template.js";
9+
import { Template as Stepper } from "@spectrum-css/stepper/stories/template.js";
10+
11+
import "../index.css";
12+
13+
export const Template = ({
14+
rootClass = "spectrum-Form",
15+
labelsAbove,
16+
customClasses = [],
17+
id,
18+
...globals
19+
}) => {
20+
const { express } = globals;
21+
22+
try {
23+
if (!express) import(/* webpackPrefetch: true */ "../themes/spectrum.css");
24+
else import(/* webpackPrefetch: true */ "../themes/express.css");
25+
} catch (e) {
26+
console.warn(e);
27+
}
28+
29+
return html`
30+
<form
31+
class=${classMap({
32+
[rootClass]: true,
33+
[`${rootClass}--labelsAbove`]: labelsAbove,
34+
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
35+
})}
36+
id=${ifDefined(id)}
37+
>
38+
<div class="spectrum-Form-item">
39+
${FieldLabel({
40+
label: 'Company Title',
41+
forInput: 'form-example-company',
42+
alignment: 'left',
43+
})}
44+
<div class="spectrum-Form-itemField">
45+
${TextField({
46+
multiline: true,
47+
placeholder: 'Enter your company name',
48+
name: 'field',
49+
id: 'form-example-company',
50+
})}
51+
</div>
52+
</div>
53+
<div class="spectrum-Form-item">
54+
${FieldLabel({
55+
label: 'Email Address',
56+
forInput: 'form-example-email',
57+
alignment: labelsAbove ? undefined : 'left',
58+
})}
59+
<div class="spectrum-Form-itemField">
60+
${TextField({
61+
placeholder: 'Enter your email address',
62+
name: 'email',
63+
type: 'email',
64+
id: 'form-example-email',
65+
})}
66+
</div>
67+
</div>
68+
<div class="spectrum-Form-item">
69+
${FieldLabel({
70+
label: 'Country',
71+
forInput: 'form-example-country',
72+
alignment: labelsAbove ? undefined : 'left',
73+
})}
74+
<div class="spectrum-Form-itemField">
75+
${Picker({
76+
placeholder: 'Select a Country',
77+
name: 'country',
78+
id: 'form-example-country',
79+
})}
80+
</div>
81+
</div>
82+
<div class="spectrum-Form-item">
83+
${FieldLabel({
84+
label: 'Amount',
85+
forInput: 'form-example-amount',
86+
alignment: labelsAbove ? undefined : 'left',
87+
})}
88+
<div class="spectrum-Form-itemField">
89+
${Stepper({
90+
id: 'form-example-amount'
91+
})}
92+
</div>
93+
</div>
94+
</form>
95+
`;
96+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Template } from "./form-template";
2+
3+
export default {
4+
title: "Components/Form",
5+
description: "The Form component is used for aligning multiple inputs and field groups within a form.",
6+
component: "Form",
7+
argTypes: {
8+
labelsAbove: {
9+
name: "Labels Above",
10+
type: { name: "boolean" },
11+
table: {
12+
type: { summary: "boolean" },
13+
category: "State",
14+
},
15+
control: "boolean",
16+
},
17+
},
18+
args: {
19+
rootClass: "spectrum-Form",
20+
labelsAbove: false,
21+
},
22+
parameters: {
23+
actions: {
24+
handles: [],
25+
},
26+
status: {
27+
type: process.env.MIGRATED_PACKAGES.includes("fieldlabel")
28+
? "migrated"
29+
: undefined,
30+
},
31+
},
32+
};
33+
34+
export const Standard = Template.bind({});
35+
Standard.args = {
36+
labelsAbove: false,
37+
};
38+
39+
export const LabelsAbove = Template.bind({});
40+
LabelsAbove.args = {
41+
labelsAbove: true,
42+
};

0 commit comments

Comments
 (0)