Skip to content

Commit ed24ed4

Browse files
authored
chore: swatch group storybook rendering fix (#2252)
1 parent a931f59 commit ed24ed4

File tree

16 files changed

+269
-360
lines changed

16 files changed

+269
-360
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ npm-debug.log*
1414
lerna-debug.log
1515
yarn-error.log
1616
package-lock.json
17+
.nx
1718

1819
# Storybook build output
1920
tools/preview/storybook-static

components/colorarea/stories/template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ export const Template = ({
3131
>
3232
<div
3333
class="spectrum-ColorArea-gradient"
34-
style="background: linear-gradient(to top, black 0%, rgba(0, 0, 0, 0) 100%), linear-gradient(to right, white 0%, rgba(0, 0, 0, 0) 100%), rgb(255, 0, 0);"
34+
style="background: linear-gradient(to top, black 0%, rgba(0, 0, 0, 0) 100%), linear-gradient(to right, white 0%, rgba(0, 0, 0, 0) 100%), rgba(255, 0, 0);"
3535
></div>
3636
${ColorHandle({
3737
...globals,
3838
isDisabled,
3939
customClasses: [`${rootClass}-handle`],
40-
colorHandleStyle: {
40+
customStyles: {
4141
"--spectrum-picked-color": "rgba(255, 0, 0)",
4242
transfom: `translate(${customWidth}, 0px)`,
4343
},

components/colorhandle/stories/colorhandle.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
title: "Components/Color handle",
66
description:
77
"The Color Handle component is used with ColorArea, ColorSlider and ColorWheel as the color selector",
8-
component: "Colorhandle",
8+
component: "ColorHandle",
99
argTypes: {
1010
isDisabled: {
1111
name: "Disabled",
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { html } from "lit";
21
import { Template as OpacityCheckerboard } from "@spectrum-css/opacitycheckerboard/stories/template.js";
2+
import { html } from "lit";
33

44
import "../index.css";
55

@@ -8,24 +8,18 @@ export const Template = ({
88
customClasses = [],
99
isDisabled = false,
1010
isFocused = false,
11-
colorHandleStyle = {
11+
customStyles = {
1212
"--spectrum-picked-color": "rgba(255, 0, 0, 0.5)",
1313
},
1414
...globals
15-
}) => {
16-
const checkerboardContent = html `<div class="${rootClass}-inner"></div>`
17-
18-
return html`
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-
}
15+
}) => OpacityCheckerboard({
16+
...globals,
17+
customClasses: [
18+
`${rootClass}`,
19+
...!isDisabled && isFocused ? ["is-focused"] : [],
20+
...isDisabled ? ["is-disabled"] : [],
21+
...customClasses,
22+
],
23+
content: [html `<div class="${rootClass}-inner"></div>`],
24+
customStyles,
25+
});

components/colorslider/stories/colorslider.stories.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
"The Color slider component lets users visually change an individual channel of a color.",
88
component: "ColorSlider",
99
argTypes: {
10+
colorHandleStyle: { table: { disable: true } },
1011
vertical: { table: { disable: true } },
1112
isDisabled: {
1213
name: "Disabled",
@@ -28,14 +29,14 @@ export default {
2829
if: { arg: "isDisabled", truthy: false },
2930
},
3031
gradientStops: {
31-
name: "Gradient Stops",
32+
name: "Gradient stops",
3233
description:
3334
"The <linear-color-stop> value of the CSS linear-gradient. Can be multiple stops separated by commas.",
34-
type: { name: "string" },
35+
type: { name: "array" },
3536
table: { disable: true },
3637
},
3738
gradientType: {
38-
name: "Gradient Type",
39+
name: "Gradient type",
3940
description: "The gradient can be defined in the markup using CSS or with an image.",
4041
options: ['gradient', 'image'],
4142
control: { type: 'select' },
@@ -47,8 +48,9 @@ export default {
4748
isDisabled: false,
4849
isFocused: false,
4950
gradientType: "gradient",
51+
vertical: false,
5052
gradientStops:
51-
"rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0)",
53+
["rgb(255, 0, 0) 0%", "rgb(255, 255, 0) 17%", "rgb(0, 255, 0) 33%", "rgb(0, 255, 255) 50%", "rgb(0, 0, 255) 67%", "rgb(255, 0, 255) 83%", "rgb(255, 0, 0) 100%"],
5254
},
5355
parameters: {
5456
actions: {
@@ -72,7 +74,7 @@ Vertical.args = {
7274

7375
export const Alpha = Template.bind({});
7476
Alpha.args = {
75-
gradientStops: "rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%",
77+
gradientStops: ["rgba(0, 0, 0, 1) 0%", "rgba(0, 0, 0, 0) 100%"],
7678
colorHandleStyle: {
7779
"--spectrum-picked-color": "rgba(0, 0, 0, 1)",
7880
},
@@ -91,4 +93,4 @@ WithImage.storyName = "Image";
9193
export const Disabled = Template.bind({});
9294
Disabled.args = {
9395
isDisabled: true,
94-
};
96+
};
Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { html } from "lit";
22
import { classMap } from "lit/directives/class-map.js";
3+
import { styleMap } from "lit/directives/style-map.js";
4+
import { when } from "lit/directives/when.js";
35

46
import { Template as ColorHandle } from "@spectrum-css/colorhandle/stories/template.js";
57
import { Template as OpacityCheckerboard } from "@spectrum-css/opacitycheckerboard/stories/template.js";
@@ -11,59 +13,63 @@ export const Template = ({
1113
customClasses = [],
1214
isDisabled = false,
1315
isFocused = false,
14-
vertical,
15-
gradientStops,
16-
gradientType,
16+
vertical = false,
17+
gradientStops = [
18+
"rgb(255, 0, 0) 0%",
19+
"rgb(255, 255, 0) 17%",
20+
"rgb(0, 255, 0) 33%",
21+
"rgb(0, 255, 255) 50%",
22+
"rgb(0, 0, 255) 67%",
23+
"rgb(255, 0, 255) 83%",
24+
"rgb(255, 0, 0)"],
25+
gradientType = "gradient",
1726
colorHandleStyle = {
1827
"--spectrum-picked-color": "rgba(255, 0, 0)",
1928
},
2029
...globals
21-
}) => {
22-
const checkerboardContent = gradientType == "image"
23-
? html`
24-
<img
25-
class="spectrum-ColorSlider-gradient"
26-
role="presentation"
27-
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAAeCAIAAAAkbYJ/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyVpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQ4IDc5LjE2NDAzNiwgMjAxOS8wOC8xMy0wMTowNjo1NyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIDIxLjAgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RjNBMTBENzk4QkQzMTFFQThDOTdDN0QyNDNGMUNFMzAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RjNBMTBEN0E4QkQzMTFFQThDOTdDN0QyNDNGMUNFMzAiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpGM0ExMEQ3NzhCRDMxMUVBOEM5N0M3RDI0M0YxQ0UzMCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpGM0ExMEQ3ODhCRDMxMUVBOEM5N0M3RDI0M0YxQ0UzMCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PrmQ8p4AAADbSURBVHja7JFLDsMgDAWNc/9L9h7YiQ0Gou66rGaUWHxegDDN5SPiEm/Uo+3S3LPWIzEy2uqu1Vh1dy3q5TM/ks38yprJbGdXK38GdHwVs94sAtXNas9h/LIK2zE11jlHrI5ksa9a5r+mdJ3E8i+OveISurzCvldr3V/dp91XQLTPvWYdgbFCr/tcp81BqW/bzKxLkz2epxLzPWglS7Y1ERX4axCMYEAwIBgQDAgGBAOCEQwIBgQDggHBgGBAMIIBwYBgQDAgGBAMCAYEIxgQDAgGBAOC4RduAQYALiXYw9aNKvcAAAAASUVORK5CYII="
28-
>`
29-
: html`
30-
<div
31-
class="${rootClass}-gradient"
32-
role="presentation"
33-
style="background: linear-gradient(to ${vertical ? "bottom" : "right"}, ${gradientStops});"
34-
></div>`;
35-
36-
return html`
37-
<div
38-
class=${classMap({
39-
[rootClass]: true,
40-
[`${rootClass}--vertical`]: vertical,
41-
"is-disabled": isDisabled,
42-
"is-focused": isFocused,
43-
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
44-
})}
45-
>
46-
${OpacityCheckerboard({
47-
...globals,
48-
componentOnly: true,
49-
customClasses: [`${rootClass}-checkerboard`],
50-
content: checkerboardContent,
51-
role: 'presentation',
52-
})}
53-
${ColorHandle({
54-
...globals,
55-
isDisabled,
56-
isFocused,
57-
customClasses: [`${rootClass}-handle`],
58-
colorHandleStyle,
59-
})}
60-
<input
61-
type="range"
62-
class="${rootClass}-slider"
63-
min="0"
64-
max="100"
65-
step="1"
66-
/>
67-
</div>
68-
`;
69-
};
30+
}) => html`
31+
<div
32+
class=${classMap({
33+
[rootClass]: true,
34+
[`${rootClass}--vertical`]: vertical,
35+
"is-disabled": isDisabled,
36+
"is-focused": isFocused,
37+
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
38+
})}
39+
>
40+
${OpacityCheckerboard({
41+
...globals,
42+
customClasses: [`${rootClass}-checkerboard`],
43+
content: [
44+
when(gradientType === "image",
45+
() => html`<img
46+
class="${rootClass}-gradient"
47+
role="presentation"
48+
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAAeCAIAAAAkbYJ/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyVpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQ4IDc5LjE2NDAzNiwgMjAxOS8wOC8xMy0wMTowNjo1NyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIDIxLjAgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RjNBMTBENzk4QkQzMTFFQThDOTdDN0QyNDNGMUNFMzAiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RjNBMTBEN0E4QkQzMTFFQThDOTdDN0QyNDNGMUNFMzAiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpGM0ExMEQ3NzhCRDMxMUVBOEM5N0M3RDI0M0YxQ0UzMCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpGM0ExMEQ3ODhCRDMxMUVBOEM5N0M3RDI0M0YxQ0UzMCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PrmQ8p4AAADbSURBVHja7JFLDsMgDAWNc/9L9h7YiQ0Gou66rGaUWHxegDDN5SPiEm/Uo+3S3LPWIzEy2uqu1Vh1dy3q5TM/ks38yprJbGdXK38GdHwVs94sAtXNas9h/LIK2zE11jlHrI5ksa9a5r+mdJ3E8i+OveISurzCvldr3V/dp91XQLTPvWYdgbFCr/tcp81BqW/bzKxLkz2epxLzPWglS7Y1ERX4axCMYEAwIBgQDAgGBAOCEQwIBgQDggHBgGBAMIIBwYBgQDAgGBAMCAYEIxgQDAgGBAOC4RduAQYALiXYw9aNKvcAAAAASUVORK5CYII="
49+
>`,
50+
() => html`<div
51+
class="${rootClass}-gradient"
52+
role="presentation"
53+
style=${when(gradientStops && gradientStops.length, () => styleMap({
54+
background: `linear-gradient(to ${vertical ? "bottom" : "right"}, ${gradientStops.join(', ')})`,
55+
}))}
56+
></div>`
57+
)
58+
],
59+
role: 'presentation',
60+
})}
61+
${ColorHandle({
62+
...globals,
63+
isDisabled,
64+
isFocused,
65+
customClasses: [`${rootClass}-handle`],
66+
customStyles: colorHandleStyle,
67+
})}
68+
<input
69+
type="range"
70+
class="${rootClass}-slider"
71+
min="0"
72+
max="100"
73+
step="1"
74+
/>
75+
</div>`;

components/colorwheel/stories/template.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { Template as ColorHandle } from "@spectrum-css/colorhandle/stories/template.js";
12
import { html } from "lit";
23
import { classMap } from "lit/directives/class-map.js";
3-
import { Template as ColorHandle } from "@spectrum-css/colorhandle/stories/template.js";
44

55
import "../index.css";
66

@@ -35,11 +35,11 @@ export const Template = ({
3535
</div>
3636
</div>
3737
${ColorHandle({
38-
...globals,
39-
isDisabled,
40-
customClasses: [`${rootClass}-handle`],
41-
colorHandleStyle,
42-
})}
38+
...globals,
39+
isDisabled,
40+
customClasses: [`${rootClass}-handle`],
41+
customStyles: colorHandleStyle,
42+
})}
4343
<input type="range" class="${rootClass}-slider" aria-label="hue" min="0" max="360" step="">
4444
</div>
4545
</div>
Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { html } from "lit";
2+
import { styleMap } from "lit/directives/style-map.js";
3+
4+
15
import { Template } from "./template";
26

37
export default {
@@ -6,23 +10,6 @@ export default {
610
"Opacity checkerboard is used with other components to highlight opacity.",
711
component: "OpacityCheckerboard",
812
argTypes: {
9-
hasColorOverlay: {
10-
name: "Has Color Overlay",
11-
type: { name: "boolean" },
12-
table: {
13-
category: "Component",
14-
},
15-
control: "boolean",
16-
},
17-
overlayColor: {
18-
name: "Overlay Color",
19-
type: { name: "string" },
20-
table: {
21-
category: "Component",
22-
},
23-
control: "text",
24-
if: { arg: "hasColorOverlay", truthy: true },
25-
},
2613
backgroundPosition: {
2714
name: "Position",
2815
type: { name: "string" },
@@ -32,21 +19,10 @@ export default {
3219
control: "text",
3320
description: "Value for <code>--mod-opacity-checkerboard-position</code>. Accepts any valid CSS background-position property value.",
3421
},
35-
componentOnly: {
36-
name: "Use Component Markup Only",
37-
type: { name: "boolean" },
38-
table: {
39-
disable: true,
40-
},
41-
},
4222
},
4323
args: {
4424
rootClass: "spectrum-OpacityCheckerboard",
45-
hasColorOverlay: false,
46-
overlayColor: "rgba(255, 0, 0, 0.5)",
47-
backgroundPosition: "top left",
48-
componentOnly: false,
49-
content: '',
25+
backgroundPosition: "top left"
5026
},
5127
parameters: {
5228
actions: {
@@ -58,6 +34,9 @@ export default {
5834
: undefined,
5935
},
6036
},
37+
decorators: [
38+
(Story, context) => html`<div style=${styleMap({ inlineSize: "100px", blockSize: "100px" })}>${Story(context)}</div>`
39+
],
6140
};
6241
export const Default = Template.bind({});
6342
Default.args = {};
@@ -73,4 +52,4 @@ CheckerboardPosition.parameters = {
7352
"An example of using the <code>--mod-opacity-checkerboard-position</code> custom property to adjust the position of the checkerboard pattern.",
7453
},
7554
},
76-
};
55+
};

0 commit comments

Comments
 (0)