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-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-05-31 00:31:10 +02:00
|
|
|
export let iconSize: number = 75;
|
2021-05-31 00:17:06 +02:00
|
|
|
export let widthMultiplier: number = 1;
|
2021-07-21 16:48:02 +02:00
|
|
|
export let flipX: boolean = 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}
|
|
|
|
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}
|
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-07-21 16:48:02 +02:00
|
|
|
<span class:flip-x={flipX} style={`--width-multiplier: ${widthMultiplier};`}>
|
|
|
|
<slot />
|
|
|
|
</span>
|
2021-05-26 01:21:33 +02:00
|
|
|
</button>
|
|
|
|
|
2021-04-28 13:09:25 +02:00
|
|
|
<style lang="scss">
|
2021-08-17 22:07:28 +02:00
|
|
|
@use "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;
|
|
|
|
|
|
|
|
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-31 00:17:06 +02:00
|
|
|
width: calc((var(--buttons-size) - 2px) * var(--width-multiplier));
|
2021-05-27 17:13:36 +02:00
|
|
|
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;
|
|
|
|
}
|
2021-07-21 16:48:02 +02:00
|
|
|
|
|
|
|
&.flip-x > :global(svg),
|
|
|
|
&.flip-x > :global(img) {
|
|
|
|
transform: scaleX(-1);
|
|
|
|
}
|
2021-04-28 13:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.dropdown-toggle::after {
|
|
|
|
margin-right: 0.25rem;
|
|
|
|
}
|
|
|
|
</style>
|