Skip to content

Commit 8226bae

Browse files
committed
docs(list): improve examples & clarify things a bit more
This will also make it easier to test the implementation of the new `limel-list-item` component later.
1 parent 18cd13c commit 8226bae

File tree

9 files changed

+169
-135
lines changed

9 files changed

+169
-135
lines changed
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LimelListCustomEvent, ListItem } from '@limetech/lime-elements';
2-
import { Component, h } from '@stencil/core';
2+
import { Component, h, Host, State } from '@stencil/core';
33

44
/**
55
* List with action menu
@@ -9,6 +9,9 @@ import { Component, h } from '@stencil/core';
99
shadow: true,
1010
})
1111
export class ListActionExample {
12+
@State()
13+
private lastEvent: string = 'No actions yet';
14+
1215
private actionItems: Array<ListItem<number>> = [
1316
{ text: 'Go to my fab object', value: 10 },
1417
{ text: 'Delete object', value: 11 },
@@ -22,16 +25,24 @@ export class ListActionExample {
2225
actions: this.actionItems,
2326
},
2427
{ text: 'Smash Up!', value: 2, icon: 'alien' },
25-
{ text: 'Pandemic', value: 3, icon: 'virus' },
26-
{ text: 'Catan', value: 4, icon: 'wheat' },
27-
{ text: 'Ticket to Ride', value: 5, icon: 'steam_engine' },
2828
];
2929

3030
public render() {
31-
return <limel-list items={this.items} onSelect={this.onSelectAction} />;
31+
return (
32+
<Host>
33+
<limel-list items={this.items} onSelect={this.onSelectAction} />
34+
<limel-example-value
35+
label="Last action"
36+
value={this.lastEvent}
37+
/>
38+
</Host>
39+
);
3240
}
3341

34-
private onSelectAction(event: LimelListCustomEvent<ListItem>) {
35-
console.log('Executing action:', event.detail);
36-
}
42+
private onSelectAction = (event: LimelListCustomEvent<ListItem>) => {
43+
const detail = event.detail as any;
44+
const valuePart =
45+
detail && 'value' in detail ? `, value: ${detail.value}` : '';
46+
this.lastEvent = `Executing action: ${detail?.text ?? 'unknown'}${valuePart}`;
47+
};
3748
}

src/components/list/examples/list-badge-icons.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import { ListItem } from '@limetech/lime-elements';
2-
import { Component, h } from '@stencil/core';
2+
import { Component, h, Host, State } from '@stencil/core';
33

44
/**
55
* List with badge icons
6+
* When `badgeIcons` is set to `true`, the icon's visual motif will be
7+
* rendered slightly smaller, to provide more space for a colorful background.
8+
* So when using a `backgroundColor` on the icon, it could be a good idea to
9+
* also set the `badgeIcons` property to `true`.
610
*/
711
@Component({
812
tag: 'limel-example-list-badge-icons',
913
shadow: true,
1014
styleUrl: 'list-badge-icons.scss',
1115
})
1216
export class BadgeIconsListExample {
17+
@State()
18+
private badgeIcons = true;
19+
1320
private items: Array<ListItem<number>> = [
1421
{
1522
text: 'King of Tokyo',
@@ -42,6 +49,7 @@ export class BadgeIconsListExample {
4249
icon: {
4350
name: 'wheat',
4451
color: 'rgb(var(--color-amber-default))',
52+
backgroundColor: 'rgb(var(--color-cyan-default))',
4553
},
4654
},
4755
{
@@ -50,12 +58,28 @@ export class BadgeIconsListExample {
5058
value: 5,
5159
icon: {
5260
name: 'steam_engine',
53-
color: 'rgb(var(--color-glaucous-default))',
61+
color: 'rgb(var(--color-pink-lighter))',
5462
},
5563
},
5664
];
5765

5866
public render() {
59-
return <limel-list items={this.items} badgeIcons={true} />;
67+
return (
68+
<Host>
69+
<limel-list items={this.items} badgeIcons={this.badgeIcons} />
70+
<limel-example-controls>
71+
<limel-checkbox
72+
checked={this.badgeIcons}
73+
label="badgeIcons"
74+
onChange={this.setBadgeIcons}
75+
/>
76+
</limel-example-controls>
77+
</Host>
78+
);
6079
}
80+
81+
private setBadgeIcons = (event: CustomEvent<boolean>) => {
82+
event.stopPropagation();
83+
this.badgeIcons = event.detail;
84+
};
6185
}

src/components/list/examples/list-checkbox-icons.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { Component, h, State } from '@stencil/core';
33

44
/**
55
* List with checkboxes and icons
6+
*
7+
* By setting `type="checkbox"`, each list item will
8+
* render a checkbox next to it, indicating the user can select
9+
* more than one of the items, empowering you to create
10+
* UIs that clearly indicate multiple selections.
611
*/
712
@Component({
813
tag: 'limel-example-list-checkbox-icons',
@@ -72,10 +77,19 @@ export class ListCheckboxIconsExample {
7277
@State()
7378
private selectedItems: ListItem[] = [];
7479

80+
@State()
81+
private showIcons: boolean = true;
82+
83+
private originalIcons: Record<string, ListItem['icon']> = {};
84+
7585
constructor() {
7686
this.selectedItems = this.items.filter((item) => {
7787
return !!item.selected;
7888
});
89+
90+
for (const item of this.items) {
91+
this.originalIcons[String(item.value)] = item.icon;
92+
}
7993
}
8094

8195
public render() {
@@ -86,6 +100,13 @@ export class ListCheckboxIconsExample {
86100
type="checkbox"
87101
/>,
88102
<limel-example-value value={this.selectedItems} />,
103+
<limel-example-controls>
104+
<limel-checkbox
105+
checked={this.showIcons}
106+
label="icon"
107+
onChange={this.setIcon}
108+
/>
109+
</limel-example-controls>,
89110
];
90111
}
91112

@@ -99,4 +120,14 @@ export class ListCheckboxIconsExample {
99120
return { ...item, selected: selected };
100121
});
101122
};
123+
124+
private setIcon = (event: CustomEvent<boolean>) => {
125+
this.showIcons = event.detail;
126+
this.items = this.items.map((item) => ({
127+
...item,
128+
icon: this.showIcons
129+
? this.originalIcons[String(item.value)]
130+
: undefined,
131+
}));
132+
};
102133
}

src/components/list/examples/list-checkbox.tsx

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/components/list/examples/list-primary-component.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { Component, h } from '@stencil/core';
33

44
/**
55
* List with a primary component
6+
*
7+
* List items can render a custom primary component using the
8+
* `primaryComponent` prop.
9+
*
10+
* :::tip
11+
* By default, the primary component is rendered after the icon
12+
* and before the item's text.
13+
*
14+
* Since the list item is a flexbox, you can easily change the
15+
* order of the primary component by applying a different `order`
16+
* via `style`.
17+
*
18+
* You can set `order` either via the primary component's own styles,
19+
* or via its `props`.
20+
* :::
621
*/
722
@Component({
823
tag: 'limel-example-list-primary-component',
@@ -21,6 +36,10 @@ export class ListCircularProgressExample {
2136
maxValue: 10,
2237
suffix: '%',
2338
displayPercentageColors: true,
39+
size: 'small',
40+
style: {
41+
order: 3,
42+
},
2443
},
2544
},
2645
},
@@ -35,6 +54,7 @@ export class ListCircularProgressExample {
3554
maxValue: 10,
3655
suffix: '%',
3756
displayPercentageColors: true,
57+
size: 'small',
3858
},
3959
},
4060
},
@@ -49,6 +69,7 @@ export class ListCircularProgressExample {
4969
maxValue: 10,
5070
suffix: '%',
5171
displayPercentageColors: true,
72+
size: 'small',
5273
},
5374
},
5475
},
@@ -63,6 +84,7 @@ export class ListCircularProgressExample {
6384
maxValue: 10,
6485
suffix: '%',
6586
displayPercentageColors: true,
87+
size: 'small',
6688
},
6789
},
6890
},

src/components/list/examples/list-radio-button-icons.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { Component, h, State } from '@stencil/core';
33

44
/**
55
* List with radio buttons and icons
6+
*
7+
* By setting `type="radio"`, each list item will
8+
* render a radio button next to it, indicating the user can select
9+
* only one of the items at a time, empowering you to create
10+
* UIs that clearly indicate single selections.
611
*/
712
@Component({
813
tag: 'limel-example-list-radio-button-icons',
@@ -72,10 +77,19 @@ export class ListRadioButtonIconsExample {
7277
@State()
7378
private selectedItem: ListItem;
7479

80+
@State()
81+
private showIcons: boolean = true;
82+
83+
private originalIcons: Record<string, ListItem['icon']> = {};
84+
7585
constructor() {
7686
this.selectedItem = this.items.find((item) => {
7787
return !!item.selected;
7888
});
89+
90+
for (const item of this.items) {
91+
this.originalIcons[String(item.value)] = item.icon;
92+
}
7993
}
8094

8195
public render() {
@@ -86,6 +100,13 @@ export class ListRadioButtonIconsExample {
86100
type="radio"
87101
/>,
88102
<limel-example-value value={this.selectedItem} />,
103+
<limel-example-controls>
104+
<limel-checkbox
105+
checked={this.showIcons}
106+
label="icon"
107+
onChange={this.setIcon}
108+
/>
109+
</limel-example-controls>,
89110
];
90111
}
91112

@@ -99,4 +120,14 @@ export class ListRadioButtonIconsExample {
99120
return item;
100121
});
101122
};
123+
124+
private setIcon = (event: CustomEvent<boolean>) => {
125+
this.showIcons = event.detail;
126+
this.items = this.items.map((item) => ({
127+
...item,
128+
icon: this.showIcons
129+
? this.originalIcons[String(item.value)]
130+
: undefined,
131+
}));
132+
};
102133
}

0 commit comments

Comments
 (0)