Skip to content

Commit 2083a3b

Browse files
committed
Update slider gradient for saturation and lightness
1 parent 8567fb3 commit 2083a3b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/uui-color-slider/lib/uui-color-slider.element.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LitElement, html, css } from 'lit';
2+
import { Colord } from 'colord';
23
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
34
import { property } from 'lit/decorators.js';
45
import { styleMap } from 'lit/directives/style-map.js';
@@ -117,6 +118,20 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
117118
}
118119

119120
this.precision = this.precision ?? 1;
121+
122+
if (this.color) {
123+
const colord = new Colord(this.color);
124+
const { h, s, l } = colord.toHsl();
125+
126+
const gradient =
127+
this.type === 'saturation'
128+
? `linear-gradient(to ${this.vertical ? 'top' : 'right'}, hsl(${h}, 0%, ${l}%), hsl(${h}, 100%, ${l}%))`
129+
: this.type === 'lightness'
130+
? `linear-gradient(to ${this.vertical ? 'top' : 'right'}, hsl(${h}, ${s}%, 0%), hsl(${h}, ${s}%, 100%))`
131+
: null;
132+
133+
this.style.setProperty('--uui-slider-background-image', gradient);
134+
}
120135
}
121136
}
122137

packages/uui-color-slider/lib/uui-color-slider.story.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const meta: Meta = {
1818
title: 'Inputs/Color/Color Slider',
1919
argTypes: {
2020
type: {
21-
options: ['hue', 'opacity'],
21+
options: ['hue', 'opacity', 'saturation', 'lightness'],
2222
control: { type: 'select' },
2323
},
2424
},

0 commit comments

Comments
 (0)