@@ -2,7 +2,8 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
22import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils' ;
33import { css , html } from 'lit' ;
44import { InputType , UUIInputElement } from '@umbraco-ui/uui-input/lib' ;
5- import { property , state } from 'lit/decorators.js' ;
5+ import { property , query , state } from 'lit/decorators.js' ;
6+ import type { UUIColorPickerElement } from '@umbraco-ui/uui-color-picker/lib' ;
67
78/**
89 * @element uui-input-color
@@ -13,7 +14,27 @@ export class UUIInputColorElement extends UUIInputElement {
1314 @state ( )
1415 private inputType : InputType = 'text' ;
1516
16- // this overrides the inherited type property, and moves the input's type handling to the passwordType state.
17+ @state ( )
18+ private _valueHex = '' ;
19+
20+ @query ( '#color' )
21+ protected _colorPicker ! : UUIColorPickerElement ;
22+
23+ @property ( { type : String } )
24+ public override set value ( value : string ) {
25+ if ( value . startsWith ( '#' ) ) {
26+ this . _valueHex = value ;
27+ super . value = value . substring ( 1 ) ;
28+ } else {
29+ super . value = value ;
30+ this . _valueHex = `#${ value } ` ;
31+ }
32+ }
33+ public override get value ( ) {
34+ return super . value as string ;
35+ }
36+
37+ // this overrides the inherited type property, and moves the input's type handling to the inputType state.
1738 @property ( )
1839 get type ( ) {
1940 return this . inputType ;
@@ -22,9 +43,13 @@ export class UUIInputColorElement extends UUIInputElement {
2243 this . inputType = newValue ;
2344 }
2445
25- onChange ( e : Event ) : void {
26- const target = e . target as HTMLInputElement ;
27- this . value = target . value ;
46+ #onColorClick( ) {
47+ this . _colorPicker . click ( ) ;
48+ }
49+
50+ #onColorChange( event : Event ) {
51+ event . stopPropagation ( ) ;
52+ this . value = this . _colorPicker . value ;
2853 }
2954
3055 connectedCallback ( ) : void {
@@ -34,20 +59,21 @@ export class UUIInputColorElement extends UUIInputElement {
3459 }
3560
3661 renderPrepend ( ) {
37- return html `<label id = "color-picker " >
62+ return html `<div class = "color-wrapper " >
3863 <uui- color - swatch
3964 ?dis abled= ${ this . disabled }
4065 ?readonly = ${ this . readonly }
41- . value = ${ this . value } >
42- </ uui- color - swatch>
66+ value= ${ this . _valueHex }
67+ @click = ${ this . #onColorClick } > </ uui- color - swatch>
4368 <input
4469 type= "color"
45- id = "color-input "
46- . value = "${ this . value } "
70+ id = "color"
71+ value = "${ this . value } "
4772 ?dis abled= ${ this . disabled }
4873 ?readonly = ${ this . readonly }
74+ @change = ${ this . #onColorChange}
4975 aria- hidden= "true" / >
50- </ label > ` ;
76+ </ div > ` ;
5177 }
5278
5379 static styles = [
@@ -56,16 +82,21 @@ export class UUIInputColorElement extends UUIInputElement {
5682 : host {
5783 }
5884
59- # color-picker {
85+ . color-wrapper {
6086 cursor : pointer;
87+ display : inline-flex;
6188 position : relative;
6289 border-right : var (--uui-input-border-width , 1px ) solid
6390 var (--uui-input-border-color , var (--uui-color-border ));
6491 }
6592
66- # color-input {
67- visibility : hidden;
93+ input [type = 'color' ] {
6894 appearance : none;
95+ visibility : hidden;
96+ width : 0px ;
97+ padding : 0 ;
98+ margin : 0 ;
99+ position : absolute;
69100 }
70101
71102 uui-color-swatch {
0 commit comments