tp-tabs/tp-tabs.js

61 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2023-04-04 11:03:16 +02:00
/**
@license
Copyright (c) 2023 trading_peter
This program is available under Apache License Version 2.0
*/
import { closest } from '@tp/helpers';
2023-09-18 13:03:20 +02:00
import { LitElement, html, css } from 'lit';
2023-04-04 11:03:16 +02:00
class TpTabs extends LitElement {
static get styles() {
return css`
2023-09-02 00:18:57 +02:00
:host {
display: block;
}
2023-04-04 11:03:16 +02:00
:host([orientation="vertical"]) .tabs {
flex-direction: column;
}
2024-08-04 22:55:14 +02:00
2023-04-04 11:03:16 +02:00
.tabs {
display: flex;
flex-direction: row;
}
2024-08-04 22:55:14 +02:00
slot::slotted(.tab) {
2023-04-04 11:03:16 +02:00
cursor: pointer;
padding: 8px;
}
`;
}
2023-09-02 00:18:57 +02:00
static get properties() {
return {
orientation: { type: String, reflect: true }
};
}
2023-04-04 11:03:16 +02:00
constructor() {
super();
this.orientation = 'horizontal';
}
render() {
return html`
<div class="tabs" @click="${this.selectTab}">
<slot></slot>
</div>
`;
}
selectTab(e) {
const tab = closest(e.target, '.tab');
if (tab) {
this.dispatchEvent(new CustomEvent('tab-changed', { detail: tab }));
}
}
}
customElements.define('tp-tabs', TpTabs);