@docsvision/material-ui-pickers 3.2.0-beta.24 → 3.2.0-beta.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.size-snapshot.json +11 -11
- package/9db1cba1a61cb58db53f38425bbd1f95.7z +0 -0
- package/build/DatePicker/DatePicker.d.ts +2 -2
- package/build/DatePicker/DatePicker.js +1 -1
- package/build/DateTimePicker/DateTimePicker.js +1 -1
- package/build/Picker/Picker.js +1 -1
- package/build/TimePicker/TimePicker.js +1 -1
- package/build/_helpers/text-field-helper.d.ts +1 -1
- package/build/_shared/KeyboardDateInput.js +1 -1
- package/build/_shared/ModalDialog.d.ts +2 -2
- package/build/_shared/PureDateInput.js +1 -1
- package/build/_shared/ToolbarButton.d.ts +2 -2
- package/build/_shared/hooks/useKeyboardPickerState.js +2 -2
- package/build/constants/prop-types.js +2 -2
- package/build/dist/material-ui-pickers.esm.js +12 -12
- package/build/dist/material-ui-pickers.esm.js.map +1 -1
- package/build/dist/material-ui-pickers.js +62 -62
- package/build/dist/material-ui-pickers.js.map +1 -1
- package/build/dist/material-ui-pickers.umd.js +5790 -4511
- package/build/dist/material-ui-pickers.umd.min.js +1 -1
- package/build/package.json +1 -1
- package/build/views/Calendar/Calendar.js +2 -2
- package/build/views/Clock/Clock.d.ts +1 -1
- package/build/views/Clock/ClockPointer.d.ts +1 -1
- package/package.json +1 -1
- package/src/DatePicker/DatePicker.tsx +91 -0
- package/src/DatePicker/DatePickerToolbar.tsx +75 -0
- package/src/DatePicker/index.ts +7 -0
- package/src/DateTimePicker/DateTimePicker.tsx +72 -0
- package/src/DateTimePicker/DateTimePickerTabs.tsx +86 -0
- package/src/DateTimePicker/DateTimePickerToolbar.tsx +123 -0
- package/src/DateTimePicker/index.ts +7 -0
- package/src/MuiPickersUtilsProvider.tsx +39 -0
- package/src/Picker/Picker.tsx +275 -0
- package/src/Picker/WrappedKeyboardPicker.tsx +136 -0
- package/src/Picker/WrappedPurePicker.tsx +128 -0
- package/src/Rifm/Rifm.ts +213 -0
- package/src/TimePicker/TimePicker.tsx +67 -0
- package/src/TimePicker/TimePickerToolbar.tsx +180 -0
- package/src/TimePicker/index.tsx +7 -0
- package/src/__tests__/DatePicker/Calendar.test.tsx +51 -0
- package/src/__tests__/DatePicker/Month.test.tsx +36 -0
- package/src/__tests__/DatePicker/MonthSelection.test.tsx +37 -0
- package/src/__tests__/MuiPickersUtilsProvider.test.tsx +21 -0
- package/src/__tests__/TimePicker/Clock.test.tsx +68 -0
- package/src/__tests__/_helpers/date-utils.test.tsx +197 -0
- package/src/__tests__/_helpers/text-field-helper.test.tsx +34 -0
- package/src/__tests__/_shared/ModalDialog.test.tsx +109 -0
- package/src/__tests__/e2e/DatePicker.test.tsx +233 -0
- package/src/__tests__/e2e/DatePickerProps.test.tsx +18 -0
- package/src/__tests__/e2e/DatePickerRoot.test.tsx +154 -0
- package/src/__tests__/e2e/DateTimePicker.test.tsx +86 -0
- package/src/__tests__/e2e/DateTimePickerRoot.test.tsx +72 -0
- package/src/__tests__/e2e/KeyboardDatePicker.test.tsx +140 -0
- package/src/__tests__/e2e/KeyboardDateTimePicker.test.tsx +48 -0
- package/src/__tests__/e2e/Theme.test.tsx +30 -0
- package/src/__tests__/e2e/TimePicker.test.tsx +121 -0
- package/src/__tests__/e2e/commands.tsx +8 -0
- package/src/__tests__/setup.js +26 -0
- package/src/__tests__/test-utils.tsx +45 -0
- package/src/__tests__/tsconfig.json +5 -0
- package/src/_helpers/date-utils.ts +92 -0
- package/src/_helpers/text-field-helper.ts +239 -0
- package/src/_helpers/time-utils.ts +83 -0
- package/src/_helpers/utils.ts +8 -0
- package/src/_shared/KeyboardDateInput.tsx +161 -0
- package/src/_shared/ModalDialog.tsx +114 -0
- package/src/_shared/PickerToolbar.tsx +52 -0
- package/src/_shared/PureDateInput.tsx +45 -0
- package/src/_shared/ToolbarButton.tsx +63 -0
- package/src/_shared/ToolbarText.tsx +49 -0
- package/src/_shared/WithUtils.tsx +19 -0
- package/src/_shared/hooks/useIsLandscape.tsx +27 -0
- package/src/_shared/hooks/useKeyDown.ts +34 -0
- package/src/_shared/hooks/useKeyboardPickerState.ts +72 -0
- package/src/_shared/hooks/useOpenState.ts +22 -0
- package/src/_shared/hooks/usePickerState.ts +134 -0
- package/src/_shared/hooks/useUtils.ts +20 -0
- package/src/_shared/hooks/useViews.tsx +31 -0
- package/src/_shared/icons/ArrowLeftIcon.tsx +11 -0
- package/src/_shared/icons/ArrowRightIcon.tsx +11 -0
- package/src/_shared/icons/DateRangeIcon.tsx +11 -0
- package/src/_shared/icons/KeyboardIcon.tsx +11 -0
- package/src/_shared/icons/TimeIcon.tsx +12 -0
- package/src/constants/ClockType.ts +11 -0
- package/src/constants/dimensions.ts +5 -0
- package/src/constants/prop-types.ts +37 -0
- package/src/index.ts +48 -0
- package/src/typings/BasePicker.tsx +60 -0
- package/src/typings/date.ts +3 -0
- package/src/typings/extendMui.ts +10 -0
- package/src/typings/overrides.ts +44 -0
- package/src/views/Calendar/Calendar.tsx +361 -0
- package/src/views/Calendar/CalendarHeader.tsx +141 -0
- package/src/views/Calendar/Day.tsx +97 -0
- package/src/views/Calendar/DayWrapper.tsx +33 -0
- package/src/views/Calendar/SlideTransition.tsx +100 -0
- package/src/views/Clock/Clock.tsx +172 -0
- package/src/views/Clock/ClockNumber.tsx +91 -0
- package/src/views/Clock/ClockNumbers.tsx +76 -0
- package/src/views/Clock/ClockPointer.tsx +104 -0
- package/src/views/Clock/ClockView.tsx +105 -0
- package/src/views/Month/Month.tsx +76 -0
- package/src/views/Month/MonthView.tsx +94 -0
- package/src/views/Year/Year.tsx +77 -0
- package/src/views/Year/YearView.tsx +91 -0
- package/src/wrappers/InlineWrapper.tsx +80 -0
- package/src/wrappers/ModalWrapper.tsx +113 -0
- package/src/wrappers/StaticWrapper.tsx +22 -0
- package/src/wrappers/Wrapper.tsx +75 -0
- package/coverage/clover.xml +0 -601
- package/coverage/coverage-final.json +0 -22
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/index.html +0 -201
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/src/MuiPickersUtilsProvider.tsx.html +0 -186
- package/coverage/lcov-report/src/_helpers/date-utils.ts.html +0 -345
- package/coverage/lcov-report/src/_helpers/index.html +0 -123
- package/coverage/lcov-report/src/_helpers/time-utils.ts.html +0 -318
- package/coverage/lcov-report/src/_helpers/utils.ts.html +0 -93
- package/coverage/lcov-report/src/_shared/ModalDialog.tsx.html +0 -411
- package/coverage/lcov-report/src/_shared/WithUtils.tsx.html +0 -126
- package/coverage/lcov-report/src/_shared/hooks/index.html +0 -110
- package/coverage/lcov-report/src/_shared/hooks/useKeyDown.ts.html +0 -171
- package/coverage/lcov-report/src/_shared/hooks/useUtils.ts.html +0 -129
- package/coverage/lcov-report/src/_shared/icons/ArrowLeftIcon.tsx.html +0 -102
- package/coverage/lcov-report/src/_shared/icons/ArrowRightIcon.tsx.html +0 -102
- package/coverage/lcov-report/src/_shared/icons/index.html +0 -110
- package/coverage/lcov-report/src/_shared/index.html +0 -110
- package/coverage/lcov-report/src/constants/ClockType.ts.html +0 -102
- package/coverage/lcov-report/src/constants/dimensions.ts.html +0 -84
- package/coverage/lcov-report/src/constants/index.html +0 -110
- package/coverage/lcov-report/src/index.html +0 -97
- package/coverage/lcov-report/src/views/Calendar/Calendar.tsx.html +0 -1152
- package/coverage/lcov-report/src/views/Calendar/CalendarHeader.tsx.html +0 -492
- package/coverage/lcov-report/src/views/Calendar/Day.tsx.html +0 -360
- package/coverage/lcov-report/src/views/Calendar/DayWrapper.tsx.html +0 -168
- package/coverage/lcov-report/src/views/Calendar/SlideTransition.tsx.html +0 -369
- package/coverage/lcov-report/src/views/Calendar/index.html +0 -149
- package/coverage/lcov-report/src/views/Clock/Clock.tsx.html +0 -585
- package/coverage/lcov-report/src/views/Clock/ClockPointer.tsx.html +0 -381
- package/coverage/lcov-report/src/views/Clock/index.html +0 -110
- package/coverage/lcov-report/src/views/Month/Month.tsx.html +0 -297
- package/coverage/lcov-report/src/views/Month/MonthView.tsx.html +0 -351
- package/coverage/lcov-report/src/views/Month/index.html +0 -110
- package/coverage/lcov.info +0 -1094
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docsvision/material-ui-pickers",
|
|
3
|
-
"version": "3.2.0-beta.
|
|
3
|
+
"version": "3.2.0-beta.26",
|
|
4
4
|
"description": "Fork @material-ui/pickers that implements advanced features required for DocsVision WebClient. Original repository https://github.com/mui-org/material-ui-pickers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"material-ui",
|
|
@@ -79,7 +79,7 @@ var Calendar = /** @class */ (function (_super) {
|
|
|
79
79
|
var now = utils.date();
|
|
80
80
|
var moment = utils.moment;
|
|
81
81
|
return Boolean((disableFuture && utils.isAfterDay(day, now)) ||
|
|
82
|
-
(disablePast && moment(day).isBefore(now,
|
|
82
|
+
(disablePast && moment(day).isBefore(now, 'second')) ||
|
|
83
83
|
(minDate && utils.isBeforeDay(day, utils.date(minDate))) ||
|
|
84
84
|
(maxDate && utils.isAfterDay(day, utils.date(maxDate))));
|
|
85
85
|
};
|
|
@@ -195,7 +195,7 @@ var Calendar = /** @class */ (function (_super) {
|
|
|
195
195
|
};
|
|
196
196
|
Calendar.defaultProps = {
|
|
197
197
|
minDate: new Date('1900-01-01'),
|
|
198
|
-
maxDate: new Date('
|
|
198
|
+
maxDate: new Date('2200-01-01'),
|
|
199
199
|
disablePast: false,
|
|
200
200
|
disableFuture: false,
|
|
201
201
|
allowKeyboardControl: true,
|
|
@@ -24,6 +24,6 @@ export declare class Clock extends React.Component<ClockProps> {
|
|
|
24
24
|
hasSelected: () => boolean;
|
|
25
25
|
render(): JSX.Element;
|
|
26
26
|
}
|
|
27
|
-
export declare const styles: (theme: Theme) => Record<"container" | "clock" | "squareMask" | "pin", import("@material-ui/
|
|
27
|
+
export declare const styles: (theme: Theme) => Record<"container" | "clock" | "squareMask" | "pin", import("@material-ui/styles").CSSProperties | (() => import("@material-ui/styles").CSSProperties)>;
|
|
28
28
|
declare const _default: React.ComponentType<(Pick<ClockProps, "children" | "onChange" | "type" | "value" | "ampm" | "minutesStep"> & import("@material-ui/core/styles").StyledComponentProps<"container" | "clock" | "squareMask" | "pin">) | (Pick<React.PropsWithChildren<ClockProps>, "children" | "onChange" | "type" | "value" | "ampm" | "minutesStep"> & import("@material-ui/core/styles").StyledComponentProps<"container" | "clock" | "squareMask" | "pin">)>;
|
|
29
29
|
export default _default;
|
|
@@ -26,6 +26,6 @@ export declare class ClockPointer extends React.Component<ClockPointerProps> {
|
|
|
26
26
|
};
|
|
27
27
|
render(): JSX.Element;
|
|
28
28
|
}
|
|
29
|
-
export declare const styles: (theme: Theme) => Record<"animateTransform" | "pointer" | "thumb" | "noPoint", import("@material-ui/
|
|
29
|
+
export declare const styles: (theme: Theme) => Record<"animateTransform" | "pointer" | "thumb" | "noPoint", import("@material-ui/styles").CSSProperties | (() => import("@material-ui/styles").CSSProperties)>;
|
|
30
30
|
declare const _default: React.ComponentType<(Pick<ClockPointerProps, "type" | "value" | "hasSelected" | "isInner"> & import("@material-ui/core").StyledComponentProps<"animateTransform" | "pointer" | "thumb" | "noPoint">) | (Pick<React.PropsWithChildren<ClockPointerProps>, "children" | "type" | "value" | "hasSelected" | "isInner"> & import("@material-ui/core").StyledComponentProps<"animateTransform" | "pointer" | "thumb" | "noPoint">)>;
|
|
31
31
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docsvision/material-ui-pickers",
|
|
3
|
-
"version": "3.2.0-beta.
|
|
3
|
+
"version": "3.2.0-beta.26",
|
|
4
4
|
"description": "Fork @material-ui/pickers that implements advanced features required for DocsVision WebClient. Original repository https://github.com/mui-org/material-ui-pickers",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useUtils } from '../_shared/hooks/useUtils';
|
|
2
|
+
import { DatePickerToolbar } from './DatePickerToolbar';
|
|
3
|
+
import { MaterialUiPickersDate } from '../typings/date';
|
|
4
|
+
import { getFormatByViews } from '../_helpers/date-utils';
|
|
5
|
+
import { OutterCalendarProps } from '../views/Calendar/Calendar';
|
|
6
|
+
import { datePickerDefaultProps, ParsableDate } from '../constants/prop-types';
|
|
7
|
+
import { WrappedPurePickerProps, makePurePicker } from '../Picker/WrappedPurePicker';
|
|
8
|
+
import { makeKeyboardPicker, WrappedKeyboardPickerProps } from '../Picker/WrappedKeyboardPicker';
|
|
9
|
+
|
|
10
|
+
export type DatePickerView = 'year' | 'date' | 'month';
|
|
11
|
+
|
|
12
|
+
export interface BaseDatePickerProps extends OutterCalendarProps {
|
|
13
|
+
/**
|
|
14
|
+
* Min selectable date
|
|
15
|
+
* @default Date(1900-01-01)
|
|
16
|
+
*/
|
|
17
|
+
minDate?: ParsableDate;
|
|
18
|
+
/**
|
|
19
|
+
* Max selectable date
|
|
20
|
+
* @default Date(2200-01-01)
|
|
21
|
+
*/
|
|
22
|
+
maxDate?: ParsableDate;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Compare dates by the exact timestamp, instead of start/end of date
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
strictCompareDates?: boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Disable past dates
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
disablePast?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Disable future dates
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
disableFuture?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* To animate scrolling to current year (using scrollIntoView)
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
animateYearScrolling?: boolean;
|
|
45
|
+
/** Callback firing on year change */
|
|
46
|
+
onYearChange?: (date: MaterialUiPickersDate) => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface DatePickerViewsProps extends BaseDatePickerProps {
|
|
50
|
+
/**
|
|
51
|
+
* Array of views to show
|
|
52
|
+
* @type {Array<"year" | "date" | "month">}
|
|
53
|
+
*/
|
|
54
|
+
views?: DatePickerView[];
|
|
55
|
+
/** Open to DatePicker */
|
|
56
|
+
openTo?: DatePickerView;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type DatePickerProps = WrappedPurePickerProps & DatePickerViewsProps;
|
|
60
|
+
|
|
61
|
+
export type KeyboardDatePickerProps = WrappedKeyboardPickerProps & DatePickerViewsProps;
|
|
62
|
+
|
|
63
|
+
const defaultProps = {
|
|
64
|
+
...datePickerDefaultProps,
|
|
65
|
+
openTo: 'date' as DatePickerView,
|
|
66
|
+
views: ['year', 'date'] as DatePickerView[],
|
|
67
|
+
showActionsBar: false,
|
|
68
|
+
todayLabel: 'TODAY',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function useOptions(props: DatePickerViewsProps) {
|
|
72
|
+
const utils = useUtils();
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
getDefaultFormat: () => getFormatByViews(props.views!, utils),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const DatePicker = makePurePicker<DatePickerViewsProps>({
|
|
80
|
+
useOptions,
|
|
81
|
+
DefaultToolbarComponent: DatePickerToolbar,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const KeyboardDatePicker = makeKeyboardPicker<DatePickerViewsProps>({
|
|
85
|
+
useOptions,
|
|
86
|
+
DefaultToolbarComponent: DatePickerToolbar,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
DatePicker.defaultProps = defaultProps;
|
|
90
|
+
|
|
91
|
+
KeyboardDatePicker.defaultProps = defaultProps;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import ToolbarButton from '../_shared/ToolbarButton';
|
|
4
|
+
import PickerToolbar from '../_shared/PickerToolbar';
|
|
5
|
+
import { useUtils } from '../_shared/hooks/useUtils';
|
|
6
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
7
|
+
import { ToolbarComponentProps } from '../Picker/Picker';
|
|
8
|
+
import { isYearAndMonthViews, isYearOnlyView } from '../_helpers/date-utils';
|
|
9
|
+
|
|
10
|
+
export const useStyles = makeStyles(
|
|
11
|
+
{
|
|
12
|
+
toolbar: {
|
|
13
|
+
flexDirection: 'column',
|
|
14
|
+
alignItems: 'flex-start',
|
|
15
|
+
},
|
|
16
|
+
toolbarLandscape: {
|
|
17
|
+
padding: 16,
|
|
18
|
+
},
|
|
19
|
+
dateLandscape: {
|
|
20
|
+
marginRight: 16,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{ name: 'MuiPickersDatePickerRoot' }
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
export const DatePickerToolbar: React.FC<ToolbarComponentProps> = ({
|
|
27
|
+
date,
|
|
28
|
+
views,
|
|
29
|
+
setOpenView,
|
|
30
|
+
isLandscape,
|
|
31
|
+
openView,
|
|
32
|
+
}) => {
|
|
33
|
+
const utils = useUtils();
|
|
34
|
+
const classes = useStyles();
|
|
35
|
+
|
|
36
|
+
const isYearOnly = React.useMemo(() => isYearOnlyView(views as any), [views]);
|
|
37
|
+
const isYearAndMonth = React.useMemo(() => isYearAndMonthViews(views as any), [views]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<PickerToolbar
|
|
41
|
+
isLandscape={isLandscape}
|
|
42
|
+
className={clsx({
|
|
43
|
+
[classes.toolbar]: !isYearOnly,
|
|
44
|
+
[classes.toolbarLandscape]: isLandscape,
|
|
45
|
+
})}
|
|
46
|
+
>
|
|
47
|
+
<ToolbarButton
|
|
48
|
+
variant={isYearOnly ? 'h3' : 'subtitle1'}
|
|
49
|
+
onClick={() => setOpenView('year')}
|
|
50
|
+
selected={openView === 'year'}
|
|
51
|
+
label={utils.getYearText(date)}
|
|
52
|
+
/>
|
|
53
|
+
|
|
54
|
+
{!isYearOnly && !isYearAndMonth && (
|
|
55
|
+
<ToolbarButton
|
|
56
|
+
variant="h4"
|
|
57
|
+
selected={openView === 'date'}
|
|
58
|
+
onClick={() => setOpenView('date')}
|
|
59
|
+
align={isLandscape ? 'left' : 'center'}
|
|
60
|
+
label={utils.getDatePickerHeaderText(date)}
|
|
61
|
+
className={clsx({ [classes.dateLandscape]: isLandscape })}
|
|
62
|
+
/>
|
|
63
|
+
)}
|
|
64
|
+
|
|
65
|
+
{isYearAndMonth && (
|
|
66
|
+
<ToolbarButton
|
|
67
|
+
variant="h4"
|
|
68
|
+
onClick={() => setOpenView('month')}
|
|
69
|
+
selected={openView === 'month'}
|
|
70
|
+
label={utils.getMonthText(date)}
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
</PickerToolbar>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useUtils } from '../_shared/hooks/useUtils';
|
|
2
|
+
import { BaseDatePickerProps } from '../DatePicker/DatePicker';
|
|
3
|
+
import { BaseTimePickerProps } from '../TimePicker/TimePicker';
|
|
4
|
+
import { DateTimePickerToolbar } from './DateTimePickerToolbar';
|
|
5
|
+
import { pick12hOr24hFormat } from '../_helpers/text-field-helper';
|
|
6
|
+
import { dateTimePickerDefaultProps } from '../constants/prop-types';
|
|
7
|
+
import { WrappedPurePickerProps, makePurePicker } from '../Picker/WrappedPurePicker';
|
|
8
|
+
import { makeKeyboardPicker, WrappedKeyboardPickerProps } from '../Picker/WrappedKeyboardPicker';
|
|
9
|
+
|
|
10
|
+
export type DateTimePickerView = 'year' | 'date' | 'month' | 'hours' | 'minutes';
|
|
11
|
+
|
|
12
|
+
export type BaseDateTimePickerProps = BaseTimePickerProps & BaseDatePickerProps;
|
|
13
|
+
|
|
14
|
+
export interface DateTimePickerViewsProps extends BaseDateTimePickerProps {
|
|
15
|
+
/** Array of views to show */
|
|
16
|
+
views?: ('year' | 'date' | 'month' | 'hours' | 'minutes')[];
|
|
17
|
+
/** Open to DatePicker */
|
|
18
|
+
openTo?: 'year' | 'date' | 'month' | 'hours' | 'minutes';
|
|
19
|
+
/** To show tabs */
|
|
20
|
+
hideTabs?: boolean;
|
|
21
|
+
/** Date tab icon */
|
|
22
|
+
dateRangeIcon?: React.ReactNode;
|
|
23
|
+
/** Time tab icon */
|
|
24
|
+
timeIcon?: React.ReactNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type DateTimePickerProps = WrappedPurePickerProps & DateTimePickerViewsProps;
|
|
28
|
+
|
|
29
|
+
export type KeyboardDateTimePickerProps = WrappedKeyboardPickerProps & DateTimePickerViewsProps;
|
|
30
|
+
|
|
31
|
+
const defaultProps = {
|
|
32
|
+
...dateTimePickerDefaultProps,
|
|
33
|
+
showActionsBar: false,
|
|
34
|
+
todayLabel: 'TODAY',
|
|
35
|
+
wider: true,
|
|
36
|
+
orientation: 'portrait' as const,
|
|
37
|
+
openTo: 'date' as DateTimePickerView,
|
|
38
|
+
views: ['year', 'date', 'hours', 'minutes'] as DateTimePickerView[],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function useOptions(props: DateTimePickerProps | KeyboardDateTimePickerProps) {
|
|
42
|
+
const utils = useUtils();
|
|
43
|
+
|
|
44
|
+
if (props.orientation !== 'portrait') {
|
|
45
|
+
throw new Error('We are not supporting custom orientation for DateTimePicker yet :(');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
getDefaultFormat: () =>
|
|
50
|
+
pick12hOr24hFormat(props.format, props.ampm, {
|
|
51
|
+
'12h': utils.dateTime12hFormat,
|
|
52
|
+
'24h': utils.dateTime24hFormat,
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const DateTimePicker = makePurePicker<DateTimePickerProps>({
|
|
58
|
+
useOptions,
|
|
59
|
+
DefaultToolbarComponent: DateTimePickerToolbar,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const KeyboardDateTimePicker = makeKeyboardPicker<KeyboardDateTimePickerProps>({
|
|
63
|
+
useOptions,
|
|
64
|
+
DefaultToolbarComponent: DateTimePickerToolbar,
|
|
65
|
+
getCustomProps: props => ({
|
|
66
|
+
refuse: props.ampm ? /[^\dap]+/gi : /[^\d]+/gi,
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
DateTimePicker.defaultProps = defaultProps;
|
|
71
|
+
|
|
72
|
+
KeyboardDateTimePicker.defaultProps = defaultProps;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import Tab from '@material-ui/core/Tab';
|
|
3
|
+
import Tabs from '@material-ui/core/Tabs';
|
|
4
|
+
import Paper from '@material-ui/core/Paper';
|
|
5
|
+
import { TimeIcon } from '../_shared/icons/TimeIcon';
|
|
6
|
+
import { DateTimePickerView } from './DateTimePicker';
|
|
7
|
+
import { DateRangeIcon } from '../_shared/icons/DateRangeIcon';
|
|
8
|
+
import { makeStyles, useTheme } from '@material-ui/core/styles';
|
|
9
|
+
|
|
10
|
+
const viewToTabIndex = (openView: DateTimePickerView) => {
|
|
11
|
+
if (openView === 'date' || openView === 'year') {
|
|
12
|
+
return 'date';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return 'time';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const tabIndexToView = (tab: DateTimePickerView) => {
|
|
19
|
+
if (tab === 'date') {
|
|
20
|
+
return 'date';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return 'hours';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface DateTimePickerTabsProps {
|
|
27
|
+
view: DateTimePickerView;
|
|
28
|
+
onChange: (view: DateTimePickerView) => void;
|
|
29
|
+
dateRangeIcon?: React.ReactNode;
|
|
30
|
+
timeIcon?: React.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const useStyles = makeStyles(
|
|
34
|
+
theme => {
|
|
35
|
+
// prettier-ignore
|
|
36
|
+
const tabsBackground = theme.palette.type === 'light'
|
|
37
|
+
? theme.palette.primary.main
|
|
38
|
+
: theme.palette.background.default;
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
tabs: {
|
|
42
|
+
color: theme.palette.getContrastText(tabsBackground),
|
|
43
|
+
backgroundColor: tabsBackground,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
{ name: 'MuiPickerDTTabs' }
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const DateTimePickerTabs: React.SFC<DateTimePickerTabsProps> = ({
|
|
51
|
+
view,
|
|
52
|
+
onChange,
|
|
53
|
+
dateRangeIcon,
|
|
54
|
+
timeIcon,
|
|
55
|
+
}) => {
|
|
56
|
+
const classes = useStyles();
|
|
57
|
+
const theme = useTheme();
|
|
58
|
+
const indicatorColor = theme.palette.type === 'light' ? 'secondary' : 'primary';
|
|
59
|
+
const handleChange = (e: React.ChangeEvent<{}>, value: DateTimePickerView) => {
|
|
60
|
+
if (value !== viewToTabIndex(view)) {
|
|
61
|
+
onChange(tabIndexToView(value));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Paper>
|
|
67
|
+
<Tabs
|
|
68
|
+
variant="fullWidth"
|
|
69
|
+
value={viewToTabIndex(view)}
|
|
70
|
+
onChange={handleChange}
|
|
71
|
+
className={classes.tabs}
|
|
72
|
+
indicatorColor={indicatorColor}
|
|
73
|
+
>
|
|
74
|
+
<Tab value="date" icon={<>{dateRangeIcon}</>} />
|
|
75
|
+
<Tab value="time" icon={<>{timeIcon}</>} />
|
|
76
|
+
</Tabs>
|
|
77
|
+
</Paper>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
DateTimePickerTabs.defaultProps = {
|
|
82
|
+
dateRangeIcon: <DateRangeIcon />,
|
|
83
|
+
timeIcon: <TimeIcon />,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default DateTimePickerTabs;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import ToolbarText from '../_shared/ToolbarText';
|
|
3
|
+
import PickerToolbar from '../_shared/PickerToolbar';
|
|
4
|
+
import ToolbarButton from '../_shared/ToolbarButton';
|
|
5
|
+
import DateTimePickerTabs from './DateTimePickerTabs';
|
|
6
|
+
import { Grid } from '@material-ui/core';
|
|
7
|
+
import { useUtils } from '../_shared/hooks/useUtils';
|
|
8
|
+
import { DateTimePickerView } from './DateTimePicker';
|
|
9
|
+
import { ToolbarComponentProps } from '../Picker/Picker';
|
|
10
|
+
import { makeStyles, useTheme } from '@material-ui/core/styles';
|
|
11
|
+
import { useMeridiemMode } from '../TimePicker/TimePickerToolbar';
|
|
12
|
+
|
|
13
|
+
export const useStyles = makeStyles(
|
|
14
|
+
_ => ({
|
|
15
|
+
toolbar: {
|
|
16
|
+
paddingLeft: 16,
|
|
17
|
+
paddingRight: 16,
|
|
18
|
+
justifyContent: 'space-around',
|
|
19
|
+
},
|
|
20
|
+
separator: {
|
|
21
|
+
margin: '0 4px 0 2px',
|
|
22
|
+
cursor: 'default',
|
|
23
|
+
},
|
|
24
|
+
}),
|
|
25
|
+
{ name: 'MuiPickerDTToolbar' }
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const DateTimePickerToolbar: React.FC<ToolbarComponentProps> = ({
|
|
29
|
+
date,
|
|
30
|
+
openView,
|
|
31
|
+
setOpenView,
|
|
32
|
+
ampm,
|
|
33
|
+
hideTabs,
|
|
34
|
+
dateRangeIcon,
|
|
35
|
+
timeIcon,
|
|
36
|
+
onChange,
|
|
37
|
+
}) => {
|
|
38
|
+
const utils = useUtils();
|
|
39
|
+
const classes = useStyles();
|
|
40
|
+
const showTabs = !hideTabs && typeof window !== 'undefined' && window.innerHeight > 667;
|
|
41
|
+
const { meridiemMode, handleMeridiemChange } = useMeridiemMode(date, ampm, onChange);
|
|
42
|
+
const theme = useTheme();
|
|
43
|
+
const rtl = theme.direction === 'rtl';
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<>
|
|
47
|
+
<PickerToolbar isLandscape={false} className={classes.toolbar}>
|
|
48
|
+
<Grid container justify="center" wrap="nowrap">
|
|
49
|
+
<Grid item container xs={5} justify="flex-start" direction="column">
|
|
50
|
+
<div>
|
|
51
|
+
<ToolbarButton
|
|
52
|
+
variant="subtitle1"
|
|
53
|
+
onClick={() => setOpenView('year')}
|
|
54
|
+
selected={openView === 'year'}
|
|
55
|
+
label={utils.getYearText(date)}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
<div>
|
|
59
|
+
<ToolbarButton
|
|
60
|
+
variant="h4"
|
|
61
|
+
onClick={() => setOpenView('date')}
|
|
62
|
+
selected={openView === 'date'}
|
|
63
|
+
label={utils.getDateTimePickerHeaderText(date)}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
</Grid>
|
|
67
|
+
|
|
68
|
+
<Grid
|
|
69
|
+
item
|
|
70
|
+
container
|
|
71
|
+
xs={6}
|
|
72
|
+
justify="center"
|
|
73
|
+
alignItems="flex-end"
|
|
74
|
+
direction={rtl ? 'row-reverse' : 'row'}
|
|
75
|
+
>
|
|
76
|
+
<ToolbarButton
|
|
77
|
+
variant="h3"
|
|
78
|
+
onClick={() => setOpenView('hours')}
|
|
79
|
+
selected={openView === 'hours'}
|
|
80
|
+
label={utils.getHourText(date, ampm!)}
|
|
81
|
+
/>
|
|
82
|
+
|
|
83
|
+
<ToolbarText variant="h3" label=":" className={classes.separator} />
|
|
84
|
+
|
|
85
|
+
<ToolbarButton
|
|
86
|
+
variant="h3"
|
|
87
|
+
onClick={() => setOpenView('minutes')}
|
|
88
|
+
selected={openView === 'minutes'}
|
|
89
|
+
label={utils.getMinuteText(date)}
|
|
90
|
+
/>
|
|
91
|
+
</Grid>
|
|
92
|
+
|
|
93
|
+
{ampm && (
|
|
94
|
+
<Grid item container xs={1} direction="column" justify="flex-end">
|
|
95
|
+
<ToolbarButton
|
|
96
|
+
variant="subtitle1"
|
|
97
|
+
selected={meridiemMode === 'am'}
|
|
98
|
+
label={utils.getMeridiemText('am')}
|
|
99
|
+
onClick={() => handleMeridiemChange('am')}
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
<ToolbarButton
|
|
103
|
+
variant="subtitle1"
|
|
104
|
+
selected={meridiemMode === 'pm'}
|
|
105
|
+
label={utils.getMeridiemText('pm')}
|
|
106
|
+
onClick={() => handleMeridiemChange('pm')}
|
|
107
|
+
/>
|
|
108
|
+
</Grid>
|
|
109
|
+
)}
|
|
110
|
+
</Grid>
|
|
111
|
+
</PickerToolbar>
|
|
112
|
+
|
|
113
|
+
{showTabs && (
|
|
114
|
+
<DateTimePickerTabs
|
|
115
|
+
dateRangeIcon={dateRangeIcon}
|
|
116
|
+
timeIcon={timeIcon}
|
|
117
|
+
view={openView as DateTimePickerView}
|
|
118
|
+
onChange={setOpenView}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DateTimePickerProps, KeyboardDateTimePickerProps } from './DateTimePicker';
|
|
2
|
+
|
|
3
|
+
export type DateTimePickerProps = DateTimePickerProps;
|
|
4
|
+
|
|
5
|
+
export type KeyboardDateTimePickerProps = KeyboardDateTimePickerProps;
|
|
6
|
+
|
|
7
|
+
export { KeyboardDateTimePicker, DateTimePicker } from './DateTimePicker';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as PropTypes from 'prop-types';
|
|
3
|
+
import { IUtils } from '@date-io/core/IUtils';
|
|
4
|
+
import { MaterialUiPickersDate } from './typings/date';
|
|
5
|
+
|
|
6
|
+
export const MuiPickersContext = React.createContext<IUtils<MaterialUiPickersDate> | null>(null);
|
|
7
|
+
|
|
8
|
+
export interface MuiPickersUtilsProviderProps {
|
|
9
|
+
utils: any;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
locale?: any;
|
|
12
|
+
libInstance?: any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const MuiPickersUtilsProvider: React.FC<MuiPickersUtilsProviderProps> = ({
|
|
16
|
+
utils: Utils,
|
|
17
|
+
children,
|
|
18
|
+
locale,
|
|
19
|
+
libInstance,
|
|
20
|
+
}) => {
|
|
21
|
+
const utils = React.useMemo(() => new Utils({ locale, moment: libInstance }), [
|
|
22
|
+
Utils,
|
|
23
|
+
libInstance,
|
|
24
|
+
locale,
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
return <MuiPickersContext.Provider value={utils} children={children} />;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
MuiPickersUtilsProvider.propTypes = {
|
|
31
|
+
utils: PropTypes.func.isRequired,
|
|
32
|
+
locale: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
33
|
+
children: PropTypes.oneOfType([
|
|
34
|
+
PropTypes.element.isRequired,
|
|
35
|
+
PropTypes.arrayOf(PropTypes.element.isRequired),
|
|
36
|
+
]).isRequired,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default MuiPickersUtilsProvider;
|