89 lines
1.7 KiB
JavaScript
89 lines
1.7 KiB
JavaScript
|
/**
|
||
|
@license
|
||
|
Copyright (c) 2022 trading_peter
|
||
|
This program is available under Apache License Version 2.0
|
||
|
*/
|
||
|
|
||
|
import '@tp/tp-icon/tp-icon.js'
|
||
|
import { LitElement, html, css } from 'lit';
|
||
|
|
||
|
class TpCmdItem extends LitElement {
|
||
|
static get styles() {
|
||
|
return [
|
||
|
css`
|
||
|
:host {
|
||
|
display: block;
|
||
|
cursor: pointer;
|
||
|
position: relative;
|
||
|
}
|
||
|
|
||
|
:host(:hover) {
|
||
|
background: var(--tp-cmd-item-hover, #c1c1c1);
|
||
|
}
|
||
|
|
||
|
:host([disabled]) {
|
||
|
opacity: 0.4;
|
||
|
pointer-events: none;
|
||
|
}
|
||
|
|
||
|
div {
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
}
|
||
|
|
||
|
div[part="wrap"] {
|
||
|
padding: 6px 12px;
|
||
|
}
|
||
|
|
||
|
div[part="icon"] {
|
||
|
min-width: 20px;
|
||
|
padding-right: 8px;
|
||
|
--tp-icon-width: 18px;
|
||
|
--tp-icon-height: 18px;
|
||
|
}
|
||
|
|
||
|
div[part="label"] {
|
||
|
text-overflow: ellipsis;
|
||
|
white-space: nowrap;
|
||
|
}
|
||
|
|
||
|
.sub {
|
||
|
display: none;
|
||
|
position: absolute;
|
||
|
left: 0;
|
||
|
top: 0;
|
||
|
margin-left: calc(100% - 2px);
|
||
|
}
|
||
|
|
||
|
:host(:hover) .sub {
|
||
|
display: block;
|
||
|
}
|
||
|
`
|
||
|
];
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
return html`
|
||
|
<div part="wrap">
|
||
|
<div part="icon">
|
||
|
${this.icon ? html`<tp-icon .icon=${this.icon}></tp-icon>` : null}
|
||
|
</div>
|
||
|
<div part="label">
|
||
|
<slot></slot>
|
||
|
</div>
|
||
|
<div class="sub"><slot name="sub"></slot></div>
|
||
|
</div>
|
||
|
`;
|
||
|
}
|
||
|
|
||
|
static get properties() {
|
||
|
return {
|
||
|
icon: { type: Object },
|
||
|
};
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
window.customElements.define('tp-cmd-item', TpCmdItem);
|