euv_example/pages/display/
fn.rs1use super::*;
2
3pub(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(|(lbl, tone): &(&str, EuvTone)| {
38 let tone_val: EuvTone = *tone;
39 view! {
40 EuvBadge {
41 label: (*lbl).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(|(lbl, tone): &(&str, EuvTone)| {
56 let tone_val: EuvTone = *tone;
57 view! {
58 EuvTag {
59 label: (*lbl).to_string()
60 tone: tone_val
61 tokens: tokens
62 }
63 }
64 })
65 .collect();
66 view! {
67 EuvCard {
68 title: DISPLAY_IDENTITY_TITLE.to_string()
69 tokens: tokens
70 subtitle: DISPLAY_IDENTITY_SUB
71 column {
72 style: {
73 width: Length::Percent(100.0)
74 gap: SPACE_MD
75 }
76 row {
77 style: c_action_row()
78 ..avatars
79 }
80 EuvHoverCard {
81 trigger_label: DISPLAY_HOVER_TRIGGER.to_string()
82 title: DISPLAY_HOVER_TITLE.to_string()
83 tokens: tokens
84 open: state.get_hover_card_open()
85 description: DISPLAY_HOVER_DESC
86 }
87 EuvSeparator {
88 label: DISPLAY_SEP_BADGES.to_string()
89 tokens: tokens
90 }
91 row {
92 style: c_action_row()
93 ..badges
94 }
95 row {
96 style: c_action_row()
97 ..tags
98 }
99 }
100 }
101 }
102}
103
104pub(crate) fn mount_display_alerts_card(tokens: ThemeTokens) -> NodeId {
114 view! {
115 EuvCard {
116 title: DISPLAY_ALERTS_TITLE.to_string()
117 tokens: tokens
118 subtitle: DISPLAY_ALERTS_SUB
119 column {
120 style: {
121 width: Length::Percent(100.0)
122 gap: SPACE_MD
123 }
124 EuvAlert {
125 title: DISPLAY_ALERT_INFO_TITLE.to_string()
126 description: DISPLAY_ALERT_INFO_DESC.to_string()
127 tone: EuvTone::Primary
128 tokens: tokens
129 }
130 EuvSeparator {
131 label: DISPLAY_SEP_DIVIDER.to_string()
132 tokens: tokens
133 }
134 EuvAlert {
135 title: DISPLAY_ALERT_OK_TITLE.to_string()
136 description: DISPLAY_ALERT_OK_DESC.to_string()
137 tone: EuvTone::Success
138 tokens: tokens
139 }
140 EuvAlert {
141 title: DISPLAY_ALERT_WARN_TITLE.to_string()
142 description: DISPLAY_ALERT_WARN_DESC.to_string()
143 tone: EuvTone::Warning
144 tokens: tokens
145 }
146 }
147 }
148 }
149}
150
151pub(crate) fn mount_display_disclosure_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
162 let p: ThemePalette = tokens.get_palette();
163 let acc_items: Vec<EuvAccordionItem> = vec![
164 EuvAccordionItem::new(
165 DISPLAY_ACC_1_TITLE.to_string(),
166 DISPLAY_ACC_1_BODY.to_string(),
167 ),
168 EuvAccordionItem::new(
169 DISPLAY_ACC_2_TITLE.to_string(),
170 DISPLAY_ACC_2_BODY.to_string(),
171 ),
172 EuvAccordionItem::new(
173 DISPLAY_ACC_3_TITLE.to_string(),
174 DISPLAY_ACC_3_BODY.to_string(),
175 ),
176 ];
177 let collapsible_body: NodeId = view! {
178 text {
179 style: {
180 width: Length::Percent(100.0)
181 font_size: 13.0
182 color: p.get_muted_foreground()
183 }
184 { DISPLAY_COLLAPSE_BODY }
185 }
186 };
187 view! {
188 EuvCard {
189 title: DISPLAY_DISCLOSURE_TITLE.to_string()
190 tokens: tokens
191 subtitle: DISPLAY_DISCLOSURE_SUB
192 column {
193 style: {
194 width: Length::Percent(100.0)
195 gap: SPACE_MD
196 }
197 EuvAccordion {
198 items: acc_items
199 open_index: state.get_accordion_open()
200 tokens: tokens
201 }
202 EuvCollapsible {
203 open: state.get_collapsible_open()
204 title: DISPLAY_COLLAPSE_TITLE.to_string()
205 content: collapsible_body
206 tokens: tokens
207 }
208 }
209 }
210 }
211}
212
213pub(crate) fn mount_display_timeline_card(tokens: ThemeTokens) -> NodeId {
223 let items: Vec<EuvTimelineItem> = vec![
224 EuvTimelineItem::new(
225 DISPLAY_TL_1_TITLE.to_string(),
226 DISPLAY_TL_1_TIME.to_string(),
227 DISPLAY_TL_1_DESC.to_string(),
228 ),
229 EuvTimelineItem::new(
230 DISPLAY_TL_2_TITLE.to_string(),
231 DISPLAY_TL_2_TIME.to_string(),
232 DISPLAY_TL_2_DESC.to_string(),
233 ),
234 EuvTimelineItem::new(
235 DISPLAY_TL_3_TITLE.to_string(),
236 DISPLAY_TL_3_TIME.to_string(),
237 DISPLAY_TL_3_DESC.to_string(),
238 ),
239 ];
240 view! {
241 EuvCard {
242 title: DISPLAY_TIMELINE_TITLE.to_string()
243 tokens: tokens
244 subtitle: DISPLAY_TIMELINE_SUB
245 EuvTimeline {
246 items: items
247 tokens: tokens
248 }
249 }
250 }
251}
252
253pub(crate) fn mount_display_carousel_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
264 let p: ThemePalette = tokens.get_palette();
265 let slide_sig: Signal<usize> = state.get_carousel_index();
266 let slides: Vec<String> = vec![
267 DISPLAY_SLIDE_1.to_string(),
268 DISPLAY_SLIDE_2.to_string(),
269 DISPLAY_SLIDE_3.to_string(),
270 ];
271 let slide_readout = move || -> String { format!("Active Slide: {} / 3", slide_sig.get() + 1) };
272 view! {
273 EuvCard {
274 title: DISPLAY_CAROUSEL_TITLE.to_string()
275 tokens: tokens
276 subtitle: DISPLAY_CAROUSEL_SUB
277 column {
278 style: {
279 width: Length::Percent(100.0)
280 gap: SPACE_MD
281 }
282 EuvCarousel {
283 slides: slides
284 active_slide: slide_sig
285 tokens: tokens
286 }
287 text {
288 style: {
289 width: Length::Percent(100.0)
290 font_size: 12.0
291 color: p.get_muted_foreground()
292 }
293 { slide_readout }
294 }
295 EuvItem {
296 title: DISPLAY_ITEM_TITLE.to_string()
297 tokens: tokens
298 leading: "EU"
299 description: DISPLAY_ITEM_DESC
300 trailing: DISPLAY_ITEM_VER
301 }
302 }
303 }
304 }
305}
306
307pub(crate) fn mount_display_calendar_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
318 let p: ThemePalette = tokens.get_palette();
319 let day_sig: Signal<u32> = state.get_calendar_day();
320 let day_readout = move || -> String {
321 let day: u32 = day_sig.get();
322 format!("Selected Date: {LABEL_CALENDAR_MONTH} {day}")
323 };
324 view! {
325 EuvCard {
326 title: DISPLAY_CALENDAR_TITLE.to_string()
327 tokens: tokens
328 subtitle: DISPLAY_CALENDAR_SUB
329 column {
330 style: {
331 width: Length::Percent(100.0)
332 gap: SPACE_MD
333 }
334 EuvCalendar {
335 month_label: LABEL_CALENDAR_MONTH.to_string()
336 days_in_month: 30
337 selected_day: day_sig
338 tokens: tokens
339 }
340 text {
341 style: {
342 width: Length::Percent(100.0)
343 font_size: 12.0
344 color: p.get_muted_foreground()
345 }
346 { day_readout }
347 }
348 }
349 }
350 }
351}
352
353pub(crate) fn mount_display_placeholder_card(tokens: ThemeTokens) -> NodeId {
363 view! {
364 EuvCard {
365 title: DISPLAY_PLACEHOLDER_TITLE.to_string()
366 tokens: tokens
367 subtitle: DISPLAY_PLACEHOLDER_SUB
368 column {
369 style: {
370 width: Length::Percent(100.0)
371 gap: SPACE_MD
372 }
373 column {
374 style: {
375 width: Length::Percent(100.0)
376 gap: SPACE_SM
377 }
378 EuvSkeleton {
379 width: 200.0
380 height: 18.0
381 tokens: tokens
382 }
383 EuvSkeleton {
384 width: 150.0
385 height: 14.0
386 tokens: tokens
387 }
388 }
389 EuvSeparator {
390 label: String::new()
391 tokens: tokens
392 }
393 EuvEmpty {
394 title: DISPLAY_EMPTY_TITLE.to_string()
395 description: DISPLAY_EMPTY_DESC.to_string()
396 tokens: tokens
397 }
398 }
399 }
400 }
401}
402
403pub fn mount_display_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
414 let cards: Vec<NodeId> = vec![
415 mount_display_identity_card(state, tokens),
416 mount_display_alerts_card(tokens),
417 mount_display_disclosure_card(state, tokens),
418 mount_display_timeline_card(tokens),
419 mount_display_carousel_card(state, tokens),
420 mount_display_calendar_card(state, tokens),
421 mount_display_placeholder_card(tokens),
422 ];
423 let grid: NodeId = mount_responsive_grid(cards, 2);
424 view! {
425 EuvPage {
426 title: DISPLAY_TITLE.to_string()
427 subtitle: DISPLAY_SUBTITLE.to_string()
428 tokens: tokens
429 { grid }
430 }
431 }
432}