@mohasinac/appkit 2.7.45 → 2.7.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,8 @@ export interface StepFormProps<T extends object = Record<string, unknown>> {
23
23
  onStepChange: (step: number) => void;
24
24
  /** Suppress the built-in action bar. Use FormShell's renderBottomBar instead. */
25
25
  hideActions?: boolean;
26
+ /** Per-step error flags — when true, step button shows a red error badge */
27
+ stepErrors?: boolean[];
26
28
  }
27
29
  export interface StepFormActionsProps {
28
30
  currentStep: number;
@@ -36,11 +38,13 @@ export interface StepFormActionsProps {
36
38
  /** Standalone step nav bar — use as `renderBottomBar` in FormShell. */
37
39
  export declare function StepFormActions({ currentStep, totalSteps, onNext, onPrev, completeLabel, isLoading, disabled, }: StepFormActionsProps): import("react/jsx-runtime").JSX.Element;
38
40
  /** Step indicator bar shown above step content. */
39
- export declare function StepIndicator({ steps, currentStep, onStepClick, }: {
41
+ export declare function StepIndicator({ steps, currentStep, onStepClick, stepErrors, }: {
40
42
  steps: {
41
43
  label: string;
42
44
  }[];
43
45
  currentStep: number;
44
46
  onStepClick?: (index: number) => void;
47
+ /** True for each step that has a validation error — renders a red dot badge */
48
+ stepErrors?: boolean[];
45
49
  }): import("react/jsx-runtime").JSX.Element;
46
- export declare function StepForm<T extends object = Record<string, unknown>>({ steps, values, onChange, onComplete, completeLabel, isLoading, formId, currentStep, onStepChange, hideActions, }: StepFormProps<T>): import("react/jsx-runtime").JSX.Element;
50
+ export declare function StepForm<T extends object = Record<string, unknown>>({ steps, values, onChange, onComplete, completeLabel, isLoading, formId, currentStep, onStepChange, hideActions, stepErrors, }: StepFormProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -13,25 +13,28 @@ export function StepFormActions({ currentStep, totalSteps, onNext, onPrev, compl
13
13
  return (_jsxs("div", { className: "flex items-center justify-between gap-2 px-5 py-3 border-t border-[var(--appkit-color-border)] bg-[var(--appkit-color-surface)]", children: [_jsx(_Fragment, { children: !isFirst && onPrev && (_jsx(Button, { variant: "outline", size: "sm", onClick: onPrev, disabled: disabled || isLoading, children: "\u2190 Back" })) }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsxs("span", { className: "text-xs text-[var(--appkit-color-text-muted)]", children: [currentStep + 1, " / ", totalSteps] }), _jsx(Button, { variant: "primary", size: "sm", onClick: onNext, disabled: disabled || isLoading, isLoading: isLoading && isLast, children: isLast ? completeLabel : nextStepLabel })] })] }));
14
14
  }
15
15
  /** Step indicator bar shown above step content. */
16
- export function StepIndicator({ steps, currentStep, onStepClick, }) {
16
+ export function StepIndicator({ steps, currentStep, onStepClick, stepErrors, }) {
17
17
  return (_jsx("nav", { "aria-label": "Form steps", className: "flex items-center gap-0 mb-6 overflow-x-auto", children: steps.map((step, i) => {
18
18
  const isDone = i < currentStep;
19
19
  const isActive = i === currentStep;
20
+ const hasError = stepErrors?.[i] === true;
20
21
  return (_jsxs("div", { className: "flex items-center gap-0 flex-shrink-0", children: [_jsxs("button", { type: "button", disabled: !isDone && !isActive, onClick: () => isDone && onStepClick?.(i), className: classNames("flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors", isActive
21
22
  ? "font-semibold text-[var(--appkit-color-primary)]"
22
23
  : isDone
23
24
  ? "text-[var(--appkit-color-text-muted)] cursor-pointer hover:text-[var(--appkit-color-text)]"
24
- : "text-[var(--appkit-color-text-faint)] cursor-default"), children: [_jsx("span", { className: classNames("flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold border-2", isActive
25
- ? "border-[var(--appkit-color-primary)] bg-[var(--appkit-color-primary)] text-white"
26
- : isDone
27
- ? "border-[var(--appkit-color-primary)] bg-[var(--appkit-color-primary)] text-white"
28
- : "border-[var(--appkit-color-border)] text-[var(--appkit-color-text-faint)]"), children: isDone ? _jsx(Check, { className: "w-3 h-3" }) : i + 1 }), _jsx("span", { className: "hidden sm:inline", children: step.label })] }), i < steps.length - 1 && (_jsx("div", { className: classNames("w-6 h-px flex-shrink-0 mx-1", i < currentStep
25
+ : "text-[var(--appkit-color-text-faint)] cursor-default"), children: [_jsxs("span", { className: "relative flex-shrink-0", children: [hasError && (_jsx("span", { className: "absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-[var(--appkit-color-error)] z-10", "aria-label": "This step has errors" })), _jsx("span", { className: classNames("flex-shrink-0 w-6 h-6 rounded-full flex items-center justify-center text-xs font-bold border-2", hasError
26
+ ? "border-[var(--appkit-color-error)] bg-[var(--appkit-color-error)] text-white"
27
+ : isActive
28
+ ? "border-[var(--appkit-color-primary)] bg-[var(--appkit-color-primary)] text-white"
29
+ : isDone
30
+ ? "border-[var(--appkit-color-primary)] bg-[var(--appkit-color-primary)] text-white"
31
+ : "border-[var(--appkit-color-border)] text-[var(--appkit-color-text-faint)]"), children: isDone && !hasError ? _jsx(Check, { className: "w-3 h-3" }) : hasError ? "!" : i + 1 })] }), _jsx("span", { className: "hidden sm:inline", children: step.label })] }), i < steps.length - 1 && (_jsx("div", { className: classNames("w-6 h-px flex-shrink-0 mx-1", i < currentStep
29
32
  ? "bg-[var(--appkit-color-primary)]"
30
33
  : "bg-[var(--appkit-color-border)]") }))] }, i));
31
34
  }) }));
32
35
  }
33
- export function StepForm({ steps, values, onChange, onComplete, completeLabel = "Publish Now", isLoading = false, formId, currentStep, onStepChange, hideActions = false, }) {
34
- const [stepErrors, setStepErrors] = useState({});
36
+ export function StepForm({ steps, values, onChange, onComplete, completeLabel = "Publish Now", isLoading = false, formId, currentStep, onStepChange, hideActions = false, stepErrors, }) {
37
+ const [fieldErrors, setFieldErrors] = useState({});
35
38
  const [stepError, setStepError] = useState(null);
36
39
  // Persist step to localStorage if formId provided
37
40
  useEffect(() => {
@@ -75,8 +78,8 @@ export function StepForm({ steps, values, onChange, onComplete, completeLabel =
75
78
  }, [currentStep, onStepChange]);
76
79
  const currentStepDef = steps[currentStep];
77
80
  const isLast = currentStep === steps.length - 1;
78
- return (_jsxs("div", { className: "flex flex-col", children: [_jsx(StepIndicator, { steps: steps, currentStep: currentStep, onStepClick: (i) => { if (i < currentStep) {
81
+ return (_jsxs("div", { className: "flex flex-col", children: [_jsx(StepIndicator, { steps: steps, currentStep: currentStep, stepErrors: stepErrors, onStepClick: (i) => { if (i < currentStep) {
79
82
  setStepError(null);
80
83
  onStepChange(i);
81
- } } }), _jsx("div", { className: "flex-1", children: currentStepDef?.render({ values, onChange, errors: stepErrors }) }), !hideActions && stepError && (_jsx(Text, { className: "mt-3 text-sm text-[var(--appkit-color-error)]", children: stepError })), !hideActions && (_jsx(StepFormActions, { currentStep: currentStep, totalSteps: steps.length, onNext: () => void goNext(), onPrev: currentStep > 0 ? goPrev : undefined, completeLabel: completeLabel, isLoading: isLoading && isLast, disabled: isLoading }))] }));
84
+ } } }), _jsx("div", { className: "flex-1", children: currentStepDef?.render({ values, onChange, errors: fieldErrors }) }), !hideActions && stepError && (_jsx(Text, { className: "mt-3 text-sm text-[var(--appkit-color-error)]", children: stepError })), !hideActions && (_jsx(StepFormActions, { currentStep: currentStep, totalSteps: steps.length, onNext: () => void goNext(), onPrev: currentStep > 0 ? goPrev : undefined, completeLabel: completeLabel, isLoading: isLoading && isLast, disabled: isLoading }))] }));
82
85
  }