2023-02-24 05:32:18 +08:00
|
|
|
<script lang="ts">
|
|
|
|
import { fly } from "svelte/transition";
|
|
|
|
import { createEventDispatcher } from "svelte";
|
|
|
|
export let value: string | Array<string> | undefined = undefined;
|
|
|
|
export let filtered: Array<string>;
|
|
|
|
export let showOptions: boolean = false;
|
|
|
|
export let activeOption: string;
|
|
|
|
export let disabled: boolean = false;
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if showOptions && !disabled}
|
|
|
|
<ul
|
|
|
|
class="options"
|
|
|
|
aria-expanded={showOptions}
|
|
|
|
transition:fly={{ duration: 200, y: 5 }}
|
|
|
|
on:mousedown|preventDefault={(e) => dispatch("change", e)}
|
|
|
|
>
|
|
|
|
{#each filtered as choice}
|
|
|
|
<li
|
|
|
|
class="item"
|
|
|
|
role="button"
|
|
|
|
class:selected={value?.includes(choice)}
|
|
|
|
class:active={activeOption === choice}
|
|
|
|
class:bg-gray-100={activeOption === choice}
|
|
|
|
class:dark:bg-gray-600={activeOption === choice}
|
|
|
|
data-value={choice}
|
|
|
|
aria-label={choice}
|
|
|
|
>
|
2023-03-11 01:52:17 +08:00
|
|
|
<span
|
|
|
|
class:hide={!(Array.isArray(value) ? value : [value])?.includes(
|
|
|
|
choice
|
|
|
|
)}
|
|
|
|
class="inner-item pr-1"
|
|
|
|
>
|
2023-02-24 05:32:18 +08:00
|
|
|
✓
|
|
|
|
</span>
|
|
|
|
{choice}
|
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.options {
|
|
|
|
position: absolute;
|
|
|
|
z-index: var(--layer-5);
|
|
|
|
margin-left: 0;
|
|
|
|
box-shadow: var(--shadow-drop-lg);
|
2023-03-07 04:52:31 +08:00
|
|
|
border-radius: var(--container-radius);
|
2023-03-17 22:41:53 +08:00
|
|
|
background: var(--background-primary);
|
2023-02-24 05:32:18 +08:00
|
|
|
width: var(--size-full);
|
|
|
|
max-height: var(--size-32);
|
|
|
|
overflow: auto;
|
2023-03-07 04:52:31 +08:00
|
|
|
color: var(--body-text-color);
|
2023-02-24 05:32:18 +08:00
|
|
|
list-style: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.item {
|
|
|
|
display: flex;
|
|
|
|
cursor: pointer;
|
|
|
|
padding: var(--size-2);
|
|
|
|
}
|
|
|
|
|
|
|
|
.item:hover,
|
|
|
|
.active {
|
2023-03-17 22:41:53 +08:00
|
|
|
background: var(--background-secondary);
|
2023-02-24 05:32:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.inner-item {
|
|
|
|
padding-right: var(--size-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
.hide {
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
</style>
|