Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Color picker #202

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
{/if}
</div>
{#if type === 'colorpicker'}
<ColorPicker
label="{false}"
color="{value}"
position="right"
on:color="{onChange}"
previewClass="h-5 rounded"
/>
<div class="w-1/2">
<ColorPicker
label="{false}"
color="{value}"
on:color="{onChange}"
previewClass="h-5 rounded"
/>
</div>
{:else if type === 'fontpicker'}
<Fontpicker
font="{value}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@

<ColorPicker
label="{false}"
position="right"
color="{attrs.color}"
previewClass="h-5 rounded"
on:color="{onChange.bind(null, 'color')}"
Expand Down
18 changes: 0 additions & 18 deletions front-src/client/components/App/Connected.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@
import FirstStart from "./FirstStart.svelte";
import CheckUpdate from "./CheckUpdate.svelte";
import Dashboard from "@/components/Dashboard/Main.svelte";

// import ModalRefacto from "@/components/UI/Modal.svelte";

// function onClose() {
// console.log("modal closed");
// }

// let modalOpened = false;

// function openModal() {
// modalOpened = true;
// }
</script>

<Dashboard />
<FirstStart />
<CheckUpdate />

<!-- <button on:click="{openModal}">open modal</button>

<ModalRefacto bind:opened="{modalOpened}" title="prout" on:close="{onClose}">
<div class="p-2">Prout...</div>
</ModalRefacto> -->
68 changes: 23 additions & 45 deletions front-src/client/components/UI/ColorPicker.svelte
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>