import { html } from '@design.estate/dees-element'; import { DeesStepper, type IStep } from './dees-stepper.js'; const waitForProgressTick = async (timeoutArg: number, signal?: AbortSignal): Promise => { return new Promise((resolve) => { let completed = false; const finish = (result: boolean) => { if (completed) { return; } completed = true; if (signal) { signal.removeEventListener('abort', handleAbort); } resolve(result); }; const handleAbort = () => { window.clearTimeout(timeoutId); finish(false); }; const timeoutId = window.setTimeout(() => { finish(true); }, timeoutArg); if (signal) { signal.addEventListener('abort', handleAbort, { once: true }); } }); }; const createContinueMenuOptions = (labelArg = 'Continue') => [ { name: labelArg, action: async (stepper?: DeesStepper) => stepper?.goNext(), }, ]; const createDemoSteps = (): IStep[] => [ { title: 'Account Setup', content: html` `, menuOptions: createContinueMenuOptions(), }, { title: 'Profile Details', content: html` `, menuOptions: createContinueMenuOptions(), }, { title: 'Contact Information', content: html` `, menuOptions: createContinueMenuOptions(), }, { title: 'Provision Workspace', content: html`

We are creating your starter workspace, applying your onboarding choices, and preparing a live preview. This step moves forward automatically when the environment is ready.

`, progressStep: { label: 'Workspace setup', percentage: 8, indeterminate: true, statusRows: 4, statusText: 'Allocating a clean workspace...', terminalLines: ['Allocating a clean workspace'], }, validationFunc: async (stepper, _htmlElement, signal) => { const progressFrames = [ { line: 'Allocating a clean workspace', percentage: 8, delay: 500 }, { line: 'Syncing account preferences', percentage: 24, delay: 650 }, { line: 'Installing selected integrations', percentage: 47, delay: 700 }, { line: 'Generating starter project files', percentage: 71, delay: 650 }, { line: 'Booting the live preview environment', percentage: 92, delay: 700 }, ]; stepper.resetProgressStep(); for (const [index, progressFrame] of progressFrames.entries()) { if (signal?.aborted) { return; } if (index === 0) { stepper.updateProgressStep({ percentage: progressFrame.percentage, indeterminate: true, statusText: `${progressFrame.line}...`, terminalLines: [progressFrame.line], }); } else { stepper.appendProgressStepLine(progressFrame.line); stepper.updateProgressStep({ percentage: progressFrame.percentage, indeterminate: true, statusText: `${progressFrame.line}...`, }); } const completed = await waitForProgressTick(progressFrame.delay, signal); if (!completed) { return; } } stepper.appendProgressStepLine('Workspace ready'); stepper.updateProgressStep({ percentage: 100, indeterminate: false, statusText: 'Workspace ready.', }); await waitForProgressTick(350, signal); }, }, { title: 'Team Size', content: html` `, menuOptions: createContinueMenuOptions(), }, { title: 'Goals', content: html` `, menuOptions: createContinueMenuOptions(), }, { title: 'Review & Launch', content: html`

Your workspace is ready. Review the collected details and launch when you are ready to start.

`, menuOptions: [ { name: 'Launch', action: async (stepper?: DeesStepper) => { if (stepper?.overlay) { await stepper.destroy(); } }, }, ], }, ]; export const stepperDemo = () => html`
{ await DeesStepper.createAndShow({ steps: createDemoSteps() }); }} >Open stepper as overlay
`;