dioxus_material/
theme.rs

1use dioxus::prelude::*;
2use std::{borrow::Cow, rc::Rc};
3
4/// Theme component.
5///
6/// This component provides access to [`UseTheme`](UseTheme) to its children.
7#[component]
8pub fn Theme(
9    /// Primary color.
10    #[props(into, default = Cow::Borrowed("#6750A4"))]
11    primary_color: Cow<'static, str>,
12
13    /// Background color.
14    #[props(into, default = Cow::Borrowed("#eeeeee"))]
15    background_color: Cow<'static, str>,
16
17    /// Secondary container color.
18    #[props(into, default = Cow::Borrowed("#E8DEF8"))]
19    secondary_container_color: Cow<'static, str>,
20
21    /// Border radius medium.
22    #[props(into, default = Cow::Borrowed("25px"))]
23    border_radius_medium: Cow<'static, str>,
24
25    /// Border radius.
26    #[props(into, default = Cow::Borrowed("8px"))]
27    border_radius_small: Cow<'static, str>,
28
29    /// Small label font size.
30    #[props(default = 12.)]
31    label_small: f32,
32
33    /// Medium label font size.
34    #[props(default = 16.)]
35    label_medium: f32,
36
37    children: Element,
38) -> Element {
39    use_context_provider(move || {
40        Rc::new(UseTheme {
41            primary_color: primary_color.clone(),
42            background_color: background_color.clone(),
43            secondary_container_color: secondary_container_color.clone(),
44            border_radius_medium: border_radius_medium.clone(),
45            border_radius_small: border_radius_small.clone(),
46            label_small,
47            label_medium,
48        })
49    });
50
51    children
52}
53
54pub struct UseTheme {
55    pub primary_color: Cow<'static, str>,
56    pub background_color: Cow<'static, str>,
57    pub secondary_container_color: Cow<'static, str>,
58    pub border_radius_medium: Cow<'static, str>,
59    pub border_radius_small: Cow<'static, str>,
60    pub label_small: f32,
61    pub label_medium: f32,
62}
63
64pub fn use_theme() -> Rc<UseTheme> {
65    use_context()
66}