Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
31 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,37 @@ | ||
<script> | ||
import { _ } from "@/libs/i18next"; | ||
import clickoutside from "@/libs/svelte/click-outside"; | ||
import ChromePicker from "svelte-color/Chrome.svelte"; | ||
import { createEventDispatcher } from "svelte"; | ||
const dispatch = createEventDispatcher(); | ||
export let label = _("words.color"); | ||
export let color = "#fff"; | ||
export let alpha = false; | ||
export let colapsed = true; | ||
export let previewClass = ""; | ||
export let position = "left"; | ||
export let label = _("words.color"); | ||
export let labelMinWidth = "50%"; | ||
export let previewClass = ""; | ||
let cls = "flex-auto"; | ||
export { cls as class }; | ||
let pos = position === "left" ? "left-0" : "right-0"; | ||
$: labelStyle = labelMinWidth ? `min-width:${labelMinWidth}` : ""; | ||
function onColor(event) { | ||
color = event.detail.hex; | ||
dispatch("color", event.detail); | ||
} | ||
$: hidden = colapsed && "hidden"; | ||
$: style = `background-color: ${color}`; | ||
function toggle() { | ||
colapsed = !colapsed; | ||
} | ||
function hide() { | ||
colapsed = true; | ||
function onChange({ target }) { | ||
color = target.value; | ||
dispatch("color", { hex: color }); | ||
} | ||
</script> | ||
|
||
<div use:clickoutside on:clickoutside="{hide}" class="relative {cls}"> | ||
<div class="flex cursor-pointer" on:click="{toggle}"> | ||
{#if label} | ||
<div | ||
style="{labelStyle}" | ||
class="p-2 uppercase font-medium bg-dark-lighter" | ||
> | ||
{label} | ||
</div> | ||
{/if} | ||
<div class="p-2 text-dark flex-auto {previewClass}" style="{style}"></div> | ||
</div> | ||
<div class="absolute z-10 text-dark {hidden} {pos}"> | ||
<ChromePicker | ||
on:input="{onColor}" | ||
startColor="{color}" | ||
disableAlpha="{!alpha}" | ||
/> | ||
</div> | ||
</div> | ||
<label class="flex w-full h-full" style="background-color:{color}"> | ||
{#if label} | ||
<div style="{labelStyle}" class="p-2 uppercase font-medium bg-dark-lighter"> | ||
{label} | ||
</div> | ||
{/if} | ||
{#if previewClass} | ||
<div class="{previewClass}"></div> | ||
{/if} | ||
<input | ||
type="color" | ||
value="{color}" | ||
class="opacity-0" | ||
on:input="{onChange}" | ||
style="width:1px;height:1px;" | ||
/> | ||
</label> |