Skip to content

Commit 193ebab

Browse files
committed
[*] DatePicker: fix Test Suite
1 parent 242de5f commit 193ebab

File tree

4 files changed

+257
-49
lines changed

4 files changed

+257
-49
lines changed

preview/src/components/date_picker/component.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ use dioxus::prelude::*;
33
use dioxus_primitives::{
44
calendar::CalendarProps,
55
date_picker::{self, DatePickerInputProps, DatePickerProps},
6-
popover::{PopoverContent, PopoverContentProps, PopoverRootProps, PopoverTrigger},
7-
ContentAlign,
6+
popover::{PopoverContentProps, PopoverRootProps, PopoverTriggerProps},
87
};
98

109
use crate::components::calendar::component::*;
11-
use time::UtcDateTime;
1210

1311
#[component]
1412
pub fn DatePicker(props: DatePickerProps) -> Element {
@@ -57,14 +55,11 @@ pub fn DatePickerPopover(props: PopoverRootProps) -> Element {
5755
}
5856

5957
#[component]
60-
pub fn DatePickerPopoverTrigger(
61-
#[props(extends = GlobalAttributes)] attributes: Vec<Attribute>,
62-
) -> Element {
58+
pub fn DatePickerPopoverTrigger(props: PopoverTriggerProps) -> Element {
6359
rsx! {
64-
PopoverTrigger {
60+
date_picker::DatePickerPopoverTrigger {
6561
class: "date-picker-trigger",
66-
aria_label: "trigger",
67-
attributes,
62+
attributes: props.attributes,
6863
svg {
6964
class: "date-picker-expand-icon",
7065
view_box: "0 0 24 24",
@@ -78,11 +73,11 @@ pub fn DatePickerPopoverTrigger(
7873
#[component]
7974
pub fn DatePickerPopoverContent(props: PopoverContentProps) -> Element {
8075
rsx! {
81-
PopoverContent {
76+
date_picker::DatePickerPopoverContent {
8277
class: "popover-content",
8378
id: props.id,
8479
side: props.side,
85-
align: ContentAlign::End,
80+
align: props.align,
8681
attributes: props.attributes,
8782
{props.children}
8883
}
@@ -91,23 +86,16 @@ pub fn DatePickerPopoverContent(props: PopoverContentProps) -> Element {
9186

9287
#[component]
9388
pub fn DatePickerCalendar(props: CalendarProps) -> Element {
94-
let mut view_date = use_signal(|| UtcDateTime::now().date());
95-
96-
use_effect(move || {
97-
if let Some(date) = (props.selected_date)() {
98-
view_date.set(date);
99-
}
100-
});
101-
10289
rsx! {
103-
Calendar {
90+
date_picker::DatePickerCalendar {
91+
class: "calendar",
10492
selected_date: props.selected_date,
10593
on_date_change: props.on_date_change,
10694
on_format_weekday: props.on_format_weekday,
10795
on_format_month: props.on_format_month,
108-
view_date: view_date(),
96+
view_date: props.view_date,
10997
today: props.today,
110-
on_view_change: move |date| view_date.set(date),
98+
on_view_change: props.on_view_change,
11199
disabled: props.disabled,
112100
first_day_of_week: props.first_day_of_week,
113101
min_date: props.min_date,

preview/src/components/date_picker/docs.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,34 @@ The DatePicker component is used to display a date input and a Calendar popover,
33
## Component Structure
44

55
```rust
6+
DatePicker {
7+
// The currently value in the date picker (type DatePickerValue).
8+
value,
9+
// The currently selected date in the date picker (if any).
10+
selected_date,
11+
on_value_change: move |v: DatePickerValue| {
12+
// This callback is triggered when a date is selected in the
13+
// calendar or the user entered it from the keyboard.
14+
// The date parameter contains the selected date.
15+
},
16+
// Allows the user to enter a date using the keyboard.
17+
// The input field should contain a button to display the calendar and the calendar itself.
18+
DatePickerInput {
19+
// The DatePickerPopover is the root popover component that contains the trigger and Calendar.
20+
DatePickerPopover {
21+
// The DatePickerPopoverTrigger contains the elements that will trigger the popover
22+
// to display Calendar when clicked.
23+
DatePickerPopoverTrigger {}
24+
// The DatePickerPopoverContent contains the Calendar that will be displayed when
25+
// the user clicks on the trigger.
26+
DatePickerPopoverContent {
27+
// The alignment of the DatePickerPopoverContent relative to the DatePickerPopoverTrigger.
28+
// Can be one of Start, Center, or End. Recommended use End for default value.
29+
align: ContentAlign::End,
30+
// Customized Calendar components
31+
DatePickerCalendar {}
32+
}
33+
}
34+
}
35+
}
636
```

preview/src/components/date_picker/variants/main/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::super::component::*;
22
use dioxus::prelude::*;
33

44
use dioxus_i18n::tid;
5-
use dioxus_primitives::date_picker::DatePickerValue;
5+
use dioxus_primitives::{date_picker::DatePickerValue, ContentAlign};
66

77
use time::{Date, Month, Weekday};
88

@@ -19,17 +19,18 @@ pub fn Demo() -> Element {
1919
value: value(),
2020
selected_date: selected_date(),
2121
on_value_change: move |v| {
22-
tracing::info!("Selected: {v}");
22+
tracing::info!("Date changed to: {v}");
2323
value.set(v);
2424
selected_date.set(v.date());
2525
},
2626
DatePickerInput {
2727
on_format_day_placeholder: || tid!("D_Abbr"),
2828
on_format_month_placeholder: || tid!("M_Abbr"),
2929
on_format_year_placeholder: || tid!("Y_Abbr"),
30-
DatePickerPopover {
30+
DatePickerPopover {
3131
DatePickerPopoverTrigger {}
3232
DatePickerPopoverContent {
33+
align: ContentAlign::End,
3334
DatePickerCalendar {
3435
selected_date: selected_date(),
3536
on_date_change: move |date| selected_date.set(date),

0 commit comments

Comments
 (0)