patternfly_yew/components/page/
mod.rs1use crate::prelude::{Button, ButtonType, ButtonVariant};
3use std::rc::Rc;
4use yew::prelude::*;
5
6mod section;
7mod sidebar;
8
9pub use section::*;
10pub use sidebar::*;
11
12#[derive(Clone, PartialEq, Properties)]
14pub struct PageProperties {
15 #[prop_or_default]
16 pub children: Html,
17 #[prop_or_default]
18 pub sidebar: ChildrenWithProps<PageSidebar>,
19 #[prop_or_default]
20 pub tools: Html,
21
22 #[prop_or_default]
28 pub brand: Html,
29
30 #[prop_or_default]
31 pub nav: Html,
32 #[prop_or(true)]
33 pub open: bool,
34 #[prop_or_default]
35 pub full_height: bool,
36
37 #[prop_or_default]
38 pub id: Option<AttrValue>,
39 #[prop_or_default]
40 pub on_main_scroll: Callback<Event>,
41}
42
43#[function_component(Page)]
62pub fn page(props: &PageProperties) -> Html {
63 let open = use_state_eq(|| props.open);
64
65 let onclick = {
66 let open = open.clone();
67 Callback::from(move |_| {
68 open.set(!(*open));
69 })
70 };
71 let onscroll = props.on_main_scroll.clone();
72 html! (
73 <div class="pf-v5-c-page" id={&props.id} role="main" tabindex="-1">
74 <header class="pf-v5-c-masthead">
75 if !props.sidebar.is_empty() {
78 <span class="pf-v5-c-masthead__toggle">
79 <Button
80 r#type={ButtonType::Button}
81 variant={ButtonVariant::Plain}
82 {onclick}
83 >
84 <i class="fas fa-bars" aria-hidden="true" />
85 </Button>
86 </span>
87 }
88
89 <div class="pf-v5-c-masthead__main">
90 { props.brand.clone() }
91 </div>
92
93 <div class="pf-v5-c-masthead__content"> { props.nav.clone() }
95 { props.tools.clone() }
96 </div>
97
98 </header>
99
100 { for props.sidebar.iter().map(|mut s|{
101 let props = Rc::make_mut(&mut s.props);
102 props.open = *open;
103 s
104 }) }
105
106 <main class="pf-v5-c-page__main" tabindex="-1" {onscroll}>
107 { props.children.clone() }
108 </main>
109 </div>
110 )
111}
112
113#[derive(Clone, Debug, PartialEq, Properties)]
114pub struct MastheadBrandProperties {
115 #[prop_or_default]
119 pub children: Html,
120
121 #[prop_or_default]
123 pub onclick: Option<Callback<()>>,
124}
125
126#[function_component(MastheadBrand)]
137pub fn masthead_brand(props: &MastheadBrandProperties) -> Html {
138 match &props.onclick {
139 Some(onclick) => {
140 let onclick = onclick.reform(|_| ());
141 html!(
142 <a class="pf-v5-c-masthead__brand" href="#" {onclick}>
143 { props.children.clone() }
144 </a>
145 )
146 }
147 None => {
148 html!(
149 <div class="pf-v5-c-masthead__brand">
150 { props.children.clone() }
151 </div>
152 )
153 }
154 }
155}