|
1 | 1 | import { disableDefaultModes } from "@spectrum-css/preview/modes";
|
2 | 2 | import { isDisabled, isRequired, size } from "@spectrum-css/preview/types";
|
| 3 | +import { Sizes } from "@spectrum-css/preview/decorators"; |
3 | 4 | import pkgJson from "../package.json";
|
4 | 5 | import { FieldLabelGroup } from "./fieldlabel.test.js";
|
| 6 | +import { Template } from "./template.js"; |
5 | 7 |
|
6 | 8 | /**
|
7 | 9 | * The field label component is used along with inputs to display a label for that input.
|
@@ -39,15 +41,91 @@ export default {
|
39 | 41 | alignment: "left",
|
40 | 42 | isDisabled: false,
|
41 | 43 | isRequired: false,
|
| 44 | + label: "Label", |
42 | 45 | },
|
43 | 46 | parameters: {
|
44 | 47 | packageJson: pkgJson,
|
45 | 48 | },
|
46 | 49 | };
|
47 | 50 |
|
| 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 | + */ |
48 | 57 | 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 = { |
50 | 83 | 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 }, |
51 | 129 | };
|
52 | 130 |
|
53 | 131 | // ********* VRT ONLY ********* //
|
|
0 commit comments