mirror of
https://github.com/ankitects/anki.git
synced 2026-01-16 07:19:01 -05:00
52 lines
1.2 KiB
Svelte
52 lines
1.2 KiB
Svelte
<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 {
|
|
height: 30px;
|
|
width: auto;
|
|
|
|
font-size: smaller;
|
|
border-radius: 0;
|
|
}
|
|
</style>
|
|
|
|
<select
|
|
bind:this={buttonRef}
|
|
{disabled}
|
|
{id}
|
|
class={extendClassName(className)}
|
|
{...props}>
|
|
{#each options as option}
|
|
<SelectOption {...option} />
|
|
{/each}
|
|
</select>
|