-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathChipGroup.svelte
More file actions
43 lines (38 loc) · 947 Bytes
/
ChipGroup.svelte
File metadata and controls
43 lines (38 loc) · 947 Bytes
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
<script lang="ts" context="module">
export interface ChipData {
label: string;
id: string;
selected: boolean;
}
</script>
<script lang="ts">
import { createEventDispatcher } from "svelte";
import Chip from "./Chip.svelte";
export let chips: ChipData[] = [];
export let testId: string = "chip-group-component";
const dispatch = createEventDispatcher();
const onChipClick = ({ detail: selectedId }: CustomEvent<string>) => {
chips = chips.map((chip) => ({
...chip,
selected: chip.id === selectedId,
}));
dispatch("nnsSelect", selectedId);
};
</script>
<div
data-tid={testId}
class="chip-group"
role="radiogroup"
aria-label="Options"
>
{#each chips as { id, label, selected } (id)}
<Chip {id} {label} {selected} on:nnsClick={onChipClick} />
{/each}
</div>
<style lang="scss">
.chip-group {
display: flex;
flex-wrap: wrap;
gap: var(--padding-0_5x);
}
</style>