import type WizardTab from './wizard-tab'; import { Prop, toNative } from 'vue-facing-decorator'; import PowerduckState from '../../app/powerduck-state'; import TsxComponent, { Component } from '../../app/vuetsx'; import { slotUnwrapper } from '../../common/slot-unwrapper'; import Button from '../button/button'; import { ButtonLayout } from '../button/button-layout'; import LaddaButton from '../button/ladda-button'; import './css/wizard.css'; interface WizardArgs { fullSizeOnMobile?: boolean; tabListCssClass?: string; cssClass?: string; activePageChanged?: (tabId: string) => void; validate?: (tabId: string) => Promise; submitClicked?: () => Promise; headerButtonCustomRender?: (h, tab: typeof WizardTab.prototype, index: number) => void; submitText?: string; customButtons?: (h, tabId: string) => any; includeHeaderButtonIndex?: boolean; } @Component class WizardComponentComponent extends TsxComponent implements WizardArgs { @Prop() submitClicked: () => Promise; @Prop() tabListCssClass?: string; @Prop() cssClass?: string; @Prop() validate: (tabId: string) => Promise; @Prop() activePageChanged?: (tabId: string) => void; @Prop() customButtons: (h, tabId: string) => any; @Prop() headerButtonCustomRender?: (h, tab: typeof WizardTab.prototype, index: number) => void; @Prop() fullSizeOnMobile: boolean; @Prop() submitText!: string; @Prop() includeHeaderButtonIndex: boolean; activePageIndex: number = 0; private getChildTabs(): typeof WizardTab.prototype[] { return (this.getSlotProperties('WizardTab') as typeof WizardTab.prototype[]).filter(p => p.visible != false); } public setActivePageIndex(index: number): void { this.activePageIndex = index; } public getActivePageIndex(): number { return this.activePageIndex; } public nextPage(): void { if (this.validate != null) { const activeTab = this.getChildTabs()[this.getActivePageIndex()]; this.validate(activeTab.id).then((valid) => { if (valid) { this.performNextPage(); } }); } else { this.performNextPage(); } } private performNextPage(): void { this.activePageIndex += 1; if (this.activePageIndex >= this.getChildTabs().length) { this.activePageIndex = this.getChildTabs().length - 1; } if (this.activePageChanged != null) { this.activePageChanged(this.getChildTabs()[this.activePageIndex].id); } } private previousPage(): void { this.activePageIndex -= 1; if (this.activePageIndex < 0) { this.activePageIndex = 0; } if (this.activePageChanged != null) { this.activePageChanged(this.getChildTabs()[this.activePageIndex].id); } } private handleHeaderClicked(newIndex: number): void { if (this.activePageIndex > newIndex) { this.activePageIndex = newIndex; if (this.activePageChanged != null) { this.activePageChanged(this.getChildTabs()[this.activePageIndex].id); } } } private render(h) { const childTabs = this.getChildTabs(); const activeIndex = this.getActivePageIndex(); const activeTab: typeof WizardTab.prototype = childTabs[activeIndex] || ({} as any); const widthPct = 100 / childTabs.length; const lineWidth = 100 - widthPct + 1; const btnRender = (this.customButtons != null ? this.customButtons(h, activeTab.id) : null); const renderCustomHeaderButton = this.headerButtonCustomRender != null; return (

{activeTab.title}

{activeTab.subtitle &&

{activeTab.subtitle}

} {slotUnwrapper(this.$slots.default?.())[activeIndex]}
{activeIndex > 0 && (
); } } const WizardComponent = toNative(WizardComponentComponent); export default WizardComponent;