an-anime-game-launcher/src/components/SelectionBox.svelte
Observer KRypt0n_ fca10371b8
Added settings tooltips
- added `tooltip` property for the `Checkbox` and `SelectionBox` components
- changed text selection cursor to default
- added tooltips for some options in the settings menu
2021-12-28 14:16:54 +02:00

74 lines
1.9 KiB
Svelte

<script lang="ts">
import { _ } from 'svelte-i18n';
import Configs from '../ts/Configs';
export let prop: string = '';
export let lang: string = '';
export let tooltip: string = '';
export let items = {};
export let valueChanged: (value: string) => void = () => {};
import Arrow from '../assets/svgs/arrow.svg';
let selectionOpen = false;
let selectedValue;
const selectionChanged = (e: MouseEvent) => {
const li = e.target as HTMLElement;
if (!li.classList.contains('selected'))
{
const lis = li.parentElement!.children!;
for (let i = 0; i < lis.length; i++)
lis[i].classList.remove('selected');
li.classList.add('selected');
Configs.set(prop, li.getAttribute('data-value'));
selectionOpen = false;
}
};
Configs.get(prop).then((value) => selectedValue = value);
</script>
<div class="select" class:select-active={selectionOpen}>
<span>{ $_(lang) }</span>
<div class="select-options">
<ul>
{#each Object.keys(items) as itemLang}
<li
data-value={itemLang}
on:click={selectionChanged}
on:click={() => {
selectedValue = itemLang;
valueChanged(selectedValue);
}}
class:selected={itemLang === selectedValue}
>{ $_(items[itemLang]) }</li>
{/each}
</ul>
</div>
<div
class="selected-item"
class:hint--left={tooltip !== ''}
class:hint--medium={tooltip !== ''}
aria-label={$_(tooltip)}
on:click={() => selectionOpen = !selectionOpen}
>
<span>{ $_(items[selectedValue]) }</span>
<!-- svelte-ignore a11y-missing-attribute -->
<img src={Arrow} />
</div>
</div>