From bd19c13797fa81b2a893af2c0ecf461be12eed57 Mon Sep 17 00:00:00 2001 From: Bjarne Fyrstenborg Date: Sun, 22 Sep 2024 13:09:02 +0200 Subject: [PATCH] Add readonly for color swatch component --- .../lib/uui-color-swatch.element.ts | 30 ++++++++++++++---- .../lib/uui-color-swatch.story.ts | 31 ++++++++++++++++++- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/packages/uui-color-swatch/lib/uui-color-swatch.element.ts b/packages/uui-color-swatch/lib/uui-color-swatch.element.ts index fa527b0f1..55b1674a4 100644 --- a/packages/uui-color-swatch/lib/uui-color-swatch.element.ts +++ b/packages/uui-color-swatch/lib/uui-color-swatch.element.ts @@ -51,13 +51,23 @@ export class UUIColorSwatchElement extends LabelMixin( private _color?: string; /** - * Determines if the options is disabled. If true the option can't be selected - * + * Sets the swatch to disabled. + * @type {boolean} * @attr + * @default false */ @property({ type: Boolean, reflect: true }) disabled = false; + /** + * Sets the swatch to readonly mode. + * @type {boolean} + * @attr + * @default false + */ + @property({ type: Boolean, reflect: true }) + readonly = false; + /** * When true shows element label below the color checkbox * @@ -82,10 +92,13 @@ export class UUIColorSwatchElement extends LabelMixin( } willUpdate(changedProperties: Map) { - if (changedProperties.has('disabled')) { + if ( + changedProperties.has('disabled') || + changedProperties.has('readonly') + ) { if (this.selectable) { - this.selectable = !this.disabled; - this.deselectable = !this.disabled; + this.selectable = !this.disabled && !this.readonly; + this.deselectable = !this.disabled && !this.readonly; } } if ( @@ -101,7 +114,8 @@ export class UUIColorSwatchElement extends LabelMixin(