Skip to content

Commit 4d296a4

Browse files
authored
Merge pull request #917 from bjarnef/feature/color-slider-readonly
Feat: Readonly state for uui-color-slider
2 parents 203487c + 870137b commit 4d296a4

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

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

+25-5
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,22 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
8484
@property() value = 0;
8585

8686
/**
87-
* Disables the color slider.
87+
* Sets the color slider to readonly mode.
88+
* @type {boolean}
89+
* @attr
90+
* @default false
91+
*/
92+
@property({ type: Boolean, reflect: true })
93+
readonly = false;
94+
95+
/**
96+
* Sets the color slider to disabled.
8897
* @type {boolean}
8998
* @attr
9099
* @default false
91100
**/
92-
@property({ type: Boolean, reflect: true }) disabled = false;
101+
@property({ type: Boolean, reflect: true })
102+
disabled = false;
93103

94104
private container!: HTMLElement;
95105
private handle!: HTMLElement;
@@ -115,7 +125,8 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
115125
}
116126

117127
handleDrag(event: PointerEvent) {
118-
if (this.disabled || !this.container || !this.handle) return;
128+
if (this.disabled || this.readonly || !this.container || !this.handle)
129+
return;
119130

120131
const { width, height } = this.container.getBoundingClientRect();
121132

@@ -140,7 +151,7 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
140151
}
141152

142153
handleClick(event: MouseEvent) {
143-
if (this.disabled) return;
154+
if (this.disabled || this.readonly) return;
144155

145156
this.value = this.getValueFromMousePosition(event);
146157
this.syncValues();
@@ -258,7 +269,8 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
258269
<span
259270
id="color-slider__handle"
260271
style="--current-value: ${this.cssPropCurrentValue}%;"
261-
tabindex=${ifDefined(this.disabled ? undefined : '0')}></span>
272+
tabindex=${ifDefined(this.disabled ? undefined : '0')}>
273+
</span>
262274
</div>
263275
${Math.round(this.value)}`;
264276
}
@@ -340,6 +352,14 @@ export class UUIColorSliderElement extends LabelMixin('label', LitElement) {
340352
opacity: 0.55;
341353
}
342354
355+
:host([readonly]) {
356+
cursor: default;
357+
}
358+
359+
:host([readonly]) #color-slider {
360+
pointer-events: none;
361+
}
362+
343363
#color-slider__handle {
344364
position: absolute;
345365
top: calc(50% - var(--uui-slider-handle-size) / 2);

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,21 @@ export const Disabled: Story = {
5353
parameters: {
5454
docs: {
5555
source: {
56-
code: `<uui-color-slider label="Slider label" disabled="true"></uui-color-slider>`,
56+
code: `<uui-color-slider label="Slider label" disabled></uui-color-slider>`,
57+
},
58+
},
59+
},
60+
};
61+
62+
export const Readonly: Story = {
63+
args: {
64+
readonly: true,
65+
value: 50,
66+
},
67+
parameters: {
68+
docs: {
69+
source: {
70+
code: `<uui-color-slider label="Slider label" readonly></uui-color-slider>`,
5771
},
5872
},
5973
},

0 commit comments

Comments
 (0)