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-25 23:32:23 +01:00
|
|
|
<script lang="typescript">
|
2021-04-15 02:32:58 +02:00
|
|
|
import type { Readable } from "svelte/store";
|
2021-03-30 18:57:50 +02:00
|
|
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
2021-05-06 01:58:14 +02:00
|
|
|
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
2021-05-06 03:37:21 +02:00
|
|
|
import type { DropdownProps } from "./dropdown";
|
2021-03-30 18:57:50 +02:00
|
|
|
|
2021-05-05 01:22:51 +02:00
|
|
|
export let id: string | undefined = undefined;
|
|
|
|
let className: string = "";
|
|
|
|
export { className as class };
|
2021-05-18 16:32:29 +02:00
|
|
|
export let theme = "anki";
|
|
|
|
|
|
|
|
function extendClassName(className: string, theme: string): string {
|
|
|
|
return `btn ${theme !== "anki" ? `btn-${theme}` : ""}${className}`;
|
|
|
|
}
|
2021-04-22 14:18:48 +02:00
|
|
|
|
2021-05-06 20:48:11 +02:00
|
|
|
export let tooltip: string | undefined = undefined;
|
|
|
|
export let active = false;
|
2021-05-05 01:22:51 +02:00
|
|
|
export let disables = true;
|
|
|
|
export let tabbable = false;
|
2021-04-09 22:02:34 +02:00
|
|
|
|
2021-04-15 02:32:58 +02:00
|
|
|
const disabled = getContext<Readable<boolean>>(disabledKey);
|
2021-04-01 18:36:03 +02:00
|
|
|
$: _disabled = disables && $disabled;
|
2021-04-14 16:26:23 +02:00
|
|
|
|
2021-04-15 02:32:58 +02:00
|
|
|
const nightMode = getContext<boolean>(nightModeKey);
|
2021-05-06 03:37:21 +02:00
|
|
|
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
|
2021-04-14 16:26:23 +02:00
|
|
|
|
2021-05-05 01:22:51 +02:00
|
|
|
let buttonRef: HTMLButtonElement;
|
|
|
|
|
2021-04-14 16:26:23 +02:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
2021-03-25 23:32:23 +01:00
|
|
|
</script>
|
2021-03-29 14:54:10 +02:00
|
|
|
|
2021-05-26 01:21:33 +02:00
|
|
|
<button
|
|
|
|
bind:this={buttonRef}
|
|
|
|
{id}
|
|
|
|
class={extendClassName(className, theme)}
|
|
|
|
class:active
|
|
|
|
class:dropdown-toggle={dropdownProps.dropdown}
|
|
|
|
class:btn-day={theme === "anki" && !nightMode}
|
|
|
|
class:btn-night={theme === "anki" && nightMode}
|
|
|
|
title={tooltip}
|
|
|
|
{...dropdownProps}
|
|
|
|
disabled={_disabled}
|
|
|
|
tabindex={tabbable ? 0 : -1}
|
|
|
|
on:click
|
|
|
|
on:mousedown|preventDefault
|
|
|
|
>
|
|
|
|
<slot />
|
|
|
|
</button>
|
|
|
|
|
2021-03-25 23:32:23 +01:00
|
|
|
<style lang="scss">
|
2021-04-14 15:45:14 +02:00
|
|
|
@use "ts/sass/button_mixins" as button;
|
|
|
|
|
2021-03-25 23:32:23 +01:00
|
|
|
button {
|
2021-04-14 15:45:14 +02:00
|
|
|
padding: 0 calc(var(--toolbar-size) / 3);
|
|
|
|
width: auto;
|
|
|
|
height: var(--toolbar-size);
|
2021-05-05 01:22:51 +02:00
|
|
|
|
2021-05-06 20:29:55 +02:00
|
|
|
@include button.btn-border-radius;
|
2021-03-25 23:32:23 +01:00
|
|
|
}
|
2021-04-14 20:06:35 +02:00
|
|
|
|
2021-04-15 18:35:46 +02:00
|
|
|
@include button.btn-day;
|
|
|
|
@include button.btn-night;
|
2021-03-25 23:32:23 +01:00
|
|
|
</style>
|