forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.svelte
More file actions
100 lines (88 loc) · 2.09 KB
/
select.svelte
File metadata and controls
100 lines (88 loc) · 2.09 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script generics="Value extends string" lang="ts">
import { mdiChevronDown } from '@mdi/js'
import Icon from './icon.svelte'
import Label from './label.svelte'
let {
label,
onchange,
value,
values
}: {
label: string
onchange: (value: Value) => void
value: Value
values: readonly [Value, string][]
} = $props()
let id = $props.id()
let current = $derived.by(() => {
let currentOption = values.find(i => i[0] === value)
return currentOption ? currentOption[1] : ' '
})
</script>
<div class="select">
<Label {id}>{label}</Label>
<div class="select_fake">
<div class="select_overflow">
<div class="select_text">{current}</div>
</div>
<Icon path={mdiChevronDown} />
<select
{id}
class="select_select"
onchange={e => {
onchange(e.currentTarget.value as Value)
}}
>
{#each values as [key, name] (key)}
<option selected={value === key} value={key}>{name}</option>
{/each}
</select>
</div>
</div>
<style lang="postcss">
:global {
.select {
flex-shrink: 1;
width: stretch;
}
.select_fake {
position: relative;
box-sizing: border-box;
display: flex;
flex-shrink: 1;
gap: 0.25rem;
align-items: center;
justify-content: space-between;
height: var(--control-height);
padding: 0 var(--control-padding);
overflow: hidden;
font: var(--control-font);
background: --tune-background(--field);
border-radius: var(--base-radius);
box-shadow: var(--field-shadow);
&:has(.select_select:focus-visible) {
@mixin focus;
}
&:has(.select_select:open) {
padding-top: var(--min-size);
box-shadow: var(--pressed-shadow);
}
}
.select_overflow {
flex-shrink: 1;
overflow: hidden;
}
.select_text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.select_select {
position: absolute;
inset: 0;
font: revert;
appearance: none;
opacity: 0%;
}
}
</style>