import type { DropdownButtonItemArgs } from './../dropdown-button/dropdown-button-item'; import type { FormItemWrapperArgs, HintType, MarginType } from './form-item-wrapper'; import { Prop, toNative } from 'vue-facing-decorator'; import TsxComponent, { Component } from '../../app/vuetsx'; import { slotUnwrapper } from '../../common/slot-unwrapper'; import FormItemWrapper from './form-item-wrapper'; export interface FormInputAction { icon?: string; text: string; clicked: () => void; } export type MultipleInputWrapperCols = 1 | 2 | 3 | 4 | 6; interface MultipleInputWrapperArgs extends Omit { label?: string; actions?: FormInputAction[]; colCount: MultipleInputWrapperCols; } @Component class MultipleInputWrapperComponent extends TsxComponent implements MultipleInputWrapperArgs { @Prop() label?: string; @Prop() actions!: FormInputAction[]; @Prop() labelButtons: DropdownButtonItemArgs[]; @Prop() mandatory: boolean; @Prop() flex: boolean; @Prop() hint: string; @Prop() subtitle: string; @Prop() hintType: HintType; @Prop() marginType?: MarginType; @Prop() maxWidth?: number; @Prop() appendIcon: string; @Prop() prependIcon: string; @Prop() cssClass: string; @Prop() appendClicked: () => void; @Prop() prependClicked: () => void; @Prop() wrap: boolean; @Prop() colCount: MultipleInputWrapperCols; getColsCssClass() { switch (this.colCount) { case 1: return 'col-12'; case 2: return 'col-6'; case 3: return 'col-4'; case 4: return 'col-3'; case 6: return 'col-2'; } } renderInputs(h) { const cols = []; const unwrappedSlots = slotUnwrapper(this.$slots.default?.()); for (let i = 0; i < unwrappedSlots?.length; i += this.colCount) { cols.push(unwrappedSlots?.slice(i, i + this.colCount)); } return (cols.map((col, index) => (
{col.map((item, subIndex) => (
{item}
))}
))); } renderActions(h) { return (
{this.actions.map((action, index) => ( action.clicked()}> {action.icon && } {action.text} ))}
); } render(h) { if (this.label) { return ( {this.$slots.default && this.renderInputs(h)} {this.actions && this.renderActions(h)} ); } else { return (
{this.$slots.default && this.renderInputs(h)} {this.actions && this.renderActions(h)}
); } } } const MultipleInputWrapper = toNative(MultipleInputWrapperComponent); export default MultipleInputWrapper;