Skip to content

Commit 3818a39

Browse files
committed
Move ColorConverter inputs to index.html
1 parent 468f78c commit 3818a39

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

Diff for: dist/index.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
<body>
2323
<color-picker>
2424
<color-selection></color-selection>
25-
<color-converter></color-converter>
25+
<color-converter>
26+
<color-converter-input type="HEX"></color-converter-input>
27+
<color-converter-input type="RGB255"></color-converter-input>
28+
<color-converter-input type="RGB01"></color-converter-input>
29+
<color-converter-input type="HSV"></color-converter-input>
30+
</color-converter>
2631
<image-sampling></image-sampling>
2732
<color-interpolation></color-interpolation>
2833
<other-tools></other-tools>

Diff for: src/ColorConverter.ts

+20-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Coordinates } from "./Coordinates";
77
import { styles } from "./styles/ColorConverter";
88
import { ColorPickerSetColorEvent } from "./ColorPickerSetColorEvent";
99
import {
10+
ColorConverterInput,
1011
InputType,
1112
inputTypeToInputValueKey,
1213
InputValues,
@@ -53,6 +54,14 @@ export class ColorConverter extends LitElement {
5354
this.dispatchEvent(new ColorPickerSetColorEvent(color));
5455
}
5556

57+
get _slottedChildren() {
58+
return (
59+
this.shadowRoot
60+
?.querySelector("slot")
61+
?.assignedElements({ flatten: true }) ?? []
62+
);
63+
}
64+
5665
render() {
5766
const floatCoordinates = {
5867
x: this.coordinates.x / this.coordinates.width,
@@ -66,6 +75,12 @@ export class ColorConverter extends LitElement {
6675
Math.round(this.coordinates.x),
6776
Math.round(this.coordinates.y),
6877
];
78+
this._slottedChildren.forEach((child) => {
79+
if (child instanceof ColorConverterInput) {
80+
child.inputValues = this.inputValues;
81+
child.color = this.color;
82+
}
83+
});
6984
return html`
7085
${bootstrap}
7186
<h5>Color Converter</h5>
@@ -83,28 +98,11 @@ export class ColorConverter extends LitElement {
8398
</tr>
8499
</tbody>
85100
</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>
108106
`;
109107
}
110108
}

0 commit comments

Comments
 (0)