Skip to content

Commit 5a80fc8

Browse files
committed
fixup! feat(menu): use primaryComponent from the limel-list
1 parent d58487e commit 5a80fc8

6 files changed

Lines changed: 87 additions & 5 deletions

File tree

src/components/list-item/list-item.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ limel-list-item[disabled]:not([disabled='false']) {
6767
.text,
6868
limel-icon,
6969
img,
70-
.boolean-input {
70+
.boolean-input,
71+
limel-menu-item-meta {
7172
opacity: 0.4;
7273
}
7374
}

src/components/list-item/list-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class ListItemComponent implements ListItem {
252252
const PrimaryComponent: any = primary.name;
253253
const props = primary.props || {};
254254

255-
return <PrimaryComponent {...props} />;
255+
return <PrimaryComponent {...props} disabled={this.disabled} />;
256256
};
257257

258258
private renderImage = () => {

src/components/list-item/menu-item-meta/menu-item-meta.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class MenuItemMeta {
9797
const PrimaryComponent: any = primary.name;
9898
const props = primary.props || {};
9999

100-
return <PrimaryComponent {...props} />;
100+
return <PrimaryComponent {...props} disabled={this.disabled} />;
101101
}
102102

103103
private renderChevron() {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { LimelMenuCustomEvent, MenuItem } from '@limetech/lime-elements';
2+
import { Component, h, State } from '@stencil/core';
3+
4+
/**
5+
* With a primary component
6+
*
7+
* Menu items can render a custom primary component using the
8+
* `primaryComponent` prop, just like list items.
9+
*
10+
* The component is rendered before the item's text.
11+
*/
12+
@Component({
13+
tag: 'limel-example-menu-primary-component',
14+
shadow: true,
15+
})
16+
export class MenuPrimaryComponentExample {
17+
@State()
18+
private lastSelectedItem: string;
19+
20+
private items: MenuItem[] = [
21+
{
22+
text: 'Upload file',
23+
secondaryText: 'Completed',
24+
primaryComponent: {
25+
name: 'limel-circular-progress',
26+
props: {
27+
value: 10,
28+
maxValue: 10,
29+
suffix: '%',
30+
displayPercentageColors: true,
31+
size: 'small',
32+
},
33+
},
34+
},
35+
{
36+
text: 'Sync contacts',
37+
secondaryText: 'In progress…',
38+
primaryComponent: {
39+
name: 'limel-circular-progress',
40+
props: {
41+
value: 4,
42+
maxValue: 10,
43+
suffix: '%',
44+
displayPercentageColors: true,
45+
size: 'small',
46+
},
47+
},
48+
},
49+
{
50+
text: 'Generate report',
51+
secondaryText: 'Just started',
52+
primaryComponent: {
53+
name: 'limel-circular-progress',
54+
props: {
55+
value: 1,
56+
maxValue: 10,
57+
suffix: '%',
58+
displayPercentageColors: true,
59+
size: 'small',
60+
},
61+
},
62+
},
63+
];
64+
65+
public render() {
66+
return [
67+
<limel-menu items={this.items} onSelect={this.handleSelect}>
68+
<limel-button label="Tasks" slot="trigger" />
69+
</limel-menu>,
70+
<limel-example-value value={this.lastSelectedItem} />,
71+
];
72+
}
73+
74+
private handleSelect = (event: LimelMenuCustomEvent<MenuItem>) => {
75+
this.lastSelectedItem = event.detail.text;
76+
};
77+
}

src/components/menu/menu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const DEFAULT_ROOT_BREADCRUMBS_ITEM: BreadcrumbsItem = {
6060
* @exampleComponent limel-example-menu-surface-width
6161
* @exampleComponent limel-example-menu-separators
6262
* @exampleComponent limel-example-menu-icons
63+
* @exampleComponent limel-example-menu-primary-component
6364
* @exampleComponent limel-example-menu-badge-icons
6465
* @exampleComponent limel-example-menu-grid
6566
* @exampleComponent limel-example-menu-secondary-text

src/components/menu/menu.types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ export interface MenuItem<T = any> {
124124

125125
/**
126126
* Component used to render additional content in the menu item.
127-
* Rendered before the item's text, similar to `primaryComponent`
128-
* on `ListItem`.
127+
*
128+
* When the menu item is disabled, the `disabled` prop is automatically
129+
* propagated to the primary component.
130+
*
131+
* See `limel-example-menu-primary-component` for usage.
129132
*/
130133
primaryComponent?: ListComponent;
131134

0 commit comments

Comments
 (0)