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#[component]
62pub fn Page(props: &PageProperties) -> Html {
63 let open = use_state_eq(|| props.open);
64
65 let onclick = use_callback(open.clone(), |_, open| {
66 open.set(!(**open));
67 });
68
69 let onscroll = props.on_main_scroll.clone();
70
71 let mut class = classes!["pf-v6-c-page__main-container"];
72
73 if props.full_height {
74 class.push("pf-m-fill");
75 }
76
77 html! (
78 <div class="pf-v6-c-page" id={&props.id} role="main" tabindex="-1">
79 <header class="pf-v6-c-masthead">
80 <div class="pf-v6-c-masthead__main">
81 if !props.sidebar.is_empty() {
84 <span class="pf-v6-c-masthead__toggle">
85 <Button
86 r#type={ButtonType::Button}
87 variant={ButtonVariant::Plain}
88 {onclick}
89 >
90 <i class="fas fa-bars" aria-hidden="true" />
91 </Button>
92 </span>
93 }
94 { props.brand.clone() }
95 </div>
96 <div class="pf-v6-c-masthead__content">
97 { props.nav.clone() }
99 { props.tools.clone() }
100 </div>
101 </header>
102 { for props.sidebar.iter().map(|mut s|{
103 let props = Rc::make_mut(&mut s.props);
104 props.open = *open;
105 s
106 }) }
107 <div {class}>
108 <main class="pf-v6-c-page__main" tabindex="-1" {onscroll}>
109 { props.children.clone() }
110 </main>
111 </div>
112 </div>
113 )
114}
115
116#[derive(Clone, Debug, PartialEq, Properties)]
117pub struct MastheadBrandProperties {
118 #[prop_or_default]
122 pub children: Html,
123
124 #[prop_or_default]
126 pub onclick: Option<Callback<()>>,
127}
128
129#[component]
140pub fn MastheadBrand(props: &MastheadBrandProperties) -> Html {
141 match &props.onclick {
142 Some(onclick) => {
143 let onclick = onclick.reform(|_| ());
144 html!(
145 <a class="pf-v6-c-masthead__brand" href="#" {onclick}>{ props.children.clone() }</a>
146 )
147 }
148 None => {
149 html!(<div class="pf-v6-c-masthead__brand">{ props.children.clone() }</div>)
150 }
151 }
152}