kopia lustrzana https://github.com/shoelace-style/shoelace
92 wiersze
2.5 KiB
TypeScript
92 wiersze
2.5 KiB
TypeScript
import { html, LitElement } from 'lit';
|
|
import { customElement, property, query } from 'lit/decorators.js';
|
|
import { classMap } from 'lit/directives/class-map.js';
|
|
import '~/components/icon/icon';
|
|
import { watch } from '~/internal/watch';
|
|
import styles from './menu-item.styles';
|
|
|
|
/**
|
|
* @since 2.0
|
|
* @status stable
|
|
*
|
|
* @dependency sl-icon
|
|
*
|
|
* @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.
|
|
*
|
|
* @csspart base - The component's internal wrapper.
|
|
* @csspart prefix - The prefix container.
|
|
* @csspart label - The menu item label.
|
|
* @csspart suffix - The suffix container.
|
|
*/
|
|
@customElement('sl-menu-item')
|
|
export default class SlMenuItem extends LitElement {
|
|
static styles = styles;
|
|
|
|
@query('.menu-item') menuItem: HTMLElement;
|
|
|
|
/** Draws the item in a checked state. */
|
|
@property({ type: Boolean, reflect: true }) checked = false;
|
|
|
|
/** A unique value to store in the menu item. This can be used as a way to identify menu items when selected. */
|
|
@property() value = '';
|
|
|
|
/** Draws the menu item in a disabled state. */
|
|
@property({ type: Boolean, reflect: true }) disabled = false;
|
|
|
|
firstUpdated() {
|
|
this.setAttribute('role', 'menuitem');
|
|
}
|
|
|
|
@watch('checked')
|
|
handleCheckedChange() {
|
|
this.setAttribute('aria-checked', this.checked ? 'true' : 'false');
|
|
}
|
|
|
|
@watch('disabled')
|
|
handleDisabledChange() {
|
|
this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false');
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
<div
|
|
part="base"
|
|
class=${classMap({
|
|
'menu-item': true,
|
|
'menu-item--checked': this.checked,
|
|
'menu-item--disabled': this.disabled,
|
|
'menu-item--has-submenu': false // reserved for future use
|
|
})}
|
|
>
|
|
<span class="menu-item__check">
|
|
<sl-icon name="check-lg" library="default" aria-hidden="true"></sl-icon>
|
|
</span>
|
|
|
|
<span part="prefix" class="menu-item__prefix">
|
|
<slot name="prefix"></slot>
|
|
</span>
|
|
|
|
<span part="label" class="menu-item__label">
|
|
<slot></slot>
|
|
</span>
|
|
|
|
<span part="suffix" class="menu-item__suffix">
|
|
<slot name="suffix"></slot>
|
|
</span>
|
|
|
|
<span class="menu-item__chevron">
|
|
<sl-icon name="chevron-right" library="default" aria-hidden="true"></sl-icon>
|
|
</span>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'sl-menu-item': SlMenuItem;
|
|
}
|
|
}
|