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 14:54:10 +02:00
|
|
|
<script lang="typescript">
|
2021-04-28 13:09:25 +02:00
|
|
|
import type { Readable } from "svelte/store";
|
2021-04-30 20:01:40 +02:00
|
|
|
import { getContext, onMount, createEventDispatcher } from "svelte";
|
2021-04-28 22:15:24 +02:00
|
|
|
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
2021-05-06 03:37:21 +02:00
|
|
|
import type { DropdownProps } from "./dropdown";
|
2021-03-29 14:54:10 +02:00
|
|
|
|
2021-05-06 01:58:14 +02:00
|
|
|
export let id: string | undefined = undefined;
|
2021-04-27 22:35:25 +02:00
|
|
|
let className = "";
|
|
|
|
export { className as class };
|
2021-04-20 03:24:08 +02:00
|
|
|
|
2021-05-06 01:58:14 +02:00
|
|
|
export let tooltip: string | undefined = undefined;
|
2021-05-30 21:05:16 +02:00
|
|
|
export let iconSize: number = 80;
|
2021-04-28 13:09:25 +02:00
|
|
|
export let active = false;
|
2021-04-20 03:24:08 +02:00
|
|
|
export let disables = true;
|
2021-05-06 01:58:14 +02:00
|
|
|
export let tabbable = false;
|
2021-04-28 13:09:25 +02:00
|
|
|
|
|
|
|
let buttonRef: HTMLButtonElement;
|
|
|
|
|
|
|
|
const disabled = getContext<Readable<boolean>>(disabledKey);
|
|
|
|
$: _disabled = disables && $disabled;
|
|
|
|
|
|
|
|
const nightMode = getContext<boolean>(nightModeKey);
|
2021-05-06 03:37:21 +02:00
|
|
|
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
|
2021-04-28 22:15:24 +02:00
|
|
|
|
2021-04-28 13:09:25 +02:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
2021-03-29 14:54:10 +02:00
|
|
|
</script>
|
|
|
|
|
2021-05-26 01:21:33 +02:00
|
|
|
<button
|
|
|
|
bind:this={buttonRef}
|
|
|
|
{id}
|
|
|
|
class={`btn ${className}`}
|
|
|
|
class:active
|
|
|
|
class:dropdown-toggle={dropdownProps.dropdown}
|
|
|
|
class:btn-day={!nightMode}
|
|
|
|
class:btn-night={nightMode}
|
2021-05-30 21:05:16 +02:00
|
|
|
style={`--icon-size: ${iconSize}%`}
|
2021-05-26 01:21:33 +02:00
|
|
|
title={tooltip}
|
|
|
|
{...dropdownProps}
|
|
|
|
disabled={_disabled}
|
|
|
|
tabindex={tabbable ? 0 : -1}
|
|
|
|
on:click
|
|
|
|
on:mousedown|preventDefault
|
|
|
|
>
|
2021-05-30 21:05:16 +02:00
|
|
|
<span> <slot /> </span>
|
2021-05-26 01:21:33 +02:00
|
|
|
</button>
|
|
|
|
|
2021-04-28 13:09:25 +02:00
|
|
|
<style lang="scss">
|
|
|
|
@use "ts/sass/button_mixins" as button;
|
|
|
|
|
|
|
|
button {
|
|
|
|
padding: 0;
|
2021-05-06 20:29:55 +02:00
|
|
|
@include button.btn-border-radius;
|
2021-04-28 13:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@include button.btn-day;
|
|
|
|
@include button.btn-night;
|
|
|
|
|
|
|
|
span {
|
|
|
|
display: inline-block;
|
2021-05-30 21:05:16 +02:00
|
|
|
position: relative;
|
2021-04-28 13:09:25 +02:00
|
|
|
vertical-align: middle;
|
|
|
|
|
|
|
|
/* constrain icon */
|
2021-05-27 17:13:36 +02:00
|
|
|
width: calc(var(--buttons-size) - 2px);
|
|
|
|
height: calc(var(--buttons-size) - 2px);
|
2021-04-28 13:09:25 +02:00
|
|
|
|
|
|
|
& > :global(svg),
|
|
|
|
& > :global(img) {
|
2021-05-30 21:05:16 +02:00
|
|
|
position: absolute;
|
|
|
|
width: var(--icon-size);
|
|
|
|
height: var(--icon-size);
|
|
|
|
top: calc((100% - var(--icon-size)) / 2);
|
|
|
|
bottom: calc((100% - var(--icon-size)) / 2);
|
|
|
|
left: calc((100% - var(--icon-size)) / 2);
|
|
|
|
right: calc((100% - var(--icon-size)) / 2);
|
|
|
|
|
2021-04-28 13:09:25 +02:00
|
|
|
fill: currentColor;
|
|
|
|
vertical-align: unset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.dropdown-toggle::after {
|
|
|
|
margin-right: 0.25rem;
|
|
|
|
}
|
|
|
|
</style>
|