import type { ValidationState } from './../../common/static-wrappers/interfaces/validation-interface'; import { Prop, toNative } from 'vue-facing-decorator'; import TsxComponent, { Component } from '../../app/vuetsx'; import { isNullOrEmpty } from '../../common/utils/is-null-or-empty'; import './css/fieldset.css'; interface FieldsetArgs { caption: string; cssClass?: string; equalHeight?: boolean; validationState?: ValidationState; bottomMargin?: boolean; pulsate?: boolean; customValidationMessage?: ((item) => string) | string; isCollapsedByDefault?: boolean; disableCollapsing?: boolean; } @Component class FieldsetComponent extends TsxComponent implements FieldsetArgs { @Prop() caption!: string; @Prop() cssClass!: string; @Prop() equalHeight!: boolean; @Prop() bottomMargin?: boolean; @Prop() pulsate?: boolean; @Prop() customValidationMessage: (() => string) | string; @Prop() isCollapsedByDefault: boolean; @Prop() disableCollapsing?: boolean; isCollapsed: boolean = false; slotsMaxHeight = 10000; getErrorCssClass(): string { return this.hasValidationError ? ' has-danger' : ''; } getCustomCssClass(): string { return !isNullOrEmpty(this.cssClass) ? ` ${this.cssClass}` : ''; } getPulsatingCssClass(): string { return (this.pulsate == true ? ' btn-pulsating' : ''); } getEqualHeightCssClass(): string { return this.equalHeight == true ? ' fieldset-equal-height' : ''; } getNoBottomMarginCssClass(): string { return this.bottomMargin == false ? ' fieldset-no-bottom-margin' : ''; } getValidationErrorMessage(): string { if (this.customValidationMessage != null) { if (this.customValidationMessage.length && this.customValidationMessage.length == 0) { return this.validationErrorMessage; } else { return (this.customValidationMessage as any)(this); } } return this.validationErrorMessage; } mounted() { if (this.disableCollapsing != true) { this.isCollapsed = this.isCollapsedByDefault === true; } } render(h) { return (
{ if (this.disableCollapsing != true) { this.isCollapsed = !this.isCollapsed; } }} > {this.caption} {' '}
{this.$slots.default?.()}
{this.hasValidationError &&
{this.getValidationErrorMessage()}
}
); } } const Fieldset = toNative(FieldsetComponent); export default Fieldset;