Skip to content

Commit

Permalink
Move ColorConverter inputs to index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
dli7319 committed Feb 2, 2025
1 parent 468f78c commit 3818a39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
7 changes: 6 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
<body>
<color-picker>
<color-selection></color-selection>
<color-converter></color-converter>
<color-converter>
<color-converter-input type="HEX"></color-converter-input>
<color-converter-input type="RGB255"></color-converter-input>
<color-converter-input type="RGB01"></color-converter-input>
<color-converter-input type="HSV"></color-converter-input>
</color-converter>
<image-sampling></image-sampling>
<color-interpolation></color-interpolation>
<other-tools></other-tools>
Expand Down
42 changes: 20 additions & 22 deletions src/ColorConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Coordinates } from "./Coordinates";
import { styles } from "./styles/ColorConverter";
import { ColorPickerSetColorEvent } from "./ColorPickerSetColorEvent";
import {
ColorConverterInput,
InputType,
inputTypeToInputValueKey,
InputValues,
Expand Down Expand Up @@ -53,6 +54,14 @@ export class ColorConverter extends LitElement {
this.dispatchEvent(new ColorPickerSetColorEvent(color));
}

get _slottedChildren() {
return (
this.shadowRoot
?.querySelector("slot")
?.assignedElements({ flatten: true }) ?? []
);
}

render() {
const floatCoordinates = {
x: this.coordinates.x / this.coordinates.width,
Expand All @@ -66,6 +75,12 @@ export class ColorConverter extends LitElement {
Math.round(this.coordinates.x),
Math.round(this.coordinates.y),
];
this._slottedChildren.forEach((child) => {
if (child instanceof ColorConverterInput) {
child.inputValues = this.inputValues;
child.color = this.color;
}
});
return html`
${bootstrap}
<h5>Color Converter</h5>
Expand All @@ -83,28 +98,11 @@ export class ColorConverter extends LitElement {
</tr>
</tbody>
</table>
<div class="d-flex flex-column inputs-container">
<color-converter-input
type=${InputType.HEX}
.inputValues=${this.inputValues}
.color=${this.color}
></color-converter-input>
<color-converter-input
type=${InputType.RGB255}
.inputValues=${this.inputValues}
.color=${this.color}
></color-converter-input>
<color-converter-input
type=${InputType.RGB01}
.inputValues=${this.inputValues}
.color=${this.color}
></color-converter-input>
<color-converter-input
type=${InputType.HSV}
.inputValues=${this.inputValues}
.color=${this.color}
></color-converter-input>
</div>
<slot
class="d-flex flex-column inputs-container"
@slotchange=${this.render}
>
</slot>
`;
}
}

0 comments on commit 3818a39

Please sign in to comment.