import { css, html } from 'lit' import type { PropertyValues } from 'lit' import { property, state } from 'lit/decorators.js' import { when } from 'lit/directives/when.js' import { classMap } from 'lit/directives/class-map.js' import { customElementIfNotExist } from '../../utils/customElementIfNotExist' import { dispatchCustomEvent } from '../../utils/dispatchCustomEvent' import { UsBaseElement } from '../base/UsBaseElement' import { localizeManager, localized } from '../../dependencies' import type { IGroupBoxProps } from './model/IGroupBoxProps' import UsGroupBox_css from './groupBox.pcss' // import '../icon/UsIcon' declare global { interface HTMLElementTagNameMap { 'us-group-box': UsGroupBox } } @localized() @customElementIfNotExist('us-group-box') export class UsGroupBox extends UsBaseElement implements IGroupBoxProps { static styles = [ UsBaseElement.styles, css([UsGroupBox_css] as TemplateStringsArray | any), ] @property({ type: Boolean }) hasBackground = false @property({ type: Boolean }) collapse = false @property({ type: Boolean }) collapseOpened = false @property({ type: Boolean }) showClearButton = false @property({ type: String, attribute: 'data-testid', reflect: true }) dataTestId = 'box_group' @state() isOpened = false willUpdate(changedProperties: PropertyValues) { if (changedProperties.has('collapseOpened')) this.isOpened = this.collapseOpened if (changedProperties.has('collapse') && !this.collapse) this.isOpened = true } render() { return html`
${when(this.showClearButton, () => html` ${localizeManager.button_clear()} `)} ${when(this.collapse, () => html` `)}
${when(this.isOpened || !this.collapse, () => html` `)}
` } handleCollapse() { this.isOpened = !this.isOpened dispatchCustomEvent('collapse', this.isOpened, this) } handleCollapseByClick(event: PointerEvent) { event.stopImmediatePropagation() this.handleCollapse() } handleClearButton() { dispatchCustomEvent('clear', true, this) } handleCollapseByEnter(e: KeyboardEvent) { if (e.key === 'Enter') this.handleCollapse() } }