import type { PropertyValues } from 'lit'
import { css, html } from 'lit'
import { property, query, state } from 'lit/decorators.js'
import { when } from 'lit/directives/when.js'
import { classMap } from 'lit/directives/class-map.js'
import { styleMap } from 'lit/directives/style-map.js'
import { UsBaseElement } from '../base/UsBaseElement'
import { customElementIfNotExist } from '../../utils/customElementIfNotExist'
import { dispatchCustomEvent } from '../../utils/dispatchCustomEvent'
import { EnumModalHeaderTypes } from '../modalHeader/model/IModalHeaderProps'
import type { IPopupPositions, IPopupProps } from './model/IPopupProps'
import UsPopup_css from './popup.pcss'
import vars_css from './vars.pcss'
import '../../layouts/scrollLayout/ScrollLayout'
import '../modalHeader/UsModalHeader'
import '../header/UsHeader'
import '../button/UsButton'
declare global {
interface HTMLElementTagNameMap {
'us-popup': UsPopup
}
}
@customElementIfNotExist('us-popup')
export class UsPopup extends UsBaseElement implements IPopupProps {
static styles = [
UsBaseElement.styles,
css([vars_css] as TemplateStringsArray | any),
css([UsPopup_css] as TemplateStringsArray | any),
]
@property({ type: String }) width = '256px'
@property({ type: String }) maxWidth = 'none'
@property({ type: String }) height = 'auto'
@property({ type: String }) maxHeight = 'none'
@property({ type: String }) name!: string
@property({ type: Boolean }) boxShadow = false
@property({ type: Boolean }) overlay = false
@property({ type: Boolean }) show = false
@property({ type: Boolean }) alternativeHeader = false
@property({ type: Boolean }) scrollable = false
@property({ type: Boolean }) hideCloseButton = false
@property({ type: Boolean }) notFullWidth = false
@property({ type: Boolean }) noContentPadding = false
@property({ type: String }) beforeTitleIcon: EnumModalHeaderTypes = EnumModalHeaderTypes.DEFAULT
@property({ type: Boolean }) readonly = false
// if you need open the modal over another one
@property({ type: Boolean }) openOver = false
@property({ type: String }) position: IPopupPositions = 'center'
@property({ type: String }) variant: IPopupProps['variant'] = 'default'
@property({ type: String, attribute: 'data-testid', reflect: true })
dataTestId = 'popup'
@property({ type: Boolean }) transparent = false
@state() innerShow!: boolean
@query('.us-popup') _popupContainer: HTMLDivElement | undefined
connectedCallback() {
super.connectedCallback()
this.addEventListener('keyup', this.onKeypress)
}
disconnectedCallback() {
this.removeEventListener('keyup', this.onKeypress)
super.disconnectedCallback()
}
firstUpdated(_changedProperties: PropertyValues) {
this.focusContainer()
super.firstUpdated(_changedProperties)
}
async updated(changeProperties: PropertyValues) {
await super.updated(changeProperties)
if (changeProperties.has('show'))
this.innerShow = this.show
}
render() {
const defaultHeader = html`
${when(!this.hideCloseButton, () => html`