|
| 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 | +} |
0 commit comments