use crate::prelude::{Button, ButtonType, ButtonVariant};
use std::rc::Rc;
use yew::prelude::*;
mod section;
mod sidebar;
pub use section::*;
pub use sidebar::*;
#[derive(Clone, PartialEq, Properties)]
pub struct PageProperties {
#[prop_or_default]
pub children: Html,
#[prop_or_default]
pub sidebar: ChildrenWithProps<PageSidebar>,
#[prop_or_default]
pub tools: Html,
#[prop_or_default]
pub brand: Html,
#[prop_or_default]
pub nav: Html,
#[prop_or(true)]
pub open: bool,
#[prop_or_default]
pub full_height: bool,
#[prop_or_default]
pub id: Option<AttrValue>,
#[prop_or_default]
pub on_main_scroll: Callback<Event>,
}
#[component]
pub fn Page(props: &PageProperties) -> Html {
let open = use_state_eq(|| props.open);
let onclick = use_callback(open.clone(), |_, open| {
open.set(!(**open));
});
let onscroll = props.on_main_scroll.clone();
let mut class = classes!["pf-v6-c-page__main-container"];
if props.full_height {
class.push("pf-m-fill");
}
html! (
<div class="pf-v6-c-page" id={&props.id} role="main" tabindex="-1">
<header class="pf-v6-c-masthead">
<div class="pf-v6-c-masthead__main">
if !props.sidebar.is_empty() {
<span class="pf-v6-c-masthead__toggle">
<Button
r#type={ButtonType::Button}
variant={ButtonVariant::Plain}
{onclick}
>
<i class="fas fa-bars" aria-hidden="true" />
</Button>
</span>
}
{ props.brand.clone() }
</div>
<div class="pf-v6-c-masthead__content">
{ props.nav.clone() }
{ props.tools.clone() }
</div>
</header>
{ for props.sidebar.iter().map(|mut s|{
let props = Rc::make_mut(&mut s.props);
props.open = *open;
s
}) }
<div {class}>
<main class="pf-v6-c-page__main" tabindex="-1" {onscroll}>
{ props.children.clone() }
</main>
</div>
</div>
)
}
#[derive(Clone, Debug, PartialEq, Properties)]
pub struct MastheadBrandProperties {
#[prop_or_default]
pub children: Html,
#[prop_or_default]
pub onclick: Option<Callback<()>>,
}
#[component]
pub fn MastheadBrand(props: &MastheadBrandProperties) -> Html {
match &props.onclick {
Some(onclick) => {
let onclick = onclick.reform(|_| ());
html!(
<a class="pf-v6-c-masthead__brand" href="#" {onclick}>{ props.children.clone() }</a>
)
}
None => {
html!(<div class="pf-v6-c-masthead__brand">{ props.children.clone() }</div>)
}
}
}