Skip to content

Commit 992d7f9

Browse files
authored
Merge pull request #916 from bjarnef/feature/color-swatch-readonly
Feat: Readonly state for uui-color-swatch
2 parents eae3730 + c7d74bc commit 992d7f9

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@umbraco-ui/uui-base/lib/mixins';
1010

1111
/**
12-
* Color swatch, can have label and be selectable.
12+
* Color swatch, can have label and be selectable, disabled or readonly.
1313
*
1414
* @element uui-color-swatch
1515
* @cssprop --uui-swatch-size - The size of the swatch.
@@ -51,13 +51,23 @@ export class UUIColorSwatchElement extends LabelMixin(
5151
private _color?: string;
5252

5353
/**
54-
* Determines if the options is disabled. If true the option can't be selected
55-
*
54+
* Sets the swatch to disabled.
55+
* @type {boolean}
5656
* @attr
57+
* @default false
5758
*/
5859
@property({ type: Boolean, reflect: true })
5960
disabled = false;
6061

62+
/**
63+
* Sets the swatch to readonly mode.
64+
* @type {boolean}
65+
* @attr
66+
* @default false
67+
*/
68+
@property({ type: Boolean, reflect: true })
69+
readonly: boolean = false;
70+
6171
/**
6272
* When true shows element label below the color checkbox
6373
*
@@ -82,10 +92,13 @@ export class UUIColorSwatchElement extends LabelMixin(
8292
}
8393

8494
willUpdate(changedProperties: Map<string, any>) {
85-
if (changedProperties.has('disabled')) {
95+
if (
96+
changedProperties.has('disabled') ||
97+
changedProperties.has('readonly')
98+
) {
8699
if (this.selectable) {
87-
this.selectable = !this.disabled;
88-
this.deselectable = !this.disabled;
100+
this.selectable = !this.disabled && !this.readonly;
101+
this.deselectable = !this.disabled && !this.readonly;
89102
}
90103
}
91104
if (
@@ -101,7 +114,7 @@ export class UUIColorSwatchElement extends LabelMixin(
101114
<button
102115
id="swatch"
103116
aria-label=${this.label}
104-
aria-disabled="${this.disabled}"
117+
?disabled="${this.disabled}"
105118
title="${this.label}">
106119
<div class="color-swatch color-swatch--transparent-bg">
107120
<div
@@ -166,6 +179,10 @@ export class UUIColorSwatchElement extends LabelMixin(
166179
opacity: 0.5;
167180
}
168181
182+
:host([readonly]) {
183+
cursor: default;
184+
}
185+
169186
#swatch {
170187
cursor: inherit;
171188
outline: none;

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ export const InvalidValue: Story = {
4848
export const Disabled: Story = {
4949
args: {
5050
disabled: true,
51+
selectable: true,
52+
},
53+
parameters: {
54+
docs: {
55+
source: {
56+
code: `<uui-color-swatch disabled selectable></uui-color-swatch>`,
57+
},
58+
},
5159
},
5260
};
5361

@@ -58,7 +66,36 @@ export const DisabledSelected: Story = {
5866
},
5967
};
6068

61-
export const Label: Story = {
69+
export const Readonly: Story = {
70+
args: {
71+
readonly: true,
72+
selectable: true,
73+
},
74+
parameters: {
75+
docs: {
76+
source: {
77+
code: `<uui-color-swatch readonly selectable></uui-color-swatch>`,
78+
},
79+
},
80+
},
81+
};
82+
83+
export const ReadonlySelected: Story = {
84+
args: {
85+
readonly: true,
86+
selectable: true,
87+
selected: true,
88+
},
89+
parameters: {
90+
docs: {
91+
source: {
92+
code: `<uui-color-swatch readonly selectable selected></uui-color-swatch>`,
93+
},
94+
},
95+
},
96+
};
97+
98+
export const WithLabel: Story = {
6299
args: {
63100
label: 'Label',
64101
showLabel: true,

0 commit comments

Comments
 (0)