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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
//! Static feedback states: `Callout`, `Empty`, `ErrorState`, `StatusDot`, and `Skeleton`.

use dioxus::prelude::*;

use super::shared::has_content;
use crate::class::{Glass, compose};

/// Props for [`Callout`].
#[derive(Props, Clone, PartialEq)]
pub struct CalloutProps {
    /// Extra classes appended after the Lumen class.
    #[props(into)]
    pub class: Option<String>,
    /// Any other `<aside>` or global attribute.
    #[props(extends = GlobalAttributes, extends = aside)]
    pub attributes: Vec<Attribute>,
    /// Callout content.
    pub children: Element,
}

/// A highlighted note set apart from the surrounding content.
#[component]
pub fn Callout(props: CalloutProps) -> Element {
    let class = compose([Some("ui-callout"), props.class.as_deref()]);

    rsx! {
        aside { class, ..props.attributes, {props.children} }
    }
}

/// Spacing of an [`Empty`] state.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum EmptyVariant {
    /// Default spacing.
    #[default]
    Default,
    /// Tighter spacing for panels and table bodies.
    Compact,
}

impl EmptyVariant {
    /// The `data-variant` value.
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Default => "default",
            Self::Compact => "compact",
        }
    }
}

/// Props for [`Empty`].
#[derive(Props, Clone, PartialEq)]
pub struct EmptyProps {
    /// Spacing.
    #[props(default)]
    pub variant: EmptyVariant,
    /// Glass intensity. Needs a renderer with `backdrop-filter` support.
    #[props(default, into)]
    pub glass: Glass,
    /// Extra classes appended after the Lumen classes.
    #[props(into)]
    pub class: Option<String>,
    /// Any other `<section>` or global attribute.
    #[props(extends = GlobalAttributes, extends = section)]
    pub attributes: Vec<Attribute>,
    /// Heading, description, and actions.
    pub children: Element,
}

/// An empty state for lists, searches, and panels with nothing to show yet.
#[component]
pub fn Empty(props: EmptyProps) -> Element {
    let glass = props.glass.class("ui-empty");
    let class = compose([
        Some("ui-empty"),
        (props.variant == EmptyVariant::Compact).then_some("ui-empty--compact"),
        glass.as_deref(),
        props.class.as_deref(),
    ]);

    rsx! {
        section {
            class,
            "data-variant": props.variant.as_str(),
            ..props.attributes,
            {props.children}
        }
    }
}

/// The kind of failure an [`ErrorState`] reports.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorStateKind {
    /// A generic error.
    #[default]
    Error,
    /// The app or a service is offline.
    Offline,
}

impl ErrorStateKind {
    /// The class suffix and `data-kind` value.
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Error => "error",
            Self::Offline => "offline",
        }
    }
}

/// Layout of an [`ErrorState`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorStateLayout {
    /// Small inline layout with a small illustration.
    Compact,
    /// The default section layout.
    #[default]
    Default,
    /// A roomy whole-page layout.
    Page,
}

impl ErrorStateLayout {
    /// The class suffix and `data-layout` value.
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Compact => "compact",
            Self::Default => "default",
            Self::Page => "page",
        }
    }
}

/// How an [`ErrorState`] is announced to assistive technology.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum ErrorStateAnnounce {
    /// Not announced; the state is read in document order.
    #[default]
    Off,
    /// Announced politely as a `status`.
    Polite,
    /// Announced immediately as an `alert`.
    Assertive,
}

/// Props for [`ErrorState`].
#[derive(Props, Clone, PartialEq)]
pub struct ErrorStateProps {
    /// The heading, and the accessible name of the section.
    #[props(into)]
    pub title: String,
    /// Supporting sentence under the title.
    #[props(into)]
    pub description: Option<String>,
    /// Kind of failure. Picks the default illustration.
    #[props(default)]
    pub kind: ErrorStateKind,
    /// Layout and illustration size.
    #[props(default)]
    pub layout: ErrorStateLayout,
    /// Live-region announcement.
    #[props(default)]
    pub announce: ErrorStateAnnounce,
    /// Heading level of the title, clamped to 1-6. Defaults to 2.
    #[props(default = 2)]
    pub heading_level: u8,
    /// Section id. When set, the title gets the id `{id}-title` and labels the section.
    #[props(into)]
    pub id: Option<String>,
    /// A support reference, such as a request id.
    #[props(into)]
    pub reference: Option<String>,
    /// Label before the reference.
    #[props(default = "Reference".to_string(), into)]
    pub reference_label: String,
    /// Actions, usually buttons, under the content.
    pub actions: Option<Element>,
    /// Custom artwork in place of the default illustration.
    pub graphic: Option<Element>,
    /// Hides the illustration.
    #[props(default)]
    pub hide_graphic: bool,
    /// Overrides the live-region politeness.
    #[props(into)]
    pub aria_live: Option<String>,
    /// Overrides the section role.
    #[props(into)]
    pub role: Option<String>,
    /// Extra classes appended after the Lumen classes.
    #[props(into)]
    pub class: Option<String>,
    /// Any other `<section>` or global attribute.
    #[props(extends = GlobalAttributes, extends = section)]
    pub attributes: Vec<Attribute>,
    /// Extra details under the description.
    pub children: Element,
}

fn error_state_announcement(
    announce: ErrorStateAnnounce,
    aria_live: Option<String>,
    role: Option<String>,
) -> (Option<String>, Option<String>) {
    match announce {
        ErrorStateAnnounce::Assertive => (
            Some(aria_live.unwrap_or_else(|| "assertive".to_string())),
            Some(role.unwrap_or_else(|| "alert".to_string())),
        ),
        ErrorStateAnnounce::Polite => (
            Some(aria_live.unwrap_or_else(|| "polite".to_string())),
            Some(role.unwrap_or_else(|| "status".to_string())),
        ),
        ErrorStateAnnounce::Off => (aria_live, role),
    }
}

/// An illustration from Lumen's shared artwork, as `Illustration` renders it in lumen-react.
fn error_illustration(kind: ErrorStateKind, small: bool) -> Element {
    let class = format!(
        "ui-illustration ui-illustration--{} ui-illustration--auto ui-illustration--{}",
        kind.as_str(),
        if small { "sm" } else { "md" }
    );

    let artwork = match kind {
        ErrorStateKind::Error => rsx! {
            circle { cx: "60", cy: "60", r: "28" }
            line { x1: "49", x2: "71", y1: "49", y2: "71" }
            line { x1: "71", x2: "49", y1: "49", y2: "71" }
        },
        ErrorStateKind::Offline => rsx! {
            rect { height: "35", rx: "18", width: "72", x: "24", y: "45" }
            line { x1: "30", x2: "90", y1: "30", y2: "90" }
        },
    };

    rsx! {
        span { aria_hidden: "true", class,
            svg { "aria-hidden": "true", fill: "none", "viewBox": "0 0 120 120",
                circle { class: "ui-illustration__wash", cx: "60", cy: "60", r: "48" }
                {artwork}
            }
        }
    }
}

fn error_title(level: u8, id: Option<String>, title: String) -> Element {
    match level.clamp(1, 6) {
        1 => {
            rsx! { h1 { class: "ui-error-state__title", "data-slot": "error-state-title", id, {title} } }
        }
        2 => {
            rsx! { h2 { class: "ui-error-state__title", "data-slot": "error-state-title", id, {title} } }
        }
        3 => {
            rsx! { h3 { class: "ui-error-state__title", "data-slot": "error-state-title", id, {title} } }
        }
        4 => {
            rsx! { h4 { class: "ui-error-state__title", "data-slot": "error-state-title", id, {title} } }
        }
        5 => {
            rsx! { h5 { class: "ui-error-state__title", "data-slot": "error-state-title", id, {title} } }
        }
        _ => {
            rsx! { h6 { class: "ui-error-state__title", "data-slot": "error-state-title", id, {title} } }
        }
    }
}

/// A recoverable failure: an illustration, a titled explanation, an optional reference, and
/// recovery actions.
#[component]
pub fn ErrorState(props: ErrorStateProps) -> Element {
    let kind = props.kind.as_str();
    let layout = props.layout.as_str();
    let kind_class = format!("ui-error-state--{kind}");
    let layout_class = format!("ui-error-state--{layout}");
    let class = compose([
        Some("ui-error-state"),
        Some(kind_class.as_str()),
        Some(layout_class.as_str()),
        props.class.as_deref(),
    ]);
    let id = props.id.filter(|value| !value.is_empty());
    let title_id = id.as_ref().map(|value| format!("{value}-title"));
    let (aria_live, role) = error_state_announcement(props.announce, props.aria_live, props.role);
    let description = props.description.filter(|value| !value.is_empty());
    let reference = props.reference.filter(|value| !value.is_empty());
    let graphic = if props.hide_graphic {
        None
    } else {
        Some(props.graphic.unwrap_or_else(|| {
            error_illustration(props.kind, props.layout == ErrorStateLayout::Compact)
        }))
    };
    let show_details = has_content(&props.children);
    let title = error_title(props.heading_level, title_id.clone(), props.title.clone());
    let aria_label = title_id.is_none().then(|| props.title.clone());

    rsx! {
        section {
            aria_label,
            aria_labelledby: title_id,
            aria_live,
            class,
            "data-kind": kind,
            "data-layout": layout,
            "data-ui-error-state": "true",
            id,
            role,
            ..props.attributes,
            if let Some(graphic) = graphic {
                div {
                    aria_hidden: "true",
                    class: "ui-error-state__graphic",
                    "data-slot": "error-state-graphic",
                    {graphic}
                }
            }
            div { class: "ui-error-state__content", "data-slot": "error-state-content",
                {title}
                if let Some(description) = description {
                    p { class: "ui-error-state__description", "data-slot": "error-state-description", {description} }
                }
                if show_details {
                    div { class: "ui-error-state__details", "data-slot": "error-state-details", {props.children} }
                }
                if let Some(reference) = reference {
                    p { class: "ui-error-state__reference", "data-slot": "error-state-reference",
                        span { "{props.reference_label}:" }
                        " "
                        code { {reference} }
                    }
                }
            }
            if let Some(actions) = props.actions.filter(has_content) {
                div { class: "ui-error-state__actions", "data-slot": "error-state-actions", {actions} }
            }
        }
    }
}

/// Semantic color of a [`StatusDot`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum StatusDotTone {
    /// Brand color.
    Brand,
    /// Follows the surrounding text or `Badge` variant.
    #[default]
    Current,
    /// Error or outage.
    Danger,
    /// Inactive or unknown.
    Neutral,
    /// Healthy or online.
    Success,
    /// Degraded or pending.
    Warning,
}

impl StatusDotTone {
    /// The class suffix and `data-tone` value.
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Brand => "brand",
            Self::Current => "current",
            Self::Danger => "danger",
            Self::Neutral => "neutral",
            Self::Success => "success",
            Self::Warning => "warning",
        }
    }
}

/// Props for [`StatusDot`].
#[derive(Props, Clone, PartialEq)]
pub struct StatusDotProps {
    /// Accessible name. Omit it when nearby text already states the status.
    #[props(into)]
    pub label: Option<String>,
    /// Animates a soft ring around the dot. Suppressed when the user prefers reduced motion.
    #[props(default)]
    pub pulse: bool,
    /// Semantic color.
    #[props(default)]
    pub tone: StatusDotTone,
    /// Extra classes appended after the Lumen classes.
    #[props(into)]
    pub class: Option<String>,
    /// Any other `<span>` or global attribute.
    #[props(extends = GlobalAttributes, extends = span)]
    pub attributes: Vec<Attribute>,
}

/// A small colored dot for presence and health. Decorative unless it has a `label`.
#[component]
pub fn StatusDot(props: StatusDotProps) -> Element {
    let label = props
        .label
        .map(|value| value.trim().to_string())
        .filter(|value| !value.is_empty());
    let tone = (props.tone != StatusDotTone::Current)
        .then(|| format!("ui-status-dot--{}", props.tone.as_str()));
    let class = compose([
        Some("ui-status-dot"),
        tone.as_deref(),
        props.pulse.then_some("ui-status-dot--pulse"),
        props.class.as_deref(),
    ]);
    let named = label.is_some();

    rsx! {
        span {
            aria_hidden: (!named).then_some("true"),
            aria_label: label,
            class,
            "data-tone": props.tone.as_str(),
            role: named.then_some("img"),
            ..props.attributes,
        }
    }
}

/// Shape of a [`Skeleton`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum SkeletonShape {
    /// A rounded block.
    #[default]
    Rectangle,
    /// A text line.
    Text,
    /// A circle, for avatars.
    Circle,
}

impl SkeletonShape {
    fn class(self) -> Option<&'static str> {
        match self {
            Self::Rectangle => None,
            Self::Text => Some("ui-skeleton--text"),
            Self::Circle => Some("ui-skeleton--circle"),
        }
    }
}

/// Loading animation of a [`Skeleton`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum SkeletonAnimation {
    /// A sweeping highlight.
    #[default]
    Shimmer,
    /// A fading pulse.
    Pulse,
    /// No animation.
    None,
}

/// A [`Skeleton`] width or height: pixels, or a CSS length such as `0.75rem` or `60%`.
///
/// Numbers and strings convert into it, so props accept `width: 48` or `width: "60%"`.
#[derive(Clone, Debug, Default, PartialEq)]
#[non_exhaustive]
pub enum SkeletonSize {
    /// No size; the stylesheet default applies.
    #[default]
    Auto,
    /// A length in pixels. Negative and non-finite values are ignored.
    Pixels(f64),
    /// A CSS length, percentage, or math expression. Unsafe values are ignored.
    Css(String),
}

impl From<f64> for SkeletonSize {
    fn from(value: f64) -> Self {
        Self::Pixels(value)
    }
}

impl From<i32> for SkeletonSize {
    fn from(value: i32) -> Self {
        Self::Pixels(f64::from(value))
    }
}

impl From<u32> for SkeletonSize {
    fn from(value: u32) -> Self {
        Self::Pixels(f64::from(value))
    }
}

impl From<&str> for SkeletonSize {
    fn from(value: &str) -> Self {
        Self::Css(value.to_string())
    }
}

impl From<String> for SkeletonSize {
    fn from(value: String) -> Self {
        Self::Css(value)
    }
}

const SKELETON_SIZE_MAX_LENGTH: usize = 64;

fn pixel_size(value: f64) -> Option<String> {
    (value.is_finite() && value >= 0.0).then(|| format!("{value}px"))
}

fn is_safe_size_character(character: char) -> bool {
    character.is_ascii_alphanumeric() || "%.+-*/(), _".contains(character)
}

fn is_identifier_character(character: char) -> bool {
    character.is_ascii_alphanumeric() || character == '_' || character == '-'
}

/// Whether the text calls `url(…)`, found with one linear scan.
fn has_css_url_call(size: &str) -> bool {
    let lower: Vec<char> = size.to_lowercase().chars().collect();
    let mut index = 0;

    while index + 3 <= lower.len() {
        let is_url = lower[index] == 'u' && lower[index + 1] == 'r' && lower[index + 2] == 'l';
        let boundary = index == 0 || !is_identifier_character(lower[index - 1]);

        if is_url && boundary {
            let mut cursor = index + 3;

            while cursor < lower.len() && lower[cursor] == ' ' {
                cursor += 1;
            }

            if cursor < lower.len() && lower[cursor] == '(' {
                return true;
            }
        }

        index += 1;
    }

    false
}

fn is_safe_size_expression(size: &str) -> bool {
    if size.is_empty() || size.chars().count() > SKELETON_SIZE_MAX_LENGTH {
        return false;
    }

    if size.contains("/*") || size.contains("*/") || has_css_url_call(size) {
        return false;
    }

    size.chars().all(is_safe_size_character)
}

impl SkeletonSize {
    /// The CSS length, or `None` when the value is not safe to put in a style attribute.
    ///
    /// Follows `resolveLumenSkeletonSize` in lumen-core: numbers become pixels, numeric strings
    /// become pixels, and other strings may only use ASCII letters, digits, and math characters.
    pub fn resolve(&self) -> Option<String> {
        match self {
            Self::Auto => None,
            Self::Pixels(value) => pixel_size(*value),
            Self::Css(value) => {
                let size = value.trim();

                if !is_safe_size_expression(size) {
                    return None;
                }

                match size.parse::<f64>() {
                    Ok(number) if number.is_finite() => pixel_size(number),
                    _ => Some(size.to_string()),
                }
            }
        }
    }
}

/// Props for [`Skeleton`].
#[derive(Props, Clone, PartialEq)]
pub struct SkeletonProps {
    /// Shape.
    #[props(default)]
    pub shape: SkeletonShape,
    /// Loading animation.
    #[props(default)]
    pub animation: SkeletonAnimation,
    /// Width, such as `120`, `"60%"`, or `"12rem"`.
    #[props(default, into)]
    pub width: SkeletonSize,
    /// Height, such as `48` or `"0.75rem"`.
    #[props(default, into)]
    pub height: SkeletonSize,
    /// Accessible name. A named skeleton becomes a `status` region.
    #[props(into)]
    pub aria_label: Option<String>,
    /// Id of the element that names the skeleton.
    #[props(into)]
    pub aria_labelledby: Option<String>,
    /// Overrides the computed `aria-hidden`.
    pub aria_hidden: Option<bool>,
    /// Overrides the computed role.
    #[props(into)]
    pub role: Option<String>,
    /// Extra classes appended after the Lumen classes.
    #[props(into)]
    pub class: Option<String>,
    /// Any other `<div>` or global attribute.
    #[props(extends = GlobalAttributes, extends = div)]
    pub attributes: Vec<Attribute>,
}

fn has_name(value: Option<&String>) -> bool {
    value.is_some_and(|text| !text.trim().is_empty())
}

/// A placeholder block shown while content loads. Decorative unless named.
#[component]
pub fn Skeleton(props: SkeletonProps) -> Element {
    let named = has_name(props.aria_label.as_ref()) || has_name(props.aria_labelledby.as_ref());
    let aria_hidden = match props.aria_hidden {
        Some(hidden) => Some(hidden.to_string()),
        None => (!named).then(|| "true".to_string()),
    };
    let role = props.role.or_else(|| named.then(|| "status".to_string()));
    let class = compose([
        Some("ui-skeleton"),
        props.shape.class(),
        (props.animation == SkeletonAnimation::Pulse).then_some("ui-skeleton--pulse"),
        (props.animation == SkeletonAnimation::None).then_some("ui-skeleton--static"),
        props.class.as_deref(),
    ]);
    let height = props.height.resolve();
    let width = props.width.resolve();
    let mut declarations = Vec::new();

    if let Some(height) = height {
        declarations.push(format!("--ui-skeleton-height:{height}"));
    }

    if let Some(width) = width {
        declarations.push(format!("--ui-skeleton-width:{width}"));
    }

    let style = (!declarations.is_empty()).then(|| declarations.join(";"));

    rsx! {
        div {
            aria_hidden,
            aria_label: props.aria_label,
            aria_labelledby: props.aria_labelledby,
            class,
            role,
            style,
            ..props.attributes,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::{ErrorStateAnnounce, SkeletonSize, error_state_announcement};

    #[test]
    fn skeleton_sizes_follow_lumen_core() {
        assert_eq!(SkeletonSize::from(48).resolve().as_deref(), Some("48px"));
        assert_eq!(SkeletonSize::from(4.5).resolve().as_deref(), Some("4.5px"));
        assert_eq!(SkeletonSize::from(-1).resolve(), None);
        assert_eq!(SkeletonSize::from(f64::NAN).resolve(), None);
        assert_eq!(SkeletonSize::from("60%").resolve().as_deref(), Some("60%"));
        assert_eq!(
            SkeletonSize::from(" 12 ").resolve().as_deref(),
            Some("12px")
        );
        assert_eq!(
            SkeletonSize::from("calc(100% - 2rem)").resolve().as_deref(),
            Some("calc(100% - 2rem)")
        );
        assert_eq!(
            SkeletonSize::from("var(--gap)").resolve().as_deref(),
            Some("var(--gap)")
        );
        assert_eq!(SkeletonSize::from("").resolve(), None);
        assert_eq!(SkeletonSize::from("1rem; color: red").resolve(), None);
        assert_eq!(SkeletonSize::from("url(x)").resolve(), None);
        assert_eq!(SkeletonSize::from("URL (x)").resolve(), None);
        assert_eq!(SkeletonSize::from("1rem /* x */").resolve(), None);
        assert_eq!(
            SkeletonSize::from("curl(1)").resolve().as_deref(),
            Some("curl(1)")
        );
        assert_eq!(SkeletonSize::Auto.resolve(), None);
    }

    #[test]
    fn skeleton_sizes_reject_long_input_quickly() {
        let long = "1".repeat(100_000);
        assert_eq!(SkeletonSize::Css(long).resolve(), None);
        let urls = "url ".repeat(16);
        assert_eq!(
            SkeletonSize::Css(urls).resolve().as_deref(),
            Some("url url url url url url url url url url url url url url url url")
        );
    }

    #[test]
    fn error_state_announcements_keep_overrides() {
        assert_eq!(
            error_state_announcement(ErrorStateAnnounce::Assertive, None, None),
            (Some("assertive".into()), Some("alert".into()))
        );
        assert_eq!(
            error_state_announcement(ErrorStateAnnounce::Polite, Some("off".into()), None),
            (Some("off".into()), Some("status".into()))
        );
        assert_eq!(
            error_state_announcement(ErrorStateAnnounce::Off, None, None),
            (None, None)
        );
    }
}