2021-03-31 15:40:11 +02:00
|
|
|
<script lang="typescript">
|
|
|
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
|
|
|
import { disabledKey } from "./contextKeys";
|
|
|
|
import SelectOption from "./SelectOption.svelte";
|
|
|
|
|
|
|
|
interface Option {
|
|
|
|
label: string;
|
|
|
|
value: string;
|
|
|
|
selected: boolean;
|
|
|
|
}
|
|
|
|
|
2021-04-09 22:02:34 +02:00
|
|
|
export let id: string;
|
2021-03-31 15:40:11 +02:00
|
|
|
export let className = "";
|
2021-04-08 16:40:42 +02:00
|
|
|
export let tooltip: string;
|
2021-03-31 15:40:11 +02:00
|
|
|
|
|
|
|
function extendClassName(classes: string) {
|
|
|
|
return `form-select ${classes}`;
|
|
|
|
}
|
|
|
|
|
2021-04-01 18:55:34 +02:00
|
|
|
export let disables = true;
|
2021-03-31 15:40:11 +02:00
|
|
|
export let options: Option[];
|
|
|
|
|
|
|
|
let buttonRef: HTMLSelectElement;
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
|
|
|
|
2021-04-01 18:36:03 +02:00
|
|
|
const disabled = getContext(disabledKey);
|
|
|
|
$: _disabled = disables && $disabled;
|
2021-03-31 15:40:11 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
select {
|
2021-03-31 19:19:24 +02:00
|
|
|
display: inline-block;
|
|
|
|
vertical-align: middle;
|
|
|
|
|
2021-03-31 16:24:28 +02:00
|
|
|
height: var(--toolbar-size);
|
2021-03-31 15:40:11 +02:00
|
|
|
width: auto;
|
|
|
|
|
2021-03-31 16:24:28 +02:00
|
|
|
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;
|
2021-03-31 16:24:28 +02:00
|
|
|
|
2021-03-31 21:09:08 +02:00
|
|
|
&:hover {
|
|
|
|
background-color: #eee;
|
|
|
|
}
|
|
|
|
|
2021-03-31 16:24:28 +02:00
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
}
|
2021-03-31 15:40:11 +02:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<select
|
2021-03-31 16:24:28 +02:00
|
|
|
tabindex="-1"
|
2021-03-31 15:40:11 +02:00
|
|
|
bind:this={buttonRef}
|
2021-04-01 18:36:03 +02:00
|
|
|
disabled={_disabled}
|
2021-03-31 15:40:11 +02:00
|
|
|
{id}
|
|
|
|
class={extendClassName(className)}
|
2021-04-09 22:02:34 +02:00
|
|
|
title={tooltip}>
|
2021-03-31 15:40:11 +02:00
|
|
|
{#each options as option}
|
|
|
|
<SelectOption {...option} />
|
|
|
|
{/each}
|
|
|
|
</select>
|