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-v6-c-page" id={&props.id} role="main" tabindex="-1">
74 <header class="pf-v6-c-masthead">
75 <div class="pf-v6-c-masthead__main">
76 if !props.sidebar.is_empty() {
79 <span class="pf-v6-c-masthead__toggle">
80 <Button
81 r#type={ButtonType::Button}
82 variant={ButtonVariant::Plain}
83 {onclick}
84 >
85 <i class="fas fa-bars" aria-hidden="true" />
86 </Button>
87 </span>
88 }
89 { props.brand.clone() }
90 </div>
91
92 <div class="pf-v6-c-masthead__content"> { props.nav.clone() }
94 { props.tools.clone() }
95 </div>
96
97 </header>
98
99 { for props.sidebar.iter().map(|mut s|{
100 let props = Rc::make_mut(&mut s.props);
101 props.open = *open;
102 s
103 }) }
104
105 <div class="pf-v6-c-page__main-container">
106 <main class="pf-v6-c-page__main" tabindex="-1" {onscroll}>
107 { props.children.clone() }
108 </main>
109 </div>
110 </div>
111 )
112}
113
114#[derive(Clone, Debug, PartialEq, Properties)]
115pub struct MastheadBrandProperties {
116 #[prop_or_default]
120 pub children: Html,
121
122 #[prop_or_default]
124 pub onclick: Option<Callback<()>>,
125}
126
127#[function_component(MastheadBrand)]
138pub fn masthead_brand(props: &MastheadBrandProperties) -> Html {
139 match &props.onclick {
140 Some(onclick) => {
141 let onclick = onclick.reform(|_| ());
142 html!(
143 <a class="pf-v6-c-masthead__brand" href="#" {onclick}>
144 { props.children.clone() }
145 </a>
146 )
147 }
148 None => {
149 html!(
150 <div class="pf-v6-c-masthead__brand">
151 { props.children.clone() }
152 </div>
153 )
154 }
155 }
156}