orbital-ui 0.1.1

Leptos component library and design system for focused, accessible product UIs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
//! Stepper component for multi-step workflows.
//!
//! A generic stepper for deployment pipelines, setup wizards, onboarding
//! flows, and similar multi-step processes. Supports vertical (default)
//! and horizontal orientations with status indicators and connector lines.

use leptos::prelude::*;
use leptos::tachys::view::any_view::{AnyView, IntoAny};
use orbital_macros::component_doc;
use turf::inline_style_sheet_values;

use super::{Body1, Caption1};
use crate::primitives::*;

#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum StepStatus {
    #[default]
    Pending,
    Active,
    Done,
    Failed,
    /// Step omitted from the flow (e.g. optional phase not enabled).
    Skipped,
}

#[slot]
pub struct Step {
    #[prop(into)]
    pub label: String,
    pub status: StepStatus,
    #[prop(optional, into)]
    pub message: Option<String>,
}

/// A status-driven timeline for wizards, deployments, and onboarding flows.
///
/// Renders steps with icons, connector lines, and an optional progress bar. Declare steps as `<Step slot:steps label=… status=… />` children — each step carries its own [`StepStatus`] rather than a single active index.
///
/// # When to use
///
/// - Setup wizards, deployment pipelines, and onboarding flows
/// - Vertical timelines (default) or horizontal wizard headers via `vertical=false`
/// - Optional `progress` bar (0–100) for long-running operations
///
/// # Don't
///
/// - **Not for carousel slide dots** — use `CarouselStepper` inside a `Carousel` instead
/// - Display-only today — parent drives `status` updates; steps are not clickable navigation
///
/// # Examples
///
/// ## Default
/// Vertical stepper with mixed step statuses and an active-step message. Use for deployment pipelines, setup wizards, and any multi-step workflow timeline.
/// <!-- default -->
/// <!-- preview -->
/// ```rust
/// view! {
///     <div data-testid="stepper-preview">
///     <Stepper>
///         <Step slot:steps label="Build Docker image" status=StepStatus::Done />
///         <Step slot:steps label="Export image" status=StepStatus::Active message="Compressing layers..." />
///         <Step slot:steps label="Transfer to server" status=StepStatus::Pending />
///         <Step slot:steps label="Start container" status=StepStatus::Pending />
///     </Stepper>
///     </div>
/// }
/// ```
///
/// ## All Done
/// Every step marked complete with green check icons and solid connectors. Use when a process has finished successfully and you want a clear completion state.
/// <!-- preview -->
/// ```rust
/// view! {
///     <Stepper>
///         <Step slot:steps label="Download" status=StepStatus::Done />
///         <Step slot:steps label="Install" status=StepStatus::Done />
///         <Step slot:steps label="Configure" status=StepStatus::Done />
///     </Stepper>
/// }
/// ```
///
/// ## With Failure
/// Failed step with a danger icon, error message, and dashed connectors to pending steps. Use when a step fails and you need to surface the failure reason inline.
/// <!-- preview -->
/// ```rust
/// view! {
///     <Stepper>
///         <Step slot:steps label="Validate input" status=StepStatus::Done />
///         <Step slot:steps label="Connect to server" status=StepStatus::Failed message="Connection refused" />
///         <Step slot:steps label="Upload data" status=StepStatus::Pending />
///     </Stepper>
/// }
/// ```
///
/// ## Horizontal Wizard
/// Horizontal layout with step labels centered under icons, suited to wizard headers. Use at the top of multi-page forms where steps read left to right.
/// <!-- preview -->
/// ```rust
/// view! {
///     <Stepper vertical=false>
///         <Step slot:steps label="Account" status=StepStatus::Done />
///         <Step slot:steps label="Profile" status=StepStatus::Active />
///         <Step slot:steps label="Preferences" status=StepStatus::Pending />
///         <Step slot:steps label="Review" status=StepStatus::Pending />
///     </Stepper>
/// }
/// ```
///
/// ## With Progress Bar
/// Overall progress bar below the steps, driven by a reactive 0–100 signal. Use for long-running operations where percent complete matters alongside step status.
/// <!-- preview -->
/// ```rust
/// view! {
///     <Stepper progress=Signal::derive(|| 60u32)>
///         <Step slot:steps label="Downloading" status=StepStatus::Done />
///         <Step slot:steps label="Installing" status=StepStatus::Active message="Package 3/5" />
///         <Step slot:steps label="Configuring" status=StepStatus::Pending />
///     </Stepper>
/// }
/// ```
///
/// ## Deployment Pipeline
/// Realistic seven-step deployment with progress bar and an active upload message. Use as a reference for CI/CD or release pipelines with many sequential phases.
/// <!-- preview -->
/// ```rust
/// view! {
///     <Stepper progress=Signal::derive(|| 40u32)>
///         <Step slot:steps label="Build Docker image" status=StepStatus::Done />
///         <Step slot:steps label="Export image" status=StepStatus::Done />
///         <Step slot:steps label="Transfer to server" status=StepStatus::Active message="Uploading 1.2 GB..." />
///         <Step slot:steps label="Install container runtime" status=StepStatus::Pending />
///         <Step slot:steps label="Load image" status=StepStatus::Pending />
///         <Step slot:steps label="Start container" status=StepStatus::Pending />
///         <Step slot:steps label="Health check" status=StepStatus::Pending />
///     </Stepper>
/// }
/// ```
#[component_doc(
    category = "Feedback",
    preview_slug = "stepper",
    preview_label = "Stepper",
    preview_icon = icondata::AiOrderedListOutlined,
)]
#[component]
pub fn Stepper(
    /// Step children declared via `<Step slot:steps ... />`.
    #[prop(optional, default = Vec::new())]
    steps: Vec<Step>,
    /// When true (default), steps stack vertically. When false, steps flow horizontally.
    #[prop(optional, default = true)]
    vertical: bool,
    /// Optional overall progress (0-100). When provided, renders a ProgressBar below the steps.
    #[prop(optional, into)]
    progress: Option<Signal<u32>>,
) -> impl IntoView {
    let total = steps.len();

    let (style_sheet, class_names) = inline_style_sheet_values! {
        .Wrapper {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        // ── Vertical ────────────────────────────────────────────────

        .Vertical {
            display: flex;
            flex-direction: column;
        }

        .StepRowV {
            display: flex;
            flex-direction: row;
            align-items: flex-start;
            gap: 12px;
        }

        .IconColumnV {
            display: flex;
            flex-direction: column;
            align-items: center;
            flex-shrink: 0;
            width: 24px;
        }

        .ConnectorV {
            width: 2px;
            flex: 1;
            min-height: 16px;
            margin-top: 4px;
            margin-bottom: 4px;
        }

        .ConnectorSolid {
            border-left: 2px solid var(--orb-color-status-success-fg);
        }

        .ConnectorActive {
            border-left: 2px solid var(--orb-color-brand-fg);
        }

        .ConnectorDashed {
            border-left: 2px dashed var(--orb-color-border-default);
        }

        .ContentV {
            display: flex;
            flex-direction: column;
            gap: 2px;
            padding-bottom: 4px;
        }

        // ── Horizontal ──────────────────────────────────────────────

        .Horizontal {
            display: flex;
            flex-direction: row;
            align-items: flex-start;
        }

        .StepItemH {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
            flex-shrink: 0;
        }

        .IconRowH {
            display: flex;
            flex-direction: row;
            align-items: center;
            width: 100%;
        }

        .ConnectorH {
            height: 2px;
            flex: 1;
        }

        .ConnectorHSolid {
            border-top: 2px solid var(--orb-color-status-success-fg);
        }

        .ConnectorHActive {
            border-top: 2px solid var(--orb-color-brand-fg);
        }

        .ConnectorHDashed {
            border-top: 2px dashed var(--orb-color-border-default);
        }

        .ContentH {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 2px;
            text-align: center;
            max-width: 120px;
        }

        // ── Shared ──────────────────────────────────────────────────

        .IconWrap {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 24px;
            height: 24px;
            flex-shrink: 0;
        }

        .StatusDone {
            color: var(--orb-color-status-success-fg);
        }

        .StatusActive {
            color: var(--orb-color-brand-fg);
        }

        .StatusFailed {
            color: var(--orb-color-status-danger-fg);
        }

        .StatusPending {
            color: var(--orb-color-text-tertiary);
        }

        .StatusSkipped {
            color: var(--orb-color-text-tertiary);
        }

        .Message {
            color: var(--orb-color-text-tertiary);
        }
    };

    let icon_class = |status: StepStatus| -> String {
        let base = &class_names.icon_wrap;
        let modifier = match status {
            StepStatus::Done => &class_names.status_done,
            StepStatus::Active => &class_names.status_active,
            StepStatus::Failed => &class_names.status_failed,
            StepStatus::Pending => &class_names.status_pending,
            StepStatus::Skipped => &class_names.status_skipped,
        };
        format!("{base} {modifier}")
    };

    let connector_v_class = |status: StepStatus| -> String {
        let base = &class_names.connector_v;
        let modifier = match status {
            StepStatus::Done => &class_names.connector_solid,
            StepStatus::Active => &class_names.connector_active,
            StepStatus::Pending | StepStatus::Failed | StepStatus::Skipped => {
                &class_names.connector_dashed
            }
        };
        format!("{base} {modifier}")
    };

    let connector_h_class = |status: StepStatus| -> String {
        let base = &class_names.connector_h;
        let modifier = match status {
            StepStatus::Done => &class_names.connector_h_solid,
            StepStatus::Active => &class_names.connector_h_active,
            StepStatus::Pending | StepStatus::Failed | StepStatus::Skipped => {
                &class_names.connector_h_dashed
            }
        };
        format!("{base} {modifier}")
    };

    let step_icon = |status: StepStatus| -> AnyView {
        match status {
            StepStatus::Done => view! {
                <Icon icon=icondata::AiCheckCircleOutlined width="20px" height="20px" />
            }
            .into_any(),
            StepStatus::Active => view! {
                <Spinner size=SpinnerSize::ExtraTiny />
            }
            .into_any(),
            StepStatus::Failed => view! {
                <Icon icon=icondata::AiCloseCircleOutlined width="20px" height="20px" />
            }
            .into_any(),
            StepStatus::Pending => view! {
                <Icon icon=icondata::AiClockCircleOutlined width="20px" height="20px" />
            }
            .into_any(),
            StepStatus::Skipped => view! {
                <Icon icon=icondata::BiSkipNextRegular width="20px" height="20px" />
            }
            .into_any(),
        }
    };

    let steps_view = if vertical {
        view! {
            <div class=class_names.vertical>
                {steps.into_iter().enumerate().map(|(i, step)| {
                    let is_last = i == total - 1;
                    let ic = icon_class(step.status);
                    let cc = connector_v_class(step.status);
                    view! {
                        <div class=class_names.step_row_v>
                            <div class=class_names.icon_column_v>
                                <div class=ic>{step_icon(step.status)}</div>
                                {if !is_last {
                                    view! { <div class=cc></div> }.into_any()
                                } else {
                                    ().into_any()
                                }}
                            </div>
                            <div class=class_names.content_v>
                                <Body1>{step.label}</Body1>
                                {step.message.map(|msg| view! {
                                    <Caption1 class=class_names.message>{msg}</Caption1>
                                })}
                            </div>
                        </div>
                    }
                }).collect::<Vec<_>>()}
            </div>
        }
        .into_any()
    } else {
        view! {
            <div class=class_names.horizontal>
                {steps.into_iter().enumerate().map(|(i, step)| {
                    let is_last = i == total - 1;
                    let ic = icon_class(step.status);
                    let cc = connector_h_class(step.status);
                    view! {
                        <div class=class_names.step_item_h style="flex: 1;">
                            <div class=class_names.icon_row_h>
                                <div class=ic>{step_icon(step.status)}</div>
                                {if !is_last {
                                    view! { <div class=cc></div> }.into_any()
                                } else {
                                    ().into_any()
                                }}
                            </div>
                            <div class=class_names.content_h>
                                <Body1>{step.label}</Body1>
                                {step.message.map(|msg| view! {
                                    <Caption1 class=class_names.message>{msg}</Caption1>
                                })}
                            </div>
                        </div>
                    }
                }).collect::<Vec<_>>()}
            </div>
        }
        .into_any()
    };

    view! {
        <style>{style_sheet}</style>
        <div class=class_names.wrapper>
            {steps_view}
            {progress.map(|p| view! {
                <ProgressBar value=Signal::derive(move || p.get() as f64 / 100.0) />
            })}
        </div>
    }
}