Skip to content

Commit 3504363

Browse files
authored
fix: Don't render swatches in color picker for empty array (#1116)
2 parents 9c528f0 + a6778a6 commit 3504363

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
530530
}
531531

532532
private _renderSwatches() {
533-
if (!this.swatches) return nothing;
533+
if (!this.swatches?.length) return nothing;
534534
return html`<uui-color-swatches
535535
id="swatches"
536536
class="color-picker__swatches"

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ import '@umbraco-ui/uui-popover-container/lib';
1717
const formats = ['hex', 'rgb', 'hsl', 'hsv'];
1818
const sizes = ['small', 'medium', 'large'];
1919

20+
const swatchesTransparent = [
21+
'rgba(208, 2, 27, 0.5)',
22+
'rgba(245, 166, 35, 0.5)',
23+
'rgba(248, 231, 28, 0.5)',
24+
'rgba(139, 87, 42, 0.5)',
25+
'rgba(126, 211, 33, 0.5)',
26+
'rgba(65, 117, 5, 0.5)',
27+
'rgba(189, 16, 224, 0.5)',
28+
'rgba(144, 19, 254, 0.5)',
29+
'rgba(74, 144, 226, 0.5)',
30+
'rgba(80, 227, 194, 0.5)',
31+
'rgba(184, 233, 134, 0.5)',
32+
'rgba(0, 0, 0, 0.5)',
33+
'rgba(68, 68, 68, 0.5)',
34+
'rgba(136, 136, 136, 0.5)',
35+
'rgba(204, 204, 204, 0.5)',
36+
'rgba(255, 255, 255, 0.5)',
37+
];
38+
2039
const meta: Meta = {
2140
id: 'uui-color-picker',
2241
component: 'uui-color-picker',
@@ -83,3 +102,16 @@ export const Readonly: Story = {
83102
readonly: true,
84103
},
85104
};
105+
106+
export const NoSwatches: Story = {
107+
args: {
108+
swatches: [],
109+
},
110+
};
111+
112+
export const TransparentSwatches: Story = {
113+
args: {
114+
opacity: true,
115+
swatches: swatchesTransparent,
116+
},
117+
};

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,9 @@ export const Gradient: Story = {
122122
value: 'lemon-twist',
123123
},
124124
};
125+
126+
export const NoSwatches: Story = {
127+
args: {
128+
swatches: [],
129+
},
130+
};

0 commit comments

Comments
 (0)