@@ -46,12 +46,13 @@ interface EyeDropperInterface {
46
46
open : ( ) => Promise < { sRGBHex : string } > ;
47
47
}
48
48
49
- export type UUIColorPickerFormat = 'hex' | 'rgb' | 'hsl' ;
49
+ export type UUIColorPickerFormat = 'hex' | 'rgb' | 'hsl' | 'hsv' ;
50
50
export type UUIColorPickerFormatWithAlpha =
51
51
| UUIColorPickerFormat
52
52
| 'hexa'
53
53
| 'rgba'
54
- | 'hsla' ;
54
+ | 'hsla'
55
+ | 'hsva' ;
55
56
56
57
declare const EyeDropper : EyeDropperConstructor ;
57
58
@@ -85,7 +86,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
85
86
@property ( ) value = '' ;
86
87
87
88
/**
88
- * The format to use for the display value. If opacity is enabled, these will translate to HEXA, RGBA, and HSLA
89
+ * The format to use for the display value. If opacity is enabled, these will translate to HEXA, RGBA, HSLA, and HSVA
89
90
* respectively. The color picker will always accept user input in any format (including CSS color names) and convert
90
91
* it to the desired format.
91
92
* @attr
@@ -153,7 +154,7 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
153
154
154
155
/**
155
156
* An array of predefined color swatches to display. Can include any format the color picker can parse, including
156
- * HEX(A), RGB(A), HSL(A), and CSS color names.
157
+ * HEX(A), RGB(A), HSL(A), HSV(A), and CSS color names.
157
158
*/
158
159
@property ( { attribute : false } ) swatches : string [ ] = [
159
160
'#d0021b' ,
@@ -198,26 +199,31 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
198
199
/** Returns the current value as a string in the specified format. */
199
200
getFormattedValue ( format : UUIColorPickerFormat ) {
200
201
const formatToUse = this . opacity ? `${ format } a` : format ;
201
- const { h, l, s } = this . _colord . toHsl ( ) ;
202
+ const hexa = this . _colord . toHex ( ) ;
203
+ const hex = hexa . length > 7 ? hexa . substring ( 0 , hexa . length - 2 ) : hexa ;
204
+
202
205
const { r, g, b } = this . _colord . toRgb ( ) ;
203
- const hexa = this . setLetterCase ( this . _colord . toHex ( ) ) ;
204
- const hex = this . setLetterCase (
205
- hexa . length > 7 ? hexa . substring ( 0 , hexa . length - 2 ) : hexa
206
- ) ;
206
+ const { h, s, l } = this . _colord . toHsl ( ) ;
207
+ const { v } = this . _colord . toHsv ( ) ;
208
+ const a = this . _colord . alpha ( ) ;
207
209
208
210
switch ( formatToUse ) {
209
211
case 'hex' :
210
- return hex ;
212
+ return this . setLetterCase ( hex ) ;
211
213
case 'hexa' :
212
- return hexa ;
214
+ return this . setLetterCase ( hexa ) ;
213
215
case 'rgb' :
214
- return `rgb(${ r } ${ g } ${ b } )` ;
216
+ return this . setLetterCase ( `rgb(${ r } , ${ g } , ${ b } )` ) ;
215
217
case 'rgba' :
216
- return this . _colord . toRgbString ( ) ;
218
+ return this . setLetterCase ( this . _colord . toRgbString ( ) ) ;
217
219
case 'hsl' :
218
- return `hsl(${ h } ${ s } ${ l } )` ;
220
+ return this . setLetterCase ( `hsl(${ h } , ${ s } %, ${ l } %)` ) ;
219
221
case 'hsla' :
220
- return this . _colord . toHslString ( ) ;
222
+ return this . setLetterCase ( this . _colord . toHslString ( ) ) ;
223
+ case 'hsv' :
224
+ return this . setLetterCase ( `hsv(${ h } , ${ s } %, ${ l } %)` ) ;
225
+ case 'hsva' :
226
+ return this . setLetterCase ( `hsva(${ h } , ${ s } %, ${ v } %, ${ a } )` ) ; //this._colord.toHsvString();
221
227
default :
222
228
return '' ;
223
229
}
@@ -236,9 +242,9 @@ export class UUIColorPickerElement extends LabelMixin('label', LitElement) {
236
242
}
237
243
238
244
handleFormatToggle ( ) {
239
- const formats = [ 'hex' , 'rgb' , 'hsl' ] ;
245
+ const formats = [ 'hex' , 'rgb' , 'hsl' , 'hsv' ] ;
240
246
const nextIndex = ( formats . indexOf ( this . format ) + 1 ) % formats . length ;
241
- this . format = formats [ nextIndex ] as 'hex' | 'rgb' | 'hsl' ;
247
+ this . format = formats [ nextIndex ] as 'hex' | 'rgb' | 'hsl' | 'hsv' ;
242
248
this . _syncValues ( ) ;
243
249
}
244
250
0 commit comments