Start month and year dropdown in date time picker

This commit is contained in:
Adrian Woźniak 2020-08-22 23:40:02 +02:00
parent a382991cfd
commit bc7c65306c
5 changed files with 121 additions and 93 deletions

1
Cargo.lock generated
View File

@ -1722,6 +1722,7 @@ dependencies = [
"jirs-data", "jirs-data",
"js-sys", "js-sys",
"lazy_static", "lazy_static",
"num-traits",
"seed", "seed",
"serde", "serde",
"syntect", "syntect",

View File

@ -31,6 +31,7 @@ uuid = { version = "0.8.1", features = ["serde"] }
futures = "^0.1.26" futures = "^0.1.26"
comrak = "*" comrak = "*"
wee_alloc = "*" wee_alloc = "*"
num-traits = { version = "*" }
lazy_static = "*" lazy_static = "*"
syntect = { version = "*", default-features = false, features = ["html", "regex-fancy", "dump-load-rs"] } syntect = { version = "*", default-features = false, features = ["html", "regex-fancy", "dump-load-rs"] }

View File

@ -7,19 +7,11 @@
.dateTimeTooltip { .dateTimeTooltip {
padding: 15px; padding: 15px;
position: absolute; position: absolute;
top: 0; top: -50px;
width: 100%;
}
@media (max-width: 1100px) {
.dateTimeTooltip {
padding: 15px;
position: absolute;
top: -50px;
left: 110px; left: 110px;
width: 610px; width: 610px;
min-width: 610px; min-width: 610px;
max-width: 610px; max-width: 610px;
} }
.dateTimeTooltip:before { .dateTimeTooltip:before {
@ -35,6 +27,19 @@
z-index: -1; z-index: -1;
border-left: 1px solid rgba(9, 30, 66, 0.25); border-left: 1px solid rgba(9, 30, 66, 0.25);
border-bottom: 1px solid rgba(9, 30, 66, 0.25); border-bottom: 1px solid rgba(9, 30, 66, 0.25);
}
@media (max-width: 1100px) {
.dateTimeTooltip {
padding: 15px;
position: absolute;
top: 0;
left: 0;
width: 100%;
}
.dateTimeTooltip:before {
display: none;
} }
} }
@ -45,11 +50,8 @@
font-size: 1.1rem; font-size: 1.1rem;
} }
.dateTimeTooltip > .actions { .dateTimeTooltip > h2 > .headerText {
display: flex; line-height: 34px;
justify-content: space-between;
height: 2rem;
line-height: 2rem;
} }
.dateTimeTooltip > .calendar { .dateTimeTooltip > .calendar {
@ -57,16 +59,6 @@
.dateTimeTooltip > .calendar > .week { .dateTimeTooltip > .calendar > .week {
display: flex; display: flex;
border-left: 1px solid var(--textDarkest);
border-right: 1px solid var(--textDarkest);
}
.dateTimeTooltip > .calendar > .week:first-child {
border-top: 1px solid var(--textDarkest);
}
.dateTimeTooltip > .calendar > .week:last-child {
border-bottom: 1px solid var(--textDarkest);
} }
.dateTimeTooltip > .calendar > .week.weekHeader { .dateTimeTooltip > .calendar > .week.weekHeader {

View File

@ -10,6 +10,11 @@
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
} }
.modal > .clickableOverlay {
min-height: 100%;
background: rgba(9, 30, 66, 0.54);
}
.modal > .clickableOverlay.center { .modal > .clickableOverlay.center {
display: flex; display: flex;
justify-content: center; justify-content: center;

View File

@ -9,7 +9,9 @@ use {
use crate::shared::styled_button::StyledButton; use crate::shared::styled_button::StyledButton;
use crate::shared::styled_icon::Icon; use crate::shared::styled_icon::Icon;
use crate::shared::styled_select::StyledSelect;
use crate::shared::styled_tooltip::StyledTooltip; use crate::shared::styled_tooltip::StyledTooltip;
use crate::shared::ToChild;
use crate::{shared::ToNode, FieldId, Msg}; use crate::{shared::ToNode, FieldId, Msg};
#[derive(Debug)] #[derive(Debug)]
@ -165,86 +167,113 @@ fn render(values: StyledDateTimeInput) -> Node<Msg> {
weeks.push(div![C!["week"], current_week]); weeks.push(div![C!["week"], current_week]);
} }
let close_tooltip = { let left_action = {
let field_id = values.field_id.clone(); let field_id = values.field_id.clone();
let current = timestamp;
let on_click_left = mouse_ev(Ev::Click, move |ev| {
ev.stop_propagation();
ev.prevent_default();
let last_day_of_prev_month = current.with_day0(0).unwrap() - Duration::days(1);
let date = last_day_of_prev_month
.with_day0(timestamp.day0())
.unwrap_or_else(|| last_day_of_prev_month);
Msg::StyledDateTimeInputChanged(
field_id,
StyledDateTimeChanged::MonthChanged(Some(date)),
)
});
StyledButton::build() StyledButton::build()
.on_click(on_click_left)
.icon(Icon::DoubleLeft)
.empty()
.build()
.into_node()
};
let right_action = {
let field_id = values.field_id.clone();
let current = timestamp;
let on_click_right = mouse_ev(Ev::Click, move |ev| {
ev.stop_propagation();
ev.prevent_default();
let first_day_of_next_month = (current + Duration::days(32)).with_day0(0).unwrap();
let last_day_of_next_month = (first_day_of_next_month + Duration::days(32))
.with_day0(0)
.unwrap()
- Duration::days(1);
let date = first_day_of_next_month
.with_day0(timestamp.day0())
.unwrap_or_else(|| last_day_of_next_month);
Msg::StyledDateTimeInputChanged(
field_id,
StyledDateTimeChanged::MonthChanged(Some(date)),
)
});
StyledButton::build()
.on_click(on_click_right)
.icon(Icon::DoubleRight)
.empty() .empty()
.icon(Icon::Close)
.on_click(mouse_ev(Ev::Click, move |ev| {
ev.prevent_default();
Some(Msg::StyledDateTimeInputChanged(
field_id,
StyledDateTimeChanged::PopupVisibilityChanged(false),
))
}))
.build() .build()
.into_node() .into_node()
}; };
let actions = { let month_select = {
let left_action = { use num_traits::FromPrimitive;
let field_id = values.field_id.clone(); let field_id = values.field_id.clone();
let current = timestamp; let selected_month = Month::from_u32(current.month()).unwrap_or_else(|| Month::January);
let on_click_left = mouse_ev(Ev::Click, move |ev| {
ev.stop_propagation();
ev.prevent_default();
let last_day_of_prev_month = current.with_day0(0).unwrap() - Duration::days(1);
let date = last_day_of_prev_month StyledSelect::build()
.with_day0(timestamp.day0()) .options(
.unwrap_or_else(|| last_day_of_prev_month); vec![
Msg::StyledDateTimeInputChanged( Month::January,
field_id, Month::February,
StyledDateTimeChanged::MonthChanged(Some(date)), Month::March,
) Month::April,
}); Month::May,
StyledButton::build() Month::June,
.on_click(on_click_left) Month::July,
.icon(Icon::DoubleLeft) Month::August,
.empty() Month::September,
.build() Month::October,
.into_node() Month::November,
}; Month::December,
let right_action = { ]
let field_id = values.field_id.clone(); .into_iter()
let current = timestamp; .map(|month| (month.name().to_string(), month.number_from_month()).to_child())
let on_click_right = mouse_ev(Ev::Click, move |ev| { .collect(),
ev.stop_propagation(); )
ev.prevent_default(); .selected(vec![(
let first_day_of_next_month = (current + Duration::days(32)).with_day0(0).unwrap(); selected_month.name().to_string(),
let last_day_of_next_month = (first_day_of_next_month + Duration::days(32)) selected_month.number_from_month(),
.with_day0(0) )
.unwrap() .to_child()])
- Duration::days(1); .build(field_id)
let date = first_day_of_next_month .into_node()
.with_day0(timestamp.day0())
.unwrap_or_else(|| last_day_of_next_month);
Msg::StyledDateTimeInputChanged(
field_id,
StyledDateTimeChanged::MonthChanged(Some(date)),
)
});
StyledButton::build()
.on_click(on_click_right)
.icon(Icon::DoubleRight)
.empty()
.build()
.into_node()
};
div![
C!["actions"],
button![C!["prev"], left_action],
button![C!["next"], right_action],
]
}; };
let header_text = current.format("%B %Y").to_string(); let year_select = {
let field_id = values.field_id.clone();
let selected_year = current.year();
StyledSelect::build()
.options(
(1980..=Utc::today().year())
.into_iter()
.map(|i| (i as u32).to_child())
.collect(),
)
.selected(vec![(selected_year as u32).to_child()])
.build(field_id)
.into_node()
};
let tooltip = StyledTooltip::build() let tooltip = StyledTooltip::build()
.visible(values.popup_visible) .visible(values.popup_visible)
.date_time_picker() .date_time_picker()
.add_child(h2![span![" "], span![header_text], close_tooltip]) .add_child(h2![
.add_child(actions) left_action,
span![C!["headerText"], month_select, year_select],
right_action
])
.add_child(div![ .add_child(div![
C!["calendar"], C!["calendar"],
div![ div![