Skip to main content

euv_example/pages/display/
fn.rs

1use super::*;
2
3/// Mounts the Avatars, Hover Card, Badges & Tags card.
4///
5/// # Arguments
6///
7/// - `&ShowcaseState` - Reactive showcase state.
8/// - `ThemeTokens` - Active design tokens.
9///
10/// # Returns
11///
12/// - `NodeId` - Mounted card node.
13pub(crate) fn mount_display_identity_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
14    let avatar_specs: [(&str, f32); 3] = [("EU", 28.0), ("RS", 36.0), ("UI", 44.0)];
15    let avatars: Vec<NodeId> = avatar_specs
16        .iter()
17        .map(|(init, sz): &(&str, f32)| {
18            let size_px: f32 = *sz;
19            view! {
20                EuvAvatar {
21                    initials: (*init).to_string()
22                    size: size_px
23                    tokens: tokens
24                }
25            }
26        })
27        .collect();
28    let badge_specs: [(&str, EuvTone); 5] = [
29        (DISPLAY_BADGE_PRIMARY, EuvTone::Primary),
30        (DISPLAY_BADGE_SUCCESS, EuvTone::Success),
31        (DISPLAY_BADGE_WARNING, EuvTone::Warning),
32        (DISPLAY_BADGE_DESTRUCTIVE, EuvTone::Destructive),
33        (DISPLAY_BADGE_NEUTRAL, EuvTone::Neutral),
34    ];
35    let badges: Vec<NodeId> = badge_specs
36        .iter()
37        .map(|(label_text, tone): &(&str, EuvTone)| {
38            let tone_val: EuvTone = *tone;
39            view! {
40                EuvBadge {
41                    label: (*label_text).to_string()
42                    tone: tone_val
43                    tokens: tokens
44                }
45            }
46        })
47        .collect();
48    let tag_specs: [(&str, EuvTone); 3] = [
49        (DISPLAY_TAG_RUST, EuvTone::Primary),
50        (DISPLAY_TAG_GPU, EuvTone::Success),
51        (DISPLAY_TAG_WASM, EuvTone::Neutral),
52    ];
53    let tags: Vec<NodeId> = tag_specs
54        .iter()
55        .map(|(caption_label, tone): &(&str, EuvTone)| {
56            let tone_val: EuvTone = *tone;
57            view! {
58                EuvTag {
59                    label: (*caption_label).to_string()
60                    tone: tone_val
61                    tokens: tokens
62                }
63            }
64        })
65        .collect();
66    let column_seventh_style: Style = style! {
67        Width(Length::Percent(100.0))
68        Gap(SPACE_MD)
69    };
70    view! {
71        EuvCard {
72            title: DISPLAY_IDENTITY_TITLE.to_string()
73            tokens: tokens
74            subtitle: DISPLAY_IDENTITY_SUB
75            column {
76                style: column_seventh_style
77                row {
78                    style: c_action_row()
79                    ..avatars
80                }
81                EuvHoverCard {
82                    trigger_label: DISPLAY_HOVER_TRIGGER.to_string()
83                    title: DISPLAY_HOVER_TITLE.to_string()
84                    tokens: tokens
85                    open: state.get_hover_card_open()
86                    description: DISPLAY_HOVER_DESC
87                }
88                EuvSeparator {
89                    label: DISPLAY_SEP_BADGES.to_string()
90                    tokens: tokens
91                }
92                row {
93                    style: c_action_row()
94                    ..badges
95                }
96                row {
97                    style: c_action_row()
98                    ..tags
99                }
100            }
101        }
102    }
103}
104
105/// Mounts the Semantic Alerts & Separators card.
106///
107/// # Arguments
108///
109/// - `ThemeTokens` - Active design tokens.
110///
111/// # Returns
112///
113/// - `NodeId` - Mounted card node.
114pub(crate) fn mount_display_alerts_card(tokens: ThemeTokens) -> NodeId {
115    let column_sixth_style: Style = style! {
116        Width(Length::Percent(100.0))
117        Gap(SPACE_MD)
118    };
119    view! {
120        EuvCard {
121            title: DISPLAY_ALERTS_TITLE.to_string()
122            tokens: tokens
123            subtitle: DISPLAY_ALERTS_SUB
124            column {
125                style: column_sixth_style
126                EuvAlert {
127                    title: DISPLAY_ALERT_INFO_TITLE.to_string()
128                    description: DISPLAY_ALERT_INFO_DESC.to_string()
129                    tone: EuvTone::Primary
130                    tokens: tokens
131                }
132                EuvSeparator {
133                    label: DISPLAY_SEP_DIVIDER.to_string()
134                    tokens: tokens
135                }
136                EuvAlert {
137                    title: DISPLAY_ALERT_OK_TITLE.to_string()
138                    description: DISPLAY_ALERT_OK_DESC.to_string()
139                    tone: EuvTone::Success
140                    tokens: tokens
141                }
142                EuvAlert {
143                    title: DISPLAY_ALERT_WARN_TITLE.to_string()
144                    description: DISPLAY_ALERT_WARN_DESC.to_string()
145                    tone: EuvTone::Warning
146                    tokens: tokens
147                }
148            }
149        }
150    }
151}
152
153/// Mounts the Accordion & Collapsible disclosure card.
154///
155/// # Arguments
156///
157/// - `&ShowcaseState` - Reactive showcase state.
158/// - `ThemeTokens` - Active design tokens.
159///
160/// # Returns
161///
162/// - `NodeId` - Mounted card node.
163pub(crate) fn mount_display_disclosure_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
164    let palette: ThemePalette = tokens.get_palette();
165    let acc_items: Vec<EuvAccordionItem> = vec![
166        EuvAccordionItem::new(
167            DISPLAY_ACC_1_TITLE.to_string(),
168            DISPLAY_ACC_1_BODY.to_string(),
169        ),
170        EuvAccordionItem::new(
171            DISPLAY_ACC_2_TITLE.to_string(),
172            DISPLAY_ACC_2_BODY.to_string(),
173        ),
174        EuvAccordionItem::new(
175            DISPLAY_ACC_3_TITLE.to_string(),
176            DISPLAY_ACC_3_BODY.to_string(),
177        ),
178    ];
179    let text_tertiary_style: Style = style! {
180        Width(Length::Percent(100.0))
181        FontSize(13.0)
182        TextColor(palette.get_muted_foreground())
183    };
184    let collapsible_body: NodeId = view! {
185        text {
186            style: text_tertiary_style
187            { DISPLAY_COLLAPSE_BODY }
188        }
189    };
190    let column_fifth_style: Style = style! {
191        Width(Length::Percent(100.0))
192        Gap(SPACE_MD)
193    };
194    view! {
195        EuvCard {
196            title: DISPLAY_DISCLOSURE_TITLE.to_string()
197            tokens: tokens
198            subtitle: DISPLAY_DISCLOSURE_SUB
199            column {
200                style: column_fifth_style
201                EuvAccordion {
202                    items: acc_items
203                    open_index: state.get_accordion_open()
204                    tokens: tokens
205                }
206                EuvCollapsible {
207                    open: state.get_collapsible_open()
208                    title: DISPLAY_COLLAPSE_TITLE.to_string()
209                    content: collapsible_body
210                    tokens: tokens
211                }
212            }
213        }
214    }
215}
216
217/// Mounts the Chronological Release Timeline card.
218///
219/// # Arguments
220///
221/// - `ThemeTokens` - Active design tokens.
222///
223/// # Returns
224///
225/// - `NodeId` - Mounted card node.
226pub(crate) fn mount_display_timeline_card(tokens: ThemeTokens) -> NodeId {
227    let items: Vec<EuvTimelineItem> = vec![
228        EuvTimelineItem::new(
229            DISPLAY_TL_1_TITLE.to_string(),
230            DISPLAY_TL_1_TIME.to_string(),
231            DISPLAY_TL_1_DESC.to_string(),
232        ),
233        EuvTimelineItem::new(
234            DISPLAY_TL_2_TITLE.to_string(),
235            DISPLAY_TL_2_TIME.to_string(),
236            DISPLAY_TL_2_DESC.to_string(),
237        ),
238        EuvTimelineItem::new(
239            DISPLAY_TL_3_TITLE.to_string(),
240            DISPLAY_TL_3_TIME.to_string(),
241            DISPLAY_TL_3_DESC.to_string(),
242        ),
243    ];
244    view! {
245        EuvCard {
246            title: DISPLAY_TIMELINE_TITLE.to_string()
247            tokens: tokens
248            subtitle: DISPLAY_TIMELINE_SUB
249            EuvTimeline {
250                items: items
251                tokens: tokens
252            }
253        }
254    }
255}
256
257/// Mounts the Carousel & Structured List Item card.
258///
259/// # Arguments
260///
261/// - `&ShowcaseState` - Reactive showcase state.
262/// - `ThemeTokens` - Active design tokens.
263///
264/// # Returns
265///
266/// - `NodeId` - Mounted card node.
267pub(crate) fn mount_display_carousel_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
268    let palette: ThemePalette = tokens.get_palette();
269    let slide_sig: Signal<usize> = state.get_carousel_index();
270    let slides: Vec<String> = vec![
271        DISPLAY_SLIDE_1.to_string(),
272        DISPLAY_SLIDE_2.to_string(),
273        DISPLAY_SLIDE_3.to_string(),
274    ];
275    let slide_readout = move || -> String { format!("Active Slide: {} / 3", slide_sig.get() + 1) };
276    let column_quaternary_style: Style = style! {
277        Width(Length::Percent(100.0))
278        Gap(SPACE_MD)
279    };
280    let text_secondary_style: Style = style! {
281        Width(Length::Percent(100.0))
282        FontSize(12.0)
283        TextColor(palette.get_muted_foreground())
284    };
285    view! {
286        EuvCard {
287            title: DISPLAY_CAROUSEL_TITLE.to_string()
288            tokens: tokens
289            subtitle: DISPLAY_CAROUSEL_SUB
290            column {
291                style: column_quaternary_style
292                EuvCarousel {
293                    slides: slides
294                    active_slide: slide_sig
295                    tokens: tokens
296                }
297                text {
298                    style: text_secondary_style
299                    { slide_readout }
300                }
301                EuvItem {
302                    title: DISPLAY_ITEM_TITLE.to_string()
303                    tokens: tokens
304                    leading: "EU"
305                    description: DISPLAY_ITEM_DESC
306                    trailing: DISPLAY_ITEM_VER
307                }
308            }
309        }
310    }
311}
312
313/// Mounts the Calendar Picker card.
314///
315/// # Arguments
316///
317/// - `&ShowcaseState` - Reactive showcase state.
318/// - `ThemeTokens` - Active design tokens.
319///
320/// # Returns
321///
322/// - `NodeId` - Mounted card node.
323pub(crate) fn mount_display_calendar_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
324    let palette: ThemePalette = tokens.get_palette();
325    let day_sig: Signal<u32> = state.get_calendar_day();
326    let day_readout = move || -> String {
327        let day: u32 = day_sig.get();
328        format!("Selected Date: {LABEL_CALENDAR_MONTH} {day}")
329    };
330    let column_tertiary_style: Style = style! {
331        Width(Length::Percent(100.0))
332        Gap(SPACE_MD)
333    };
334    let text_style: Style = style! {
335        Width(Length::Percent(100.0))
336        FontSize(12.0)
337        TextColor(palette.get_muted_foreground())
338    };
339    view! {
340        EuvCard {
341            title: DISPLAY_CALENDAR_TITLE.to_string()
342            tokens: tokens
343            subtitle: DISPLAY_CALENDAR_SUB
344            column {
345                style: column_tertiary_style
346                EuvCalendar {
347                    month_label: LABEL_CALENDAR_MONTH.to_string()
348                    days_in_month: 30
349                    selected_day: day_sig
350                    tokens: tokens
351                }
352                text {
353                    style: text_style
354                    { day_readout }
355                }
356            }
357        }
358    }
359}
360
361/// Mounts the Skeleton & Empty States placeholder card.
362///
363/// # Arguments
364///
365/// - `ThemeTokens` - Active design tokens.
366///
367/// # Returns
368///
369/// - `NodeId` - Mounted card node.
370pub(crate) fn mount_display_placeholder_card(tokens: ThemeTokens) -> NodeId {
371    let column_style: Style = style! {
372        Width(Length::Percent(100.0))
373        Gap(SPACE_MD)
374    };
375    let column_secondary_style: Style = style! {
376        Width(Length::Percent(100.0))
377        Gap(SPACE_SM)
378    };
379    let euv_skeleton_style: Style = style! {
380        Width(Length::Px(200.0))
381        Height(Length::Px(18.0))
382    };
383    let euv_skeleton_secondary_style: Style = style! {
384        Width(Length::Px(150.0))
385        Height(Length::Px(14.0))
386    };
387    view! {
388        EuvCard {
389            title: DISPLAY_PLACEHOLDER_TITLE.to_string()
390            tokens: tokens
391            subtitle: DISPLAY_PLACEHOLDER_SUB
392            column {
393                style: column_style
394                column {
395                    style: column_secondary_style
396                    EuvSkeleton {
397                        tokens: tokens
398                        style: euv_skeleton_style
399                    }
400                    EuvSkeleton {
401                        tokens: tokens
402                        style: euv_skeleton_secondary_style
403                    }
404                }
405                EuvSeparator {
406                    label: String::new()
407                    tokens: tokens
408                }
409                EuvEmpty {
410                    title: DISPLAY_EMPTY_TITLE.to_string()
411                    description: DISPLAY_EMPTY_DESC.to_string()
412                    tokens: tokens
413                }
414            }
415        }
416    }
417}
418
419/// Mounts the dedicated Cards, Badges & Content Display page in a full-width responsive grid.
420///
421/// # Arguments
422///
423/// - `&ShowcaseState` - Reactive showcase state.
424/// - `ThemeTokens` - Active design tokens.
425///
426/// # Returns
427///
428/// - `NodeId` - Mounted display page node.
429pub fn mount_display_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
430    let cards: Vec<NodeId> = vec![
431        mount_display_identity_card(state, tokens),
432        mount_display_alerts_card(tokens),
433        mount_display_disclosure_card(state, tokens),
434        mount_display_timeline_card(tokens),
435        mount_display_carousel_card(state, tokens),
436        mount_display_calendar_card(state, tokens),
437        mount_display_placeholder_card(tokens),
438    ];
439    let grid: NodeId = mount_responsive_grid(cards, 2);
440    view! {
441        EuvPage {
442            title: DISPLAY_TITLE.to_string()
443            subtitle: DISPLAY_SUBTITLE.to_string()
444            tokens: tokens
445            { grid }
446        }
447    }
448}