anki/ts/components/SelectButton.svelte

56 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
-->
<script lang="ts">
import { onMount, createEventDispatcher } from "svelte";
import { pageTheme } from "../sveltelib/theme";
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-07-05 18:15:03 +02:00
export let disabled = false;
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}
{id}
2021-07-05 18:15:03 +02:00
{disabled}
class="{className} form-select"
class:btn-day={!$pageTheme.isDark}
class:btn-night={$pageTheme.isDark}
class:visible-down-arrow={$pageTheme.isDark}
title={tooltip}
on:change
>
<slot />
2021-03-31 15:40:11 +02:00
</select>
<style lang="scss">
@use "sass/button-mixins" as button;
select {
height: var(--buttons-size);
/* Long option name can create overflow */
overflow-x: hidden;
}
.visible-down-arrow {
/* override the default down arrow */
2021-06-05 00:40:55 +02:00
background-image: button.down-arrow(white);
}
@include button.btn-day($with-hover: false);
@include button.btn-night($with-hover: false);
</style>