lumen-dioxus 6.0.0

Lumen UI components for Dioxus: web, desktop, mobile, and Dioxus Native (Blitz).
Documentation
//! [`ChartMotion`]: the wrapper that marks a chart for motion between data updates.

use dioxus::prelude::*;

/// The motion token used by a [`ChartMotion`] wrapper.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum ChartMotionDuration {
    /// `--ui-duration-fast`.
    Fast,
    /// `--ui-duration`.
    #[default]
    Standard,
    /// `--ui-duration-slow`.
    Slow,
}

impl ChartMotionDuration {
    /// The token name: `fast`, `standard`, or `slow`.
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Fast => "fast",
            Self::Standard => "standard",
            Self::Slow => "slow",
        }
    }
}

/// Props for [`ChartMotion`].
#[derive(Props, Clone, PartialEq)]
pub struct ChartMotionProps {
    /// The motion token lumen-react's mark animations use.
    #[props(default)]
    pub duration: ChartMotionDuration,
    /// Classes for the wrapper.
    #[props(into)]
    pub class: Option<String>,
    /// Any other `<div>` or global attribute.
    #[props(extends = GlobalAttributes, extends = div)]
    pub attributes: Vec<Attribute>,
    /// The chart to wrap.
    pub children: Element,
}

/// Wraps a chart so data updates read as motion, without delaying accessible data.
///
/// lumen-react animates stable SVG marks between updates with the Web Animations API. That API
/// has no equivalent on Dioxus Native, so lumen-dioxus renders the same `data-ui-chart-motion`
/// wrapper and lets Lumen's CSS fade empty and error states in; marks update in place on every
/// renderer.
#[component]
pub fn ChartMotion(props: ChartMotionProps) -> Element {
    rsx! {
        div {
            class: props.class,
            "data-ui-chart-motion": "true",
            ..props.attributes,
            {props.children}
        }
    }
}