Add ColorPicker component

This commit is contained in:
qowevisa 2024-11-11 21:28:15 +02:00
parent df3bd83f70
commit f01ec5fc93

View File

@ -0,0 +1,51 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
export let color = "#ff0000";
function handleColorChange(event: Event) {
const target = event.target as HTMLInputElement;
color = target.value;
dispatch("change", color);
}
export let borderRadius;
const actualBorderRadius = borderRadius || "50%";
</script>
<div class="color-picker" style="border-radius: {actualBorderRadius};">
<label style="border-radius: inherit;">
<input type="color" bind:value={color} on:input={handleColorChange} />
<div
class="color-circle"
style="background-color: {color || '#000'};"
></div>
</label>
</div>
<style>
.color-picker {
position: relative;
display: inline-block;
}
.color-picker input[type="color"] {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
border-radius: inherit;
}
.color-picker .color-circle {
width: var(--color-picker-size, 40px);
height: var(--color-picker-size, 40px);
border-radius: inherit;
display: flex;
align-items: center;
justify-content: center;
}
</style>