Skip to content

Commit

Permalink
feat(date): add examples for calendar and datepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
rick-gnous authored and ctron committed Sep 22, 2023
1 parent a803664 commit 41c4b87
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum Component {
CodeBlock,
#[target(rename = "context_selector")]
ContextSelector,
Date(Date),
DescriptionList,
Divider,
Drawer,
Expand Down Expand Up @@ -76,6 +77,14 @@ pub enum Menu {
Select,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Target)]
pub enum Date {
#[default]
#[target(index)]
Calendar,
DatePicker,
}

#[derive(Debug, Clone, PartialEq, Eq, Target)]
pub enum Layout {
Bullseye,
Expand Down Expand Up @@ -134,6 +143,8 @@ fn switch_app_route(target: AppRoute) -> Html {
Component::Clipboard => html! {<components::ClipboardExample/>},
Component::CodeBlock => html! {<components::CodeBlockExample/>},
Component::ContextSelector => html! {<components::ContextSelectorExample/>},
Component::Date(Date::Calendar) => html! {<components::CalendarExample/>},
Component::Date(Date::DatePicker) => html! {<components::DatePickerExample/>},
Component::DescriptionList => html! {<components::DescriptionListExample/>},
Component::Divider => html! {<components::DividerExample/>},
Component::Drawer => html! {<components::DrawerExample/>},
Expand Down Expand Up @@ -262,6 +273,10 @@ fn page(props: &PageProps) -> Html {
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Clipboard)}>{"Clipboard"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::CodeBlock)}>{"Code Block"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::ContextSelector)}>{"Context Selector"}</NavRouterItem<AppRoute>>
<NavExpandable title="Date">
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Date(Date::Calendar))}>{"Calendar"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Date(Date::DatePicker))}>{"DatePicker"}</NavRouterItem<AppRoute>>
</NavExpandable>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::DescriptionList)}>{"DescriptionList"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Divider)}>{"Divider"}</NavRouterItem<AppRoute>>
<NavRouterItem<AppRoute> to={AppRoute::Component(Component::Drawer)}>{"Drawer"}</NavRouterItem<AppRoute>>
Expand Down
6 changes: 6 additions & 0 deletions src/components/date/calendar/calendar.1.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
html!{
<>
<CalendarView date={*date} {onchange} weekday_start={Weekday::Sun} />
<p>{date.to_string()}</p>
</>
}
8 changes: 8 additions & 0 deletions src/components/date/calendar/calendar.2.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
html!{
<>
<CalendarView
date={NaiveDate::from_ymd_opt(2023, 9, 20).unwrap()}
rangestart={NaiveDate::from_ymd_opt(2023, 9, 8).unwrap()}
/>
</>
}
25 changes: 25 additions & 0 deletions src/components/date/calendar/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::{example, example::ExamplePage};
use patternfly_yew::prelude::*;
use yew::prelude::*;
use chrono::*;

#[function_component(CalendarExample)]
pub fn datepicker_example() -> yew::Html {
let date = use_state(|| NaiveDate::from_ymd_opt(2011, 1, 14).unwrap());
let onchange = {
let date = date.clone();
Callback::from(move |d| date.set(d))
};

let select_date = example! ("Selectable date" => "calendar.1.example");
let range = example! ("Date range" => "calendar.2.example");

html! {
<>
<ExamplePage title="Calendar month">
{ select_date }
{ range }
</ExamplePage>
</>
}
}
5 changes: 5 additions & 0 deletions src/components/date/date/date.1.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
html!{
<>
<DatePicker />
</>
}
17 changes: 17 additions & 0 deletions src/components/date/date/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::{example, example::ExamplePage};
use patternfly_yew::prelude::*;
use yew::prelude::*;
use chrono::*;

#[function_component(DatePickerExample)]
pub fn datepicker_example() -> yew::Html {
let date = example! ("Basic" => "date.1.example");

html! {
<>
<ExamplePage title="DatePicker">
{ date }
</ExamplePage>
</>
}
}
5 changes: 5 additions & 0 deletions src/components/date/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod date;
mod calendar;

pub use date::*;
pub use calendar::*;
2 changes: 2 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod chip;
mod clipboard;
mod code_block;
mod context_selector;
mod date;
mod description_list;
mod divider;
mod drawer;
Expand Down Expand Up @@ -54,6 +55,7 @@ pub use chip::*;
pub use clipboard::*;
pub use code_block::*;
pub use context_selector::*;
pub use date::*;
pub use description_list::*;
pub use divider::*;
pub use drawer::*;
Expand Down

0 comments on commit 41c4b87

Please sign in to comment.