|
| 1 | +import { Template as Checkbox } from "@spectrum-css/checkbox/stories/template.js"; |
| 2 | +import { Template as Fieldgroup } from "@spectrum-css/fieldgroup/stories/template.js"; |
1 | 3 | import { Template as Picker } from "@spectrum-css/picker/stories/template.js";
|
2 | 4 | import { disableDefaultModes } from "@spectrum-css/preview/modes";
|
3 | 5 | import { Template as Stepper } from "@spectrum-css/stepper/stories/template.js";
|
4 | 6 | import { Template as TextField } from "@spectrum-css/textfield/stories/template.js";
|
| 7 | +import { Template } from "./form.template.js"; |
5 | 8 | import pkgJson from "../package.json";
|
6 | 9 | import { FormGroup } from "./form.test.js";
|
7 | 10 |
|
8 | 11 | /**
|
9 |
| - * The form component is used for aligning multiple inputs and field groups within a form. |
| 12 | + * The form component is used for aligning multiple inputs and field groups within a form. It provides structure and spacing for your form fields. |
10 | 13 | */
|
11 | 14 | export default {
|
12 | 15 | title: "Form",
|
13 | 16 | component: "Form",
|
14 | 17 | argTypes: {
|
15 |
| - labelsAbove: { |
16 |
| - name: "Labels above", |
17 |
| - type: { name: "boolean" }, |
| 18 | + labelPosition: { |
| 19 | + name: "Label position", |
| 20 | + description: "Position of the field label in relation to the input.", |
| 21 | + type: { name: "string" }, |
18 | 22 | table: {
|
19 |
| - type: { summary: "boolean" }, |
| 23 | + type: { summary: "string" }, |
20 | 24 | category: "Component",
|
21 | 25 | },
|
22 |
| - control: "boolean", |
| 26 | + control: "select", |
| 27 | + options: ["top", "side"], |
23 | 28 | },
|
| 29 | + fieldLabelAlignment: { |
| 30 | + name: "Field label alignment", |
| 31 | + type: { name: "string" }, |
| 32 | + table: { |
| 33 | + type: { summary: "string" }, |
| 34 | + category: "Component", |
| 35 | + }, |
| 36 | + control: "select", |
| 37 | + options: ["left", "right"], |
| 38 | + if: { arg: "labelPosition", eq: "side" }, |
| 39 | + }, |
| 40 | + items: { table: { disable: true } }, |
24 | 41 | },
|
25 | 42 | args: {
|
26 | 43 | rootClass: "spectrum-Form",
|
27 |
| - labelsAbove: false, |
| 44 | + labelPosition: "top", |
| 45 | + items: [ |
| 46 | + { |
| 47 | + label: "Company title", |
| 48 | + id: "form-example-company", |
| 49 | + content: [ |
| 50 | + (passthroughs, context) => TextField({ |
| 51 | + ...passthroughs, |
| 52 | + multiline: true, |
| 53 | + name: "field", |
| 54 | + }, context), |
| 55 | + ], |
| 56 | + }, { |
| 57 | + label: "Email address", |
| 58 | + id: "form-example-email", |
| 59 | + content: [ |
| 60 | + (passthroughs, context) => TextField({ |
| 61 | + ...passthroughs, |
| 62 | + type: "email", |
| 63 | + name: "email", |
| 64 | + }, context), |
| 65 | + ], |
| 66 | + }, { |
| 67 | + label: "Country", |
| 68 | + id: "form-example-country", |
| 69 | + content: [ |
| 70 | + (passthroughs, context) => Picker({ |
| 71 | + ...passthroughs, |
| 72 | + placeholder: "Select a country", |
| 73 | + name: "country", |
| 74 | + }, context), |
| 75 | + ], |
| 76 | + }, { |
| 77 | + label: "Interest", |
| 78 | + id: "form-example-interests", |
| 79 | + content: [ |
| 80 | + (passthroughs, context) => Fieldgroup({ |
| 81 | + layout: "horizontal", |
| 82 | + items: [ |
| 83 | + Checkbox({ |
| 84 | + ...passthroughs, |
| 85 | + label: "Kittens", |
| 86 | + customClasses: ["spectrum-FieldGroup-item"], |
| 87 | + }, context), |
| 88 | + Checkbox({ |
| 89 | + ...passthroughs, |
| 90 | + label: "Puppies", |
| 91 | + customClasses: ["spectrum-FieldGroup-item"], |
| 92 | + }, context),] |
| 93 | + }), |
| 94 | + ], |
| 95 | + },{ |
| 96 | + label: "Age", |
| 97 | + id: "form-example-amount", |
| 98 | + content: [ |
| 99 | + (passthroughs, context) => Stepper({ |
| 100 | + ...passthroughs, |
| 101 | + }, context), |
| 102 | + ] |
| 103 | + } |
| 104 | + ], |
28 | 105 | },
|
29 | 106 | parameters: {
|
30 | 107 | packageJson: pkgJson,
|
31 | 108 | },
|
32 | 109 | };
|
33 | 110 |
|
| 111 | +/** |
| 112 | + * A stacked layout with the labels above the form fields. The class `.spectrum-Form--labelPosition` is applied to the form itself. You do not need to apply a specific class to the field label because `.spectrum-FieldLabel--left` is applied to each to each [field label](/docs/components-field-label--docs) by default. |
| 113 | + */ |
34 | 114 | export const Default = FormGroup.bind({});
|
35 |
| -Default.args = { |
36 |
| - items: [ |
37 |
| - { |
38 |
| - label: "Company title", |
39 |
| - id: "form-example-company", |
40 |
| - content: [ |
41 |
| - (passthroughs, context) => TextField({ |
42 |
| - ...passthroughs, |
43 |
| - multiline: true, |
44 |
| - name: "field", |
45 |
| - }, context), |
46 |
| - ], |
47 |
| - }, { |
48 |
| - label: "Email address", |
49 |
| - id: "form-example-email", |
50 |
| - content: [ |
51 |
| - (passthroughs, context) => TextField({ |
52 |
| - ...passthroughs, |
53 |
| - type: "email", |
54 |
| - name: "email", |
55 |
| - }, context), |
56 |
| - ], |
57 |
| - }, { |
58 |
| - label: "Country", |
59 |
| - id: "form-example-country", |
60 |
| - content: [ |
61 |
| - (passthroughs, context) => Picker({ |
62 |
| - ...passthroughs, |
63 |
| - placeholder: "Select a country", |
64 |
| - name: "country", |
65 |
| - }, context), |
66 |
| - ], |
67 |
| - }, { |
68 |
| - label: "Amount", |
69 |
| - id: "form-example-amount", |
70 |
| - content: [ |
71 |
| - (passthroughs, context) => Stepper({ |
72 |
| - ...passthroughs, |
73 |
| - }, context), |
74 |
| - ] |
75 |
| - } |
76 |
| - ], |
| 115 | +Default.args = {}; |
| 116 | + |
| 117 | +/** |
| 118 | + * A two column layout with left-aligned label text. |
| 119 | + */ |
| 120 | +export const LeftAlignedSideLabels = Template.bind({}); |
| 121 | +LeftAlignedSideLabels.args = { |
| 122 | + ...Default.args, |
| 123 | + labelPosition: "side", |
| 124 | +}; |
| 125 | +LeftAlignedSideLabels.tags = ["!dev"]; |
| 126 | +LeftAlignedSideLabels.parameters = { |
| 127 | + chromatic: { disableSnapshot: true }, |
| 128 | +}; |
| 129 | +LeftAlignedSideLabels.storyName = "Left-aligned side labels"; |
| 130 | + |
| 131 | +/** |
| 132 | + * A two column layout with right-aligned label text. `.spectrum-FieldLabel--right` is applied to each to each [field label](/docs/components-field-label--docs). |
| 133 | + */ |
| 134 | +export const RightAlignedSideLabels = Template.bind({}); |
| 135 | +RightAlignedSideLabels.args = { |
| 136 | + ...Default.args, |
| 137 | + labelPosition: "side", |
| 138 | + fieldLabelAlignment: "right", |
| 139 | +}; |
| 140 | +RightAlignedSideLabels.tags = ["!dev"]; |
| 141 | +RightAlignedSideLabels.parameters = { |
| 142 | + chromatic: { disableSnapshot: true }, |
77 | 143 | };
|
| 144 | +RightAlignedSideLabels.storyName = "Right-aligned side labels"; |
78 | 145 |
|
79 | 146 | // ********* VRT ONLY ********* //
|
80 | 147 | export const WithForcedColors = FormGroup.bind({});
|
|
0 commit comments