-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathlist-checkbox.tsx
More file actions
57 lines (51 loc) · 1.63 KB
/
list-checkbox.tsx
File metadata and controls
57 lines (51 loc) · 1.63 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
import {
LimelListCustomEvent,
ListItem,
ListSeparator,
} from '@limetech/lime-elements';
import { Component, h, State } from '@stencil/core';
/**
* List with checkboxes
*/
@Component({
tag: 'limel-example-list-checkbox',
shadow: true,
})
export class ListCheckboxExample {
@State()
private items: Array<ListItem | ListSeparator> = [
{ text: 'Pikachu', value: 1, selected: true },
{ text: 'Charmander', value: 2, selected: false, disabled: true },
{ text: 'Super Mario', value: 3, selected: false },
{ separator: true },
{ text: 'Yoshi', value: 4, selected: false, disabled: true },
{ text: 'Minion', value: 6, selected: true },
{ text: 'Pokéball', value: 5, selected: false },
];
@State()
private selectedItems: Array<ListItem | ListSeparator> = [];
constructor() {
this.selectedItems = this.items.filter((item: ListItem) => {
return !!item.selected;
});
}
public render() {
return [
<limel-list
onChange={this.handleChange}
items={this.items}
type="checkbox"
/>,
<limel-example-value value={this.selectedItems} />,
];
}
private handleChange = (event: LimelListCustomEvent<ListItem[]>) => {
this.selectedItems = event.detail;
this.items = this.items.map((item: ListItem) => {
const selected = event.detail.some((selectedItem: ListItem) => {
return selectedItem.value === item.value;
});
return { ...item, selected: selected };
});
};
}