anki/ts/components/SelectButton.svelte

54 lines
1.4 KiB
Svelte
Raw Normal View History

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-31 15:40:11 +02:00
<script lang="typescript">
import type { Readable } from "svelte/store";
2021-03-31 15:40:11 +02:00
import { onMount, createEventDispatcher, getContext } from "svelte";
import { disabledKey, nightModeKey } from "./contextKeys";
2021-03-31 15:40:11 +02:00
export let id: string | undefined = undefined;
let className = "";
export { className as class };
2021-03-31 15:40:11 +02:00
export let tooltip: string | undefined = undefined;
2021-03-31 15:40:11 +02:00
2021-04-01 18:55:34 +02:00
export let disables = true;
2021-03-31 15:40:11 +02:00
const nightMode = getContext<boolean>(nightModeKey);
const disabled = getContext<Readable<boolean>>(disabledKey);
$: _disabled = disables && $disabled;
2021-03-31 15:40:11 +02:00
let buttonRef: HTMLSelectElement;
const dispatch = createEventDispatcher();
onMount(() => dispatch("mount", { button: buttonRef }));
</script>
<!-- svelte-ignore a11y-no-onchange -->
2021-03-31 15:40:11 +02:00
<select
tabindex="-1"
2021-03-31 15:40:11 +02:00
bind:this={buttonRef}
disabled={_disabled}
2021-03-31 15:40:11 +02:00
{id}
class="{className} form-select"
class:btn-day={!nightMode}
class:btn-night={nightMode}
title={tooltip}
on:change
>
<slot />
2021-03-31 15:40:11 +02:00
</select>
<style lang="scss">
@use "ts/sass/button_mixins" as button;
select {
height: var(--toolbar-size);
}
@include button.btn-day($with-hover: false);
@include button.btn-night($with-hover: false);
</style>