Skip to content

Commit 89742f4

Browse files
committed
chore(swatch+swatchgroup): support interactive states for add swatch + story updates
1 parent 13e2ce7 commit 89742f4

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

components/swatch/dist/metadata.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
".spectrum-Swatch-fill:before",
2525
".spectrum-Swatch-icon",
2626
".spectrum-Swatch-image",
27+
".spectrum-Swatch.is-addSwatch",
2728
".spectrum-Swatch.is-addSwatch .spectrum-Swatch-fill",
2829
".spectrum-Swatch.is-addSwatch .spectrum-Swatch-icon",
30+
".spectrum-Swatch.is-addSwatch.is-keyboardFocused",
31+
".spectrum-Swatch.is-addSwatch:active",
32+
".spectrum-Swatch.is-addSwatch:focus-visible",
33+
".spectrum-Swatch.is-addSwatch:hover",
2934
".spectrum-Swatch.is-disabled",
3035
".spectrum-Swatch.is-disabled .spectrum-Swatch-disabledIcon",
3136
".spectrum-Swatch.is-image .spectrum-Swatch-fill:before",
37+
".spectrum-Swatch.is-mixedValue",
3238
".spectrum-Swatch.is-mixedValue .spectrum-Swatch-fill",
3339
".spectrum-Swatch.is-mixedValue .spectrum-Swatch-icon",
3440
".spectrum-Swatch.is-nothing .spectrum-Swatch-fill",
@@ -45,7 +51,12 @@
4551
".spectrum-Swatch[disabled] .spectrum-Swatch-disabledIcon"
4652
],
4753
"modifiers": [
54+
"--mod-add-button-background",
55+
"--mod-add-button-background-down",
56+
"--mod-add-button-background-hover",
57+
"--mod-add-button-background-keyboard-focus",
4858
"--mod-animation-duration-100",
59+
"--mod-mixed-button-background",
4960
"--mod-swatch-border-color",
5061
"--mod-swatch-border-color-light",
5162
"--mod-swatch-border-color-rgb",
@@ -97,16 +108,23 @@
97108
"--spectrum-swatch-slash-thickness-small"
98109
],
99110
"global": [
111+
"--spectrum-add-button-background",
112+
"--spectrum-add-button-background-down",
113+
"--spectrum-add-button-background-hover",
114+
"--spectrum-add-button-background-keyboard-focus",
100115
"--spectrum-animation-duration-100",
101116
"--spectrum-border-width-100",
102117
"--spectrum-border-width-200",
103118
"--spectrum-corner-radius-75",
104119
"--spectrum-focus-indicator-color",
105120
"--spectrum-focus-indicator-gap",
106121
"--spectrum-focus-indicator-thickness",
122+
"--spectrum-gray-100",
107123
"--spectrum-gray-1000",
124+
"--spectrum-gray-200",
108125
"--spectrum-gray-25",
109126
"--spectrum-gray-900-rgb",
127+
"--spectrum-mixed-button-background",
110128
"--spectrum-negative-visual-color",
111129
"--spectrum-neutral-content-color-default",
112130
"--spectrum-picked-color",

components/swatch/index.css

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
--spectrum-swatch-icon-color: var(--spectrum-neutral-content-color-default);
3636
--spectrum-swatch-slash-icon-color: var(--highcontrast-swatch-fill-foreground-color, var(--mod-swatch-slash-icon-color, var(--spectrum-negative-visual-color)));
3737
--spectrum-swatch-focus-indicator-color: var(--highcontrast-swatch-focus-indicator-color, var(--mod-swatch-focus-indicator-color, var(--spectrum-focus-indicator-color)));
38+
39+
--spectrum-mixed-button-background: var(--spectrum-gray-25);
40+
41+
--spectrum-add-button-background: var(--spectrum-gray-100);
42+
--spectrum-add-button-background-hover: var(--spectrum-gray-200);
43+
--spectrum-add-button-background-down: var(--spectrum-gray-200);
44+
--spectrum-add-button-background-keyboard-focus: var(--spectrum-gray-200);
3845
}
3946

4047
.spectrum-Swatch--sizeXS {
@@ -81,6 +88,41 @@
8188
border-radius: var(--spectrum-swatch-border-radius);
8289
}
8390

91+
&.is-mixedValue {
92+
--spectrum-picked-color: var(--mod-mixed-button-background, var(--spectrum-mixed-button-background));
93+
}
94+
95+
&.is-addSwatch {
96+
--spectrum-picked-color: var(--mod-add-button-background, var(--spectrum-add-button-background));
97+
98+
.spectrum-Swatch-fill {
99+
background: var(--spectrum-picked-color);
100+
}
101+
102+
&:hover {
103+
--spectrum-picked-color: var(--mod-add-button-background-hover, var(--spectrum-add-button-background-hover));
104+
}
105+
106+
&:active {
107+
--spectrum-picked-color: var(--mod-add-button-background-down, var(--spectrum-add-button-background-down));
108+
}
109+
110+
&:hover,
111+
&:active {
112+
cursor: pointer;
113+
}
114+
115+
&.is-keyboardFocused,
116+
&:focus-visible {
117+
--spectrum-picked-color: var(--mod-add-button-background-keyboard-focus, var(--spectrum-add-button-background-keyboard-focus));
118+
}
119+
120+
.spectrum-Swatch-icon {
121+
color: var(--spectrum-swatch-icon-color);
122+
display: block;
123+
}
124+
}
125+
84126
&.is-selected {
85127
background: var(--spectrum-swatch-inner-border-color-selected);
86128

@@ -113,8 +155,7 @@
113155
}
114156
}
115157

116-
&.is-mixedValue,
117-
&.is-addSwatch {
158+
&.is-mixedValue {
118159
.spectrum-Swatch-fill {
119160
background: var(--spectrum-picked-color, transparent);
120161
}

components/swatch/stories/template.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const Template = ({
2020
isAddSwatch = false,
2121
isSelected = false,
2222
isDisabled = false,
23+
isKeyboardFocused = false,
2324
rounding = "regular",
2425
customClasses = [],
2526
swatchColor,
@@ -37,6 +38,11 @@ export const Template = ({
3738
break;
3839
}
3940

41+
let pickedColor = swatchColor;
42+
43+
if (isMixedValue) pickedColor = "var(--spectrum-gray-25)";
44+
if (isAddSwatch) pickedColor = undefined;
45+
4046
return html`
4147
<div
4248
class=${classMap({
@@ -49,6 +55,7 @@ export const Template = ({
4955
[`${rootClass}--${borderStyle}`]: typeof borderStyle !== "undefined" && borderStyle !== "default",
5056
"is-selected": !isDisabled && isSelected,
5157
"is-disabled": isDisabled,
58+
"is-keyboardFocused": isKeyboardFocused,
5259
"is-image": (isMixedValue || isAddSwatch) || typeof imageUrl !== "undefined",
5360
"is-mixedValue": !isDisabled && isMixedValue,
5461
"is-addSwatch": !isDisabled && isAddSwatch,
@@ -59,7 +66,7 @@ export const Template = ({
5966
?disabled=${isDisabled}
6067
id=${ifDefined(id)}
6168
style=${ifDefined(styleMap({
62-
"--spectrum-picked-color": (isMixedValue || isAddSwatch) ? "var(--spectrum-gray-25)" : swatchColor,
69+
"--spectrum-picked-color": pickedColor,
6370
...customStyles,
6471
}))}
6572
tabindex="0"

0 commit comments

Comments
 (0)