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-10-18 14:01:15 +02:00
|
|
|
import IconConstrain from "./IconConstrain.svelte";
|
2021-04-30 20:01:40 +02:00
|
|
|
import { getContext, onMount, createEventDispatcher } from "svelte";
|
2021-06-30 19:55:56 +02:00
|
|
|
import { nightModeKey, dropdownKey } from "./context-keys";
|
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-04-28 13:09:25 +02:00
|
|
|
export let active = false;
|
2021-06-18 00:27:07 +02:00
|
|
|
export let disabled = false;
|
2021-05-06 01:58:14 +02:00
|
|
|
export let tabbable = false;
|
2021-04-28 13:09:25 +02:00
|
|
|
|
2021-10-18 14:01:15 +02:00
|
|
|
export let iconSize = 75;
|
|
|
|
export let widthMultiplier = 1;
|
|
|
|
export let flipX = false;
|
2021-05-31 00:17:06 +02:00
|
|
|
|
2021-04-28 13:09:25 +02:00
|
|
|
let buttonRef: HTMLButtonElement;
|
|
|
|
|
|
|
|
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}
|
2021-10-18 14:01:15 +02:00
|
|
|
class="btn {className}"
|
2021-05-26 01:21:33 +02:00
|
|
|
class:active
|
|
|
|
class:dropdown-toggle={dropdownProps.dropdown}
|
|
|
|
class:btn-day={!nightMode}
|
|
|
|
class:btn-night={nightMode}
|
|
|
|
title={tooltip}
|
|
|
|
{...dropdownProps}
|
2021-06-18 00:27:07 +02:00
|
|
|
{disabled}
|
2021-05-26 01:21:33 +02:00
|
|
|
tabindex={tabbable ? 0 : -1}
|
|
|
|
on:click
|
|
|
|
on:mousedown|preventDefault
|
|
|
|
>
|
2021-10-18 14:01:15 +02:00
|
|
|
<IconConstrain {flipX} {widthMultiplier} {iconSize}>
|
2021-07-21 16:48:02 +02:00
|
|
|
<slot />
|
2021-10-18 14:01:15 +02:00
|
|
|
</IconConstrain>
|
2021-05-26 01:21:33 +02:00
|
|
|
</button>
|
|
|
|
|
2021-04-28 13:09:25 +02:00
|
|
|
<style lang="scss">
|
2021-10-09 02:25:03 +02:00
|
|
|
@use "sass/button-mixins" as button;
|
2021-04-28 13:09:25 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
.dropdown-toggle::after {
|
|
|
|
margin-right: 0.25rem;
|
|
|
|
}
|
|
|
|
</style>
|