@@ -2,7 +2,7 @@ import { Colord } from 'colord';
2
2
import { defineElement } from '@umbraco-ui/uui-base/lib/registration' ;
3
3
import { property } from 'lit/decorators.js' ;
4
4
import { classMap } from 'lit/directives/class-map.js' ;
5
- import { css , html , LitElement } from 'lit' ;
5
+ import { css , html , LitElement , nothing } from 'lit' ;
6
6
import { iconCheck } from '@umbraco-ui/uui-icon-registry-essential/lib/svgs' ;
7
7
8
8
import { styleMap } from 'lit/directives/style-map.js' ;
@@ -49,22 +49,36 @@ export class UUIColorSwatchElement extends LabelMixin(
49
49
outline: none;
50
50
}
51
51
52
- :host(:focus:not([disabled])) .color- swatch {
52
+ :host(:focus:not([disabled])) # swatch {
53
53
outline-color: var(--uui-color-focus);
54
54
outline-width: var(--uui-swatch-border-width, 1px);
55
55
outline-style: solid;
56
56
outline-offset: var(--uui-swatch-border-width, 1px);
57
57
}
58
58
59
- :host([selectable]) {
59
+ :host([selectable]) #swatch {
60
60
cursor: pointer;
61
61
}
62
62
63
63
:host([disabled]) {
64
64
cursor: not-allowed;
65
65
}
66
66
67
- :host([selectable]) .color-swatch::after {
67
+ #swatch {
68
+ outline: none;
69
+ background: none;
70
+ border: none;
71
+ padding: 0;
72
+ margin: 0;
73
+ text-align: left;
74
+ border-radius: 3px;
75
+ }
76
+
77
+ :host(:not([selectable])) #swatch:focus {
78
+ outline: none;
79
+ }
80
+
81
+ :host([selectable]) #swatch::after {
68
82
content: '';
69
83
position: absolute;
70
84
pointer-events: none;
@@ -80,13 +94,13 @@ export class UUIColorSwatchElement extends LabelMixin(
80
94
transition: opacity 100ms ease-out;
81
95
opacity: 0;
82
96
}
83
- :host([selectable]:not([disabled]):hover) .color- swatch::after {
97
+ :host([selectable]:not([disabled]):hover) # swatch::after {
84
98
opacity: 0.33;
85
99
}
86
- :host([selectable][selected]:not([disabled]):hover) .color- swatch::after {
100
+ :host([selectable][selected]:not([disabled]):hover) # swatch::after {
87
101
opacity: 0.66;
88
102
}
89
- :host([selectable][selected]:not([disabled])) .color- swatch::after {
103
+ :host([selectable][selected]:not([disabled])) # swatch::after {
90
104
opacity: 1;
91
105
}
92
106
@@ -96,6 +110,7 @@ export class UUIColorSwatchElement extends LabelMixin(
96
110
height: var(--uui-swatch-size, 25px);
97
111
border-radius: 3px;
98
112
display: flex;
113
+ flex-direction: column;
99
114
justify-content: center;
100
115
align-items: center;
101
116
}
@@ -119,6 +134,10 @@ export class UUIColorSwatchElement extends LabelMixin(
119
134
box-sizing: border-box;
120
135
}
121
136
137
+ .color-swatch--big .color-swatch__color {
138
+ border-radius: 3px 3px 0 0;
139
+ }
140
+
122
141
.color-swatch__check {
123
142
position: absolute;
124
143
vertical-align: middle;
@@ -143,6 +162,31 @@ export class UUIColorSwatchElement extends LabelMixin(
143
162
.label {
144
163
font-size: var(--uui-size-4);
145
164
}
165
+
166
+ .color-swatch--big {
167
+ width: 120px;
168
+ height: 50px;
169
+ }
170
+
171
+ .color-swatch__label {
172
+ max-width: 120px;
173
+ box-sizing: border-box;
174
+ padding: var(--uui-size-space-1) var(--uui-size-space-2);
175
+ line-height: 1.5;
176
+ display: flex;
177
+ flex-direction: column;
178
+ background: white;
179
+ border: 1px solid var(--uui-color-border);
180
+ border-radius: 0 0 3px 3px;
181
+ font-size: var(--uui-size-4, 12px);
182
+ }
183
+
184
+ .color-swatch__label strong {
185
+ overflow: hidden;
186
+ text-overflow: ellipsis;
187
+ white-space: nowrap;
188
+ box-sizing: border-box;
189
+ }
146
190
` ,
147
191
] ;
148
192
@@ -251,23 +295,35 @@ export class UUIColorSwatchElement extends LabelMixin(
251
295
252
296
render ( ) {
253
297
return html `
254
- < div
255
- class =${ classMap ( {
256
- 'color-swatch' : true ,
257
- 'color-swatch--transparent-bg' : true ,
258
- 'color-swatch--light' : this . isLight ,
259
- } ) }
260
- role ="button"
298
+ < button
299
+ id ="swatch "
261
300
aria-label =${ this . label }
262
- aria-disabled="${ this . disabled } ">
301
+ aria-disabled ="${ this . disabled } "
302
+ title="${ this . label } ">
263
303
< div
264
- class ="color-swatch__color "
265
- style =${ styleMap ( { backgroundColor : this . value } ) } > </ div >
266
- < div class ="color-swatch__check "> ${ iconCheck } </ div >
267
- </ div >
268
- ${ this . showLabel ? this . renderLabel ( ) : '' }
304
+ class =${ classMap ( {
305
+ 'color-swatch' : true ,
306
+ 'color-swatch--transparent-bg' : true ,
307
+ 'color-swatch--light' : this . isLight ,
308
+ 'color-swatch--big' : this . showLabel ,
309
+ } ) } >
310
+ < div
311
+ class ="color-swatch__color "
312
+ style =${ styleMap ( { backgroundColor : this . value } ) } > </ div >
313
+ < div class ="color-swatch__check "> ${ iconCheck } </ div >
314
+ </ div >
315
+ ${ this . _renderWithLabel ( ) }
316
+ </ button >
269
317
` ;
270
318
}
319
+
320
+ private _renderWithLabel ( ) {
321
+ if ( ! this . showLabel ) return nothing ;
322
+ return html `< div class ="color-swatch__label ">
323
+ < strong > ${ this . renderLabel ( ) } </ strong >
324
+ ${ this . value }
325
+ </ div > ` ;
326
+ }
271
327
}
272
328
273
329
declare global {
0 commit comments