Skip to content

Commit

Permalink
feat(menu): support for icons
Browse files Browse the repository at this point in the history
  • Loading branch information
jgroth authored and adrianschmidt committed Sep 10, 2019
1 parent 20dc083 commit bb57785
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/list/list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ListItem {
disabled?: boolean;

/**
* Name of the icon to use. Not valid for `filter`
* Name of the icon to use.
*/
icon?: string;

Expand Down
18 changes: 18 additions & 0 deletions src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class Menu {
data-index={index}
{...props}
>
{item.icon ? this.renderIcon(item) : null}
<span class="mdc-list-item__text">
{this.renderText(item.text, item.secondaryText)}
</span>
Expand All @@ -164,6 +165,23 @@ export class Menu {
];
}

/**
* Render an icon for a list item
*
* @param {ListItem} item the list item
*
* @returns {HTMLElement} the icon element
*/
private renderIcon(item: ListItem) {
return (
<limel-icon
class="mdc-list-item__graphic"
name={item.icon}
size="medium"
/>
);
}

private renderTrigger() {
return (
<button
Expand Down
21 changes: 21 additions & 0 deletions src/examples/menu/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Component, State } from '@stencil/core';
import { ListItem, ListSeparator } from '../../interface';

const icons = [
'Editing/copy',
'Editing/cut',
'Editing/paste',
'',
'user_interface/add',
'Editing/delete',
];

@Component({
tag: 'limel-example-menu',
shadow: true,
Expand Down Expand Up @@ -61,6 +70,18 @@ export class MenuExample {
</limel-menu>
</p>
</section>,
<section>
<h3>With icons</h3>
<p>
<limel-menu
label="Menu"
items={this.items.map((item, index) => {
return { ...item, icon: icons[index] };
})}
onSelect={this.onSelect}
/>
</p>
</section>,
<hr />,
<p>
When importing ListItem and ListSeparator, see{' '}
Expand Down

0 comments on commit bb57785

Please sign in to comment.