import { css, html } from 'lit' import { property, state } from 'lit/decorators.js' import { when } from 'lit/directives/when.js' import { UsBaseElement } from '../base/UsBaseElement' import { dispatchCustomEvent } from '../../utils/dispatchCustomEvent' import { customElementIfNotExist } from '../../utils/customElementIfNotExist' import type { IFilterProps } from './model/IFilterProps' import UsFilter_css from './filter.pcss' import '../form/checkbox/UsCheckbox' import '../tooltip/UsTooltip' // import '../icon/UsIcon' declare global { interface HTMLElementTagNameMap { 'us-filter': UsFilter } } @customElementIfNotExist('us-filter') export class UsFilter extends UsBaseElement implements IFilterProps { static styles = [ UsBaseElement.styles, css([UsFilter_css] as TemplateStringsArray | any), ] @property({ type: String }) widgetView: IFilterProps['widgetView'] = 'vertical' @property({ type: Boolean }) checkboxControl = false @property({ type: Boolean }) checkboxControlIndeterminate = false @property({ type: Boolean }) checkboxControlChecked = false @property({ type: String }) title = '' @property({ type: Boolean }) infoTooltip = false @property({ type: String }) titleClear = '' @property({ type: String, attribute: 'data-testid', reflect: true }) dataTestId = 'filter' @state() showInfo = false @state() hovered = false render() { return html`
${when(this.checkboxControl || this.title, () => html`
${when(this.checkboxControl, () => html` `)} ${when(this.title, () => html`${this.title}`)} ${when(this.infoTooltip, () => html`
e.stopPropagation()} @focus=${this.handleFocus} @blur=${this.handleBlur} >
`)}
${when(this.titleClear.length, () => html``)}
`)}
` } onHover() { this.hovered = !this.hovered } handleFocus() { this.showInfo = true } handleBlur() { this.showInfo = false } reciveCheckboxControlValue(e: Event) { const checkbox = e.target as HTMLInputElement dispatchCustomEvent('changeMainControl', checkbox.checked, this) } clear(e: Event) { e.preventDefault() dispatchCustomEvent('clear', true, this, false, false) } }