lumen-dioxus 6.0.0

Lumen UI components for Dioxus: web, desktop, mobile, and Dioxus Native (Blitz).
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
//! Behavior and markup tests for data components whose markup intentionally differs from
//! lumen-react, and for the data-driven APIs lumen-react does not have.
//!
//! Intentional differences, each compared against lumen-react's markup with only that change:
//! - `Timer` and `ReorderableList` mark their root `data-ui-owner="dioxus"` instead of `"react"`.
//! - `PromptComposer` renders its text as the textarea `value` attribute, because Dioxus keeps
//!   form values as properties; lumen-react serializes it as text content.
//! - Selection checkboxes are lumen-dioxus `Checkbox`es (`<button role="checkbox">`).
//!
//! The `DataTable` table cases match lumen-react exactly; they live here instead of the generated
//! fixtures only because the fixture JSON cannot carry a spelling directive for the ARIA role
//! names `columnheader` and `rowgroup`.

// cspell:words columnheader fieldset rowgroup figcaption hideable offsetless peekable

mod support;

use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
use support::{Token, attribute, normalize_generated_ids, opening_tags, render, tokenize};

const COUNTDOWN_NOW: i64 = 1_767_225_600_000; // 2026-01-01T00:00:00Z
const ELAPSED_NOW: i64 = 1_767_323_045_000; // 2026-01-02T03:04:05Z

/// lumen-react `renderToStaticMarkup` output for `timer-countdown`.
const REACT_TIMER_COUNTDOWN: &str = r#"<span aria-live="off" class="ui-timer" data-slot="timer" data-state="running" data-ui-owner="react" data-ui-timer="true" role="timer"><time class="ui-timer__value" data-slot="timer-value" dateTime="PT1H2M3S">01:02:03</time><span aria-atomic="true" aria-live="polite" class="ui-sr-only" data-slot="timer-announcer"></span></span>"#;

/// lumen-react `renderToStaticMarkup` output for `timer-elapsed-units`.
const REACT_TIMER_ELAPSED_UNITS: &str = r#"<span aria-live="off" class="ui-timer" data-slot="timer" data-state="running" data-ui-owner="react" data-ui-timer="true" role="timer"><time class="ui-timer__value" data-slot="timer-value" dateTime="PT27H4M5S">27h 4m 5s</time><span aria-atomic="true" aria-live="polite" class="ui-sr-only" data-slot="timer-announcer"></span></span>"#;

/// lumen-react `renderToStaticMarkup` output for `timer-complete`.
const REACT_TIMER_COMPLETE: &str = r#"<span aria-live="off" class="ui-timer" data-slot="timer" data-state="complete" data-ui-owner="react" data-ui-timer="true" role="timer"><time class="ui-timer__value" data-slot="timer-value" dateTime="PT0S">00:00:00</time><span aria-atomic="true" aria-live="polite" class="ui-sr-only" data-slot="timer-announcer"></span></span>"#;

/// lumen-react `renderToStaticMarkup` output for `timer-invalid`.
const REACT_TIMER_INVALID: &str = r#"<span aria-live="off" class="ui-timer" data-slot="timer" data-state="invalid" data-ui-owner="react" data-ui-timer="true" role="timer" aria-label="Launch"><time class="ui-timer__value" data-slot="timer-value">--:--</time><span aria-atomic="true" aria-live="polite" class="ui-sr-only" data-slot="timer-announcer"></span></span>"#;

/// lumen-react `renderToStaticMarkup` output for `reorderable-list`.
const REACT_REORDERABLE_LIST: &str = r#"<div class="ui-reorderable-list" data-slot="reorderable-list" data-ui-owner="react" data-ui-reorderable-list=""><ol aria-label="Release steps" class="ui-reorderable-list__items" data-slot="reorderable-list-items"><li class="ui-reorderable-list__item" data-label="Draft" data-slot="reorderable-list-item" data-value="draft"><button aria-describedby="ui-reorderable-list-_R_0_-instructions" aria-label="Reorder Draft" aria-pressed="false" class="ui-reorderable-list__handle" data-slot="reorderable-list-handle" hidden="" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-grip-vertical" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><circle cx="9" cy="12" r="1"></circle><circle cx="9" cy="5" r="1"></circle><circle cx="9" cy="19" r="1"></circle><circle cx="15" cy="12" r="1"></circle><circle cx="15" cy="5" r="1"></circle><circle cx="15" cy="19" r="1"></circle></svg></button><div class="ui-reorderable-list__content" data-slot="reorderable-list-content">Draft<span class="ui-reorderable-list__description" data-slot="reorderable-list-description">Due today</span></div><div class="ui-reorderable-list__moves" data-slot="reorderable-list-moves" hidden=""><button aria-disabled="true" aria-label="Move Draft up" class="ui-reorderable-list__move" data-slot="reorderable-list-move-up" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-up" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m18 15-6-6-6 6"></path></svg></button><button aria-disabled="false" aria-label="Move Draft down" class="ui-reorderable-list__move" data-slot="reorderable-list-move-down" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-down" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m6 9 6 6 6-6"></path></svg></button></div></li><li class="ui-reorderable-list__item" data-label="Review" data-slot="reorderable-list-item" data-value="review"><button aria-describedby="ui-reorderable-list-_R_0_-instructions" aria-label="Reorder Review" aria-pressed="false" class="ui-reorderable-list__handle" data-slot="reorderable-list-handle" hidden="" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-grip-vertical" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><circle cx="9" cy="12" r="1"></circle><circle cx="9" cy="5" r="1"></circle><circle cx="9" cy="19" r="1"></circle><circle cx="15" cy="12" r="1"></circle><circle cx="15" cy="5" r="1"></circle><circle cx="15" cy="19" r="1"></circle></svg></button><div class="ui-reorderable-list__content" data-slot="reorderable-list-content">Review</div><div class="ui-reorderable-list__moves" data-slot="reorderable-list-moves" hidden=""><button aria-disabled="false" aria-label="Move Review up" class="ui-reorderable-list__move" data-slot="reorderable-list-move-up" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-up" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m18 15-6-6-6 6"></path></svg></button><button aria-disabled="false" aria-label="Move Review down" class="ui-reorderable-list__move" data-slot="reorderable-list-move-down" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-down" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m6 9 6 6 6-6"></path></svg></button></div></li><li class="ui-reorderable-list__item" data-disabled="" data-label="Ship" data-slot="reorderable-list-item" data-value="ship"><button aria-describedby="ui-reorderable-list-_R_0_-instructions" aria-label="Reorder Ship" aria-pressed="false" class="ui-reorderable-list__handle" data-slot="reorderable-list-handle" disabled="" hidden="" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-grip-vertical" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><circle cx="9" cy="12" r="1"></circle><circle cx="9" cy="5" r="1"></circle><circle cx="9" cy="19" r="1"></circle><circle cx="15" cy="12" r="1"></circle><circle cx="15" cy="5" r="1"></circle><circle cx="15" cy="19" r="1"></circle></svg></button><div class="ui-reorderable-list__content" data-slot="reorderable-list-content">Ship</div><div class="ui-reorderable-list__moves" data-slot="reorderable-list-moves" hidden=""><button aria-disabled="true" aria-label="Move Ship up" class="ui-reorderable-list__move" data-slot="reorderable-list-move-up" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-up" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m18 15-6-6-6 6"></path></svg></button><button aria-disabled="true" aria-label="Move Ship down" class="ui-reorderable-list__move" data-slot="reorderable-list-move-down" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-down" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m6 9 6 6 6-6"></path></svg></button></div></li></ol><p class="ui-reorderable-list__instructions" data-slot="reorderable-list-instructions" id="ui-reorderable-list-_R_0_-instructions">Press Space or Enter on a reorder handle to grab an item. Use the up and down arrow keys to move it, Space or Enter to drop it, and Escape to cancel.</p><span aria-atomic="true" aria-live="polite" class="ui-reorderable-list__status" data-slot="reorderable-list-status" role="status"></span></div>"#;

/// lumen-react `renderToStaticMarkup` output for `reorderable-list-move-buttons`.
const REACT_REORDERABLE_LIST_MOVE_BUTTONS: &str = r#"<div class="ui-reorderable-list" data-move-buttons="" data-slot="reorderable-list" data-ui-owner="react" data-ui-reorderable-list=""><ol aria-label="Steps" class="ui-reorderable-list__items" data-slot="reorderable-list-items"><li class="ui-reorderable-list__item" data-label="Draft" data-slot="reorderable-list-item" data-value="draft"><button aria-describedby="ui-reorderable-list-_R_0_-instructions" aria-label="Drag Draft" aria-pressed="false" class="ui-reorderable-list__handle" data-slot="reorderable-list-handle" hidden="" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-grip-vertical" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><circle cx="9" cy="12" r="1"></circle><circle cx="9" cy="5" r="1"></circle><circle cx="9" cy="19" r="1"></circle><circle cx="15" cy="12" r="1"></circle><circle cx="15" cy="5" r="1"></circle><circle cx="15" cy="19" r="1"></circle></svg></button><div class="ui-reorderable-list__content" data-slot="reorderable-list-content">Draft<span class="ui-reorderable-list__description" data-slot="reorderable-list-description">Due today</span></div><div class="ui-reorderable-list__moves" data-slot="reorderable-list-moves" hidden=""><button aria-disabled="true" aria-label="Move Draft up" class="ui-reorderable-list__move" data-slot="reorderable-list-move-up" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-up" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m18 15-6-6-6 6"></path></svg></button><button aria-disabled="false" aria-label="Move Draft down" class="ui-reorderable-list__move" data-slot="reorderable-list-move-down" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-down" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m6 9 6 6 6-6"></path></svg></button></div></li><li class="ui-reorderable-list__item" data-label="Review" data-slot="reorderable-list-item" data-value="review"><button aria-describedby="ui-reorderable-list-_R_0_-instructions" aria-label="Drag Review" aria-pressed="false" class="ui-reorderable-list__handle" data-slot="reorderable-list-handle" hidden="" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-grip-vertical" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><circle cx="9" cy="12" r="1"></circle><circle cx="9" cy="5" r="1"></circle><circle cx="9" cy="19" r="1"></circle><circle cx="15" cy="12" r="1"></circle><circle cx="15" cy="5" r="1"></circle><circle cx="15" cy="19" r="1"></circle></svg></button><div class="ui-reorderable-list__content" data-slot="reorderable-list-content">Review</div><div class="ui-reorderable-list__moves" data-slot="reorderable-list-moves" hidden=""><button aria-disabled="false" aria-label="Move Review up" class="ui-reorderable-list__move" data-slot="reorderable-list-move-up" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-up" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m18 15-6-6-6 6"></path></svg></button><button aria-disabled="true" aria-label="Move Review down" class="ui-reorderable-list__move" data-slot="reorderable-list-move-down" type="button"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-down" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m6 9 6 6 6-6"></path></svg></button></div></li></ol><p class="ui-reorderable-list__instructions" data-slot="reorderable-list-instructions" id="ui-reorderable-list-_R_0_-instructions">Press Space or Enter on a reorder handle to grab an item. Use the up and down arrow keys to move it, Space or Enter to drop it, and Escape to cancel.</p><span aria-atomic="true" aria-live="polite" class="ui-reorderable-list__status" data-slot="reorderable-list-status" role="status"></span></div>"#;

/// lumen-react `renderToStaticMarkup` output for `prompt-composer-default`.
const REACT_PROMPT_COMPOSER_DEFAULT: &str = r#"<form class="ui-form ui-prompt-composer" data-status="idle" data-disabled="false" data-pending="false" data-submit-on-enter="false" data-ui-prompt-composer="true" method="post"><label class="ui-label" for="_R_0_">Message</label><textarea class="ui-textarea" rows="3" id="_R_0_" data-ui-prompt-input="true" maxLength="4000" name="prompt" required="">Summarize the report</textarea><div class="ui-stack ui-stack--horizontal ui-stack--gap-related ui-stack--align-stretch ui-stack--justify-start ui-stack--wrap" data-direction="horizontal" data-ui-stack="true"><button class="ui-button ui-button--default ui-button--default-size" data-slot="button" type="submit" data-ui-prompt-send="true"><span class="ui-button__content">Send</span></button><button class="ui-button ui-button--secondary ui-button--default-size" data-slot="button" type="button" data-ui-prompt-stop="true" hidden=""><span class="ui-button__content">Stop</span></button></div></form>"#;

/// lumen-react `renderToStaticMarkup` output for `prompt-composer-pending`.
const REACT_PROMPT_COMPOSER_PENDING: &str = r#"<form aria-busy="true" class="ui-form ui-prompt-composer" data-status="submitting" id="chat" data-disabled="false" data-pending="true" data-submit-on-enter="true" data-ui-prompt-composer="true" method="post"><label class="ui-label" for="chat-input">Ask the assistant</label><textarea class="ui-textarea" rows="3" id="chat-input" data-ui-prompt-input="true" maxLength="200" name="prompt" required=""></textarea><div class="ui-stack ui-stack--horizontal ui-stack--gap-related ui-stack--align-stretch ui-stack--justify-start ui-stack--wrap" data-direction="horizontal" data-ui-stack="true"><button class="ui-button ui-button--default ui-button--default-size" data-slot="button" disabled="" type="submit" data-ui-prompt-send="true"><span class="ui-button__content">Submit</span></button><button class="ui-button ui-button--secondary ui-button--default-size" data-slot="button" type="button" data-ui-prompt-stop="true"><span class="ui-button__content">Cancel</span></button></div></form>"#;

/// lumen-react `renderToStaticMarkup` output for `data-table-default-sort`.
const REACT_DATA_TABLE_DEFAULT_SORT: &str = r#"<div class="ui-data-table" data-ui-datatable="true" data-ui-datatable-sort-mode="client"><span class="ui-sr-only" role="status"></span><table role="table"><thead role="rowgroup"><tr role="row"><th class="ui-table__cell--title" aria-sort="none" data-ui-datatable-sort-bound="true" data-ui-datatable-sortable="true" role="columnheader" scope="col" data-numeric="false"><button class="ui-data-table__sort" data-ui-datatable-sort="true" type="button">Name</button></th><th data-ui-datatable-sort-bound="true" role="columnheader" scope="col" data-numeric="false">Role</th><th aria-sort="descending" data-ui-datatable-sort-bound="true" data-ui-datatable-sort-direction="descending" data-ui-datatable-sort-type="number" data-ui-datatable-sortable="true" role="columnheader" scope="col" data-numeric="true"><button class="ui-data-table__sort" data-ui-datatable-sort="true" type="button">Seats</button></th></tr></thead><tbody role="rowgroup"><tr data-ui-datatable-row="true" data-value="grace" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value">Grace</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Admin</div></td><td class="ui-table__cell--wide" data-sort-value="1200" role="cell" data-numeric="true"><div class="ui-table__value">1,200</div></td></tr><tr data-ui-datatable-row="true" data-value="ada" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value">Ada</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Owner</div></td><td class="ui-table__cell--wide" role="cell" data-numeric="true"><div class="ui-table__value">12</div></td></tr><tr data-ui-datatable-row="true" data-value="linus" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value">Linus</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Member</div></td><td class="ui-table__cell--wide" role="cell" data-numeric="true"><div class="ui-table__value">3</div></td></tr></tbody></table></div>"#;

/// lumen-react `renderToStaticMarkup` output for `data-table-multi-sort`.
const REACT_DATA_TABLE_MULTI_SORT: &str = r#"<div class="ui-data-table" data-ui-datatable="true" data-ui-datatable-sort-mode="client"><span class="ui-sr-only" role="status"></span><table role="table"><thead role="rowgroup"><tr role="row"><th class="ui-table__cell--title" aria-sort="ascending" data-ui-datatable-sort-bound="true" data-ui-datatable-sort-direction="ascending" data-ui-datatable-sort-priority="1" data-ui-datatable-sortable="true" role="columnheader" scope="col" data-numeric="false"><button class="ui-data-table__sort" data-ui-datatable-sort="true" type="button">Name<span class="ui-data-table__sort-priority" aria-hidden="true">1</span><span class="ui-sr-only">Sort priority 1, ascending</span></button></th><th data-ui-datatable-sort-bound="true" role="columnheader" scope="col" data-numeric="false">Role</th><th aria-sort="none" data-ui-datatable-sort-bound="true" data-ui-datatable-sort-direction="descending" data-ui-datatable-sort-priority="2" data-ui-datatable-sort-type="number" data-ui-datatable-sortable="true" role="columnheader" scope="col" data-numeric="true"><button class="ui-data-table__sort" data-ui-datatable-sort="true" type="button">Seats<span class="ui-data-table__sort-priority" aria-hidden="true">2</span><span class="ui-sr-only">Sort priority 2, descending</span></button></th></tr></thead><tbody role="rowgroup"><tr data-ui-datatable-row="true" data-value="ada" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value">Ada</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Owner</div></td><td class="ui-table__cell--wide" role="cell" data-numeric="true"><div class="ui-table__value">12</div></td></tr><tr data-ui-datatable-row="true" data-value="grace" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value">Grace</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Admin</div></td><td class="ui-table__cell--wide" data-sort-value="1200" role="cell" data-numeric="true"><div class="ui-table__value">1,200</div></td></tr><tr data-ui-datatable-row="true" data-value="linus" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value">Linus</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Member</div></td><td class="ui-table__cell--wide" role="cell" data-numeric="true"><div class="ui-table__value">3</div></td></tr></tbody></table></div>"#;

/// lumen-react `renderToStaticMarkup` output for `data-table-records-glass`.
const REACT_DATA_TABLE_RECORDS_GLASS: &str = r#"<div class="ui-data-table ui-data-table--glass ui-glass-subtle ui-table-wrap--records" data-ui-datatable="true" data-ui-datatable-sort-mode="manual" data-ui-glass-track="true"><span class="ui-sr-only" role="status"></span><table role="table"><thead role="rowgroup"><tr role="row"><th class="ui-table__cell--title" aria-sort="none" data-ui-datatable-sort-bound="true" data-ui-datatable-sortable="true" role="columnheader" scope="col" data-numeric="false"><button class="ui-data-table__sort" data-ui-datatable-sort="true" type="button">Name</button></th><th data-ui-datatable-sort-bound="true" role="columnheader" scope="col" data-numeric="false">Role</th><th aria-sort="none" data-ui-datatable-sort-bound="true" data-ui-datatable-sort-type="number" data-ui-datatable-sortable="true" role="columnheader" scope="col" data-numeric="true"><button class="ui-data-table__sort" data-ui-datatable-sort="true" type="button">Seats</button></th></tr></thead><tbody role="rowgroup"><tr data-ui-datatable-row="true" data-value="ada" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><span class="ui-table__label" aria-hidden="true">Name</span><div class="ui-table__value">Ada</div></td><td role="cell" data-numeric="false"><span class="ui-table__label" aria-hidden="true">Role</span><div class="ui-table__value">Owner</div></td><td class="ui-table__cell--wide" role="cell" data-numeric="true"><span class="ui-table__label" aria-hidden="true">Seats</span><div class="ui-table__value">12</div></td></tr><tr data-ui-datatable-row="true" data-value="grace" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><span class="ui-table__label" aria-hidden="true">Name</span><div class="ui-table__value">Grace</div></td><td role="cell" data-numeric="false"><span class="ui-table__label" aria-hidden="true">Role</span><div class="ui-table__value">Admin</div></td><td class="ui-table__cell--wide" data-sort-value="1200" role="cell" data-numeric="true"><span class="ui-table__label" aria-hidden="true">Seats</span><div class="ui-table__value">1,200</div></td></tr><tr data-ui-datatable-row="true" data-value="linus" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><span class="ui-table__label" aria-hidden="true">Name</span><div class="ui-table__value">Linus</div></td><td role="cell" data-numeric="false"><span class="ui-table__label" aria-hidden="true">Role</span><div class="ui-table__value">Member</div></td><td class="ui-table__cell--wide" role="cell" data-numeric="true"><span class="ui-table__label" aria-hidden="true">Seats</span><div class="ui-table__value">3</div></td></tr></tbody></table></div>"#;

/// lumen-react `renderToStaticMarkup` output for `data-table-expanded`.
const REACT_DATA_TABLE_EXPANDED: &str = r#"<div class="ui-data-table" data-ui-datatable="true" data-ui-datatable-sort-mode="client"><span class="ui-sr-only" role="status"></span><table role="table"><thead role="rowgroup"><tr role="row"><th class="ui-table__cell--title" aria-sort="none" data-ui-datatable-sort-bound="true" data-ui-datatable-sortable="true" role="columnheader" scope="col" data-numeric="false"><button class="ui-data-table__sort" data-ui-datatable-sort="true" type="button">Name</button></th><th data-ui-datatable-sort-bound="true" role="columnheader" scope="col" data-numeric="false">Role</th></tr></thead><tbody role="rowgroup"><tr data-expanded="true" data-ui-datatable-row="true" data-value="ada" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value"><button class="ui-button ui-button--ghost ui-button--icon ui-data-table__expand" data-slot="button" type="button" aria-label="Collapse record: Ada" aria-expanded="true" aria-controls="_R_0_-61-64-61"><span class="ui-button__content"><span aria-hidden="true" class="ui-icon"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-right" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m9 18 6-6-6-6"></path></svg></span></span></button>Ada</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Owner</div></td></tr><tr role="row" data-ui-datatable-detail="true"><td colSpan="2" role="cell" class="ui-table__cell--wide"><section id="_R_0_-61-64-61" aria-label="Record details: Ada"><p>Ada details</p></section></td></tr><tr data-ui-datatable-row="true" data-value="grace" role="row"><td class="ui-table__cell--title" role="cell" data-numeric="false"><div class="ui-table__value"><button class="ui-button ui-button--ghost ui-button--icon ui-data-table__expand" data-slot="button" type="button" aria-label="Expand record: Grace" aria-expanded="false"><span class="ui-button__content"><span aria-hidden="true" class="ui-icon"><svg aria-hidden="true" class="ui-icon__svg lucide-chevron-right" fill="none" focusable="false" height="1em" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="m9 18 6-6-6-6"></path></svg></span></span></button>Grace</div></td><td role="cell" data-numeric="false"><div class="ui-table__value">Admin</div></td></tr></tbody></table></div>"#;

/// lumen-react `renderToStaticMarkup` output for `DataTableLayoutControls` with `name` pinned to
/// the start at 240 pixels.
const REACT_DATA_TABLE_LAYOUT_CONTROLS: &str = r#"<fieldset><legend>Column layout</legend><div class="ui-stack ui-stack--vertical ui-stack--gap-related ui-stack--align-stretch ui-stack--justify-start" data-direction="vertical" data-ui-stack="true"><div class="ui-stack ui-stack--horizontal ui-stack--gap-related ui-stack--align-stretch ui-stack--justify-start ui-stack--wrap" data-direction="horizontal" data-ui-stack="true" role="group" aria-label="Name"><div class="ui-field" data-ui-field="true" data-ui-field-control="_R_0_-0"><label class="ui-label" for="_R_0_-0">Name: Width in pixels</label><input class="ui-input" type="number" id="_R_0_-0" min="64" max="1200" value="240"/></div><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" disabled="" type="button" aria-label="Name: Move earlier"><span class="ui-button__content">Move earlier</span></button><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" disabled="" type="button" aria-label="Name: Move later"><span class="ui-button__content">Move later</span></button><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" type="button" aria-pressed="true"><span class="ui-button__content">Unpin</span></button><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" type="button" aria-pressed="false"><span class="ui-button__content">Pin to end</span></button></div><div class="ui-stack ui-stack--horizontal ui-stack--gap-related ui-stack--align-stretch ui-stack--justify-start ui-stack--wrap" data-direction="horizontal" data-ui-stack="true" role="group" aria-label="Role"><div class="ui-field" data-ui-field="true" data-ui-field-control="_R_0_-1"><label class="ui-label" for="_R_0_-1">Role: Width in pixels</label><input class="ui-input" type="number" id="_R_0_-1" min="64" max="1200" value="180"/></div><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" disabled="" type="button" aria-label="Role: Move earlier"><span class="ui-button__content">Move earlier</span></button><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" disabled="" type="button" aria-label="Role: Move later"><span class="ui-button__content">Move later</span></button><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" type="button" aria-pressed="false"><span class="ui-button__content">Pin to start</span></button><button class="ui-button ui-button--outline ui-button--default-size" data-slot="button" type="button" aria-pressed="false"><span class="ui-button__content">Pin to end</span></button></div></div></fieldset>"#;

fn tokens(html: &str) -> Vec<Token> {
    tokenize(&normalize_generated_ids(html))
}

/// lumen-react markup with the root owned by lumen-dioxus instead.
fn owned_by_dioxus(react: &str) -> Vec<Token> {
    tokens(&react.replace(r#"data-ui-owner="react""#, r#"data-ui-owner="dioxus""#))
}

/// lumen-react markup with the textarea text moved into its `value` attribute.
fn textarea_value(react: &str) -> Vec<Token> {
    let mut out = Vec::new();
    let mut tokens = tokens(react).into_iter().peekable();

    while let Some(token) = tokens.next() {
        match token {
            Token::Open(name, mut attributes) if name == "textarea" => {
                let text = match tokens.peek() {
                    Some(Token::Text(text)) => text.clone(),
                    _ => String::new(),
                };

                if !text.is_empty() {
                    tokens.next();
                }

                attributes.push(("value".to_string(), text));
                attributes.sort();
                out.push(Token::Open(name, attributes));
            }
            other => out.push(other),
        }
    }

    out
}

#[test]
fn timer_matches_lumen_react_apart_from_the_owner() {
    let cases = [
        (
            render(rsx! { Timer { now: COUNTDOWN_NOW, to: "2026-01-01T01:02:03Z" } }),
            REACT_TIMER_COUNTDOWN,
        ),
        (
            render(rsx! {
                Timer {
                    format: TimerFormat::Units,
                    from: "2026-01-01T00:00:00Z",
                    mode: TimerMode::Elapsed,
                    now: ELAPSED_NOW,
                }
            }),
            REACT_TIMER_ELAPSED_UNITS,
        ),
        (
            render(rsx! { Timer { now: COUNTDOWN_NOW + 86_400_000, to: "2026-01-01" } }),
            REACT_TIMER_COMPLETE,
        ),
        (
            render(rsx! { Timer { aria_label: "Launch", to: "2026-01-01T00:00:00" } }),
            REACT_TIMER_INVALID,
        ),
    ];

    for (dioxus, react) in cases {
        assert_eq!(
            tokens(&dioxus),
            owned_by_dioxus(react),
            "\n dioxus: {dioxus}\n  react: {react}"
        );
    }
}

#[test]
fn timer_accepts_epoch_milliseconds_and_rejects_offsetless_times() {
    let html = render(
        rsx! { Timer { now: 0, to: 90_000_i64, units: vec![TimerUnit::Minutes, TimerUnit::Seconds] } },
    );
    let time = &opening_tags(&html, "time")[0];

    assert_eq!(attribute(time, "datetime").as_deref(), Some("PT1M30S"));
    assert!(html.contains(">01:30<"), "{html}");
    assert_eq!(TimerInstant::from("2026-01-01T00:00:00").to_millis(), None);
    assert_eq!(TimerInstant::from(5_i64).to_millis(), Some(5));
    assert_eq!(TimerInstant::from(i64::MAX).to_millis(), None);
}

fn reorder_items() -> Vec<ReorderableListItem> {
    vec![
        ReorderableListItem::new("draft", "Draft").with_description("Due today"),
        ReorderableListItem::new("review", "Review"),
        ReorderableListItem::new("ship", "Ship").disabled(),
    ]
}

#[test]
fn reorderable_list_matches_lumen_react_apart_from_the_owner() {
    let plain =
        render(rsx! { ReorderableList { default_items: reorder_items(), label: "Release steps" } });
    assert_eq!(
        tokens(&plain),
        owned_by_dioxus(REACT_REORDERABLE_LIST),
        "\n{plain}"
    );

    let mut items = reorder_items();
    items.truncate(2);
    let labels = ReorderableListLabels {
        handle: "Drag {item}".into(),
        ..ReorderableListLabels::default()
    };
    let buttons = render(rsx! {
        ReorderableList { default_items: items, label: "Steps", labels, move_buttons: true }
    });
    assert_eq!(
        tokens(&buttons),
        owned_by_dioxus(REACT_REORDERABLE_LIST_MOVE_BUTTONS),
        "\n{buttons}"
    );
}

#[test]
fn prompt_composer_matches_lumen_react_apart_from_the_textarea_value() {
    let default = render(rsx! { PromptComposer { default_value: "Summarize the report" } });
    assert_eq!(
        tokens(&default),
        textarea_value(REACT_PROMPT_COMPOSER_DEFAULT),
        "\n{default}"
    );

    let pending = render(rsx! {
        PromptComposer {
            id: "chat",
            label: "Ask the assistant",
            max_length: 200,
            pending: true,
            send_label: "Submit",
            stop_label: "Cancel",
            submit_on_enter: true,
        }
    });
    assert_eq!(
        tokens(&pending),
        textarea_value(REACT_PROMPT_COMPOSER_PENDING),
        "\n{pending}"
    );
}

fn files() -> Vec<TreeNode> {
    vec![
        TreeNode::new("src", "src").with_children(vec![
            TreeNode::new("components", "components"),
            TreeNode::new("index", "index.ts"),
        ]),
        TreeNode::new("tests", "tests").with_children(vec![TreeNode::new("unit", "unit.rs")]),
        TreeNode::new("package", "package.json").disabled(),
    ]
}

#[test]
fn tree_nodes_render_items_groups_and_a_single_tab_stop() {
    let html = render(rsx! {
        Tree { aria_label: "Files", default_expanded: vec!["src".to_string()], default_selected: "index", nodes: files() }
    });
    let items = opening_tags(&html, "div")
        .into_iter()
        .filter(|attributes| attribute(attributes, "role").as_deref() == Some("treeitem"))
        .collect::<Vec<_>>();
    let values: Vec<_> = items
        .iter()
        .map(|item| attribute(item, "data-value").unwrap_or_default())
        .collect();

    assert_eq!(values, ["src", "components", "index", "tests", "package"]);
    assert_eq!(
        attribute(&items[0], "aria-expanded").as_deref(),
        Some("true")
    );
    assert_eq!(
        attribute(&items[3], "aria-expanded").as_deref(),
        Some("false")
    );
    assert_eq!(attribute(&items[1], "aria-expanded"), None);
    assert_eq!(attribute(&items[1], "aria-level").as_deref(), Some("2"));
    assert_eq!(
        attribute(&items[4], "aria-disabled").as_deref(),
        Some("true")
    );
    // The selected item holds the only tab stop.
    let stops: Vec<_> = items
        .iter()
        .filter(|item| attribute(item, "tabindex").as_deref() == Some("0"))
        .collect();
    assert_eq!(stops.len(), 1);
    assert_eq!(attribute(stops[0], "data-value").as_deref(), Some("index"));
    assert_eq!(
        attribute(stops[0], "aria-selected").as_deref(),
        Some("true")
    );
    assert!(html.contains(r#"role="group""#), "{html}");
    assert!(
        !html.contains("unit.rs"),
        "collapsed branches hide their children: {html}"
    );
}

#[test]
fn stylesheet_hides_hand_written_groups_of_collapsed_tree_branches() {
    // Children render as written, so the bundled stylesheet hides the group a collapsed branch
    // owns, whether the group follows the item or nests inside it.
    for selector in [
        r#"[role="treeitem"][aria-expanded="false"] + [role="group"]"#,
        r#"[role="treeitem"][aria-expanded="false"] > [role="group"]"#,
    ] {
        assert!(
            lumen_dioxus::LUMEN_CSS.contains(selector),
            "missing {selector}"
        );
    }
}

#[test]
fn tree_grid_rows_render_a_header_and_cells() {
    let rows = vec![
        TreeGridRow::new("packages", ["packages", "—"])
            .with_children(vec![TreeGridRow::new("astro", ["astro", "Ready"])]),
        TreeGridRow::new("docs", ["docs", "Draft"]),
    ];
    let html = render(rsx! {
        TreeGrid {
            aria_label: "Project status",
            columns: vec!["Package".to_string(), "Status".to_string()],
            default_expanded: vec!["packages".to_string()],
            rows,
        }
    });
    let rows = opening_tags(&html, "div")
        .into_iter()
        .filter(|attributes| attribute(attributes, "role").as_deref() == Some("row"))
        .collect::<Vec<_>>();

    assert_eq!(rows.len(), 4);
    assert_eq!(
        attribute(&rows[0], "tabindex"),
        None,
        "the header row is not focusable"
    );
    assert_eq!(attribute(&rows[1], "tabindex").as_deref(), Some("0"));
    assert_eq!(attribute(&rows[2], "aria-level").as_deref(), Some("2"));
    assert_eq!(
        opening_tags(&html, "span")
            .iter()
            .filter(|span| attribute(span, "role").as_deref() == Some("columnheader"))
            .count(),
        2
    );
    assert_eq!(
        opening_tags(&html, "span")
            .iter()
            .filter(|span| attribute(span, "role").as_deref() == Some("gridcell"))
            .count(),
        6
    );
}

fn selectable_rows() -> Vec<DataTableRow> {
    vec![
        DataTableRow::new("ada").cell("name", "Ada"),
        DataTableRow::new("grace").cell("name", "Grace"),
    ]
}

#[test]
fn selectable_data_tables_use_aria_checkboxes() {
    let html = render(rsx! {
        DataTable {
            columns: vec![DataTableColumn::new("name", "Name")],
            default_selected_row_ids: vec!["grace".to_string()],
            name: "people",
            rows: selectable_rows(),
            selectable: true,
        }
    });
    let checkboxes = opening_tags(&html, "button")
        .into_iter()
        .filter(|attributes| attribute(attributes, "role").as_deref() == Some("checkbox"))
        .collect::<Vec<_>>();

    assert_eq!(checkboxes.len(), 3);
    assert_eq!(
        attribute(&checkboxes[0], "aria-label").as_deref(),
        Some("Select all rows")
    );
    assert_eq!(
        attribute(&checkboxes[0], "aria-checked").as_deref(),
        Some("mixed")
    );
    assert_eq!(
        attribute(&checkboxes[1], "aria-label").as_deref(),
        Some("Select row: Ada")
    );
    assert_eq!(
        attribute(&checkboxes[2], "aria-checked").as_deref(),
        Some("true")
    );
    // The selected row submits its id with the form and carries the selected state.
    assert!(
        html.contains(r#"name="people""#) && html.contains(r#"value="grace""#),
        "{html}"
    );
    assert!(html.contains(r#"data-state="selected""#), "{html}");
    assert!(
        html.contains(r#"data-ui-datatable-selectable="true""#),
        "{html}"
    );
}

#[component]
fn PagedView() -> Element {
    let rows: Vec<DataTableRow> = (0..12)
        .map(|index| {
            DataTableRow::new(format!("r{index}"))
                .cell("name", format!("Item {index}"))
                .cell("status", if index % 2 == 0 { "Open" } else { "Closed" })
        })
        .collect();
    let columns = vec![
        DataTableViewColumn::new("name", "Name")
            .sortable()
            .always_visible(),
        DataTableViewColumn::new("status", "Status").with_filter_options(vec![
            ("Open".to_string(), "Open".to_string()),
            ("Closed".to_string(), "Closed".to_string()),
        ]),
    ];
    let state = DataTableViewState {
        pagination: DataTablePagination {
            page_index: 1,
            page_size: 5,
        },
        ..DataTableViewState::default()
    };

    rsx! {
        DataTableView {
            columns,
            default_state: state,
            label: "Records",
            render: move |view: DataTableViewResult| rsx! {
                ul { class: "page",
                    for row in view.rows {
                        li { key: "{row.value(0)}", "{row.text(\"name\")}" }
                    }
                }
            },
            rows,
        }
    }
}

#[test]
fn data_table_views_render_toolbar_page_and_status() {
    let html = render(rsx! { PagedView {} });

    assert!(
        html.contains(
            "<li>Item 5</li><li>Item 6</li><li>Item 7</li><li>Item 8</li><li>Item 9</li>"
        ),
        "{html}"
    );
    assert!(html.contains("Page 2 of 3 · 12 records"), "{html}");
    assert!(
        html.contains(r#"aria-label="Records""#) && html.contains(r#"role="group""#),
        "{html}"
    );
    assert!(
        html.contains("Search records") && html.contains("Rows per page"),
        "{html}"
    );
    // Only the hideable column gets a visibility checkbox.
    let checkboxes = opening_tags(&html, "button")
        .into_iter()
        .filter(|attributes| attribute(attributes, "role").as_deref() == Some("checkbox"))
        .count();
    assert_eq!(checkboxes, 1);
}

#[test]
fn theme_builder_editors_export_css_and_theme_their_preview() {
    let html = render(rsx! { ThemeBuilderEditor { title: "Brand theme" } });
    let textarea = &opening_tags(&html, "textarea")[0];
    let css = attribute(textarea, "value").unwrap_or_default();

    assert!(
        css.starts_with(":root {\n  color-scheme: light;\n  --canvas: 264 20% 99%;"),
        "{css}"
    );
    assert!(css.contains("--brand: 264 85% 53%;"), "{css}");
    assert!(
        html.contains("--brand:264 85% 53%"),
        "the preview applies the tokens: {html}"
    );
    assert!(html.contains(r#"class="ui-theme-builder""#), "{html}");
}

#[test]
fn world_maps_render_the_bundled_countries() {
    let countries = world_map_countries().to_vec();
    let count = countries.len();
    let html = render(rsx! {
        WorldMap { countries, highlighted_countries: vec!["co".to_string()], label: "World", variant: WorldMapVariant::Solid }
    });
    // The zoom buttons' icons draw paths too; count only the map's own geometry.
    let paths: Vec<_> = opening_tags(&html, "path")
        .into_iter()
        .filter(|path| {
            attribute(path, "class").is_some_and(|class| class.starts_with("ui-world-map__"))
        })
        .collect();

    // One path per country plus the selection outline.
    assert_eq!(paths.len(), count + 1);
    assert!(count > 230);
    assert_eq!(
        paths
            .iter()
            .filter(|path| attribute(path, "class")
                .is_some_and(|class| class.contains("--highlighted")))
            .count(),
        1
    );
    assert_eq!(opening_tags(&html, "option").len(), count + 1);
    // Zoom controls stay disabled until the map is mounted, like lumen-react's first render.
    let zoom = opening_tags(&html, "button");
    assert!(
        zoom.iter()
            .all(|button| attribute(button, "disabled").is_some())
    );
}

#[test]
fn world_map_views_zoom_and_pan_through_the_view_box() {
    let view = WorldMapView::default();
    assert_eq!(view.view_box_attribute(), "0 0 1000 400");

    let zoomed = view.zoom_in();
    assert_eq!(zoomed.zoom_percent(), "150%");
    assert!(zoomed.can_zoom_out());
    let panned = zoomed.pan_by(1000.0, 0.0);
    let box_ = panned.view_box();
    assert!(
        (box_.x + box_.width - 1000.0).abs() < 1e-9,
        "panning clamps to the map edge"
    );
}

fn table_columns() -> Vec<DataTableColumn> {
    vec![
        DataTableColumn::new("name", "Name").sortable_text(),
        DataTableColumn::new("role", "Role"),
        DataTableColumn::new("seats", "Seats")
            .sortable(DataTableSortType::Number)
            .wide(),
    ]
}

fn table_rows() -> Vec<DataTableRow> {
    vec![
        DataTableRow::new("ada")
            .cell("name", "Ada")
            .cell("role", "Owner")
            .cell("seats", 12),
        DataTableRow::new("grace")
            .cell("name", "Grace")
            .cell("role", "Admin")
            .cell("seats", DataTableCell::new("1,200").with_sort_value("1200")),
        DataTableRow::new("linus")
            .cell("name", "Linus")
            .cell("role", "Member")
            .cell("seats", 3),
    ]
}

#[component]
fn ExpandedDataTable() -> Element {
    let mut columns = table_columns();
    columns.truncate(2);
    let mut rows = table_rows();
    rows.truncate(2);

    rsx! {
        DataTable {
            columns,
            default_expanded_row_ids: vec!["ada".to_string()],
            render_details: move |row: DataTableRow| rsx! { p { "{row.text(\"name\")} details" } },
            rows,
        }
    }
}

#[test]
fn data_tables_match_lumen_react() {
    let cases = [
        (
            render(rsx! {
                DataTable { columns: table_columns(), default_sort: DataTableSort::descending("seats"), rows: table_rows() }
            }),
            REACT_DATA_TABLE_DEFAULT_SORT,
        ),
        (
            render(rsx! {
                DataTable {
                    columns: table_columns(),
                    default_sorting: vec![DataTableSort::ascending("name"), DataTableSort::descending("seats")],
                    multi_sort: true,
                    rows: table_rows(),
                }
            }),
            REACT_DATA_TABLE_MULTI_SORT,
        ),
        (
            render(rsx! {
                DataTable {
                    columns: table_columns(),
                    glass: Glass::Subtle,
                    layout: TableLayout::Records,
                    rows: table_rows(),
                    sort_mode: DataTableSortMode::Manual,
                }
            }),
            REACT_DATA_TABLE_RECORDS_GLASS,
        ),
        (
            render(rsx! { ExpandedDataTable {} }),
            REACT_DATA_TABLE_EXPANDED,
        ),
    ];

    for (dioxus, react) in cases {
        assert_eq!(
            tokens(&dioxus),
            tokens(react),
            "\n dioxus: {dioxus}\n  react: {react}"
        );
    }
}

#[test]
fn world_map_captions_render_last() {
    let html = render(rsx! {
        WorldMap { caption: "Offices in South America", countries: Vec::new(), label: "Empty", zoomable: false }
    });

    assert!(
        html.ends_with("<figcaption>Offices in South America</figcaption></figure>"),
        "{html}"
    );
}

#[component]
fn LayoutControls() -> Element {
    let layout = DataTableLayoutState {
        order: Vec::new(),
        widths: vec![("name".to_string(), 240.0)],
        pinned: vec![("name".to_string(), DataTablePin::Start)],
    };

    rsx! {
        DataTableLayoutControls {
            columns: vec![
                ("name".to_string(), "Name".to_string()),
                ("role".to_string(), "Role".to_string()),
            ],
            layout,
            on_layout_change: move |_| {},
        }
    }
}

#[test]
fn data_table_layout_controls_match_lumen_react() {
    let html = render(rsx! { LayoutControls {} });

    assert_eq!(
        tokens(&html),
        tokens(REACT_DATA_TABLE_LAYOUT_CONTROLS),
        "\n{html}"
    );
}