Skip to content

Commit aa15fb6

Browse files
authored
feat: Adjust color slider with min and max (#1159)
1 parent 34e38d1 commit aa15fb6

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
121121
if (this.color) {
122122
const colord = new Colord(this.color);
123123
const { h, s, l } = colord.toHsl();
124+
const { r, g, b } = colord.toRgb();
124125

125126
const gradient =
126127
this.type === 'saturation'
@@ -129,7 +130,13 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
129130
? `linear-gradient(to ${this.vertical ? 'top' : 'right'}, hsl(${h}, ${s}%, 0%), hsl(${h}, ${s}%, 100%))`
130131
: null;
131132

133+
const hueColor =
134+
this.type === 'opacity'
135+
? `linear-gradient(to ${this.vertical ? 'top' : 'right'}, transparent 0%, rgba(${r}, ${g}, ${b}, ${this.max}%) 100%)`
136+
: null;
137+
132138
this.style.setProperty('--uui-slider-background-image', gradient);
139+
this.style.setProperty('--uui-slider-hue-color', hueColor);
133140
}
134141
}
135142
}
@@ -275,12 +282,7 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
275282
? html`<div
276283
id="current-hue"
277284
style=${styleMap({
278-
backgroundImage: `linear-gradient(to ${
279-
this.vertical ? 'top' : 'right'
280-
},
281-
transparent 0%,
282-
${this.color} 100%
283-
)`,
285+
backgroundImage: `var(--uui-slider-hue-color)`,
284286
})}></div>`
285287
: ''}
286288
<!-- <slot name="detail"> </slot> -->

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,35 @@ export const Readonly: Story = {
4949
},
5050
};
5151

52+
export const Hue: Story = {
53+
args: {
54+
type: 'hue',
55+
value: 180,
56+
},
57+
};
58+
5259
export const Opacity: Story = {
5360
args: {
5461
type: 'opacity',
5562
color: '#0075ff',
5663
},
5764
};
5865

59-
export const Vertical: Story = {
66+
export const OpacityMin50: Story = {
67+
args: {
68+
type: 'opacity',
69+
color: '#0075ff',
70+
min: 50,
71+
value: 75,
72+
},
73+
};
74+
75+
export const OpacityMax50: Story = {
6076
args: {
61-
vertical: true,
77+
type: 'opacity',
78+
color: '#0075ff',
79+
max: 50,
80+
value: 25,
6281
},
6382
};
6483

0 commit comments

Comments
 (0)