Skip to content

Commit

Permalink
fix(slider): reimplement gradient slider track application
Browse files Browse the repository at this point in the history
  • Loading branch information
Westbrook committed Feb 2, 2024
1 parent 47d7d71 commit a10b91e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
10 changes: 3 additions & 7 deletions packages/slider/src/Slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ export class Slider extends SizedMixin(ObserveSlotText(SliderHandle, ''), {
];
const trackItems = [
{ id: 'track0', html: this.renderTrackSegment(...segments[0]) },
{ id: 'fill', html: this.renderFillOffset() },
{ id: 'ramp', html: this.renderRamp() },
...segments.slice(1).map(([start, end], index) => ({
id: `track${index + 1}`,
html: this.renderTrackSegment(start, end),
})),
{ id: 'fill', html: this.renderFillOffset() },
];

return html`
Expand Down Expand Up @@ -501,12 +501,8 @@ export class Slider extends SizedMixin(ObserveSlotText(SliderHandle, ''), {
const size = end - start;
const styles: StyleInfo = {
width: `${size * 100}%`,
...(this.handleController.size > 1 && {
'--spectrum-slider-track-background-size': `${
(1 / size) * 100
}%`,
'--spectrum-slider-track-segment-position': `${start * 100}%`,
}),
'--spectrum-slider-track-background-size': `${(1 / size) * 100}%`,
'--spectrum-slider-track-segment-position': `${start * 100}%`,
};
return styles;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/slider/src/slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,7 @@ governing permissions and limitations under the License.
:host([label-visibility='none']) #track {
align-self: flex-end;
}

.fill {
z-index: 2;
}
20 changes: 16 additions & 4 deletions packages/slider/stories/slider.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,29 @@ hideStepper.decorators = [editableDecorator];

export const Gradient = (args: StoryArgs = {}): TemplateResult => {
return html`
<style>
sp-slider {
--mod-slider-track-color: linear-gradient(
to right,
red,
green 100%
);
}
sp-slider[dir='rtl'] {
--mod-slider-track-color: linear-gradient(
to left,
red,
green 100%
);
}
</style>
<div
style="
width: 500px;
margin: 12px 20px;
"
>
<sp-slider
style="
--spectrum-slider-track-color:linear-gradient(to right, red, green 100%);
--spectrum-slider-track-color-rtl:linear-gradient(to left, red, green 100%);
"
label="Opacity"
max="100"
min="0"
Expand Down

0 comments on commit a10b91e

Please sign in to comment.