import React from 'react'; import { Box, Text, Divider, Tooltip } from '@wix/design-system'; import { ChevronRight, ChevronDown, ChevronUp } from '@wix/wix-ui-icons-common'; import { SetupWidgetStep } from '@wix/bex-core'; import { useWixPatternsContainer } from '@wix/bex-core/react'; import { SetupStepIcon } from './SetupStepIcon'; import { st, classes } from './SetupWidget.st.css.js'; export interface SetupStepCardProps { step: SetupWidgetStep; /** The recommended next step — soft blue surface + bold title. */ isPrimary: boolean; /** Inline content is shown below the header. */ expanded: boolean; onActivate: () => void; renderStepContent?: (step: SetupWidgetStep) => React.ReactNode; } /** * Mobile step card (per Figma "Support FW on mobile"). 12px padding, a 24px * icon cell and a trailing chevron that replaces the per-step CTA button: a * right chevron for navigate / completed (with a completed action) steps, and a * down/up chevron for inline-expandable steps. The whole card is the click * target. Collapsed cards are a bare title + chevron; an expanded inline card * adds a divider, its description, and the consumer content below the header. */ export const SetupStepCard = ({ step, isPrimary, expanded, onActivate, renderStepContent, }: SetupStepCardProps) => { const { translate: t } = useWixPatternsContainer(); const isInProgress = step.status === 'in-progress'; const isCompleted = step.status === 'completed'; const isDisabled = step.status === 'disabled'; const isInline = step.expansionMode === 'inline'; const isInlineExpanded = expanded && isInline; // Completed steps stay actionable only when they carry a completed action. const showCompletedCta = isCompleted && !!step.completedCtaLabel && !isDisabled; // Inline steps toggle; navigate steps act; completed steps fire their action. const isTogglable = isInline && !isCompleted && !isDisabled; const isNavigable = !isInline && !isCompleted && !isDisabled; const clickable = isTogglable || isNavigable || showCompletedCta; // Disabled steps show a muted chevron (with a permission tooltip); completed // steps without an action show none. Everything actionable shows a chevron. const showChevron = clickable || isDisabled; const ChevronIcon = isInline ? isInlineExpanded ? ChevronUp : ChevronDown : ChevronRight; const chevron = showChevron && ( ); // The description only belongs to the expanded inline state. Non-inline steps // keep theirs (if provided) inline below the header. const description = step.description && !isCompleted && ( {step.description} ); return (
{ if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); onActivate(); } } : undefined } > {/* Title + "In progress" badge stack together so the icon centers against the whole block (matches the Figma in-progress card). */} {isCompleted ? {step.title} : step.title} {isInProgress && ( {t('cairo.setupWidget.step.inProgress')} )} {isDisabled ? ( {chevron} ) : ( chevron )} {/* Expanded inline step: a divider separates the header from the description and the consumer-supplied content. */} {isInlineExpanded && ( <> {description} {/* Stop clicks/keys inside the consumer widget from bubbling to the card's toggle handler — otherwise interacting with the content (e.g. an input) would collapse the card. */}
event.stopPropagation()} onKeyDown={(event) => event.stopPropagation()} > {renderStepContent?.(step)}
)} {/* Non-inline steps render their description (if any) under the row. */} {!isInline && description}
); };