Skip to content

Commit 871b7dd

Browse files
authored
feat(uui-color-picker): Add readonly for color picker component (#933)
1 parent e35daff commit 871b7dd

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
138138
@property({ type: Boolean, reflect: true }) inline = false;
139139

140140
/**
141-
* Disables the color picker.
141+
* Sets the color picker to disabled.
142142
* @attr
143143
* @type {boolean}
144144
* @default false
@@ -153,6 +153,14 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
153153
**/
154154
@property({ type: Boolean }) opacity = false;
155155

156+
/**
157+
* Sets the color picker to readonly mode.
158+
* @type {boolean}
159+
* @attr
160+
* @default false
161+
*/
162+
@property({ type: Boolean, reflect: true }) readonly = false;
163+
156164
/**
157165
* By default, the value will be set in lowercase. Set this to true to set it in uppercase instead.
158166
* @attr
@@ -433,6 +441,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
433441
.value="${this.value}"
434442
.hue="${Math.round(this.hue)}"
435443
?disabled=${this.disabled}
444+
?readonly=${this.readonly}
436445
@change=${this.handleGridChange}>
437446
</uui-color-area>
438447
<div class="color-picker__controls">
@@ -442,6 +451,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
442451
class="hue-slider"
443452
.value=${Math.round(this.hue)}
444453
?disabled=${this.disabled}
454+
?readonly=${this.readonly}
445455
@change=${this.handleHueChange}>
446456
</uui-color-slider>
447457
${this.opacity
@@ -457,6 +467,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
457467
this.lightness,
458468
)}
459469
?disabled=${this.disabled}
470+
?readonly=${this.readonly}
460471
@change=${this.handleAlphaChange}>
461472
</uui-color-slider>
462473
`
@@ -486,6 +497,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
486497
spellcheck="false"
487498
.value=${live(this.inputValue)}
488499
?disabled=${this.disabled}
500+
?readonly=${this.readonly}
489501
@keydown=${this.handleInputKeyDown}
490502
@change=${this.handleInputChange}>
491503
</uui-input>
@@ -503,7 +515,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
503515
${hasEyeDropper
504516
? html`<uui-button
505517
label="Select a color"
506-
?disabled=${this.disabled}
518+
?disabled=${this.disabled || this.readonly}
507519
@click=${this.handleEyeDropper}
508520
compact>
509521
<uui-icon-registry-essential>
@@ -525,6 +537,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
525537
class="color-picker__swatches"
526538
label="Swatches"
527539
?disabled=${this.disabled}
540+
?readonly=${this.readonly}
528541
@change=${this.handleColorSwatchChange}>
529542
${this.swatches.map(
530543
swatch =>

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export const Disabled: Story = {
5757
},
5858
};
5959

60+
export const Formats: Story = {
61+
args: {
62+
format: 'hex',
63+
inline: true,
64+
},
65+
};
66+
6067
export const Inline: Story = {
6168
args: {
6269
inline: true,
@@ -70,9 +77,8 @@ export const Opacity: Story = {
7077
},
7178
};
7279

73-
export const Formats: Story = {
80+
export const Readonly: Story = {
7481
args: {
75-
format: 'hex',
76-
inline: true,
82+
readonly: true,
7783
},
7884
};

0 commit comments

Comments
 (0)