♻️ Make the color preview its own component
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import Button from "./Button.svelte";
|
||||
import ColorPreview from "./ColorPreview.svelte";
|
||||
|
||||
import {
|
||||
cmykToRgb,
|
||||
@ -40,16 +41,12 @@
|
||||
<!-- Color preview -->
|
||||
<div class="color_grid">
|
||||
{#if sideBySide}
|
||||
<div
|
||||
class="color"
|
||||
style:background-color="rgb({guessColor.join(",")})"
|
||||
></div>
|
||||
<ColorPreview color={guessColor} />
|
||||
{/if}
|
||||
<div class="color" style:background-color="rgb({targetColor.join(",")})">
|
||||
{#if guessScore != undefined}
|
||||
<div class="score">{guessScore}%</div>
|
||||
{/if}
|
||||
</div>
|
||||
<ColorPreview
|
||||
color={targetColor}
|
||||
text={guessScore != undefined ? `${guessScore}%` : ""}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Sliders -->
|
||||
@ -183,22 +180,6 @@
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.color {
|
||||
width: 100%;
|
||||
height: 30vh;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.score {
|
||||
font-size: 25px;
|
||||
opacity: 0.7;
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.slider_container {
|
||||
margin-top: 40px;
|
||||
display: grid;
|
||||
|
28
src/ColorPreview.svelte
Normal file
28
src/ColorPreview.svelte
Normal file
@ -0,0 +1,28 @@
|
||||
<script lang="ts">
|
||||
export let color: number[];
|
||||
export let text: string = "";
|
||||
</script>
|
||||
|
||||
<div class="color" style:background-color="rgb({color.join(",")})">
|
||||
{#if text != undefined}
|
||||
<div class="score">{text}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.color {
|
||||
width: 100%;
|
||||
height: 30vh;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.score {
|
||||
font-size: 25px;
|
||||
opacity: 0.7;
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user