Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(colorslider): S2 migration #3424

Merged
merged 13 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/serious-clouds-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@spectrum-css/colorslider": minor
---

# S2 colorslider migration

This migrates the `colorslider` component to S2. Custom properties have been remapped per the design spec.

| Before | After |
| ------------------------- | -------------------------- |
| `--spectrum-gray-900-rgb` | `--spectrum-gray-1000-rgb` |
4 changes: 3 additions & 1 deletion components/colorslider/dist/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
"--spectrum-color-slider-border-opacity",
"--spectrum-color-slider-border-rounding",
"--spectrum-color-slider-border-width",
"--spectrum-color-slider-control-track-width",
"--spectrum-color-slider-fill-color-disabled",
"--spectrum-color-slider-length",
"--spectrum-color-slider-minimum-length"
],
"global": [
"--spectrum-color-control-track-width",
"--spectrum-disabled-background-color",
"--spectrum-gray-900-rgb"
"--spectrum-gray-1000-rgb"
],
"passthroughs": ["--mod-colorhandle-hitarea-border-radius"],
"high-contrast": [
Expand Down
33 changes: 19 additions & 14 deletions components/colorslider/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,24 @@
* governing permissions and limitations under the License.
*/

@media (forced-colors: active) {
.spectrum-ColorSlider {
--highcontrast-color-slider-border-color: CanvasText;
--highcontrast-color-slider-border-color-disabled: GrayText;
--highcontrast-color-slider-background-color-disabled: Canvas;
forced-color-adjust: none;
}
}

.spectrum-ColorSlider {
/* Size and Spacing */
--spectrum-color-slider-control-track-width: var(--spectrum-color-control-track-width);

/* @todo Refactor with --spectrum-color-slider-border-color once gray rgb token is no longer necessary to workaround nested rgb color token value using rgba(). */
--spectrum-color-slider-border-color-default: rgba(var(--spectrum-gray-900-rgb), var(--spectrum-color-slider-border-opacity));
--spectrum-color-slider-border-color-default: rgba(var(--spectrum-gray-1000-rgb), var(--spectrum-color-slider-border-opacity));

/* @passthrough -- settings for nested color handle */
--mod-colorhandle-hitarea-border-radius: var(--mod-color-slider-handle-hitarea-border-radius, 0px);

--spectrum-color-slider-fill-color-disabled: var(--spectrum-disabled-background-color);

position: relative;
display: block;

min-inline-size: var(--mod-color-slider-minimum-length, var(--spectrum-color-slider-minimum-length));
inline-size: var(--mod-color-slider-length, var(--spectrum-color-slider-length));
block-size: var(--mod-color-slider-control-track-width, var(--spectrum-color-control-track-width));
block-size: var(--mod-color-slider-control-track-width, var(--spectrum-color-slider-control-track-width));

/* Otherwise we randomly drag a file icon */
user-select: none;
Expand All @@ -58,7 +54,7 @@
min-block-size: var(--mod-color-slider-vertical-minimum-height, var(--mod-color-slider-minimum-length, var(--spectrum-color-slider-minimum-length)));
block-size: var(--mod-color-slider-vertical-height, var(--mod-color-slider-length, var(--spectrum-color-slider-length)));
min-inline-size: 0;
inline-size: var(--mod-color-slider-vertical-control-track-width, var(--mod-color-slider-control-track-height, var(--spectrum-color-control-track-width)));
inline-size: var(--mod-color-slider-vertical-control-track-width, var(--mod-color-slider-control-track-height, var(--spectrum-color-slider-control-track-width)));

.spectrum-ColorSlider-handle {
inset-inline-start: 50%;
Expand All @@ -85,8 +81,8 @@
}

.spectrum-ColorSlider.is-disabled & {
--spectrum-color-slider-border-color-local: var(--highcontrast-color-slider-border-color-disabled, var(--mod-color-slider-border-color-disabled, var(--spectrum-disabled-background-color)));
background: var(--highcontrast-color-slider-background-color-disabled, var(--mod-color-slider-background-color-disabled, var(--spectrum-disabled-background-color)));
--spectrum-color-slider-border-color-local: var(--highcontrast-color-slider-border-color-disabled, var(--mod-color-slider-border-color-disabled, var(--spectrum-color-slider-fill-color-disabled)));
background: var(--highcontrast-color-slider-background-color-disabled, var(--mod-color-slider-background-color-disabled, var(--spectrum-color-slider-fill-color-disabled)));
}
}

Expand Down Expand Up @@ -114,3 +110,12 @@
margin: 0;
pointer-events: none;
}

@media (forced-colors: active) {
.spectrum-ColorSlider {
--highcontrast-color-slider-border-color: CanvasText;
--highcontrast-color-slider-border-color-disabled: GrayText;
--highcontrast-color-slider-background-color-disabled: Canvas;
forced-color-adjust: none;
}
}
37 changes: 24 additions & 13 deletions components/colorslider/stories/colorslider.stories.js
Copy link
Collaborator

@jawinn jawinn Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alpha

It looks like the Alpha story is still using the gradientStops arg that renamed, so it's not displaying correctly:
Screenshot 2025-01-17 at 3 53 30 PM
Prod:
Screenshot 2025-01-17 at 3 58 38 PM

Vertical

The Vertical story also still needs an update for its story in our docs, and the VRT tests file config. The gradient should be in the to bottom direction for these instances where we set the arg value, though we talked about not needing any complicated logic if someone is manually flipping the vertical control on the Default story:

Screenshot 2025-01-17 at 3 53 16 PM Screenshot 2025-01-17 at 3 54 08 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I renamed and updated that arg and updated the gradient direction in the tests you highlighted. ✨

Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ export default {
component: "ColorSlider",
argTypes: {
colorHandleStyle: { table: { disable: true } },
vertical: { table: { disable: true } },
isDisabled,
isFocused: {
...isFocused,
if: { arg: "isDisabled", truthy: false },
},
gradientStops: {
name: "Gradient stops",
color: {
name: "Color",
description:
"The <linear-color-stop> value of the CSS linear-gradient. Can be multiple stops separated by commas.",
type: { name: "array" },
table: { disable: true },
"Supports standard color input or any valid input for the <code>background</code> property such as, <code>linear-gradient(red, blue)</code>.",
type: { name: "string", required: true },
table: {
type: { summary: "string" },
},
control: "color",
},
selectedColor: {
name: "Selected color",
Expand All @@ -40,12 +42,19 @@ export default {
control: "color",
},
gradientType: {
name: "Gradient type",
description: "The gradient can be defined in the markup using CSS or with an image.",
options: ["gradient", "image"],
name: "Color type",
description:
"The color can be defined in the markup using CSS or with an image.",
options: ["color", "image"],
control: { type: "select" },
table: { disable: true },
},
vertical: {
name: "Vertical",
description: "The orientation of the component.",
type: { name: "boolean" },
control: "boolean",
},
Comment on lines +52 to +57
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooof, I'm still seeing that funny gradient when the vertical control is used:
image

I don't have ideas off the top of my head on how we handle this, since it would need to be one gradient for horizontal and another for vertical... although I'm sure we've run into a similar issue before... any thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked to @jawinn about this and the thinking at the time was that, since we've moved the color control to a string that the onus would then be on the user to change that direction. We could couple the two, I can investigate that a bit more and see what we'd need to do it. 😃

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine. We could add a little blurb in the Color control description about the gradient direction, maybe saying that the direction would need to be changed for the vertical variant. Not sure I feel strongly about that though, so I'll leave that up to you!

},
args: {
rootClass: "spectrum-ColorSlider",
Expand All @@ -70,8 +79,8 @@ export default {
*/
export const Default = ColorSliderGroup.bind({});
Default.args = {
gradientStops:
["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%"],
color:
"linear-gradient(to right, 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%)",
};

// ********* VRT ONLY ********* //
Expand All @@ -81,7 +90,7 @@ WithForcedColors.tags = ["!autodocs", "!dev"];
WithForcedColors.parameters = {
chromatic: {
forcedColors: "active",
modes: disableDefaultModes
modes: disableDefaultModes,
},
};

Expand All @@ -92,6 +101,8 @@ WithForcedColors.parameters = {
export const Vertical = Template.bind({});
Vertical.args = {
vertical: true,
color:
"linear-gradient(to bottom, 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%)",
};
Vertical.tags = ["!dev"];
Vertical.parameters = {
Expand All @@ -100,7 +111,7 @@ Vertical.parameters = {

export const Alpha = Template.bind({});
Alpha.args = {
gradientStops: ["rgba(0, 0, 0, 1) 0%", "rgba(0, 0, 0, 0) 100%"],
color: "linear-gradient(to right, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%)",
selectedColor: "rgba(0, 0, 0, 1)",
};
Alpha.tags = ["!dev"];
Expand Down
3 changes: 2 additions & 1 deletion components/colorslider/stories/colorslider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ export const ColorSliderGroup = Variants({
{
testHeading: "Vertical",
vertical: true,
color: "linear-gradient(to bottom, 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%)",
wrapperStyles: {
// Adjust for the indicator
"padding-block": "20px",
},
},
{
testHeading: "Alpha",
gradientStops: ["rgba(0, 0, 0, 1) 0%", "rgba(0, 0, 0, 0) 100%"],
color: "linear-gradient(to right, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%)",
selectedColor: "rgba(0, 0, 0, 1)",
wrapperStyles: {
// Adjust for the indicator
Expand Down
152 changes: 76 additions & 76 deletions components/colorslider/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,83 @@ import { when } from "lit/directives/when.js";

import "../index.css";

export const Template = ({
rootClass = "spectrum-ColorSlider",
customClasses = [],
customStyles = {},
isDisabled = false,
isFocused = false,
vertical = false,
gradientStops = [
"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)",
],
gradientType = "gradient",
selectedColor = "rgba(255, 0, 0, 1)",
colorHandleStyle = {},
} = {}, context = {}) => {
export const Template = (
{
rootClass = "spectrum-ColorSlider",
customClasses = [],
customStyles = {},
isDisabled = false,
isFocused = false,
vertical = false,
color = "linear-gradient(to right, 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%)",
gradientType = "gradient",
selectedColor = "rgba(255, 0, 0, 1)",
colorHandleStyle = {},
} = {},
context = {},
) => {
const { updateArgs } = context;

return html`
<div
class=${classMap({
[rootClass]: true,
[`${rootClass}--vertical`]: vertical,
"is-disabled": isDisabled,
"is-focused": isFocused,
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
})}
style=${styleMap(customStyles)}
@focusin=${function() {
updateArgs({ isFocused: true });
}}
@focusout=${function() {
updateArgs({ isFocused: false });
}}
>
${OpacityCheckerboard({
customClasses: [`${rootClass}-checkerboard`],
content: [
when(
gradientType === "image",
() => html`<img
class="${rootClass}-gradient"
role="presentation"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAAeCAIAAAAkbYJ/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyVpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdG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11jlHrI5ksa9a5r+mdJ3E8i+OveISurzCvldr3V/dp91XQLTPvWYdgbFCr/tcp81BqW/bzKxLkz2epxLzPWglS7Y1ERX4axCMYEAwIBgQDAgGBAOCEQwIBgQDggHBgGBAMIIBwYBgQDAgGBAMCAYEIxgQDAgGBAOC4RduAQYALiXYw9aNKvcAAAAASUVORK5CYII="
/>`,
() => html`<div
class="${rootClass}-gradient"
role="presentation"
style=${when(gradientStops && gradientStops.length, () =>
styleMap({
background: `linear-gradient(to ${
vertical ? "bottom" : "right"
}, ${gradientStops.join(", ")})`,
})
)}
></div>`
),
],
role: "presentation",
}, context)}
${ColorHandle({
isDisabled,
isFocused,
selectedColor,
customClasses: [`${rootClass}-handle`],
customStyles: colorHandleStyle,
}, context)}
<input
type="color"
value=${selectedColor}
class=${classMap({
[`${rootClass}-slider`]: true
})} />
</div>
`;
<div
class=${classMap({
[rootClass]: true,
[`${rootClass}--vertical`]: vertical,
"is-disabled": isDisabled,
"is-focused": isFocused,
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
})}
style=${styleMap(customStyles)}
@focusin=${function () {
updateArgs({ isFocused: true });
}}
@focusout=${function () {
updateArgs({ isFocused: false });
}}
>
${OpacityCheckerboard(
{
customClasses: [`${rootClass}-checkerboard`],
content: [
when(
gradientType === "image",
() =>
html`<img
class="${rootClass}-gradient"
role="presentation"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAAAeCAIAAAAkbYJ/AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyVpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQ4IDc5LjE2NDAzNiwgMjAx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cp81BqW/bzKxLkz2epxLzPWglS7Y1ERX4axCMYEAwIBgQDAgGBAOCEQwIBgQDggHBgGBAMIIBwYBgQDAgGBAMCAYEIxgQDAgGBAOC4RduAQYALiXYw9aNKvcAAAAASUVORK5CYII="
/>`,
() =>
html`<div
class="${rootClass}-gradient"
role="presentation"
style=${styleMap({
background: `${color}`,
})}
></div>`,
),
],
role: "presentation",
},
context,
)}
${ColorHandle(
{
isDisabled,
isFocused,
selectedColor,
customClasses: [`${rootClass}-handle`],
customStyles: colorHandleStyle,
},
context,
)}
<input
type="color"
value=${selectedColor}
class=${classMap({
[`${rootClass}-slider`]: true,
})}
/>
</div>
`;
};
Loading