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
//! # Themes
//!
//! All the built-in components of Freya support themes, so if you find yourself wanting to tweak a certain style attribute of a component you might want to see if it can be changed through a theme.
//!
//! ## `ThemeProvider` component
//!
//! You can wrap your whole app in a [ThemeProvider](freya_components::ThemeProvider) or maybe just a part of it.
//!
//! ### Example
//!
//! ```rust
//! # use freya::prelude::*;
//! // A custom theme based on the Light Theme that simply tweaks some parts of the Button theme.
//! const CUSTOM_THEME: Theme = Theme {
//!     button: ButtonTheme {
//!         background: Cow::Borrowed("rgb(230, 0, 0)"),
//!         hover_background: Cow::Borrowed("rgb(150, 0, 0)"),
//!         font_theme: FontTheme {
//!             color: Cow::Borrowed("white"),
//!         },
//!         ..LIGHT_THEME.button
//!     },
//!     ..LIGHT_THEME
//! };
//!
//! fn app() -> Element {
//!     rsx!(
//!         // All the components descendant of this ThemeProvider will inherit the Custom Theme
//!         // Again, this could be your whole app or maybe just a small part.
//!         ThemeProvider {
//!             theme: CUSTOM_THEME,
//!             Button {
//!                 label {
//!                     "Cancel"
//!                 }
//!             }
//!         }
//!     )
//! }
//! ```
//!
//! ## `use_init_theme` hook
//!
//! This is like `ThemeProvider` but as a hook. You can call this in your root component or somewhere else.
//!
//! ```rust
//! # use freya::prelude::*;
//! // A custom theme based on the Light Theme that simply tweaks some parts of the Button theme.
//! const CUSTOM_THEME: Theme = Theme {
//!     button: ButtonTheme {
//!         background: Cow::Borrowed("rgb(230, 0, 0)"),
//!         hover_background: Cow::Borrowed("rgb(150, 0, 0)"),
//!         font_theme: FontTheme {
//!             color: Cow::Borrowed("white"),
//!         },
//!         ..LIGHT_THEME.button
//!     },
//!     ..LIGHT_THEME
//! };
//!
//! fn app() -> Element {
//!     use_init_theme(|| CUSTOM_THEME);
//!
//!     rsx!(
//!         Button {
//!             label {
//!                 "Cancel"
//!             }
//!         }
//!     )
//! }
//! ```
//!
//! ## `theme` prop
//!
//! Most of the components also support being tweaked via their `theme` prop and with the help of the `theme_with` macro.
//!
//! ### Example
//!
//! ```rust
//! # use freya::prelude::*;
//! fn app() -> Element {
//!     rsx!(
//!         Button {
//!             // You could pass the whole theme or maybe just a part of it
//!             theme: theme_with!(ButtonTheme {
//!                 background: "red".into(),
//!                 width: "200".into(),
//!             }),
//!             label {
//!                 "Cancel"
//!             }
//!         }
//!     )
//! }
//! ```