# Stepper

## Introduction

The Stepper component visually represents a multi-step process, guiding users through sequential tasks such as forms, onboarding flows, or checkout procedures. It clearly indicates the current step, completed steps, and remaining steps, giving users a sense of progress and orientation within a workflow.

Stepper supports both horizontal and vertical layouts, customizable colors, and flexible step content including labels, extra descriptions, and indicator numbers or icons. It is well suited for wizards, registration flows, order tracking, and any process that benefits from a clear step-by-step breakdown.

```text
// Unable to derive source for Default
```

| Field                        | Description | Default |
| ---------------------------- | ----------- | ------- |
| Controls resolved at runtime | —           | —       |

## Usage

```tsx
import { Stepper } from '@ceed/cds';

function OnboardingFlow() {
  const [activeStep, setActiveStep] = useState(1);

  return (
    <Stepper
      steps={[
        { indicatorContent: 1, label: 'Account', extraContent: 'Create your account' },
        { indicatorContent: 2, label: 'Profile', extraContent: 'Set up your profile' },
        { indicatorContent: 3, label: 'Complete', extraContent: 'Review and finish' },
      ]}
      activeStep={activeStep}
    />
  );
}
```

## Default

The default form of Stepper. It requires `steps` and `activeStep` as mandatory props. Each step can include `indicatorContent`, `label`, and `extraContent`.

```text
// Unable to derive source for Default
```

## Indicator Only

Steps can be rendered with only the indicator, omitting `label` and `extraContent`. This is useful for compact layouts where full labels are not needed.

```text
// Unable to derive source for OnlyIndicator
```

## Orientation

### Horizontal

Set the `orientation` prop to `'horizontal'` to display the Stepper in a horizontal layout.

```text
// Unable to derive source for HorizontalOrientation
```

### Vertical

Set the `orientation` prop to `'vertical'` to display the Stepper vertically. This is the default orientation.

```text
// Unable to derive source for VerticalOrientation
```

## Step Orientation

### Horizontal Step Orientation

Set `stepOrientation` to `'horizontal'` to place each step's content beside the indicator. This is the default step orientation.

```text
// Unable to derive source for HorizontalStepOrientation
```

### Vertical Step Orientation

Set `stepOrientation` to `'vertical'` to place each step's content below the indicator. When `orientation` is `'horizontal'` and `stepOrientation` is `'vertical'`, content is automatically center-aligned.

> **Note:** When `orientation` is set to `'vertical'`, the `stepOrientation` is always forced to `'horizontal'` regardless of the value provided.

```text
// Unable to derive source for VerticalStepOrientation
```

## Color Customization

### Active Color

Use `activeColor` and `activeLineColor` to change the color of active and completed steps and their connecting lines.

```text
// Unable to derive source for WithActiveColor
```

### Inactive Color

Use `inactiveColor` and `inactiveLineColor` to change the color of steps that have not yet been reached.

```text
// Unable to derive source for WithInactiveColor
```

## Step State

### All Steps Complete

When the `activeStep` value exceeds the total number of steps, all steps are displayed as completed.

```text
// Unable to derive source for WithAllComplete
```

### All Steps Inactive

When `activeStep` is set to `0`, all steps are displayed in the inactive state.

```text
// Unable to derive source for WithAllInactive
```

## Common Use Cases

### Form Wizard

```tsx
function FormWizard() {
  const [activeStep, setActiveStep] = useState(1);

  const steps = [
    { indicatorContent: 1, label: 'Personal Info', extraContent: 'Name and contact' },
    { indicatorContent: 2, label: 'Address', extraContent: 'Shipping details' },
    { indicatorContent: 3, label: 'Payment', extraContent: 'Billing information' },
    { indicatorContent: 4, label: 'Confirm', extraContent: 'Review your order' },
  ];

  return (
    <Box>
      <Stepper steps={steps} activeStep={activeStep} orientation="horizontal" />
      <Box sx={{ mt: 3 }}>
        {/* Step content rendered here based on activeStep */}
        <Stack direction="row" gap={1} sx={{ mt: 2 }}>
          <Button disabled={activeStep <= 1} onClick={() => setActiveStep((prev) => prev - 1)}>
            Back
          </Button>
          <Button onClick={() => setActiveStep((prev) => prev + 1)}>
            {activeStep >= steps.length ? 'Finish' : 'Next'}
          </Button>
        </Stack>
      </Box>
    </Box>
  );
}
```

### Order Tracking

```tsx
function OrderTracking({ currentStatus }) {
  const statusToStep = { placed: 1, processing: 2, shipped: 3, delivered: 4 };

  return (
    <Stepper
      orientation="vertical"
      activeStep={statusToStep[currentStatus]}
      activeColor="success.500"
      activeLineColor="success.500"
      steps={[
        { indicatorContent: 1, label: 'Order Placed', extraContent: 'Jan 15, 2025' },
        { indicatorContent: 2, label: 'Processing', extraContent: 'Jan 16, 2025' },
        { indicatorContent: 3, label: 'Shipped', extraContent: 'In transit' },
        { indicatorContent: 4, label: 'Delivered', extraContent: 'Estimated Jan 20' },
      ]}
    />
  );
}
```

### Compact Progress Indicator

```tsx
function CompactProgress({ currentStep, totalSteps }) {
  const steps = Array.from({ length: totalSteps }, (_, i) => ({
    indicatorContent: i + 1,
  }));

  return <Stepper steps={steps} activeStep={currentStep} orientation="horizontal" stepOrientation="vertical" />;
}
```

## Props and Customization

### Key Props

| Prop                | Type                                                                              | Default         | Description                                  |
| ------------------- | --------------------------------------------------------------------------------- | --------------- | -------------------------------------------- |
| `steps`             | `{ indicatorContent?: ReactNode; label?: ReactNode; extraContent?: ReactNode }[]` | (required)      | Step definitions                             |
| `activeStep`        | `number`                                                                          | (required)      | Currently active step index (0-based)        |
| `orientation`       | `'horizontal' \| 'vertical'`                                                      | `'horizontal'`  | Stepper layout direction                     |
| `stepOrientation`   | `'horizontal' \| 'vertical'`                                                      | `'horizontal'`  | Individual step content orientation          |
| `activeColor`       | `string`                                                                          | `'primary.500'` | Color for active/completed step indicators   |
| `inactiveColor`     | `string`                                                                          | `'neutral.400'` | Color for inactive step indicators           |
| `activeLineColor`   | `string`                                                                          | `'primary.500'` | Color for connector lines of completed steps |
| `inactiveLineColor` | `string`                                                                          | `'neutral.300'` | Color for connector lines of future steps    |

## Best Practices

1. **Keep step count manageable**: Limit the number of steps to 3-7 for optimal user comprehension. If more steps are needed, consider grouping them.

```tsx
// ✅ Good: Concise steps
<Stepper steps={[step1, step2, step3, step4]} activeStep={2} />

// ❌ Bad: Too many steps overwhelm users
<Stepper steps={[s1, s2, s3, s4, s5, s6, s7, s8, s9, s10]} activeStep={3} />
```

2. **Use descriptive labels**: Provide clear, concise labels that tell users what each step involves.

```tsx
// ✅ Good: Descriptive labels
{ label: 'Shipping Address', extraContent: 'Where should we deliver?' }

// ❌ Bad: Vague labels
{ label: 'Step 2', extraContent: 'Continue' }
```

3. **Choose the right orientation**: Use horizontal for wide layouts with few steps, and vertical for narrow layouts or many steps.

4. **Indicate completion clearly**: Use `activeStep` values accurately. Setting `activeStep` higher than the step count signals completion of the entire flow.

5. **Use color meaningfully**: Apply `activeColor` to match your application's semantic palette (e.g., success green for completed tasks, primary blue for in-progress).

## Accessibility

- The Stepper uses semantic list markup, making the step sequence understandable by screen readers.
- Each step indicator and label is accessible to assistive technology, conveying both position and state.
- Use descriptive `label` and `extraContent` values so that users relying on screen readers can understand what each step represents.
- Avoid relying solely on color to communicate step status. The structural difference between active, completed, and inactive steps is also conveyed through visual indicators.
