Skip to content

Commit df8b8b0

Browse files
authored
feat: Allow color gradient in color swatch (#1074)
* Allow color gradient in color swatch * Add story
1 parent f18414d commit df8b8b0

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class UUIColorSwatchElement extends LabelMixin(
129129
<div class="color-swatch color-swatch--transparent-bg">
130130
<div
131131
class="color-swatch__color"
132-
style="background-color: var(--uui-swatch-color, ${this.color ??
132+
style="background: var(--uui-swatch-color, ${this.color ??
133133
this.value})"></div>
134134
<div
135135
class="color-swatch__check"

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,12 @@ export const Transparent: Story = {
114114
value: 'rgba(209, 2, 26, 0.4)',
115115
},
116116
};
117+
118+
export const Gradient: Story = {
119+
args: {
120+
value: 'sun',
121+
color: 'radial-gradient(orange, red)',
122+
label: 'Sun',
123+
showLabel: true,
124+
},
125+
};

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

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,57 @@ import type { Meta, StoryObj } from '@storybook/web-components';
55
import { spread } from '../../../storyhelpers';
66
import { repeat } from 'lit/directives/repeat.js';
77

8-
const swatchesColor = [
8+
const swatches = [
99
{ label: 'Blood Orange', value: '#d0021b' },
1010
{ label: 'Avocado', value: '#417505' },
1111
{ label: 'Tufts Blue', value: '#4a90e2' },
1212
];
1313

14+
const gradients = [
15+
{
16+
label: 'Vital Ocean',
17+
value: 'ocean',
18+
color:
19+
'linear-gradient(90deg,rgba(2, 0, 36, 1) 0%, rgba(9, 9, 121, 1) 35%, rgba(0, 212, 255, 1) 100%)',
20+
},
21+
{
22+
label: 'Disco Club',
23+
value: 'avocado',
24+
color:
25+
'radial-gradient(circle,rgba(63, 94, 251, 1) 0%, rgba(252, 70, 107, 1) 100%)',
26+
},
27+
{
28+
label: 'Deep Sunset',
29+
value: 'sunset',
30+
color:
31+
'linear-gradient(90deg,rgba(131, 58, 180, 1) 0%, rgba(253, 29, 29, 1) 50%, rgba(252, 176, 69, 1) 100%)',
32+
},
33+
{
34+
label: 'Bubble Gum',
35+
value: 'gum',
36+
color:
37+
'radial-gradient(circle,rgba(238, 174, 202, 1) 0%, rgba(148, 187, 233, 1) 100%)',
38+
},
39+
{
40+
label: 'Blue Lagoon',
41+
value: 'lagoon',
42+
color:
43+
'linear-gradient(90deg,rgba(67, 198, 172, 1) 0%, rgba(25, 22, 84, 1) 100%)',
44+
},
45+
{
46+
label: 'Lemon Twist',
47+
value: 'lemon-twist',
48+
color:
49+
'linear-gradient(90deg,rgba(60, 165, 92, 1) 0%, rgba(181, 172, 73, 1) 100%)',
50+
},
51+
];
52+
1453
const meta: Meta = {
1554
id: 'uui-color-swatches',
1655
component: 'uui-color-swatches',
1756
title: 'Inputs/Color/Color Swatches',
1857
args: {
19-
swatches: swatchesColor,
58+
swatches: swatches,
2059
},
2160
argTypes: {
2261
value: { control: { type: 'color' } },
@@ -26,14 +65,17 @@ const meta: Meta = {
2665
render: (args: any) => html`
2766
<uui-color-swatches
2867
${spread(args, ['swatches', 'showLabel'])}
29-
label="My color pallette">${repeat(args.swatches, (swatch: any) => {
68+
label="My color palette">${repeat(args.swatches, (swatch: any) => {
3069
const label = typeof swatch === 'string' ? swatch : swatch.label;
3170
const value = typeof swatch === 'string' ? swatch : swatch.value;
71+
const color = typeof swatch === 'string' ? swatch : swatch.color;
3272
return html`
3373
<uui-color-swatch
3474
label="${label}"
3575
.showLabel=${args.showLabel}
36-
.value=${value}></uui-color-swatch>`;
76+
.color="${color}"
77+
.value=${value}>
78+
</uui-color-swatch>`;
3779
})}
3880
</uui-color-swatches>
3981
`,
@@ -72,3 +114,11 @@ export const ShowLabel: Story = {
72114
showLabel: true,
73115
},
74116
};
117+
118+
export const Gradient: Story = {
119+
args: {
120+
swatches: gradients,
121+
showLabel: true,
122+
value: 'lemon-twist',
123+
},
124+
};

0 commit comments

Comments
 (0)