anki/ts/editor-toolbar/SelectButton.svelte

63 lines
1.4 KiB
Svelte
Raw Normal View History

2021-03-31 15:40:11 +02:00
<script lang="typescript">
import { onMount, createEventDispatcher, getContext } from "svelte";
import type { Readable } from "svelte/store";
import { disabledKey } from "./contextKeys";
import SelectOption from "./SelectOption.svelte";
interface Option {
label: string;
value: string;
selected: boolean;
}
export let id = "";
export let className = "";
export let props: Record<string, string> = {};
function extendClassName(classes: string) {
return `form-select ${classes}`;
}
export let disables;
export let options: Option[];
let buttonRef: HTMLSelectElement;
const dispatch = createEventDispatcher();
onMount(() => dispatch("mount", { button: buttonRef }));
const disabledStore = getContext(disabledKey);
$: disabled = disables && $disabledStore;
</script>
<style lang="scss">
select {
2021-03-31 19:19:24 +02:00
display: inline-block;
vertical-align: middle;
height: var(--toolbar-size);
2021-03-31 15:40:11 +02:00
width: auto;
font-size: calc(var(--toolbar-size) / 2.3);
user-select: none;
box-shadow: none;
2021-03-31 15:40:11 +02:00
border-radius: 0;
&:focus {
outline: none;
}
2021-03-31 15:40:11 +02:00
}
</style>
<select
tabindex="-1"
2021-03-31 15:40:11 +02:00
bind:this={buttonRef}
{disabled}
{id}
class={extendClassName(className)}
{...props}>
{#each options as option}
<SelectOption {...option} />
{/each}
</select>