@@ -7,6 +7,7 @@ import { Coordinates } from "./Coordinates";
7
7
import { styles } from "./styles/ColorConverter" ;
8
8
import { ColorPickerSetColorEvent } from "./ColorPickerSetColorEvent" ;
9
9
import {
10
+ ColorConverterInput ,
10
11
InputType ,
11
12
inputTypeToInputValueKey ,
12
13
InputValues ,
@@ -53,6 +54,14 @@ export class ColorConverter extends LitElement {
53
54
this . dispatchEvent ( new ColorPickerSetColorEvent ( color ) ) ;
54
55
}
55
56
57
+ get _slottedChildren ( ) {
58
+ return (
59
+ this . shadowRoot
60
+ ?. querySelector ( "slot" )
61
+ ?. assignedElements ( { flatten : true } ) ?? [ ]
62
+ ) ;
63
+ }
64
+
56
65
render ( ) {
57
66
const floatCoordinates = {
58
67
x : this . coordinates . x / this . coordinates . width ,
@@ -66,6 +75,12 @@ export class ColorConverter extends LitElement {
66
75
Math . round ( this . coordinates . x ) ,
67
76
Math . round ( this . coordinates . y ) ,
68
77
] ;
78
+ this . _slottedChildren . forEach ( ( child ) => {
79
+ if ( child instanceof ColorConverterInput ) {
80
+ child . inputValues = this . inputValues ;
81
+ child . color = this . color ;
82
+ }
83
+ } ) ;
69
84
return html `
70
85
${ bootstrap }
71
86
< h5 > Color Converter</ h5 >
@@ -83,28 +98,11 @@ export class ColorConverter extends LitElement {
83
98
</ tr >
84
99
</ tbody >
85
100
</ table >
86
- < div class ="d-flex flex-column inputs-container ">
87
- < color-converter-input
88
- type =${ InputType . HEX }
89
- .inputValues =${ this . inputValues }
90
- .color=${ this . color }
91
- > </ color-converter-input >
92
- < color-converter-input
93
- type =${ InputType . RGB255 }
94
- .inputValues =${ this . inputValues }
95
- .color=${ this . color }
96
- > </ color-converter-input >
97
- < color-converter-input
98
- type =${ InputType . RGB01 }
99
- .inputValues =${ this . inputValues }
100
- .color=${ this . color }
101
- > </ color-converter-input >
102
- < color-converter-input
103
- type =${ InputType . HSV }
104
- .inputValues =${ this . inputValues }
105
- .color=${ this . color }
106
- > </ color-converter-input >
107
- </ div >
101
+ < slot
102
+ class ="d-flex flex-column inputs-container "
103
+ @slotchange =${ this . render }
104
+ >
105
+ </ slot >
108
106
` ;
109
107
}
110
108
}
0 commit comments