|
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,95 @@ 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 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 | + */ |
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 | + * A right-aligned 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 | + * 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 }, |
51 | 133 | };
|
52 | 134 |
|
53 | 135 | // ********* VRT ONLY ********* //
|
|
0 commit comments