blob: 9cffc7a7183e9dbb630ff629d63430ff6724157e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<script>
import { CookieNames } from "$shared/lib/configuration";
import { get_cookie } from "$shared/lib/helpers";
import { currentLocale } from "$shared/lib/locale";
import { onMount } from "svelte";
export let glow = false;
export let show = false;
export let selection = "preffered";
export let size;
function change(to) {
selection = to;
currentLocale.set(to);
}
onMount(() => {
selection = get_cookie(CookieNames.locale);
document.addEventListener("keydown", (e) => {
if (e.code === "Esc") {
show = false;
}
});
document.addEventListener("click", (e) => {
if (e.target.closest("[data-locale-switcher-element]") === null) {
show = false;
}
});
});
</script>
<div class="bg-light padding-x-xs padding-bottom-xs padding-top-xxxs radius-md {glow ? 'inner-glow shadow-xs':''}"
data-locale-switcher-element
class:is-hidden={!show}
role="listbox">
<div class="flex flex-wrap flex-column"
role="group">
<div class="margin-bottom-xs flex-grow">
<span class="text-xs color-contrast-medium">Language</span>
</div>
<div class="flex gap-xs flex-row">
<div class="ld-switch-popover__option"
aria-selected="{selection === 'en' ? 'true' : 'false'}"
on:click={() => change("en")}
role="option">
<div class="text-xs margin-top-xxxs padding-x-xxxxs">English</div>
</div>
<div class="ld-switch-popover__option"
aria-selected="{selection === 'nb' ? 'true' : 'false'}"
on:click={() => change("nb")}
role="option">
<div class="text-xs margin-top-xxxs padding-x-xxxxs">Norsk</div>
</div>
<div class="ld-switch-popover__option"
aria-selected="{selection === 'preffered' ? 'true' : 'false'}"
on:click={() => change("preffered")}
role="option">
<div class="text-xs margin-top-xxxs padding-x-xxxxs">Default</div>
</div>
</div>
</div>
</div>
|