Skip to content

Commit a1411f6

Browse files
jenndiazjawinnpfulton
authored
fix(opacitycheckboard): add to component stories (#2056)
* feat(opacitycheckerboard): modify stories for use in components - Modify storybook template so that it can be imported and used by other components' stories. Allow passing in content, and excluding the storybook testing wrapper markup. - Moves defaultValue to args, as that syntax has been deprecated in newer versions of Storybook: https://storybook.js.org/docs/react/api/arg-types#defaultvalue - Adds a new story with a centered background position mod, and clarifies that the arg is changing the mod. * chore(colorhandle): add checkerboard to story * chore(swatch): add checkerboard to story * chore(thumbnail): add opacity checkerboard to stories * fix(opacitycheckerboard): capitalization * fix: resolve some chromatic differences Colorhandle had lost some of the classes being passed to it. They needed to be passed down to the new OpacityCheckerboard story template. --------- Co-authored-by: Josh Winn <965114+jawinn@users.noreply.github.com> Co-authored-by: Patrick Fulton <360251+pfulton@users.noreply.github.com>
1 parent 2a0d3c8 commit a1411f6

File tree

7 files changed

+168
-88
lines changed

7 files changed

+168
-88
lines changed
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { html } from "lit";
2-
import { classMap } from "lit/directives/class-map.js";
3-
import { styleMap } from "lit/directives/style-map.js";
2+
import { Template as OpacityCheckerboard } from "@spectrum-css/opacitycheckerboard/stories/template.js";
43

54
import "../index.css";
65

@@ -12,18 +11,21 @@ export const Template = ({
1211
colorHandleStyle = {
1312
"--spectrum-picked-color": "rgba(255, 0, 0, 0.5)",
1413
},
15-
// ...globals
14+
...globals
1615
}) => {
16+
const checkerboardContent = html `<div class="${rootClass}-inner"></div>`
17+
1718
return html`
18-
<div class=${classMap({
19-
[rootClass]: true,
20-
"is-disabled": isDisabled,
21-
"is-focused": !isDisabled && isFocused,
22-
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
23-
})}
24-
style=${styleMap(colorHandleStyle)}>
25-
<div class="${rootClass}-inner"></div>
26-
</div>
27-
</div>
28-
`;
29-
};
19+
${OpacityCheckerboard({
20+
...globals,
21+
componentOnly: true,
22+
customClasses: [
23+
`${rootClass}`,
24+
...!isDisabled && isFocused ? ["is-focused"] : [],
25+
...isDisabled ? ["is-disabled"] : [],
26+
...customClasses,
27+
],
28+
content: checkerboardContent,
29+
checkerBoardStyles: colorHandleStyle,
30+
})}`
31+
}

components/opacitycheckerboard/stories/opacitycheckerboard.stories.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Template } from "./template";
22

33
export default {
4-
title: "Components/Opacity Checkerboard",
4+
title: "Components/Opacity checkerboard",
55
description:
66
"Opacity checkerboard is used with other components to highlight opacity.",
77
component: "OpacityCheckerboard",
88
argTypes: {
99
hasColorOverlay: {
1010
name: "Has Color Overlay",
1111
type: { name: "boolean" },
12-
defaultValue: false,
1312
table: {
1413
category: "Component",
1514
},
@@ -18,7 +17,6 @@ export default {
1817
overlayColor: {
1918
name: "Overlay Color",
2019
type: { name: "string" },
21-
defaultValue: "rgba(255, 0, 0, 0.5)",
2220
table: {
2321
category: "Component",
2422
},
@@ -28,16 +26,27 @@ export default {
2826
backgroundPosition: {
2927
name: "Position",
3028
type: { name: "string" },
31-
defaultValue: "top left",
3229
table: {
3330
category: "Component",
3431
},
3532
control: "text",
36-
description: "Accepts any valid CSS background-position property value",
33+
description: "Value for <code>--mod-opacity-checkerboard-position</code>. Accepts any valid CSS background-position property value.",
34+
},
35+
componentOnly: {
36+
name: "Use Component Markup Only",
37+
type: { name: "boolean" },
38+
table: {
39+
disable: true,
40+
},
3741
},
3842
},
3943
args: {
4044
rootClass: "spectrum-OpacityCheckerboard",
45+
hasColorOverlay: false,
46+
overlayColor: "rgba(255, 0, 0, 0.5)",
47+
backgroundPosition: "top left",
48+
componentOnly: false,
49+
content: '',
4150
},
4251
parameters: {
4352
actions: {
@@ -52,3 +61,16 @@ export default {
5261
};
5362
export const Default = Template.bind({});
5463
Default.args = {};
64+
65+
export const CheckerboardPosition = Template.bind({});
66+
CheckerboardPosition.args = {
67+
backgroundPosition: 'center center',
68+
};
69+
CheckerboardPosition.parameters = {
70+
docs: {
71+
description: {
72+
story:
73+
"An example of using the <code>--mod-opacity-checkerboard-position</code> custom property to adjust the position of the checkerboard pattern.",
74+
},
75+
},
76+
};

components/opacitycheckerboard/stories/template.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { html } from "lit-html";
22
import { classMap } from "lit-html/directives/class-map.js";
33
import { styleMap } from "lit-html/directives/style-map.js";
44
import { when } from "lit-html/directives/when.js";
5+
import { ifDefined } from "lit-html/directives/if-defined.js";
56

67
import "../index.css";
78

@@ -25,8 +26,25 @@ export const Template = ({
2526
position: "relative",
2627
"inset-block": "-100%",
2728
},
29+
componentOnly,
30+
content,
31+
role,
2832
...globals
2933
}) => {
34+
// Just the component markup. For use by other component's stories.
35+
if (componentOnly){
36+
return html`
37+
<div
38+
class=${classMap({
39+
[rootClass]: true,
40+
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
41+
})}
42+
style=${styleMap(checkerBoardStyles)}
43+
role=${ifDefined(role)}
44+
>${content}</div>`;
45+
}
46+
47+
// Component with wrapper for Storybook display, and a testing overlay.
3048
return html`
3149
<div style=${styleMap(containerStyles)}>
3250
<div
@@ -35,7 +53,8 @@ export const Template = ({
3553
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
3654
})}
3755
style=${styleMap(checkerBoardStyles)}
38-
></div>
56+
role=${ifDefined(role)}
57+
>${content}</div>
3958
${when(hasColorOverlay, () => {
4059
return html` <div style=${styleMap(colorStyles)}></div>`;
4160
})}

components/swatch/stories/swatch.stories.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ export default {
66
description:
77
"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.",
88
component: "Swatch",
9-
argTypes: {},
9+
argTypes: {
10+
size: {
11+
name: "Size",
12+
type: { name: "string", required: true },
13+
table: {
14+
type: { summary: "string" },
15+
category: "Component",
16+
},
17+
options: ["xs", "s", "m", "l",],
18+
control: "select",
19+
},
20+
styles: { table: { disable: true } },
21+
},
1022
args: {
1123
rootClass: "spectrum-Swatch",
1224
},
@@ -24,3 +36,8 @@ export default {
2436

2537
export const Default = Template.bind({});
2638
Default.args = {};
39+
40+
export const Transparent = Template.bind({});
41+
Transparent.args = {
42+
styles: {"--spectrum-picked-color": "rgba(174, 216, 230, 0.3)"},
43+
};

components/swatch/stories/template.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { html } from "lit";
22
import { classMap } from "lit/directives/class-map.js";
33
import { ifDefined } from "lit/directives/if-defined.js";
4-
4+
import { styleMap } from "lit/directives/style-map.js";
5+
import { Template as OpacityCheckerboard } from "@spectrum-css/opacitycheckerboard/stories/template.js";
56
import "../index.css";
67

78
export const Template = ({
89
rootClass = "spectrum-Swatch",
910
size = "m",
1011
customClasses = [],
12+
styles = {"--spectrum-picked-color": "rgb(174, 216, 230)"},
1113
id,
1214
...globals
1315
}) => {
@@ -29,10 +31,14 @@ export const Template = ({
2931
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
3032
})}
3133
id=${ifDefined(id)}
32-
style="--spectrum-picked-color: rgb(174, 216, 230)"
34+
style=${styleMap(styles)}
3335
tabindex="0"
3436
>
35-
<div class="${rootClass}-fill"></div>
37+
${OpacityCheckerboard({
38+
...globals,
39+
componentOnly: true,
40+
customClasses: [`${rootClass}-fill`],
41+
})}
3642
</div>
3743
`;
3844
};

0 commit comments

Comments
 (0)