Skip to content

Commit 597c65b

Browse files
refactor(swatch): adds missing template elements
- corrects the misuse of `is-image` in favor of `spectrum-Swatch-image` - correctly adds `is-image` when the swatch represents mixed values
1 parent 17359b2 commit 597c65b

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

components/swatch/stories/swatch.stories.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Nothing.args = {};
204204
Nothing.tags = ["autodocs", "!dev"];
205205

206206
/**
207-
* When a swatch represents multiple values that are not identical, the preview shows a gray-50 fill and a dash UI icon.
207+
* When a swatch represents multiple values that are not identical, the preview shows a `gray-50` fill and a dash UI icon.
208208
*/
209209
export const MixedValue = Template.bind({});
210210
MixedValue.args = {

components/swatch/stories/template.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { classMap } from "lit/directives/class-map.js";
66
import { ifDefined } from "lit/directives/if-defined.js";
77
import { styleMap } from "lit/directives/style-map.js";
88
import { capitalize, lowerCase } from "lodash-es";
9+
import { when } from "lit/directives/when.js";
910

1011
import "../index.css";
1112

@@ -41,7 +42,7 @@ export const Template = ({
4142
[`${rootClass}--${withBorder}`]: typeof withBorder !== "undefined" && withBorder !== "default",
4243
"is-selected": !isDisabled && isSelected,
4344
"is-disabled": isDisabled,
44-
"is-image": (isImage || isGradient)
45+
"is-image": (isImage || isGradient || isMixedValue)
4546
&& (typeof gradient !== "undefined" || gradient !== "transparent" || imageUrl !== "undefined"),
4647
"is-mixedValue": !isDisabled && isMixedValue,
4748
[`${rootClass}--rectangle`]: typeof isRectangle !== "undefined" && isRectangle !== false,
@@ -52,8 +53,6 @@ export const Template = ({
5253
id=${ifDefined(id)}
5354
style=${ifDefined(styleMap({
5455
"--spectrum-picked-color": swatchColor,
55-
"--spectrum-gradient": gradient,
56-
"--spectrum-background": `url(${imageUrl})`,
5756
...customStyles,
5857
}))}
5958
tabindex="0"
@@ -68,22 +67,39 @@ export const Template = ({
6867
updateArgs({ isSelected: !isSelected });
6968
}}
7069
>
71-
${OpacityCheckerboard({
72-
customClasses: [`${rootClass}-fill`],
73-
content: [
74-
...(isDisabled ? [Icon({
75-
customClasses: [`${rootClass}-disabledIcon`],
76-
setName: "workflow",
77-
iconName: "Cancel",
78-
}, context)] : []),
79-
...(isMixedValue ? [Icon({
80-
customClasses: [`${rootClass}-mixedValueIcon`],
81-
setName: "ui",
82-
iconName: "Dash",
83-
}, context)] : []),
84-
]
85-
}, context)}
86-
</div>
70+
${when(isImage || isGradient, () => html`
71+
${when(isImage, () => html`
72+
<div class="${rootClass}-fill" >
73+
<img src="${imageUrl}" alt="" class="${rootClass}-image" />
74+
</div>
75+
`,
76+
() => html`
77+
${OpacityCheckerboard({
78+
customClasses: [`${rootClass}-fill`],
79+
content: [
80+
html`<div class='spectrum-Swatch-image' style='background: ${ifDefined(gradient)}'></div>`
81+
],
82+
}, context)}
83+
`
84+
)}`,
85+
() => html`
86+
${OpacityCheckerboard({
87+
customClasses: [`${rootClass}-fill`],
88+
content: [
89+
...(isDisabled ? [Icon({
90+
customClasses: [`${rootClass}-disabledIcon`],
91+
setName: "workflow",
92+
iconName: "Cancel",
93+
}, context)] : []),
94+
...(isMixedValue ? [Icon({
95+
customClasses: [`${rootClass}-mixedValueIcon`],
96+
setName: "ui",
97+
iconName: "Dash",
98+
}, context)] : []),
99+
]
100+
})}
101+
`
102+
)}
87103
`;
88104
};
89105

0 commit comments

Comments
 (0)