strata-components 0.1.3

Comprehensive high-level component library and design system for Strata
Documentation
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
//! High-Level Accessible Data Display Components for Strata UI.

#![allow(non_snake_case)]

use std::rc::Rc;
use strata_dom::{NodeBlueprint, Signal, View};
use strata_icons::prelude::{Icon, IconName};
use strata_macro::{component, rsx};

/// Card container with subtle glassmorphic backdrop and border.
#[component]
pub fn Card(children: Option<Vec<NodeBlueprint>>, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    let base = "rounded-2xl bg-neutral-900/60 border border-neutral-800 shadow-xl overflow-hidden backdrop-blur-sm";
    let combined = format!("{base} {custom}");
    let classes: Vec<String> = combined.split_whitespace().map(|s| s.to_string()).collect();

    View::new(NodeBlueprint::element(
        strata_dom::Tag::Div,
        classes,
        Vec::new(),
        children.unwrap_or_default(),
    ))
}

/// Header slot for Card containers.
#[component]
pub fn CardHeader(
    title: Option<&'static str>,
    description: Option<&'static str>,
    children: Option<Vec<NodeBlueprint>>,
    class: Option<&'static str>,
) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <div class={format!("p-6 border-b border-neutral-800/80 flex flex-col gap-1.5 {}", custom)}>
            {if let Some(t) = title {
                rsx! { <h3 class="text-base font-semibold text-white tracking-tight">{t}</h3> }
            } else {
                rsx! { <></> }
            }}
            {if let Some(d) = description {
                rsx! { <p class="text-xs text-neutral-400">{d}</p> }
            } else {
                rsx! { <></> }
            }}
            {children.unwrap_or_default()}
        </div>
    }
}

/// Body content slot for Card containers.
#[component]
pub fn CardContent(children: Option<Vec<NodeBlueprint>>, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <div class={format!("p-6 {}", custom)}>
            {children.unwrap_or_default()}
        </div>
    }
}

/// Footer slot for Card containers with top border divider.
#[component]
pub fn CardFooter(children: Option<Vec<NodeBlueprint>>, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <div class={format!("px-6 py-4 border-t border-neutral-800/80 flex items-center justify-between {}", custom)}>
            {children.unwrap_or_default()}
        </div>
    }
}

/// Visual status badge variants.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BadgeVariant {
    #[default]
    Default,
    Success,
    Warning,
    Destructive,
    Outline,
    Indigo,
}

/// Visual status Badge pill.
#[component]
pub fn Badge(
    variant: Option<BadgeVariant>,
    children: Option<Vec<NodeBlueprint>>,
    class: Option<&'static str>,
) -> View {
    let var = variant.unwrap_or_default();
    let var_classes = match var {
        BadgeVariant::Default => "bg-neutral-800 text-neutral-300 border-neutral-700",
        BadgeVariant::Success => "bg-emerald-500/10 text-emerald-400 border-emerald-500/20",
        BadgeVariant::Warning => "bg-amber-500/10 text-amber-400 border-amber-500/20",
        BadgeVariant::Destructive => "bg-rose-500/10 text-rose-400 border-rose-500/20",
        BadgeVariant::Outline => "bg-transparent text-white border-neutral-700",
        BadgeVariant::Indigo => "bg-indigo-500/10 text-indigo-400 border-indigo-500/20",
    };

    let custom = class.unwrap_or("");
    let combined = format!("inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-mono font-medium border select-none {var_classes} {custom}");

    rsx! {
        <span class={combined}>
            {children.unwrap_or_default()}
        </span>
    }
}

/// Interactive dismissable Tag / Chip with close button.
#[component]
pub fn Tag(
    label: &'static str,
    onclose: Option<Rc<dyn Fn()>>,
    class: Option<&'static str>,
) -> View {
    let custom = class.unwrap_or("");
    let cb = onclose.clone();

    rsx! {
        <span class={format!("inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs font-medium bg-neutral-800 border border-neutral-700 text-neutral-200 select-none {}", custom)}>
            <span>{label}</span>
            {if let Some(on_c) = cb {
                rsx! {
                    <button
                        type="button"
                        class="text-neutral-400 hover:text-white cursor-pointer -mr-0.5"
                        onclick={move |_| on_c()}
                    >
                        {Icon(IconName::X, Some("w-3 h-3 text-current")).root}
                    </button>
                }
            } else {
                rsx! { <></> }
            }}
        </span>
    }
}

/// User profile Avatar with initials fallback and status dot.
#[component]
pub fn Avatar(
    fallback: &'static str,
    status: Option<&'static str>,
    class: Option<&'static str>,
) -> View {
    let custom = class.unwrap_or("");
    let base = "w-9 h-9 rounded-full bg-gradient-to-tr from-indigo-500 to-purple-600 flex items-center justify-center text-xs font-bold text-white ring-2 ring-neutral-800 select-none relative";
    let combined = format!("{base} {custom}");

    rsx! {
        <div class={combined}>
            {fallback}
            {if let Some(st) = status {
                let dot_color = match st {
                    "online" => "bg-emerald-500",
                    "busy" => "bg-rose-500",
                    "away" => "bg-amber-500",
                    _ => "bg-neutral-500",
                };
                rsx! {
                    <span class={format!("absolute bottom-0 right-0 w-2.5 h-2.5 rounded-full ring-2 ring-neutral-900 {}", dot_color)} />
                }
            } else {
                rsx! { <></> }
            }}
        </div>
    }
}

/// KPI Metric / Statistic block with value, label, and trend pill.
#[component]
pub fn Stat(
    label: &'static str,
    value: &'static str,
    trend: Option<f32>,
    subtitle: Option<&'static str>,
    class: Option<&'static str>,
) -> View {
    let custom = class.unwrap_or("");

    rsx! {
        <div class={format!("p-5 rounded-2xl bg-neutral-900/60 border border-neutral-800 shadow-lg flex flex-col justify-between {}", custom)}>
            <div class="flex items-center justify-between text-neutral-400 text-xs font-mono uppercase">
                <span>{label}</span>
                {if let Some(t) = trend {
                    let (color, icon) = if t >= 0.0 {
                        ("text-emerald-400 bg-emerald-500/10 border-emerald-500/20", IconName::ArrowUpRight)
                    } else {
                        ("text-rose-400 bg-rose-500/10 border-rose-500/20", IconName::ArrowDownLeft)
                    };
                    rsx! {
                        <span class={format!("inline-flex items-center gap-1 px-1.5 py-0.5 rounded border text-xs font-mono font-semibold {}", color)}>
                            {Icon(icon, Some("w-3 h-3 text-current")).root}
                            {format!("{t:+.1}%")}
                        </span>
                    }
                } else {
                    rsx! { <></> }
                }}
            </div>
            <div class="mt-3 text-2xl font-bold font-mono text-white tracking-tight">
                {value}
            </div>
            {if let Some(sub) = subtitle {
                rsx! { <div class="mt-1 text-xs text-neutral-500">{sub}</div> }
            } else {
                rsx! { <></> }
            }}
        </div>
    }
}

/// Segmented tab switcher and tab trigger button.
#[component]
pub fn Tabs(
    items: Vec<&'static str>,
    active_index: Signal<usize>,
    class: Option<&'static str>,
) -> View {
    let active = active_index.get();
    let custom = class.unwrap_or("");

    rsx! {
        <div class={format!("inline-flex items-center p-1 rounded-xl bg-neutral-900 border border-neutral-800 gap-1 {}", custom)}>
            {items.into_iter().enumerate().map(|(idx, title)| {
                let is_sel = idx == active;
                let active_sig = active_index.clone();
                let (bg, text) = if is_sel {
                    ("bg-neutral-800 text-white shadow-sm", "font-semibold")
                } else {
                    ("bg-transparent text-neutral-400 hover:text-neutral-200", "font-normal")
                };
                rsx! {
                    <button
                        type="button"
                        class={format!("px-3.5 py-1.5 rounded-lg text-xs transition-all duration-150 cursor-pointer select-none {} {}", bg, text)}
                        onclick={move |_| active_sig.set(idx)}
                    >
                        {title}
                    </button>
                }
            })}
        </div>
    }
}

/// Collapsible Accordion section with toggleable expansion state.
#[component]
pub fn AccordionItem(
    title: &'static str,
    open: Signal<bool>,
    children: Option<Vec<NodeBlueprint>>,
    class: Option<&'static str>,
) -> View {
    let is_open = open.get();
    let op = open.clone();
    let custom = class.unwrap_or("");
    let chevron_rot = if is_open { "rotate-180" } else { "rotate-0" };

    rsx! {
        <div class={format!("border-b border-neutral-800 py-3 w-full {}", custom)}>
            <button
                type="button"
                class="flex items-center justify-between w-full text-left font-medium text-sm text-neutral-200 hover:text-white cursor-pointer select-none"
                onclick={move |_| op.update(|o| *o = !*o)}
            >
                <span>{title}</span>
                <span class={format!("transition-transform duration-200 text-neutral-400 {}", chevron_rot)}>
                    {Icon(IconName::ChevronDown, Some("w-4 h-4 text-current")).root}
                </span>
            </button>
            {if is_open {
                rsx! {
                    <div class="pt-3 text-xs text-neutral-400 leading-relaxed">
                        {children.unwrap_or_default()}
                    </div>
                }
            } else {
                rsx! { <></> }
            }}
        </div>
    }
}

/// Semantic data Table container.
#[component]
pub fn Table(children: Option<Vec<NodeBlueprint>>, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <div class="w-full overflow-x-auto rounded-xl border border-neutral-800">
            <table class={format!("w-full text-left text-sm text-neutral-300 {}", custom)}>
                {children.unwrap_or_default()}
            </table>
        </div>
    }
}

/// Table head row container.
#[component]
pub fn TableHeader(children: Option<Vec<NodeBlueprint>>) -> View {
    rsx! {
        <thead class="bg-neutral-900/80 border-b border-neutral-800 text-xs font-mono uppercase tracking-wider text-neutral-400">
            {children.unwrap_or_default()}
        </thead>
    }
}

/// Table body container.
#[component]
pub fn TableBody(children: Option<Vec<NodeBlueprint>>) -> View {
    rsx! {
        <tbody class="divide-y divide-neutral-800/60 bg-neutral-950/40">
            {children.unwrap_or_default()}
        </tbody>
    }
}

/// Table row.
#[component]
pub fn TableRow(children: Option<Vec<NodeBlueprint>>, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <tr class={format!("hover:bg-neutral-800/30 transition-colors {}", custom)}>
            {children.unwrap_or_default()}
        </tr>
    }
}

/// Table header cell.
#[component]
pub fn TableHead(children: Option<Vec<NodeBlueprint>>, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <th class={format!("px-4 py-3 font-semibold text-neutral-300 {}", custom)}>
            {children.unwrap_or_default()}
        </th>
    }
}

/// Table data cell.
#[component]
pub fn TableCell(children: Option<Vec<NodeBlueprint>>, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <td class={format!("px-4 py-3 text-neutral-300 {}", custom)}>
            {children.unwrap_or_default()}
        </td>
    }
}

/// Vertical timeline item for activity feeds.
#[component]
pub fn TimelineItem(
    title: &'static str,
    timestamp: &'static str,
    description: Option<&'static str>,
    is_last: Option<bool>,
) -> View {
    let last = is_last.unwrap_or(false);

    rsx! {
        <div class="relative pl-6 pb-6 group">
            {if !last {
                rsx! { <div class="absolute left-2.5 top-3 bottom-0 w-px bg-neutral-800" /> }
            } else {
                rsx! { <></> }
            }}
            <div class="absolute left-1 top-1.5 w-3.5 h-3.5 rounded-full border-2 border-indigo-600 bg-neutral-950" />
            <div class="flex items-center justify-between text-xs font-mono text-neutral-400">
                <span class="font-semibold text-neutral-200">{title}</span>
                <span>{timestamp}</span>
            </div>
            {if let Some(desc) = description {
                rsx! { <p class="mt-1 text-xs text-neutral-400 leading-relaxed">{desc}</p> }
            } else {
                rsx! { <></> }
            }}
        </div>
    }
}

/// Keyboard shortcut key badge (e.g. ⌘K, Shift+Enter).
#[component]
pub fn Kbd(keys: &'static str, class: Option<&'static str>) -> View {
    let custom = class.unwrap_or("");
    rsx! {
        <kbd class={format!("inline-flex items-center px-1.5 py-0.5 rounded border border-neutral-700 bg-neutral-800 font-mono text-[10px] font-semibold text-neutral-300 shadow-sm select-none {}", custom)}>
            {keys}
        </kbd>
    }
}

/// Visual horizontal or vertical separator divider.
#[component]
pub fn Separator(vertical: Option<bool>, class: Option<&'static str>) -> View {
    let is_vert = vertical.unwrap_or(false);
    let custom = class.unwrap_or("");
    let dim = if is_vert {
        "w-px h-full"
    } else {
        "h-px w-full"
    };

    rsx! {
        <div class={format!("bg-neutral-800 {} {}", dim, custom)} />
    }
}