2021-03-08 12:51:31 +00:00
|
|
|
import { LitElement, html, property, unsafeCSS } from 'lit-element';
|
|
|
|
import { tag } from '../../internal/decorators';
|
2021-02-26 14:09:13 +00:00
|
|
|
import styles from 'sass:./tab-panel.scss';
|
|
|
|
|
|
|
|
let id = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @since 2.0
|
|
|
|
* @status stable
|
|
|
|
*
|
|
|
|
* @slot - The tab panel's content.
|
|
|
|
*
|
|
|
|
* @part base - The component's base wrapper.
|
|
|
|
*/
|
2021-03-08 12:51:31 +00:00
|
|
|
@tag('sl-tab-panel')
|
2021-03-06 17:01:39 +00:00
|
|
|
export class SlTabPanel extends LitElement {
|
|
|
|
static styles = unsafeCSS(styles);
|
2021-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
private componentId = `tab-panel-${++id}`;
|
|
|
|
|
|
|
|
/** The tab panel's name. */
|
2021-03-06 17:01:39 +00:00
|
|
|
@property() name = '';
|
2021-02-26 14:09:13 +00:00
|
|
|
|
|
|
|
/** When true, the tab panel will be shown. */
|
2021-03-06 17:01:39 +00:00
|
|
|
@property({ type: Boolean, reflect: true }) active = false;
|
2021-02-26 14:09:13 +00:00
|
|
|
|
2021-03-06 17:01:39 +00:00
|
|
|
firstUpdated() {
|
2021-02-26 14:09:13 +00:00
|
|
|
this.id = this.id || this.componentId;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.style.display = this.active ? 'block' : 'none';
|
|
|
|
|
|
|
|
return html`
|
|
|
|
<div
|
|
|
|
part="base"
|
|
|
|
class="tab-panel"
|
|
|
|
role="tabpanel"
|
|
|
|
aria-selected=${this.active ? 'true' : 'false'}
|
|
|
|
aria-hidden=${this.active ? 'false' : 'true'}
|
|
|
|
>
|
2021-03-06 17:01:39 +00:00
|
|
|
<slot></slot>
|
2021-02-26 14:09:13 +00:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|