BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-base / src / demo_cards.rs

demo_cards.rs

refactor(app): extract app-base crate
metis Daniel Däschle · pushed by metis · 6 weeks ago
16e522c2 History
demo_cards.rs 20.3 KiB Download Raw
1use chrono::Local;
2use serde_json::{Value, json};
3
4const CARD_POSTER_URL: &str = "https://avatars.githubusercontent.com/u/9919?s=360";
5const CARD_ICON_URL: &str = "https://avatars.githubusercontent.com/u/9919?s=32";
6const VIDEO_URL: &str = "https://example.com/videos/release-tour.mp4";
7
8pub fn behaviour_cards() -> Vec<Value> {
9 vec![
10 refresh_card("Build status: waiting for the automatic refresh..."),
11 actions_card(),
12 text_card(),
13 select_action_card(),
14 media_and_icon_card(),
15 text_layout_card(),
16 text_runs_card(),
17 layout_card(),
18 fallback_card(),
19 target_width_card(),
20 table_card(),
21 code_block_card(),
22 badge_card(),
23 progress_card(),
24 compound_button_card(),
25 carousel_card(),
26 action_overflow_card(),
27 dates_card(),
28 ]
29}
30
31pub fn refreshed_card() -> Value {
32 refresh_card(&format!(
33 "Build #482 passed (refreshed at {})",
34 Local::now().format("%H:%M:%S")
35 ))
36}
37
38fn refresh_card(status: &str) -> Value {
39 json!({
40 "type": "AdaptiveCard",
41 "refresh": {"action": {"type": "Action.Execute", "verb": "refreshStatus", "data": {"build": 482}}},
42 "body": [
43 {"type": "TextBlock", "weight": "bolder", "text": "Refreshing card"},
44 {"type": "TextBlock", "wrap": true, "text": status},
45 {"type": "TextBlock", "wrap": true, "isSubtle": true, "size": "small", "text": "Updates itself once when it is first shown. Use the message menu to refresh again."}
46 ]
47 })
48}
49
50fn actions_card() -> Value {
51 json!({
52 "type": "AdaptiveCard",
53 "body": [
54 {"type": "TextBlock", "weight": "bolder", "text": "Submit variants"}
55 ],
56 "actions": [
57 {"type": "Action.Submit", "title": "Open tab", "iconUrl": "icon:Open", "data": {"msteams": {"type": "invoke", "value": {"type": "tab/tabInfoAction", "tabInfo": {
58 "contentUrl": "https://example.com/tabs/content", "websiteUrl": "https://example.com/tabs/site", "name": "Release tab", "entityId": "release"
59 }}}}},
60 {"type": "Action.Submit", "title": "Sign in", "iconUrl": "icon:LockClosed", "data": {"msteams": {"type": "signin", "value": "https://example.com/signin"}}},
61 {"type": "Action.Submit", "title": "Custom invoke", "data": {"msteams": {"type": "invoke", "value": {"type": "demo/custom", "payload": 1}}}},
62 {"type": "Action.Submit", "title": "Add app", "data": {"msteams": {"type": "invoke", "value": {"type": "appInstallToConversation"}}}}
63 ]
64 })
65}
66
67fn text_card() -> Value {
68 json!({
69 "type": "AdaptiveCard",
70 "msteams": {"entities": [
71 {"type": "mention", "text": "<at>Mara Lindqvist</at>", "mentioned": {"id": "29:mara", "name": "Mara Lindqvist"}}
72 ]},
73 "body": [
74 {"type": "TextBlock", "weight": "bolder", "text": "Mentions and italics"},
75 {"type": "TextBlock", "wrap": true, "text": "Hi <at>Mara Lindqvist</at>, this is _italic_, this is *also italic*, and **bold**. Names like snake_case_name and https://example.com/a_b_c stay as they are."},
76 {"type": "FactSet", "facts": [{"title": "Reviewer", "value": "<at>Dana Demo</at>"}, {"title": "Note", "value": "_soft_ launch"}]},
77 {"type": "RichTextBlock", "inlines": [{"type": "TextRun", "text": "cc "}, {"type": "TextRun", "text": "<at>Priya Nair</at>", "weight": "bolder"}]}
78 ]
79 })
80}
81
82fn select_action_card() -> Value {
83 json!({
84 "type": "AdaptiveCard",
85 "selectAction": {"type": "Action.OpenUrl", "url": "https://example.com/card"},
86 "body": [
87 {"type": "TextBlock", "weight": "bolder", "text": "Clickable areas"},
88 {"type": "TextBlock", "wrap": true, "isSubtle": true, "size": "small", "text": "The card, the container, the column and the image each open a page or toggle the note."},
89 {"type": "Container", "style": "emphasis", "selectAction": {"type": "Action.ToggleVisibility", "targetElements": ["container-note"]}, "items": [
90 {"type": "TextBlock", "wrap": true, "text": "Container: click to toggle the note"},
91 {"type": "TextBlock", "id": "container-note", "isVisible": false, "isSubtle": true, "text": "Container note"}
92 ]},
93 {"type": "ColumnSet", "columns": [
94 {"type": "Column", "width": "auto", "selectAction": {"type": "Action.OpenUrl", "url": "https://example.com/image"}, "items": [
95 {"type": "Image", "url": CARD_ICON_URL, "size": "small", "selectAction": {"type": "Action.OpenUrl", "url": "https://example.com/image"}}
96 ]},
97 {"type": "Column", "width": "stretch", "selectAction": {"type": "Action.Submit", "data": {"action": "watch"}}, "items": [
98 {"type": "TextBlock", "wrap": true, "text": "Column: click to submit"}
99 ]}
100 ]}
101 ]
102 })
103}
104
105fn media_and_icon_card() -> Value {
106 json!({
107 "type": "AdaptiveCard",
108 "body": [
109 {"type": "TextBlock", "weight": "bolder", "text": "Media and icons"},
110 {"type": "Media", "poster": CARD_POSTER_URL, "altText": "Release tour video", "sources": [{"mimeType": "video/mp4", "url": VIDEO_URL}]},
111 {"type": "ColumnSet", "columns": [
112 {"type": "Column", "width": "auto", "items": [{"type": "Icon", "name": "Calendar", "size": "Large", "color": "accent"}]},
113 {"type": "Column", "width": "auto", "items": [{"type": "Icon", "name": "Mail", "size": "Medium"}]},
114 {"type": "Column", "width": "auto", "items": [{"type": "Icon", "name": "Warning", "size": "Standard", "color": "warning", "selectAction": {"type": "Action.OpenUrl", "url": "https://example.com/warning"}}]},
115 {"type": "Column", "width": "auto", "items": [{"type": "Icon", "name": "Alert", "size": "Small", "color": "good"}]},
116 {"type": "Column", "width": "auto", "items": [{"type": "Icon", "name": "NoSuchFluentName", "size": "Large"}]}
117 ]}
118 ],
119 "actions": [
120 {"type": "Action.OpenUrl", "title": "Send", "url": "https://example.com/send", "iconUrl": "icon:Send"},
121 {"type": "Action.OpenUrl", "title": "Logo", "url": "https://example.com/logo", "iconUrl": CARD_ICON_URL}
122 ]
123 })
124}
125
126fn text_layout_card() -> Value {
127 json!({
128 "type": "AdaptiveCard",
129 "body": [
130 {"type": "TextBlock", "style": "heading", "text": "Text layout"},
131 {"type": "TextBlock", "text": "wrap is false by default, so this long line is cut off with an ellipsis at the card edge instead of overflowing"},
132 {"type": "TextBlock", "wrap": true, "maxLines": 2, "text": "maxLines 2 with wrap: this text is long enough to need more than two lines, so the third line is cut off with an ellipsis. More words follow to fill the space and prove the clamp."},
133 {"type": "TextBlock", "horizontalAlignment": "center", "text": "Centered"},
134 {"type": "TextBlock", "horizontalAlignment": "right", "text": "Right aligned"},
135 {"type": "TextBlock", "fontType": "monospace", "text": "monospace: let answer = 42;"},
136 {"type": "TextBlock", "color": "dark", "text": "Dark colour stays readable"},
137 {"type": "TextBlock", "color": "light", "text": "Light colour stays readable"}
138 ]
139 })
140}
141
142fn text_runs_card() -> Value {
143 json!({
144 "type": "AdaptiveCard",
145 "body": [
146 {"type": "TextBlock", "weight": "bolder", "text": "Text runs"},
147 {"type": "RichTextBlock", "inlines": [
148 {"type": "TextRun", "text": "highlighted ", "highlight": true},
149 {"type": "TextRun", "text": "good ", "color": "good", "weight": "bolder"},
150 {"type": "TextRun", "text": "attention ", "color": "attention"},
151 {"type": "TextRun", "text": "subtle ", "isSubtle": true},
152 {"type": "TextRun", "text": "large ", "size": "large"},
153 {"type": "TextRun", "text": "small ", "size": "small"},
154 {"type": "TextRun", "text": "mono", "fontType": "monospace"}
155 ]},
156 {"type": "RichTextBlock", "horizontalAlignment": "center", "inlines": [{"type": "TextRun", "text": "centered rich text"}]}
157 ]
158 })
159}
160
161fn layout_card() -> Value {
162 json!({
163 "type": "AdaptiveCard",
164 "minHeight": "260px",
165 "verticalContentAlignment": "center",
166 "backgroundImage": {"url": CARD_POSTER_URL, "fillMode": "cover"},
167 "body": [
168 {"type": "Container", "style": "good", "bleed": true, "items": [
169 {"type": "TextBlock", "weight": "bolder", "text": "Bleed container touches the card edges"}
170 ]},
171 {"type": "TextBlock", "weight": "bolder", "text": "Card with background image, minHeight and centered content"},
172 {"type": "Container", "style": "emphasis", "minHeight": "70px", "verticalContentAlignment": "center", "items": [
173 {"type": "TextBlock", "text": "minHeight 70 with centered text"}
174 ]},
175 {"type": "Container", "style": "accent", "rtl": true, "items": [
176 {"type": "TextBlock", "text": "rtl container aligns text right"}
177 ]},
178 {"type": "Container", "style": "warning", "minHeight": "90px", "items": [
179 {"type": "TextBlock", "text": "Top"},
180 {"type": "Container", "height": "stretch", "style": "emphasis", "items": [{"type": "TextBlock", "text": "height: stretch fills the free space"}]},
181 {"type": "TextBlock", "weight": "bolder", "text": "Bottom"}
182 ]},
183 {"type": "ColumnSet", "rtl": true, "style": "emphasis", "columns": [
184 {"type": "Column", "width": "stretch", "style": "attention", "items": [{"type": "TextBlock", "text": "First column"}]},
185 {"type": "Column", "width": "stretch", "style": "good", "items": [{"type": "TextBlock", "text": "Second column"}]}
186 ]},
187 {"type": "Image", "url": CARD_ICON_URL, "altText": "Hover for alt text", "size": "small", "horizontalAlignment": "center", "backgroundColor": "#FFB0B0B0"}
188 ]
189 })
190}
191
192fn fallback_card() -> Value {
193 json!({
194 "type": "AdaptiveCard",
195 "fallbackText": "This card needs a newer client",
196 "body": [
197 {"type": "TextBlock", "weight": "bolder", "text": "Fallback"},
198 {"type": "Hologram", "fallback": {"type": "TextBlock", "wrap": true, "text": "Unknown element replaced by its fallback"}},
199 {"type": "Hologram", "fallback": "drop"},
200 {"type": "Hologram"},
201 {"type": "TextBlock", "text": "never shown", "requires": {"adaptiveCards": "1.9"}, "fallback": {"type": "TextBlock", "wrap": true, "text": "Needs 1.9, fell back to this"}},
202 {"type": "TextBlock", "wrap": true, "text": "Requires 1.x is met", "requires": {"adaptiveCards": "1.x"}},
203 {"type": "TextBlock", "wrap": true, "text": "Hidden: unknown feature", "requires": {"fancyFeature": "1.0"}, "fallback": "drop"}
204 ]
205 })
206}
207
208fn target_width_card() -> Value {
209 json!({
210 "type": "AdaptiveCard",
211 "body": [
212 {"type": "TextBlock", "weight": "bolder", "text": "Target width (this card is standard)"},
213 {"type": "TextBlock", "targetWidth": "standard", "text": "Visible: standard"},
214 {"type": "TextBlock", "targetWidth": "atLeast:standard", "text": "Visible: atLeast:standard"},
215 {"type": "TextBlock", "targetWidth": "atMost:standard", "text": "Visible: atMost:standard"},
216 {"type": "TextBlock", "targetWidth": "wide", "text": "Hidden: wide"},
217 {"type": "TextBlock", "targetWidth": "veryNarrow", "text": "Hidden: veryNarrow"},
218 {"type": "TextBlock", "targetWidth": "atMost:narrow", "text": "Hidden: atMost:narrow"}
219 ]
220 })
221}
222
223fn table_card() -> Value {
224 json!({
225 "type": "AdaptiveCard",
226 "body": [
227 {"type": "TextBlock", "weight": "bolder", "text": "Table"},
228 {"type": "Table", "gridStyle": "accent", "horizontalCellContentAlignment": "center", "verticalCellContentAlignment": "center",
229 "columns": [{"width": 2, "horizontalCellContentAlignment": "left"}, {"width": 1}, {"width": "70px", "horizontalCellContentAlignment": "right"}],
230 "rows": [
231 {"type": "TableRow", "cells": [
232 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "Service"}]},
233 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "State"}]},
234 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "Ms"}]}
235 ]},
236 {"type": "TableRow", "cells": [
237 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "API gateway"}]},
238 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "color": "good", "text": "Healthy"}]},
239 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "42"}]}
240 ]},
241 {"type": "TableRow", "style": "attention", "cells": [
242 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "Search"}]},
243 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "color": "attention", "text": "Degraded"}]},
244 {"type": "TableCell", "selectAction": {"type": "Action.OpenUrl", "url": "https://example.com/search"}, "items": [{"type": "TextBlock", "wrap": true, "text": "1830"}]}
245 ]}
246 ]},
247 {"type": "Table", "firstRowAsHeader": false, "showGridLines": false, "rows": [
248 {"type": "TableRow", "cells": [
249 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "No header"}]},
250 {"type": "TableCell", "items": [{"type": "TextBlock", "wrap": true, "text": "No grid lines"}]}
251 ]}
252 ]}
253 ]
254 })
255}
256
257fn code_block_card() -> Value {
258 let snippet: String = (1..=14)
259 .map(|line| format!(" let value_{line} = compute({line});\n"))
260 .collect();
261 json!({
262 "type": "AdaptiveCard",
263 "body": [
264 {"type": "TextBlock", "weight": "bolder", "text": "Code blocks"},
265 {"type": "CodeBlock", "language": "Rust", "startLineNumber": 8, "codeSnippet": format!("fn main() {{\n{snippet}}}")},
266 {"type": "CodeBlock", "language": "Json", "codeSnippet": "{\"short\": true}"}
267 ]
268 })
269}
270
271fn badge_card() -> Value {
272 let styles = [
273 "default",
274 "accent",
275 "good",
276 "attention",
277 "warning",
278 "subtle",
279 "informative",
280 ];
281 let filled: Vec<Value> = styles
282 .iter()
283 .map(|style| json!({"type": "Badge", "text": style, "style": style, "icon": "Checkmark"}))
284 .collect();
285 let tinted: Vec<Value> = styles
286 .iter()
287 .map(|style| json!({"type": "Badge", "text": style, "style": style, "appearance": "tint"}))
288 .collect();
289 json!({
290 "type": "AdaptiveCard",
291 "body": [
292 {"type": "TextBlock", "weight": "bolder", "text": "Badges"},
293 {"type": "Container", "items": filled},
294 {"type": "Container", "spacing": "small", "items": tinted},
295 {"type": "ColumnSet", "spacing": "small", "columns": [
296 {"type": "Column", "width": "auto", "items": [{"type": "Badge", "text": "Square", "shape": "square", "style": "accent"}]},
297 {"type": "Column", "width": "auto", "items": [{"type": "Badge", "text": "Rounded", "shape": "rounded", "style": "accent"}]},
298 {"type": "Column", "width": "auto", "items": [{"type": "Badge", "text": "Large", "size": "large", "style": "good", "icon": "Star", "iconPosition": "After", "tooltip": "Large badge with trailing icon"}]},
299 {"type": "Column", "width": "auto", "items": [{"type": "Badge", "text": "XL", "size": "extraLarge", "style": "warning"}]}
300 ]}
301 ]
302 })
303}
304
305fn progress_card() -> Value {
306 json!({
307 "type": "AdaptiveCard",
308 "body": [
309 {"type": "TextBlock", "weight": "bolder", "text": "Progress"},
310 {"type": "ProgressBar", "value": 65},
311 {"type": "ProgressBar", "value": 30, "color": "good", "spacing": "small"},
312 {"type": "ProgressBar", "color": "attention", "spacing": "small"},
313 {"type": "ProgressRing", "label": "Loading data...", "spacing": "medium"},
314 {"type": "ProgressRing", "label": "Above", "labelPosition": "above", "size": "large", "spacing": "medium"},
315 {"type": "ProgressRing", "size": "tiny", "spacing": "medium"}
316 ]
317 })
318}
319
320fn compound_button_card() -> Value {
321 json!({
322 "type": "AdaptiveCard",
323 "body": [
324 {"type": "TextBlock", "weight": "bolder", "text": "Compound buttons"},
325 {"type": "CompoundButton", "icon": "Calendar", "title": "Schedule a meeting", "description": "Find a time that works for everyone", "badge": "New", "selectAction": {"type": "Action.OpenUrl", "url": "https://example.com/schedule"}},
326 {"type": "CompoundButton", "icon": "Document", "title": "Open the release notes", "description": "Opens in your browser", "spacing": "small", "selectAction": {"type": "Action.Submit", "data": {"action": "notes"}}}
327 ]
328 })
329}
330
331fn carousel_card() -> Value {
332 json!({
333 "type": "AdaptiveCard",
334 "body": [
335 {"type": "TextBlock", "weight": "bolder", "text": "Carousel"},
336 {"type": "Carousel", "timer": 4000, "pages": [
337 {"type": "CarouselPage", "style": "emphasis", "minHeight": "80px", "verticalContentAlignment": "center", "items": [
338 {"type": "TextBlock", "weight": "bolder", "text": "Page one"},
339 {"type": "TextBlock", "wrap": true, "text": "Use the arrows or the dots."}
340 ]},
341 {"type": "CarouselPage", "style": "good", "minHeight": "80px", "items": [
342 {"type": "TextBlock", "weight": "bolder", "text": "Page two"},
343 {"type": "Image", "url": CARD_ICON_URL, "size": "small"}
344 ]},
345 {"type": "CarouselPage", "style": "accent", "minHeight": "80px", "items": [
346 {"type": "TextBlock", "weight": "bolder", "text": "Page three"}
347 ]}
348 ]}
349 ]
350 })
351}
352
353fn action_overflow_card() -> Value {
354 let url = "https://example.com/action";
355 json!({
356 "type": "AdaptiveCard",
357 "body": [
358 {"type": "TextBlock", "weight": "bolder", "text": "Action modes, tooltips and overflow"},
359 {"type": "ActionSet", "actions": [
360 {"type": "Action.OpenUrl", "title": "Primary", "url": url, "tooltip": "Tooltip on hover"},
361 {"type": "Action.OpenUrl", "title": "Positive", "url": url, "style": "positive"},
362 {"type": "Action.OpenUrl", "title": "Destructive", "url": url, "style": "destructive"},
363 {"type": "Action.OpenUrl", "title": "Disabled", "url": url, "isEnabled": false, "tooltip": "Not available right now"},
364 {"type": "Action.OpenUrl", "title": "Secondary A", "url": url, "mode": "secondary"},
365 {"type": "Action.OpenUrl", "title": "Secondary B", "url": url, "mode": "secondary"}
366 ]}
367 ],
368 "actions": (1..=8)
369 .map(|number| json!({"type": "Action.OpenUrl", "title": format!("Action {number}"), "url": url}))
370 .collect::<Vec<_>>()
371 })
372}
373
374fn dates_card() -> Value {
375 json!({
376 "type": "AdaptiveCard",
377 "body": [
378 {"type": "TextBlock", "weight": "bolder", "text": "Dates and times"},
379 {"type": "TextBlock", "wrap": true, "text": "Short {{DATE(2026-10-09T14:05:00Z, SHORT)}}"},
380 {"type": "TextBlock", "wrap": true, "text": "Long {{DATE(2026-10-09T14:05:00Z, LONG)}}"},
381 {"type": "TextBlock", "wrap": true, "text": "Compact {{DATE(2026-10-09T14:05:00Z, COMPACT)}} at {{TIME(2026-10-09T14:05:00Z)}}"},
382 {"type": "TextBlock", "wrap": true, "text": "Malformed stays literal: {{DATE(tomorrow, SHORT)}}"},
383 {"type": "RichTextBlock", "inlines": [{"type": "TextRun", "text": "Run: {{TIME(2026-10-09T09:30:00+02:00)}}"}]},
384 {"type": "FactSet", "facts": [{"title": "Due", "value": "{{DATE(2026-10-12T08:00:00Z, SHORT)}}"}]}
385 ]
386 })
387}