Skip to content

Commit 22180bf

Browse files
Ninja-YujinYujin Wang
andauthored
[IF-623] Add histogram to time range picker (#583)
* Update initial selected time range to current time * [IF-623] Add histogram display option to time range picker * [IF-623] add default month to daypicker in time range picker * Fix submit value for days type time range picker * Bump version * Update date range when arrow clicked in time range picker * [IF-623] Update background color for day picker panel * [IF-623] Add disabled days option to time range picker * [IF-623] Fix default value of daily counts * [IF-623] Split component to fix eslint warning * [IF-623] Fix version change * [IF-623] Code refactor * [IF-623] Update story page for time range picker * [IF-623] Import components and util functions directly to new components instead of re-export in style or util file * [IF-623] Export type DailyCount * [IF-623] Replace hard-coded color with color variable for count bar * [IF-623] Code refactor * [IF-623] Update store page for time range picker, submit change if initTime and init selected date and time range not match * [IF-623] replace html input element, adjust styles --------- Co-authored-by: Yujin Wang <yujin.wang��@nordcloud.com>
1 parent 89fb528 commit 22180bf

File tree

18 files changed

+977
-506
lines changed

18 files changed

+977
-506
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nordcloud/gnui",
33
"description": "Nordcloud Design System - a collection of reusable React components used in Nordcloud's SaaS products",
4-
"version": "8.2.0",
4+
"version": "8.3.0",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

src/components/timeRangePicker/TimeRangePicker.stories.mdx

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,111 @@
11
import { Meta, Story, Canvas } from "@storybook/addon-docs";
2+
import { previousMonday, addDays } from "date-fns";
23
import { Spacer } from "../spacer";
34
import { TimeRangePicker } from ".";
45

56
<Meta title="Forms/TimeRangePicker" component={TimeRangePicker} />
67

78
# TimeRangePicker
89

9-
> The `TimeRangePicker` component accepts a `onChange` function and an optional `initTimeRange` in type of `Interval`, to privode the function of selecting a time range.
10+
> The `TimeRangePicker` component accepts a `onChange` function and an optional `initTimeRange` in type of `Interval`, to privode the function of selecting a time range or date(s). Histogram is supported in "Hours" type.
1011
1112
## TimeRangePicker properties
1213

1314
| properties | required | type | description |
1415
| ------------: | :------: | :-------------------------------------------- | :-------------------------------------------------------------------------------------------------------- |
1516
| initTimeRange | false | Interval | Start date and end date should be within the same day, current date will be used otherwise and by default |
17+
| type | false | <code>Days</code>, <code>Hours</code> | Type of time selected in component |
18+
| weekCounts | false | DailyCount[] | Item counts in each time range (Type "Hours" only) |
19+
| countsLoading | false | boolean | Loading state of week counts (Type "Hours" only) |
20+
| disabledDays | false | Matcher[] | Dates not allowed to select |
1621
| onChange | true | <code>(newTimeRange: Interval) => void</code> | Function to handle timeRange change |
22+
| onWeekChange | false | <code>(monday: Date) => void</code> | Function to submit when showing week updates (Type "Hours" only) |
1723

1824
```typescript
1925
import { Interval } from "date-fns";
26+
import { Matcher } from "react-day-picker";
2027

2128
type Interval = {
2229
start: Date | number;
2330
end: Date | number;
2431
};
32+
33+
type DailyCount = {
34+
date: Date;
35+
counts: [number, number, number, number];
36+
};
37+
38+
type Matcher = (boolean | (date: Date)) => boolean | Date | Date[] | DateRange | DateBefore | DateAfter | DateInterval | DayOfWeek
39+
// A value or a function that matches a specific day
2540
```
2641
42+
### Type "Days"
43+
2744
<Canvas>
28-
<Story name="timerangepicker">
45+
<Story name="timerangepicker of days">
2946
{() => {
30-
const handleSelect = (newTimeRange) => {
31-
console.log(newTimeRange);
47+
const initValue = {
48+
start: new Date(),
49+
end: new Date(),
3250
};
51+
const [value, setValue] = React.useState(initValue);
52+
return (
53+
<>
54+
<TimeRangePicker
55+
type="Days"
56+
initTimeRange={initValue}
57+
onChange={setValue}
58+
/>
59+
<Spacer height="20rem" />
60+
<div id="result-days">Current Value: {JSON.stringify(value)}</div>
61+
</>
62+
);
63+
}}
64+
</Story>
65+
</Canvas>
66+
67+
## Type "Hours"
68+
69+
<Canvas>
70+
<Story name="timerangepicker of hours ">
71+
{() => {
72+
const [value, setValue] = React.useState();
73+
return (
74+
<>
75+
<TimeRangePicker onChange={setValue} />
76+
<Spacer height="20rem" />
77+
<div id="result-hours">Current Value: {JSON.stringify(value)}</div>
78+
</>
79+
);
80+
}}
81+
</Story>
82+
</Canvas>
83+
84+
## Type "Hours" with Histogram
85+
86+
<Canvas>
87+
<Story name="timerangepicker of hours with histogram">
88+
{() => {
89+
const [value, setValue] = React.useState();
90+
const monday = previousMonday(new Date());
3391
return (
3492
<>
35-
type: Days
36-
<TimeRangePicker type="Days" onChange={handleSelect} />
37-
<Spacer height="1rem" />
38-
type: Hours
39-
<TimeRangePicker onChange={handleSelect} />
40-
<Spacer height="2rem" />
93+
<TimeRangePicker
94+
weekCounts={[
95+
{ date: monday, counts: [1, 2, 3, 4] },
96+
{ date: addDays(monday, 1), counts: [0, 2, 3, 4] },
97+
{ date: addDays(monday, 2), counts: [1, 0, 3, 4] },
98+
{ date: addDays(monday, 3), counts: [1, 2, 0, 4] },
99+
{ date: addDays(monday, 4), counts: [1, 2, 3, 0] },
100+
{ date: addDays(monday, 5), counts: [0, 0, 0, 0] },
101+
{ date: addDays(monday, 6), counts: [0, 0, 0, 0] },
102+
]}
103+
onChange={setValue}
104+
/>
105+
<Spacer height="20rem" />
106+
<div id="result-hours-with-histogram">
107+
Current Value: {JSON.stringify(value)}
108+
</div>
41109
</>
42110
);
43111
}}

0 commit comments

Comments
 (0)