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
|
|
|
|
-->
|
2021-03-29 17:32:43 +02:00
|
|
|
<script lang="typescript">
|
2021-04-22 14:32:44 +02:00
|
|
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
2021-04-14 17:43:55 +02:00
|
|
|
import { nightModeKey } from "./contextKeys";
|
2021-04-22 14:32:44 +02:00
|
|
|
import { mergeTooltipAndShortcut } from "./helpers";
|
2021-04-14 17:43:55 +02:00
|
|
|
|
2021-04-09 22:02:34 +02:00
|
|
|
export let id: string;
|
2021-03-30 18:57:50 +02:00
|
|
|
export let className = "";
|
2021-04-22 14:32:44 +02:00
|
|
|
export let tooltip: string | undefined;
|
|
|
|
export let shortcutLabel: string | undefined;
|
|
|
|
|
|
|
|
$: title = mergeTooltipAndShortcut(tooltip, shortcutLabel);
|
2021-03-30 18:57:50 +02:00
|
|
|
|
2021-04-01 18:55:34 +02:00
|
|
|
export let onChange: (event: Event) => void;
|
2021-04-14 17:43:55 +02:00
|
|
|
|
|
|
|
function extendClassName(className: string): string {
|
|
|
|
return `btn ${className}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nightMode = getContext(nightModeKey);
|
2021-04-14 18:33:46 +02:00
|
|
|
|
2021-04-22 14:32:44 +02:00
|
|
|
let buttonRef: HTMLButtonElement;
|
2021-04-14 21:58:58 +02:00
|
|
|
let inputRef: HTMLInputElement;
|
2021-04-14 18:33:46 +02:00
|
|
|
|
|
|
|
function delegateToInput() {
|
2021-04-14 21:58:58 +02:00
|
|
|
inputRef.click();
|
2021-04-14 18:33:46 +02:00
|
|
|
}
|
2021-04-22 14:32:44 +02:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
2021-03-29 17:32:43 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-04-14 20:06:35 +02:00
|
|
|
@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-04-14 20:23:06 +02:00
|
|
|
|
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);
|
|
|
|
|
2021-04-14 20:23:06 +02:00
|
|
|
padding: 4px;
|
2021-04-14 18:33:46 +02:00
|
|
|
overflow: hidden;
|
2021-03-29 17:32:43 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 18:35:46 +02:00
|
|
|
@include button.btn-day($with-disabled: false) using ($base) {
|
|
|
|
@include button.rainbow($base);
|
2021-04-14 20:23:06 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 18:35:46 +02:00
|
|
|
@include button.btn-night($with-disabled: false) using ($base) {
|
|
|
|
@include button.rainbow($base);
|
2021-04-14 20:06:35 +02:00
|
|
|
}
|
|
|
|
|
2021-03-29 17:32:43 +02:00
|
|
|
input {
|
2021-03-30 18:57:50 +02:00
|
|
|
display: inline-block;
|
2021-04-14 20:06:35 +02:00
|
|
|
cursor: pointer;
|
2021-03-29 17:32:43 +02:00
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2021-04-01 01:22:06 +02:00
|
|
|
<button
|
2021-04-22 14:32:44 +02:00
|
|
|
bind:this={buttonRef}
|
2021-04-01 01:22:06 +02:00
|
|
|
tabindex="-1"
|
|
|
|
{id}
|
2021-04-14 17:43:55 +02:00
|
|
|
class={extendClassName(className)}
|
2021-04-15 18:35:46 +02:00
|
|
|
class:btn-day={!nightMode}
|
|
|
|
class:btn-night={nightMode}
|
2021-04-22 14:32:44 +02:00
|
|
|
{title}
|
2021-04-14 18:33:46 +02:00
|
|
|
on:click={delegateToInput}
|
2021-04-01 01:22:06 +02:00
|
|
|
on:mousedown|preventDefault>
|
2021-04-22 15:02:41 +02:00
|
|
|
<input tabindex="-1" bind:this={inputRef} type="color" on:change={onChange} />
|
2021-03-30 00:51:44 +02:00
|
|
|
</button>
|