2020-08-08 19:45:32 +00:00
|
|
|
import { Component, Event, EventEmitter, Prop, Watch, h } from '@stencil/core';
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
/**
|
2020-07-17 10:09:10 +00:00
|
|
|
* @since 2.0
|
2020-07-15 21:30:37 +00:00
|
|
|
* @status stable
|
|
|
|
*
|
|
|
|
* @slot - The menu item's label.
|
|
|
|
* @slot prefix - Used to prepend an icon or similar element to the menu item.
|
|
|
|
* @slot suffix - Used to append an icon or similar element to the menu item.
|
|
|
|
*
|
|
|
|
* @part base - The component's base wrapper.
|
|
|
|
* @part checked-icon - The container that wraps the checked icon.
|
|
|
|
* @part prefix - The prefix container.
|
|
|
|
* @part label - The menu item label.
|
|
|
|
* @part suffix - The suffix container.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
tag: 'sl-menu-item',
|
|
|
|
styleUrl: 'menu-item.scss',
|
|
|
|
shadow: true
|
|
|
|
})
|
|
|
|
export class MenuItem {
|
|
|
|
/** Set to true to draw the item in a checked state. */
|
2020-08-16 15:26:31 +00:00
|
|
|
@Prop({ reflect: true }) checked = false;
|
2020-07-15 21:30:37 +00:00
|
|
|
|
2020-08-30 00:01:16 +00:00
|
|
|
/**
|
|
|
|
* Draws the menu in an active (i.e. or hover/focus), state to indicate the current menu selection. This is used in
|
|
|
|
* lieu of standard :hover and :focus states to prevent concurrent interactions from different devices, such as
|
|
|
|
* focusing with the keyboard and hovering with the mouse.
|
|
|
|
*/
|
2020-08-16 15:26:31 +00:00
|
|
|
@Prop({ reflect: true }) active = false;
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
/** A unique value to store in the menu item. */
|
2020-08-16 15:26:31 +00:00
|
|
|
@Prop({ reflect: true }) value = '';
|
2020-07-15 21:30:37 +00:00
|
|
|
|
|
|
|
/** Set to true to draw the menu item in a disabled state. */
|
2020-08-16 15:26:31 +00:00
|
|
|
@Prop({ reflect: true }) disabled = false;
|
2020-07-15 21:30:37 +00:00
|
|
|
|
2020-08-08 19:45:32 +00:00
|
|
|
@Watch('active')
|
|
|
|
handleActiveChange() {
|
|
|
|
this.active ? this.slActivate.emit() : this.slDeactivate.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Emitted when the menu item becomes active. */
|
2020-10-09 21:45:16 +00:00
|
|
|
@Event({ eventName: 'sl-activate' }) slActivate: EventEmitter;
|
2020-08-08 19:45:32 +00:00
|
|
|
|
|
|
|
/** Emitted when the menu item becomes inactive. */
|
2020-10-09 21:45:16 +00:00
|
|
|
@Event({ eventName: 'sl-deactivate' }) slDeactivate: EventEmitter;
|
2020-08-08 19:45:32 +00:00
|
|
|
|
2020-07-15 21:30:37 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
part="base"
|
|
|
|
class={{
|
|
|
|
'menu-item': true,
|
|
|
|
'menu-item--checked': this.checked,
|
|
|
|
'menu-item--active': this.active,
|
|
|
|
'menu-item--disabled': this.disabled
|
|
|
|
}}
|
|
|
|
role="menuitem"
|
|
|
|
aria-disabled={this.disabled}
|
2020-08-24 16:11:55 +00:00
|
|
|
aria-selected={this.checked}
|
2020-07-15 21:30:37 +00:00
|
|
|
>
|
|
|
|
<span part="checked-icon" class="menu-item__check">
|
|
|
|
<sl-icon name="check2" />
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span part="prefix" class="menu-item__prefix">
|
|
|
|
<slot name="prefix" />
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span part="label" class="menu-item__label">
|
|
|
|
<slot />
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<span part="suffix" class="menu-item__suffix">
|
|
|
|
<slot name="suffix" />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|