-
-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy path_TwoLineSelection.svelte
More file actions
95 lines (88 loc) · 1.97 KB
/
Copy path_TwoLineSelection.svelte
File metadata and controls
95 lines (88 loc) · 1.97 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
<div>
<List
class="demo-list"
bind:this={list}
twoLine
avatarList
singleSelection
selectedIndex={selectionIndex}
>
{#each options as item, i}
<Item
onSMUIAction={() => (selectionIndex = i)}
disabled={item.disabled}
selected={selectionIndex === i}
>
<Graphic
style="background-image: url(https://placehold.co/40x40?text={item.name
.split(' ')
.map((val) => val.substring(0, 1))
.join('')});"
/>
<Text>
<PrimaryText>{item.name}</PrimaryText>
<SecondaryText>{item.description}</SecondaryText>
</Text>
<Meta class="material-icons">info</Meta>
</Item>
{/each}
</List>
</div>
<pre class="status">Selected: {selectionIndex} - {options[selectionIndex]
.name}</pre>
<div style="margin-top: 1em;">
<div>Programmatically select:</div>
{#each options as option, i}
<Button onclick={() => (selectionIndex = i)}>
<Label>{option.name}</Label>
</Button>
{/each}
</div>
<div style="margin-top: 1em;">
<div>Programmatically focus:</div>
{#each options as option, i}
<Button onclick={() => list.focusItemAtIndex(i)}>
<Label>{option.name}</Label>
</Button>
{/each}
</div>
<script lang="ts">
import List, {
Item,
Graphic,
Meta,
Text,
PrimaryText,
SecondaryText,
} from '@smui/list';
import Button, { Label } from '@smui/button';
let list: List;
let options = [
{
name: 'Bruce Willis',
description: 'Actor',
disabled: false,
},
{
name: 'Austin Powers',
description: 'Fictional Character',
disabled: true,
},
{
name: 'Thomas Edison',
description: 'Inventor',
disabled: false,
},
{
name: 'Stephen Hawking',
description: 'Scientist',
disabled: false,
},
];
let selectionIndex = $state(3);
</script>
<style>
* :global(.demo-list) {
max-width: 600px;
}
</style>