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 21:05:30 +02:00
|
|
|
<script lang="typescript">
|
2021-03-30 06:14:00 +02:00
|
|
|
import type { Readable } from "svelte/store";
|
2021-04-14 19:36:41 +02:00
|
|
|
import { getContext, onMount, createEventDispatcher } from "svelte";
|
2021-04-14 16:26:23 +02:00
|
|
|
import { disabledKey, nightModeKey } from "./contextKeys";
|
2021-03-30 06:14:00 +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-08 16:40:42 +02:00
|
|
|
export let tooltip: string;
|
2021-03-30 18:57:50 +02:00
|
|
|
|
2021-04-01 18:55:34 +02:00
|
|
|
export let onClick: (event: MouseEvent) => void;
|
2021-03-29 23:26:08 +02:00
|
|
|
export let active = false;
|
2021-04-09 22:02:34 +02:00
|
|
|
export let disables = true;
|
|
|
|
export let dropdownToggle = false;
|
|
|
|
|
|
|
|
$: extraProps = dropdownToggle
|
|
|
|
? {
|
|
|
|
"data-bs-toggle": "dropdown",
|
|
|
|
"aria-expanded": "false",
|
|
|
|
}
|
|
|
|
: {};
|
2021-03-30 06:14:00 +02:00
|
|
|
|
2021-03-31 03:34:08 +02:00
|
|
|
let buttonRef: HTMLButtonElement;
|
|
|
|
|
2021-04-14 16:26:23 +02:00
|
|
|
function extendClassName(className: string): string {
|
|
|
|
return `btn ${className}`;
|
|
|
|
}
|
|
|
|
|
2021-04-15 02:32:58 +02:00
|
|
|
const disabled = getContext<Readable<boolean>>(disabledKey);
|
2021-04-09 22:02:34 +02:00
|
|
|
$: _disabled = disables && $disabled;
|
2021-03-31 03:34:08 +02:00
|
|
|
|
2021-04-15 02:32:58 +02:00
|
|
|
const nightMode = getContext<boolean>(nightModeKey);
|
2021-04-14 16:26:23 +02:00
|
|
|
|
2021-03-31 03:34:08 +02:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
2021-03-29 21:05:30 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-04-14 20:06:35 +02:00
|
|
|
@use "ts/sass/button_mixins" as button;
|
|
|
|
|
2021-03-29 21:05:30 +02:00
|
|
|
button {
|
2021-03-30 18:57:50 +02:00
|
|
|
padding: 0;
|
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-30 18:57:50 +02:00
|
|
|
|
|
|
|
span {
|
|
|
|
display: inline-block;
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
|
|
/* constrain icon */
|
2021-03-31 16:24:28 +02:00
|
|
|
width: calc(var(--toolbar-size) - 2px);
|
|
|
|
height: calc(var(--toolbar-size) - 2px);
|
2021-03-30 18:57:50 +02:00
|
|
|
|
|
|
|
& > :global(svg),
|
|
|
|
& > :global(img) {
|
|
|
|
fill: currentColor;
|
|
|
|
vertical-align: unset;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 22:02:34 +02:00
|
|
|
.dropdown-toggle::after {
|
2021-03-30 18:57:50 +02:00
|
|
|
margin-right: 0.25rem;
|
|
|
|
}
|
2021-03-29 21:05:30 +02:00
|
|
|
</style>
|
|
|
|
|
2021-03-29 23:26:08 +02:00
|
|
|
<button
|
2021-03-31 03:34:08 +02:00
|
|
|
bind:this={buttonRef}
|
2021-03-30 18:57:50 +02:00
|
|
|
{id}
|
2021-04-14 16:26:23 +02:00
|
|
|
class={extendClassName(className)}
|
2021-03-29 23:26:08 +02:00
|
|
|
class:active
|
2021-04-09 22:02:34 +02:00
|
|
|
class:dropdown-toggle={dropdownToggle}
|
2021-04-15 18:35:46 +02:00
|
|
|
class:btn-day={!nightMode}
|
|
|
|
class:btn-night={nightMode}
|
2021-03-30 03:05:21 +02:00
|
|
|
tabindex="-1"
|
2021-04-09 22:02:34 +02:00
|
|
|
title={tooltip}
|
2021-04-01 18:36:03 +02:00
|
|
|
disabled={_disabled}
|
2021-04-09 22:02:34 +02:00
|
|
|
{...extraProps}
|
2021-03-29 23:26:08 +02:00
|
|
|
on:click={onClick}
|
2021-03-29 23:43:48 +02:00
|
|
|
on:mousedown|preventDefault>
|
2021-03-30 18:57:50 +02:00
|
|
|
<span class="p-1"><slot /></span>
|
2021-03-29 21:05:30 +02:00
|
|
|
</button>
|