Skip to content

Commit 0061fba

Browse files
docs(swatch,swatchgroup,table,tabs): docs migrations to storybook (#2925)
* docs(swatch): adds missing variants, expands test coverage - missing stories are added - additional template to support new stories - expands chromatic test cases * docs(swatchgroup): adds missing variants, test coverage - adds missing stories to docs page - expands Chromatic test cases - adds documentation for border classes, density and corner rounding * docs(tabs): adds stories and test cases - adds missing variants to docs page - expands Chromatic test coverage - enhances coverage to support new variants * docs(table): adds stories and test cases - migration guide notes are moved to CHANGELOG - adds missing stories to docs page - enhances template to support new variants - expands Chromatic test coverage * docs(swatch,swatchgroup,table): clean up - renames withBorder arg to borderStyle since it isn't a boolean arg for swatch/swatchgroup - refactors template and test files to reflect arg name changes - removes unnecessary comments - removes unnecessary literals in Container() functions - corrects withColumnDividers arg name to hasColumnDividers in default table args - corrects sentence case in table control args - extend swatch.argtypes and fix containerWidth - fix sizing docs description - uses "Density - Compact" and "Density - Spacious" as story names so that both stories will be next to each other on the docs page. - calls out the default, regular density for the default table in the story description * chore(tabs): add backticks to token reference in docs docs(tabs): use passive voice in docs descriptions * docs(swatch): update descriptions for controls - adds descriptions in the control table for isMixedValue, rounding, and imageUrl - adds a better description for gradient control - changes gradient control from color to text to make it clearer that a user can input their own gradient examples. - change from isRectangle boolean, to shape inline-radio control - add description for rectangle control - update template.js & test file as needed for refactored rectangle - add nothing/empty story docs description - add opacity examples to swatch stories * docs(swatchgroup): add rounding none to roundinggroup chore(swatchgroup): remove shape control from control table * docs(tabs): update wording on docs page * chore(table): table clean up - fix sentence case in control table - because certain variants cannot be created from the default story, this adds stories to sidebar them back to the navigation for users to view and further edit via the controls - adds description of the quiet multi-select, that has emphasized styles by default, and how to remove those emphasized styles to clarify quiet emphasized multi-select story * docs(swatchgroup): refactor swatches and borders - in most stories, swatchgroup now uses colors that now meet contrast in both our light and dark mode to properly show the "default" of having no border on the swatches in the swatchgroup - for the light border story, a new set of colors that don't meet color contrast for light mode are implemented - the rounding template was updated to use a selection of the new colors that meet contrast - updated light border swatch colors for the light border test case * docs(swatch): fix no color/empty story and test - adds documentation around making sure the default border is applied in cases where a swatch is empty/undefined - updates the no-color test case to apply the default border - removes non-existent swatch arguments isGradient and isImage - fix rectangle story name to shape * docs(swatch,swatchgroup,tabs): pr fixes - fixes case of defaultValues swatch/swatchgroup - uses shorthand for borderStyles in swatch and converts in template now - simplifies isDisabled, isSelected assignments in swatchgroup template - removes unnecessary destructuring in tabs * chore(tabs): use getRandomId to generate ids for tabs/tabitems * chore(table): fix sentence case in table cells
1 parent 10375ea commit 0061fba

File tree

14 files changed

+1604
-462
lines changed

14 files changed

+1604
-462
lines changed

components/swatch/stories/swatch.stories.js

Lines changed: 194 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { disableDefaultModes } from "@spectrum-css/preview/modes";
22
import { isDisabled, isSelected, size } from "@spectrum-css/preview/types";
3+
import { Sizes } from "@spectrum-css/preview/decorators";
34
import pkgJson from "../package.json";
45
import { SwatchGroup } from "./swatch.test.js";
6+
import { Template, DisabledGroup, EmptyGroup, RoundingGroup, BorderGroup, SizingGroup } from "./template";
57

68
/**
79
* A swatch shows a small sample of a fill--such as a color, gradient, texture, or material--that is intended to be applied to an object.
10+
*
11+
* ## Usage notes
12+
*
13+
* Set `--spectrum-picked-color` to customize the swatch fill background color.
814
*/
915
export default {
1016
title: "Swatch",
@@ -22,33 +28,220 @@ export default {
2228
},
2329
rounding: {
2430
name: "Rounding",
31+
description: "The amount of corner rounding for a swatch.",
32+
defaultValue: "regular",
2533
type: { name: "string" },
2634
table: {
2735
type: { summary: "string", required: true },
2836
category: "Component",
37+
defaultValue: { summary: "regular", },
2938
},
3039
options: ["none", "regular", "full"],
3140
control: "select",
3241
},
3342
isDisabled,
3443
isSelected,
44+
borderStyle: {
45+
name: "Border style",
46+
type: { name: "string" },
47+
table: {
48+
type: { summary: "string", required: true },
49+
category: "Component",
50+
},
51+
options: ["default", "none", "light"],
52+
control: "select",
53+
},
54+
shape: {
55+
name: "Swatch shape",
56+
description: "Swatches can have a square or rectangle shape.",
57+
defaultValue: "square",
58+
type: { name: "string" },
59+
table: {
60+
type: { summary: "string" },
61+
category: "Component",
62+
defaultValue: { summary: "square", },
63+
},
64+
options: ["square", "rectangle"],
65+
control: "inline-radio",
66+
},
67+
imageUrl: {
68+
name: "Image url",
69+
description: "The image preview within the swatch.",
70+
type: { name: "string" },
71+
table: {
72+
type: { summary: "string" },
73+
category: "Content",
74+
},
75+
control: { type: "file", accept: ".svg,.png,.jpg,.jpeg,.webc" },
76+
},
77+
gradient: {
78+
name: "Gradient",
79+
description: "The gradient preview within the swatch. Input a gradient example, such as <code>linear-gradient(red, blue)</code>.",
80+
type: { name: "string" },
81+
table: {
82+
type: { summary: "string" },
83+
category: "Component",
84+
},
85+
control: "text",
86+
},
87+
isMixedValue: {
88+
name: "Mixed value",
89+
description: "A swatch that represents multiple values that are not identical.",
90+
type: { name: "boolean" },
91+
table: {
92+
type: { summary: "boolean" },
93+
category: "Component",
94+
},
95+
control: "boolean",
96+
},
3597
},
3698
args: {
3799
rootClass: "spectrum-Swatch",
38100
size: "m",
39101
isSelected: false,
40102
isDisabled: false,
41103
rounding: "regular",
42-
swatchColor: "rgb(174, 216, 230)"
104+
swatchColor: "rgb(174, 216, 230)",
105+
borderStyle: "default",
106+
shape: "square",
107+
isMixedValue: false,
43108
},
44109
parameters: {
45110
packageJson: pkgJson,
46111
},
47112
};
48113

114+
/**
115+
* The medium size is the default and most frequently used option. By default, a swatch has a square shape.
116+
*/
49117
export const Default = SwatchGroup.bind({});
50118
Default.args = {};
51119

120+
// ********* DOCS ONLY ********* //
121+
/**
122+
* The medium size is the default. Use the other sizes sparingly; they should be used to create a hierarchy of importance within the page.
123+
*/
124+
export const Sizing = (args, context) => Sizes({
125+
Template: SizingGroup,
126+
withHeading: false,
127+
...args,
128+
}, context);
129+
Sizing.tags = ["!dev"];
130+
Sizing.parameters = {
131+
chromatic: { disableSnapshot: true },
132+
};
133+
134+
/**
135+
* A swatch in a disabled state shows that the swatch exists, but is not available in that circumstance. Even though swatches can have a disabled state, hide unavailable swatches when possible to reduce visual clutter and ease cognitive load. Only show disabled swatches if hiding them would cause confusion to your users.
136+
*/
137+
export const Disabled = (args, context) => Sizes({
138+
Template: DisabledGroup,
139+
withHeading: false,
140+
...args,
141+
}, context);
142+
Disabled.args = {
143+
isDisabled: true,
144+
};
145+
Disabled.tags = ["!dev"];
146+
Disabled.parameters = {
147+
chromatic: { disableSnapshot: true },
148+
};
149+
150+
/**
151+
* Default rounding and full rounding are usually used when a swatch is presented by itself near other components. A rounding of “none” is used in a swatch group to help minimize the Hermann grid illusion that happens at the intersections of white space in the group.
152+
*/
153+
export const Rounding = RoundingGroup.bind({});
154+
Rounding.tags = ["!dev"];
155+
Rounding.args = {
156+
swatchColor: "rgba(174, 216, 230, 0.25)",
157+
};
158+
Rounding.parameters = {
159+
chromatic: { disableSnapshot: true },
160+
};
161+
162+
/**
163+
* A swatch can have a selected state to allow for selection. This is often used in a [swatch group](?path=/docs/components-swatch-group--docs).
164+
*/
165+
export const Selected = Template.bind({});
166+
Selected.args = {
167+
isSelected: true,
168+
};
169+
Selected.tags = ["!dev"];
170+
Selected.parameters = {
171+
chromatic: { disableSnapshot: true },
172+
};
173+
174+
/**
175+
* By default, swatches have a border. However, when swatches are used within a swatch group, there are additional border considerations.
176+
* - When color swatches are used in a [swatch group](?path=/docs/components-swatch-group--docs), they typically have the `.spectrum-Swatch--noBorder` class.
177+
* - When and only when color swatches used in a swatch group have low contrast (below 3:1 contrast with the background), those swatches will have a less prominent border compared to the swatch component when used by itself. They individually use the `.spectrum-Swatch--lightBorder` class.
178+
*/
179+
export const Border = BorderGroup.bind({});
180+
Border.tags = ["!dev"];
181+
Border.parameters = {
182+
chromatic: { disableSnapshot: true },
183+
};
184+
185+
/**
186+
* Swatches can also have a rectangle shape with an aspect ratio of 2:1. The square shape is the default and is used in swatch groups (e.g., a palette of colors).
187+
*/
188+
export const Shape = Template.bind({});
189+
Shape.args = {
190+
shape: "rectangle",
191+
swatchColor: "rgba(174, 216, 230, 0.25)",
192+
};
193+
Shape.tags = ["!dev"];
194+
Shape.parameters = {
195+
chromatic: { disableSnapshot: true },
196+
};
197+
Shape.storyName = "Shape - rectangle";
198+
199+
/**
200+
* A swatch will appear "empty" when its preview is undefined, for instance when the image or gradient is undefined, or when a swatch color is transparent. The `.is-nothing` class is applied to the swatch in these cases. Implementations should ensure that the default border style is applied when a swatch is empty.
201+
*/
202+
export const Empty = (args, context) => Sizes({
203+
Template: EmptyGroup,
204+
withHeading: false,
205+
...args,
206+
}, context);
207+
Empty.args = {
208+
swatchColor: "transparent",
209+
};
210+
Empty.tags = ["!dev"];
211+
Empty.parameters = {
212+
chromatic: { disableSnapshot: true },
213+
};
214+
215+
/**
216+
* When a swatch represents multiple values that are not identical, the preview shows a `gray-50` fill and a dash UI icon.
217+
*/
218+
export const MixedValue = Template.bind({});
219+
MixedValue.args = {
220+
isMixedValue: true,
221+
};
222+
MixedValue.tags = ["!dev"];
223+
MixedValue.parameters = {
224+
chromatic: { disableSnapshot: true },
225+
};
226+
227+
export const Gradient = Template.bind({});
228+
Gradient.args = {
229+
gradient: "linear-gradient(to right, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%)",
230+
};
231+
Gradient.tags = ["!dev"];
232+
Gradient.parameters = {
233+
chromatic: { disableSnapshot: true },
234+
};
235+
236+
export const Image = Template.bind({});
237+
Image.args = {
238+
imageUrl: "example-ava@2x.png",
239+
};
240+
Image.tags = ["!dev"];
241+
Image.parameters = {
242+
chromatic: { disableSnapshot: true },
243+
};
244+
52245
// ********* VRT ONLY ********* //
53246
export const WithForcedColors = SwatchGroup.bind({});
54247
WithForcedColors.tags = ["!autodocs", "!dev"];

components/swatch/stories/swatch.test.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,45 @@ export const SwatchGroup = Variants({
1919
testHeading: "Full rounding",
2020
rounding: "full"
2121
},
22+
{
23+
testHeading: "Light border",
24+
borderStyle: "lightBorder",
25+
},
26+
{
27+
testHeading: "No border",
28+
borderStyle: "noBorder",
29+
rounding: "none",
30+
},
31+
{
32+
testHeading: "Shape: rectangle",
33+
shape: "rectangle",
34+
},
35+
{
36+
testHeading: "Gradient",
37+
gradient: "linear-gradient(to right, rgba(0, 0, 0, 88%), rgb(174, 216, 230))",
38+
swatchColor: "rgba(174, 216, 230, 0.3)",
39+
},
40+
{
41+
testHeading: "Image",
42+
imageUrl: "example-ava@2x.png",
43+
},
44+
{
45+
testHeading: "Mixed value",
46+
isMixedValue: true,
47+
},
2248
],
2349
stateData: [
2450
{
25-
testHeading: "No color",
26-
swatchColor: undefined
51+
testHeading: "Disabled",
52+
isDisabled: true,
53+
},
54+
{
55+
testHeading: "No color/empty",
56+
swatchColor: undefined,
57+
imageUrl: "",
58+
gradient: "",
59+
isMixedValue: false,
60+
borderStyle: "default",
2761
},
2862
{
2963
testHeading: "Selected",

0 commit comments

Comments
 (0)