freya_components/body.rs
1use dioxus::prelude::*;
2use freya_elements as dioxus_elements;
3use freya_hooks::{
4 use_applied_theme,
5 BodyTheme,
6 BodyThemeWith,
7};
8
9/// Properties for the [`Body`] component.
10#[derive(Props, Clone, PartialEq)]
11pub struct BodyProps {
12 /// Theme override.
13 pub theme: Option<BodyThemeWith>,
14 /// Inner children for the Body.
15 pub children: Element,
16 /// Spacing for the inner children of the Body.
17 pub spacing: Option<String>,
18 /// Padding for the inner children of the Body.
19 pub padding: Option<String>,
20 /// Width of the Body.
21 #[props(default = "fill".to_string())]
22 pub width: String,
23 /// Height of the Body.
24 #[props(default = "fill".to_string())]
25 pub height: String,
26 /// Direction of the Body.
27 #[props(default = "vertical".to_string())]
28 pub direction: String,
29}
30
31/// Usually used to wrap the application root component.
32///
33/// # Styling
34/// Inherits the [`BodyTheme`](freya_hooks::BodyTheme) theme.
35///
36/// # Example
37///
38/// ```no_run
39/// # use freya::prelude::*;
40/// fn app() -> Element {
41/// rsx!(
42/// Body {
43/// label {
44/// "Click this"
45/// }
46/// }
47/// )
48/// }
49/// ```
50#[allow(non_snake_case)]
51pub fn Body(
52 BodyProps {
53 children,
54 theme,
55 spacing,
56 padding,
57 width,
58 height,
59 direction,
60 }: BodyProps,
61) -> Element {
62 let theme = use_applied_theme!(&theme, body);
63 let BodyTheme { background, color } = theme;
64
65 rsx!(
66 rect {
67 width,
68 height,
69 color: "{color}",
70 background: "{background}",
71 spacing,
72 padding,
73 direction,
74 {&children}
75 }
76 )
77}