Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 7bed283

Browse files
[DateRangePicker] Introduce new component 🎉 (#1602)
* Make value for picker be a generic type * Spread new props from passing to the dom element * Split makePickerWith state hoc * Better type inference for new makePickerWithWrapper * Refactor and opimize shared prop types inference for pickers * Rename eome type names and files * Integrate validation back to usePickerState * Remove DateRangePicker code * Remove DateRangePickerUsage from index module * Fix small linter and ts errors * Fix build erros * Run prettier manually * Display calendars for date range * [WiP] Work on displaying 2 calendars one by one * WATER ON MY MAC * Proper display days with margins with range highlights * Fix unexpected month switchings * Implement range preview * Optimize rerenders of Day and DateRangeDay, closes #1306 * Fix crash and missing rerender * Optimize rerendering performace of <Day /> * Use popper for date range wrapper * Proper displaying values in DateRangePIckerInput * Implement ClickAwayListner for popper wrapper * Fix slide animation in date range picker * Reorganize test folders * Reorganize integration test folder * Add focus managment logic * Implement autoscrolling for switching between range start/end * Improve date range picker with disabling min/max dates * Update date-io adapter version to 2.5.0 * Do not display range preview on highlighted days * Better focus and blur handling for popper * Fix range preview border style * Fix type erros * Fix fantom borders appearing * Better styling for popper and possibility to replace transition * Fix missing mui globals * Fix werid memoization issue in Safari * Implement mobile version of DateRangePicker * Better displaying in mobile mode * Make possible to switch view by clicking on month and year header * Properly spread props to mobile keyboard input view * Fix ts erros and enable api generation * Fix example ts-checks * Fix ts error in ServerRerquest.example.jsx * Fix error if mouning in open state * Add props test for DateRangePickers * Export responsive date range picker by default * Add missing displayName to the ToolbarButton * Small enhancmenets * Fix inclusivity of range for non-datefns livs * Fix ts error * Remove fake data from range example * Use tsx in date range picker examples * Add `startText` and `endText` props * Update material-ui and fix createSvgIcon import, closes #1619 * Use new TextField `focused` prop for highlighting * Close picker after range selected * Update jss version * Add more date-range-manager tests * More examples and possibility to change wrapper mode for static wrapper * Fix ts wrapper props inferring * Update lib/src/views/Calendar/CalendarView.tsx Co-Authored-By: Olivier Tassinari <[email protected]> * Update docs/pages/demo/daterangepicker/CalendarsDateRangePicker.example.tsx Co-Authored-By: Olivier Tassinari <[email protected]> * Update createSvgIcon imports * Fix ts inferrence for static wrapper props * Add missing props spreading * Fix more build errors * Update lib/src/__tests__/setup.js Co-Authored-By: Olivier Tassinari <[email protected]> * Address review * forwardRef for DateRangePicker Co-authored-by: Olivier Tassinari <[email protected]>
1 parent c38b5ed commit 7bed283

File tree

96 files changed

+3968
-800
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3968
-800
lines changed

docs/_shared/Code.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface CodeProps {
4242
language?: 'jsx' | 'typescript' | 'markup';
4343
}
4444

45-
const Code: React.SFC<CodeProps> = ({ language = 'jsx', inline, children, withMargin }) => {
45+
const Code: React.FC<CodeProps> = ({ language = 'typescript', inline, children, withMargin }) => {
4646
const classes = useStyles();
4747
const highlightedCode = highlight(children, language);
4848

docs/layout/PageWithContext.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ import { PageContext } from '../utils/getPageContext';
99
import { LocalizationProvider } from '@material-ui/pickers';
1010
import { UtilsContext } from '../_shared/UtilsServiceContext';
1111
import { NotificationManager } from 'utils/NotificationManager';
12-
import { Theme, createMuiTheme, CssBaseline } from '@material-ui/core';
1312
import { createUtilsService, UtilsLib, utilsMap } from '../utils/utilsService';
14-
import { ThemeProvider, jssPreset, StylesProvider } from '@material-ui/core/styles';
13+
import {
14+
Theme,
15+
createMuiTheme,
16+
CssBaseline,
17+
ThemeProvider,
18+
jssPreset,
19+
StylesProvider,
20+
} from '@material-ui/core';
1521

1622
export type ThemeType = 'light' | 'dark';
1723
export type Direction = Theme['direction'];

docs/next.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = withBundleAnalyzer(
4242

4343
// Process examples to inject raw code strings
4444
config.module.rules.push({
45-
test: /\.example\.(js|jsx)$/,
45+
test: /\.example\.(js|jsx|tsx|ts)$/,
4646
include: [path.resolve(__dirname, 'pages')],
4747
use: [
4848
{ loader: 'next-babel-loader' },

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@material-ui/pickers": "^4.0.0-alpha.1",
2727
"@types/fuzzy-search": "^2.1.0",
2828
"@types/isomorphic-fetch": "^0.0.35",
29+
"@types/jss": "^10.0.0",
2930
"@types/luxon": "^1.11.0",
3031
"@types/next": "^8.0.1",
3132
"@types/prismjs": "^1.9.1",

docs/pages/demo/datepicker/ServerRequest.example.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function ServerRequest() {
3030
renderDay={(day, selectedDate, DayComponentProps) => {
3131
const date = makeJSDateObject(day); // skip this step, it is required to support date libs
3232
const isSelected =
33-
DayComponentProps.isInCurrentMonth && selectedDays.includes(date.getDate());
33+
DayComponentProps.inCurrentMonth && selectedDays.includes(date.getDate());
3434

3535
return (
3636
<Badge overlap="circle" badgeContent={isSelected ? '🌚' : undefined}>

docs/pages/demo/datepicker/StaticDatePicker.example.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React, { useState } from 'react';
2+
import isWeekend from 'date-fns/isWeekend';
23
import { StaticDatePicker } from '@material-ui/pickers';
4+
import { makeJSDateObject } from '../../../utils/helpers';
5+
6+
function disableWeekends(date) {
7+
// TODO: replace with implementation for your date library
8+
return isWeekend(makeJSDateObject(date));
9+
}
310

411
const StaticDatePickerExample = () => {
512
const [date, handleDateChange] = useState(new Date());
@@ -18,6 +25,7 @@ const StaticDatePickerExample = () => {
1825
orientation="landscape"
1926
openTo="date"
2027
value={date}
28+
shouldDisableDate={disableWeekends}
2129
onChange={date => handleDateChange(date)}
2230
/>
2331
</>

docs/pages/demo/daterangepicker/BasicDateRangePicker.example.jsx

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as React from 'react';
2+
import { DateRangePicker, DateRange } from '@material-ui/pickers';
3+
4+
function BasicDateRangePicker() {
5+
const [selectedDate, handleDateChange] = React.useState<DateRange>([null, null]);
6+
7+
return (
8+
<DateRangePicker
9+
startText="Check-in"
10+
endText="Check-out"
11+
value={selectedDate}
12+
onChange={date => handleDateChange(date)}
13+
/>
14+
);
15+
}
16+
17+
export default BasicDateRangePicker;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import Grid from '@material-ui/core/Grid';
3+
import Typography from '@material-ui/core/Typography';
4+
import { DateRangePicker, DateRange } from '@material-ui/pickers';
5+
6+
function CalendarsDateRangePicker() {
7+
const [selectedDate, handleDateChange] = React.useState<DateRange>([null, null]);
8+
9+
return (
10+
<Grid container direction="column" alignItems="center">
11+
<Typography gutterBottom> 1 calendar </Typography>
12+
<DateRangePicker
13+
calendars={1}
14+
value={selectedDate}
15+
onChange={date => handleDateChange(date)}
16+
/>
17+
<Typography gutterBottom> 2 calendars</Typography>
18+
<DateRangePicker
19+
calendars={2}
20+
value={selectedDate}
21+
onChange={date => handleDateChange(date)}
22+
/>
23+
<Typography gutterBottom> 3 calendars</Typography>
24+
<DateRangePicker
25+
calendars={3}
26+
value={selectedDate}
27+
onChange={date => handleDateChange(date)}
28+
/>
29+
</Grid>
30+
);
31+
}
32+
33+
export default CalendarsDateRangePicker;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react';
2+
import addWeeks from 'date-fns/addWeeks';
3+
import { Dayjs } from 'dayjs';
4+
import { Moment } from 'moment';
5+
import { DateTime } from 'luxon';
6+
import { makeJSDateObject } from '../../../utils/helpers';
7+
import { DateRangePicker, DateRange } from '@material-ui/pickers';
8+
9+
function getWeeksAfter(date: Moment | DateTime | Dayjs | Date, amount: number) {
10+
// TODO: replace with implementation for your date library
11+
return date ? addWeeks(makeJSDateObject(date), amount) : undefined;
12+
}
13+
14+
function MinMaxDateRangePicker() {
15+
const [selectedRange, handleDateChange] = React.useState<DateRange>([null, null]);
16+
17+
return (
18+
<DateRangePicker
19+
disablePast
20+
value={selectedRange}
21+
maxDate={getWeeksAfter(selectedRange[0], 4)}
22+
onChange={date => handleDateChange(date)}
23+
/>
24+
);
25+
}
26+
27+
export default MinMaxDateRangePicker;

0 commit comments

Comments
 (0)