anki/ts/components/ColorPicker.svelte

75 lines
2.0 KiB
Svelte
Raw Normal View History

2021-04-15 15:59:52 +02:00
<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import { onMount, createEventDispatcher, getContext } from "svelte";
import { nightModeKey } from "./contextKeys";
export let id: string | undefined = undefined;
let className = "";
export { className as class };
export let tooltip: string | undefined = undefined;
2021-04-14 18:33:46 +02:00
const nightMode = getContext(nightModeKey);
2021-04-14 18:33:46 +02:00
function delegateToInput() {
inputRef.click();
2021-04-14 18:33:46 +02:00
}
let buttonRef: HTMLButtonElement;
let inputRef: HTMLInputElement;
const dispatch = createEventDispatcher();
onMount(() => dispatch("mount", { button: buttonRef, input: inputRef }));
</script>
<style lang="scss">
@use "ts/sass/button_mixins" as button;
2021-04-15 15:33:47 +02:00
@import "ts/sass/bootstrap/functions";
@import "ts/sass/bootstrap/variables";
2021-03-29 21:05:30 +02:00
button {
2021-04-14 18:33:46 +02:00
width: calc(var(--toolbar-size) - 0px);
height: calc(var(--toolbar-size) - 0px);
padding: 4px;
2021-04-14 18:33:46 +02:00
overflow: hidden;
border-top-left-radius: var(--border-left-radius);
border-bottom-left-radius: var(--border-left-radius);
border-top-right-radius: var(--border-right-radius);
border-bottom-right-radius: var(--border-right-radius);
}
@include button.btn-day($with-disabled: false) using ($base) {
@include button.rainbow($base);
}
@include button.btn-night($with-disabled: false) using ($base) {
@include button.rainbow($base);
}
input {
display: inline-block;
cursor: pointer;
opacity: 0;
}
</style>
<button
bind:this={buttonRef}
tabindex="-1"
{id}
2021-04-28 22:32:12 +02:00
class={`btn ${className}`}
class:btn-day={!nightMode}
class:btn-night={nightMode}
2021-04-28 22:32:12 +02:00
title={tooltip}
2021-04-14 18:33:46 +02:00
on:click={delegateToInput}
on:mousedown|preventDefault>
2021-04-28 22:32:12 +02:00
<input tabindex="-1" bind:this={inputRef} type="color" on:change />
2021-03-30 00:51:44 +02:00
</button>