import { Inject, Prop, toNative } from 'vue-facing-decorator'; import TsxComponent, { Component } from '../../app/vuetsx'; import { isNullOrEmpty } from '../../common/utils/is-null-or-empty'; import './css/flex.css'; /** * Registers a `DatetimePicker` with the containers around it and returns its release. A full-width container * clips its overflow on a phone, so one that holds a picker lets the calendar out (`datetime-picker.css`). * * @internal */ export type FlexContainerRegistration = () => () => void; /** * The provide/inject key of {@link FlexContainerRegistration}. * * @internal */ export const FLEX_CONTAINER_KEY = 'pd-flex-container'; interface FlexContainerArgs { cssClass?: string; fullWidthOnMobile?: boolean; verticalAlign?: 'unset' | 'top' | 'center' | 'bottom'; } @Component({ provide(this: { registerDatetimePicker: FlexContainerRegistration }) { return { [FLEX_CONTAINER_KEY]: this.registerDatetimePicker }; }, }) class FlexContainerComponent extends TsxComponent implements FlexContainerArgs { @Prop() cssClass!: string; @Prop() fullWidthOnMobile!: boolean; @Prop() verticalAlign?: 'unset' | 'top' | 'center' | 'bottom'; @Inject({ from: FLEX_CONTAINER_KEY, default: null }) outerContainer!: FlexContainerRegistration | null; datetimePickers: number = 0; /** * See {@link FlexContainerRegistration}. * * @internal */ registerDatetimePicker(): () => void { const releaseOuter = this.outerContainer?.(); this.datetimePickers++; return () => { this.datetimePickers--; releaseOuter?.(); }; } getCustomCssClass(): string { return !isNullOrEmpty(this.cssClass) ? ` ${this.cssClass}` : ''; } getFullWidthClass(): string { return this.fullWidthOnMobile != false ? ' frm-flex-mobilefw' : ''; } getVerticalAlignClass(): string { if (this.verticalAlign == null || this.verticalAlign == 'unset') { return ''; } return ` frm-item-alignment-${this.verticalAlign}`; } render(h) { return
0 ? ' frm-flex-container--has-datetime-picker' : ''}`}>{this.$slots.default?.()}
; } } const FlexContainer = toNative(FlexContainerComponent); export default FlexContainer;