anki/ts/editor-toolbar/ColorPicker.svelte

80 lines
2.1 KiB
Svelte
Raw Normal View History

<script lang="typescript">
import { getContext } from "svelte";
import { nightModeKey } from "./contextKeys";
export let id: string;
export let className = "";
export let tooltip: string;
2021-04-01 18:55:34 +02:00
export let onChange: (event: Event) => void;
function extendClassName(className: string): string {
return `btn ${className}`;
}
const nightMode = getContext(nightModeKey);
2021-04-14 18:33:46 +02:00
let inputRef: HTMLInputElement;
2021-04-14 18:33:46 +02:00
function delegateToInput() {
inputRef.click();
2021-04-14 18:33:46 +02:00
}
</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 {
padding: 0;
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;
}
.btn-light {
@include button.light-hover-active;
background: content-box
linear-gradient(217deg, rgba(255, 0, 0, 0.8), rgba(255, 0, 0, 0) 70.71%),
content-box
linear-gradient(127deg, rgba(0, 255, 0, 0.8), rgba(0, 255, 0, 0) 70.71%),
content-box
linear-gradient(336deg, rgba(0, 0, 255, 0.8), rgba(0, 0, 255, 0) 70.71%),
border-box $light;
}
.btn-secondary {
background: content-box
linear-gradient(217deg, rgba(255, 0, 0, 0.8), rgba(255, 0, 0, 0) 70.71%),
content-box
linear-gradient(127deg, rgba(0, 255, 0, 0.8), rgba(0, 255, 0, 0) 70.71%),
content-box
linear-gradient(336deg, rgba(0, 0, 255, 0.8), rgba(0, 0, 255, 0) 70.71%),
border-box $secondary;
}
input {
display: inline-block;
cursor: pointer;
opacity: 0;
}
</style>
<button
tabindex="-1"
{id}
class={extendClassName(className)}
class:btn-light={!nightMode}
class:btn-secondary={nightMode}
title={tooltip}
2021-04-14 18:33:46 +02:00
on:click={delegateToInput}
on:mousedown|preventDefault>
<input bind:this={inputRef} type="color" on:change={onChange} />
2021-03-30 00:51:44 +02:00
</button>