@docsvision/material-ui-pickers 3.2.0-beta.25 → 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.
Files changed (232) hide show
  1. package/.size-snapshot.json +26 -0
  2. package/9db1cba1a61cb58db53f38425bbd1f95.7z +0 -0
  3. package/{DatePicker → build/DatePicker}/DatePicker.d.ts +2 -2
  4. package/{DatePicker → build/DatePicker}/DatePicker.js +1 -1
  5. package/{DateTimePicker → build/DateTimePicker}/DateTimePicker.js +1 -1
  6. package/{Picker → build/Picker}/Picker.js +1 -1
  7. package/{TimePicker → build/TimePicker}/TimePicker.js +1 -1
  8. package/{_helpers → build/_helpers}/text-field-helper.d.ts +1 -1
  9. package/{_shared → build/_shared}/KeyboardDateInput.js +1 -1
  10. package/{_shared → build/_shared}/ModalDialog.d.ts +2 -2
  11. package/{_shared → build/_shared}/PureDateInput.js +1 -1
  12. package/{_shared → build/_shared}/ToolbarButton.d.ts +2 -2
  13. package/{_shared → build/_shared}/hooks/useKeyboardPickerState.js +2 -2
  14. package/{constants → build/constants}/prop-types.js +2 -2
  15. package/{dist → build/dist}/material-ui-pickers.esm.js +12 -12
  16. package/build/dist/material-ui-pickers.esm.js.map +1 -0
  17. package/{dist → build/dist}/material-ui-pickers.js +62 -62
  18. package/build/dist/material-ui-pickers.js.map +1 -0
  19. package/{dist → build/dist}/material-ui-pickers.umd.js +5790 -4511
  20. package/build/dist/material-ui-pickers.umd.min.js +1 -0
  21. package/build/package.json +62 -0
  22. package/{views → build/views}/Calendar/Calendar.js +2 -2
  23. package/{views → build/views}/Clock/Clock.d.ts +1 -1
  24. package/{views → build/views}/Clock/ClockPointer.d.ts +1 -1
  25. package/copy.js +58 -0
  26. package/package.json +135 -62
  27. package/remove-prop-types.js +37 -0
  28. package/rollup.config.js +145 -0
  29. package/src/DatePicker/DatePicker.tsx +91 -0
  30. package/src/DatePicker/DatePickerToolbar.tsx +75 -0
  31. package/src/DatePicker/index.ts +7 -0
  32. package/src/DateTimePicker/DateTimePicker.tsx +72 -0
  33. package/src/DateTimePicker/DateTimePickerTabs.tsx +86 -0
  34. package/src/DateTimePicker/DateTimePickerToolbar.tsx +123 -0
  35. package/src/DateTimePicker/index.ts +7 -0
  36. package/src/MuiPickersUtilsProvider.tsx +39 -0
  37. package/src/Picker/Picker.tsx +275 -0
  38. package/src/Picker/WrappedKeyboardPicker.tsx +136 -0
  39. package/src/Picker/WrappedPurePicker.tsx +128 -0
  40. package/src/Rifm/Rifm.ts +213 -0
  41. package/src/TimePicker/TimePicker.tsx +67 -0
  42. package/src/TimePicker/TimePickerToolbar.tsx +180 -0
  43. package/src/TimePicker/index.tsx +7 -0
  44. package/src/__tests__/DatePicker/Calendar.test.tsx +51 -0
  45. package/src/__tests__/DatePicker/Month.test.tsx +36 -0
  46. package/src/__tests__/DatePicker/MonthSelection.test.tsx +37 -0
  47. package/src/__tests__/MuiPickersUtilsProvider.test.tsx +21 -0
  48. package/src/__tests__/TimePicker/Clock.test.tsx +68 -0
  49. package/src/__tests__/_helpers/date-utils.test.tsx +197 -0
  50. package/src/__tests__/_helpers/text-field-helper.test.tsx +34 -0
  51. package/src/__tests__/_shared/ModalDialog.test.tsx +109 -0
  52. package/src/__tests__/e2e/DatePicker.test.tsx +233 -0
  53. package/src/__tests__/e2e/DatePickerProps.test.tsx +18 -0
  54. package/src/__tests__/e2e/DatePickerRoot.test.tsx +154 -0
  55. package/src/__tests__/e2e/DateTimePicker.test.tsx +86 -0
  56. package/src/__tests__/e2e/DateTimePickerRoot.test.tsx +72 -0
  57. package/src/__tests__/e2e/KeyboardDatePicker.test.tsx +140 -0
  58. package/src/__tests__/e2e/KeyboardDateTimePicker.test.tsx +48 -0
  59. package/src/__tests__/e2e/Theme.test.tsx +30 -0
  60. package/src/__tests__/e2e/TimePicker.test.tsx +121 -0
  61. package/src/__tests__/e2e/commands.tsx +8 -0
  62. package/src/__tests__/setup.js +26 -0
  63. package/src/__tests__/test-utils.tsx +45 -0
  64. package/src/__tests__/tsconfig.json +5 -0
  65. package/src/_helpers/date-utils.ts +92 -0
  66. package/src/_helpers/text-field-helper.ts +239 -0
  67. package/src/_helpers/time-utils.ts +83 -0
  68. package/src/_helpers/utils.ts +8 -0
  69. package/src/_shared/KeyboardDateInput.tsx +161 -0
  70. package/src/_shared/ModalDialog.tsx +114 -0
  71. package/src/_shared/PickerToolbar.tsx +52 -0
  72. package/src/_shared/PureDateInput.tsx +45 -0
  73. package/src/_shared/ToolbarButton.tsx +63 -0
  74. package/src/_shared/ToolbarText.tsx +49 -0
  75. package/src/_shared/WithUtils.tsx +19 -0
  76. package/src/_shared/hooks/useIsLandscape.tsx +27 -0
  77. package/src/_shared/hooks/useKeyDown.ts +34 -0
  78. package/src/_shared/hooks/useKeyboardPickerState.ts +72 -0
  79. package/src/_shared/hooks/useOpenState.ts +22 -0
  80. package/src/_shared/hooks/usePickerState.ts +134 -0
  81. package/src/_shared/hooks/useUtils.ts +20 -0
  82. package/src/_shared/hooks/useViews.tsx +31 -0
  83. package/src/_shared/icons/ArrowLeftIcon.tsx +11 -0
  84. package/src/_shared/icons/ArrowRightIcon.tsx +11 -0
  85. package/src/_shared/icons/DateRangeIcon.tsx +11 -0
  86. package/src/_shared/icons/KeyboardIcon.tsx +11 -0
  87. package/src/_shared/icons/TimeIcon.tsx +12 -0
  88. package/src/constants/ClockType.ts +11 -0
  89. package/src/constants/dimensions.ts +5 -0
  90. package/src/constants/prop-types.ts +37 -0
  91. package/src/index.ts +48 -0
  92. package/src/typings/BasePicker.tsx +60 -0
  93. package/src/typings/date.ts +3 -0
  94. package/src/typings/extendMui.ts +10 -0
  95. package/src/typings/overrides.ts +44 -0
  96. package/src/views/Calendar/Calendar.tsx +361 -0
  97. package/src/views/Calendar/CalendarHeader.tsx +141 -0
  98. package/src/views/Calendar/Day.tsx +97 -0
  99. package/src/views/Calendar/DayWrapper.tsx +33 -0
  100. package/src/views/Calendar/SlideTransition.tsx +100 -0
  101. package/src/views/Clock/Clock.tsx +172 -0
  102. package/src/views/Clock/ClockNumber.tsx +91 -0
  103. package/src/views/Clock/ClockNumbers.tsx +76 -0
  104. package/src/views/Clock/ClockPointer.tsx +104 -0
  105. package/src/views/Clock/ClockView.tsx +105 -0
  106. package/src/views/Month/Month.tsx +76 -0
  107. package/src/views/Month/MonthView.tsx +94 -0
  108. package/src/views/Year/Year.tsx +77 -0
  109. package/src/views/Year/YearView.tsx +91 -0
  110. package/src/wrappers/InlineWrapper.tsx +80 -0
  111. package/src/wrappers/ModalWrapper.tsx +113 -0
  112. package/src/wrappers/StaticWrapper.tsx +22 -0
  113. package/src/wrappers/Wrapper.tsx +75 -0
  114. package/tsconfig.json +21 -0
  115. package/typings.d.ts +6 -0
  116. package/dist/material-ui-pickers.esm.js.map +0 -1
  117. package/dist/material-ui-pickers.js.map +0 -1
  118. package/dist/material-ui-pickers.umd.min.js +0 -1
  119. /package/{DatePicker → build/DatePicker}/DatePickerToolbar.d.ts +0 -0
  120. /package/{DatePicker → build/DatePicker}/DatePickerToolbar.js +0 -0
  121. /package/{DatePicker → build/DatePicker}/index.d.ts +0 -0
  122. /package/{DatePicker → build/DatePicker}/index.js +0 -0
  123. /package/{DateTimePicker → build/DateTimePicker}/DateTimePicker.d.ts +0 -0
  124. /package/{DateTimePicker → build/DateTimePicker}/DateTimePickerTabs.d.ts +0 -0
  125. /package/{DateTimePicker → build/DateTimePicker}/DateTimePickerTabs.js +0 -0
  126. /package/{DateTimePicker → build/DateTimePicker}/DateTimePickerToolbar.d.ts +0 -0
  127. /package/{DateTimePicker → build/DateTimePicker}/DateTimePickerToolbar.js +0 -0
  128. /package/{DateTimePicker → build/DateTimePicker}/index.d.ts +0 -0
  129. /package/{DateTimePicker → build/DateTimePicker}/index.js +0 -0
  130. /package/{MuiPickersUtilsProvider.d.ts → build/MuiPickersUtilsProvider.d.ts} +0 -0
  131. /package/{MuiPickersUtilsProvider.js → build/MuiPickersUtilsProvider.js} +0 -0
  132. /package/{Picker → build/Picker}/Picker.d.ts +0 -0
  133. /package/{Picker → build/Picker}/WrappedKeyboardPicker.d.ts +0 -0
  134. /package/{Picker → build/Picker}/WrappedKeyboardPicker.js +0 -0
  135. /package/{Picker → build/Picker}/WrappedPurePicker.d.ts +0 -0
  136. /package/{Picker → build/Picker}/WrappedPurePicker.js +0 -0
  137. /package/{README.md → build/README.md} +0 -0
  138. /package/{Rifm → build/Rifm}/Rifm.d.ts +0 -0
  139. /package/{Rifm → build/Rifm}/Rifm.js +0 -0
  140. /package/{TimePicker → build/TimePicker}/TimePicker.d.ts +0 -0
  141. /package/{TimePicker → build/TimePicker}/TimePickerToolbar.d.ts +0 -0
  142. /package/{TimePicker → build/TimePicker}/TimePickerToolbar.js +0 -0
  143. /package/{TimePicker → build/TimePicker}/index.d.ts +0 -0
  144. /package/{TimePicker → build/TimePicker}/index.js +0 -0
  145. /package/{_helpers → build/_helpers}/date-utils.d.ts +0 -0
  146. /package/{_helpers → build/_helpers}/date-utils.js +0 -0
  147. /package/{_helpers → build/_helpers}/text-field-helper.js +0 -0
  148. /package/{_helpers → build/_helpers}/time-utils.d.ts +0 -0
  149. /package/{_helpers → build/_helpers}/time-utils.js +0 -0
  150. /package/{_helpers → build/_helpers}/utils.d.ts +0 -0
  151. /package/{_helpers → build/_helpers}/utils.js +0 -0
  152. /package/{_shared → build/_shared}/KeyboardDateInput.d.ts +0 -0
  153. /package/{_shared → build/_shared}/ModalDialog.js +0 -0
  154. /package/{_shared → build/_shared}/PickerToolbar.d.ts +0 -0
  155. /package/{_shared → build/_shared}/PickerToolbar.js +0 -0
  156. /package/{_shared → build/_shared}/PureDateInput.d.ts +0 -0
  157. /package/{_shared → build/_shared}/ToolbarButton.js +0 -0
  158. /package/{_shared → build/_shared}/ToolbarText.d.ts +0 -0
  159. /package/{_shared → build/_shared}/ToolbarText.js +0 -0
  160. /package/{_shared → build/_shared}/WithUtils.d.ts +0 -0
  161. /package/{_shared → build/_shared}/WithUtils.js +0 -0
  162. /package/{_shared → build/_shared}/hooks/useIsLandscape.d.ts +0 -0
  163. /package/{_shared → build/_shared}/hooks/useIsLandscape.js +0 -0
  164. /package/{_shared → build/_shared}/hooks/useKeyDown.d.ts +0 -0
  165. /package/{_shared → build/_shared}/hooks/useKeyDown.js +0 -0
  166. /package/{_shared → build/_shared}/hooks/useKeyboardPickerState.d.ts +0 -0
  167. /package/{_shared → build/_shared}/hooks/useOpenState.d.ts +0 -0
  168. /package/{_shared → build/_shared}/hooks/useOpenState.js +0 -0
  169. /package/{_shared → build/_shared}/hooks/usePickerState.d.ts +0 -0
  170. /package/{_shared → build/_shared}/hooks/usePickerState.js +0 -0
  171. /package/{_shared → build/_shared}/hooks/useUtils.d.ts +0 -0
  172. /package/{_shared → build/_shared}/hooks/useUtils.js +0 -0
  173. /package/{_shared → build/_shared}/hooks/useViews.d.ts +0 -0
  174. /package/{_shared → build/_shared}/hooks/useViews.js +0 -0
  175. /package/{_shared → build/_shared}/icons/ArrowLeftIcon.d.ts +0 -0
  176. /package/{_shared → build/_shared}/icons/ArrowLeftIcon.js +0 -0
  177. /package/{_shared → build/_shared}/icons/ArrowRightIcon.d.ts +0 -0
  178. /package/{_shared → build/_shared}/icons/ArrowRightIcon.js +0 -0
  179. /package/{_shared → build/_shared}/icons/DateRangeIcon.d.ts +0 -0
  180. /package/{_shared → build/_shared}/icons/DateRangeIcon.js +0 -0
  181. /package/{_shared → build/_shared}/icons/KeyboardIcon.d.ts +0 -0
  182. /package/{_shared → build/_shared}/icons/KeyboardIcon.js +0 -0
  183. /package/{_shared → build/_shared}/icons/TimeIcon.d.ts +0 -0
  184. /package/{_shared → build/_shared}/icons/TimeIcon.js +0 -0
  185. /package/{constants → build/constants}/ClockType.d.ts +0 -0
  186. /package/{constants → build/constants}/ClockType.js +0 -0
  187. /package/{constants → build/constants}/dimensions.d.ts +0 -0
  188. /package/{constants → build/constants}/dimensions.js +0 -0
  189. /package/{constants → build/constants}/prop-types.d.ts +0 -0
  190. /package/{index.d.ts → build/index.d.ts} +0 -0
  191. /package/{index.js → build/index.js} +0 -0
  192. /package/{typings → build/typings}/BasePicker.d.ts +0 -0
  193. /package/{typings → build/typings}/BasePicker.js +0 -0
  194. /package/{typings → build/typings}/date.d.ts +0 -0
  195. /package/{typings → build/typings}/date.js +0 -0
  196. /package/{typings → build/typings}/extendMui.d.ts +0 -0
  197. /package/{typings → build/typings}/extendMui.js +0 -0
  198. /package/{typings → build/typings}/overrides.d.ts +0 -0
  199. /package/{typings → build/typings}/overrides.js +0 -0
  200. /package/{views → build/views}/Calendar/Calendar.d.ts +0 -0
  201. /package/{views → build/views}/Calendar/CalendarHeader.d.ts +0 -0
  202. /package/{views → build/views}/Calendar/CalendarHeader.js +0 -0
  203. /package/{views → build/views}/Calendar/Day.d.ts +0 -0
  204. /package/{views → build/views}/Calendar/Day.js +0 -0
  205. /package/{views → build/views}/Calendar/DayWrapper.d.ts +0 -0
  206. /package/{views → build/views}/Calendar/DayWrapper.js +0 -0
  207. /package/{views → build/views}/Calendar/SlideTransition.d.ts +0 -0
  208. /package/{views → build/views}/Calendar/SlideTransition.js +0 -0
  209. /package/{views → build/views}/Clock/Clock.js +0 -0
  210. /package/{views → build/views}/Clock/ClockNumber.d.ts +0 -0
  211. /package/{views → build/views}/Clock/ClockNumber.js +0 -0
  212. /package/{views → build/views}/Clock/ClockNumbers.d.ts +0 -0
  213. /package/{views → build/views}/Clock/ClockNumbers.js +0 -0
  214. /package/{views → build/views}/Clock/ClockPointer.js +0 -0
  215. /package/{views → build/views}/Clock/ClockView.d.ts +0 -0
  216. /package/{views → build/views}/Clock/ClockView.js +0 -0
  217. /package/{views → build/views}/Month/Month.d.ts +0 -0
  218. /package/{views → build/views}/Month/Month.js +0 -0
  219. /package/{views → build/views}/Month/MonthView.d.ts +0 -0
  220. /package/{views → build/views}/Month/MonthView.js +0 -0
  221. /package/{views → build/views}/Year/Year.d.ts +0 -0
  222. /package/{views → build/views}/Year/Year.js +0 -0
  223. /package/{views → build/views}/Year/YearView.d.ts +0 -0
  224. /package/{views → build/views}/Year/YearView.js +0 -0
  225. /package/{wrappers → build/wrappers}/InlineWrapper.d.ts +0 -0
  226. /package/{wrappers → build/wrappers}/InlineWrapper.js +0 -0
  227. /package/{wrappers → build/wrappers}/ModalWrapper.d.ts +0 -0
  228. /package/{wrappers → build/wrappers}/ModalWrapper.js +0 -0
  229. /package/{wrappers → build/wrappers}/StaticWrapper.d.ts +0 -0
  230. /package/{wrappers → build/wrappers}/StaticWrapper.js +0 -0
  231. /package/{wrappers → build/wrappers}/Wrapper.d.ts +0 -0
  232. /package/{wrappers → build/wrappers}/Wrapper.js +0 -0
@@ -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,7 @@
1
+ import { DatePickerProps, KeyboardDatePickerProps } from './DatePicker';
2
+
3
+ export type DatePickerProps = DatePickerProps;
4
+
5
+ export type KeyboardDatePickerProps = KeyboardDatePickerProps;
6
+
7
+ export { KeyboardDatePicker, DatePicker } from './DatePicker';
@@ -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;
@@ -0,0 +1,275 @@
1
+ import * as React from 'react';
2
+ import clsx from 'clsx';
3
+ import Calendar from '../views/Calendar/Calendar';
4
+ import { useUtils } from '../_shared/hooks/useUtils';
5
+ import { useViews } from '../_shared/hooks/useViews';
6
+ import { makeStyles } from '@material-ui/core/styles';
7
+ import { YearSelection } from '../views/Year/YearView';
8
+ import { MaterialUiPickersDate } from '../typings/date';
9
+ import { BasePickerProps } from '../typings/BasePicker';
10
+ import { TimePickerView } from '../views/Clock/ClockView';
11
+ import { MonthSelection } from '../views/Month/MonthView';
12
+ import { BaseTimePickerProps } from '../TimePicker/TimePicker';
13
+ import { BaseDatePickerProps } from '../DatePicker/DatePicker';
14
+ import { useIsLandscape } from '../_shared/hooks/useIsLandscape';
15
+ import { datePickerDefaultProps } from '../constants/prop-types';
16
+ import { DIALOG_WIDTH_WIDER, DIALOG_WIDTH, VIEW_HEIGHT } from '../constants/dimensions';
17
+ import { DialogActions, Button } from '@material-ui/core';
18
+
19
+ const viewsMap = {
20
+ year: YearSelection,
21
+ month: MonthSelection,
22
+ date: Calendar,
23
+ hours: TimePickerView,
24
+ minutes: TimePickerView,
25
+ seconds: TimePickerView,
26
+ };
27
+
28
+ export type PickerView = keyof typeof viewsMap;
29
+
30
+ export type ToolbarComponentProps = BaseDatePickerProps &
31
+ BaseTimePickerProps & {
32
+ views: PickerView[];
33
+ openView: PickerView;
34
+ date: MaterialUiPickersDate;
35
+ setOpenView: (view: PickerView) => void;
36
+ onChange: (date: MaterialUiPickersDate, isFinish?: boolean) => void;
37
+ // TODO move out, cause it is DateTimePickerOnly
38
+ hideTabs?: boolean;
39
+ dateRangeIcon?: React.ReactNode;
40
+ timeIcon?: React.ReactNode;
41
+ isLandscape: boolean;
42
+ };
43
+
44
+ export interface PickerViewProps extends BaseDatePickerProps, BaseTimePickerProps {
45
+ views: PickerView[];
46
+ openTo: PickerView;
47
+ disableToolbar?: boolean;
48
+ ToolbarComponent: React.ComponentType<ToolbarComponentProps>;
49
+ // TODO move out, cause it is DateTimePickerOnly
50
+ hideTabs?: boolean;
51
+ dateRangeIcon?: React.ReactNode;
52
+ timeIcon?: React.ReactNode;
53
+ }
54
+
55
+ interface PickerProps extends PickerViewProps {
56
+ date: MaterialUiPickersDate;
57
+ orientation?: BasePickerProps['orientation'];
58
+ onChange: (date: MaterialUiPickersDate, isFinish?: boolean) => void;
59
+ showActionsBar?: boolean;
60
+ showTodayButton?: boolean;
61
+ todayLabel?: string;
62
+ showShiftButtons?: boolean;
63
+ setShiftFunction?: (days: number) => Date;
64
+ shiftButtonValues?: Object;
65
+ onSetToday?: () => void;
66
+ onSetShift?: (shiftDate: Date) => void;
67
+ }
68
+
69
+ const useStyles = makeStyles(
70
+ {
71
+ container: {
72
+ display: 'flex',
73
+ flexDirection: 'column',
74
+ },
75
+ containerLandscape: {
76
+ flexDirection: 'row',
77
+ },
78
+ pickerView: {
79
+ overflowX: 'hidden',
80
+ minHeight: VIEW_HEIGHT,
81
+ minWidth: DIALOG_WIDTH,
82
+ maxWidth: DIALOG_WIDTH_WIDER,
83
+ display: 'flex',
84
+ flexDirection: 'column',
85
+ justifyContent: 'center',
86
+ },
87
+ pickerViewLandscape: {
88
+ padding: '0 8px',
89
+ },
90
+ },
91
+ { name: 'MuiPickersBasePicker' }
92
+ );
93
+
94
+ const useButtonsStyles = makeStyles(
95
+ {
96
+ root: {
97
+ minWidth: 32,
98
+ },
99
+ },
100
+ { name: 'MuiButtonBase' }
101
+ );
102
+
103
+ export const useDialogActionsStyles = makeStyles({
104
+ withAdditionalAction: {},
105
+ });
106
+
107
+ export const Picker: React.FunctionComponent<PickerProps> = props => {
108
+ const {
109
+ date,
110
+ ampm,
111
+ views,
112
+ disableToolbar,
113
+ disablePast,
114
+ disableFuture,
115
+ hideTabs,
116
+ onChange,
117
+ openTo,
118
+ minutesStep,
119
+ dateRangeIcon,
120
+ timeIcon,
121
+ minDate: unparsedMinDate,
122
+ maxDate: unparsedMaxDate,
123
+ animateYearScrolling,
124
+ leftArrowIcon,
125
+ rightArrowIcon,
126
+ renderDay,
127
+ shouldDisableDate,
128
+ allowKeyboardControl,
129
+ onMonthChange,
130
+ onYearChange,
131
+ leftArrowButtonProps,
132
+ rightArrowButtonProps,
133
+ ToolbarComponent,
134
+ loadingIndicator,
135
+ orientation,
136
+ showActionsBar,
137
+ onSetToday,
138
+ showTodayButton,
139
+ todayLabel,
140
+ onSetShift,
141
+ showShiftButtons,
142
+ setShiftFunction,
143
+ shiftButtonValues,
144
+ } = props;
145
+
146
+ const utils = useUtils();
147
+ const classes = useStyles();
148
+ const buttonClasses = useButtonsStyles();
149
+ const dialogActionsClasses = useDialogActionsStyles();
150
+ const isLandscape = useIsLandscape(orientation);
151
+ const { openView, setOpenView, handleChangeAndOpenNext } = useViews(views, openTo, onChange);
152
+
153
+ const minDate = React.useMemo(() => utils.date(unparsedMinDate)!, [unparsedMinDate, utils]);
154
+ const maxDate = React.useMemo(() => utils.date(unparsedMaxDate)!, [unparsedMaxDate, utils]);
155
+
156
+ let shiftButtons = new Array();
157
+ if (showShiftButtons && setShiftFunction && onSetShift && shiftButtonValues) {
158
+ for (let key in shiftButtonValues) {
159
+ shiftButtons.push(
160
+ <Button
161
+ color="primary"
162
+ onClick={() => onSetShift(setShiftFunction(parseInt(key)))}
163
+ key={shiftButtonValues[key]}
164
+ >
165
+ {parseInt(key) > 0 ? '+' : ''}
166
+ {shiftButtonValues[key]}
167
+ </Button>
168
+ );
169
+ }
170
+ }
171
+
172
+ return (
173
+ <div
174
+ className={clsx(classes.container, {
175
+ [classes.containerLandscape]: isLandscape,
176
+ })}
177
+ >
178
+ {!disableToolbar && (
179
+ <ToolbarComponent
180
+ date={date}
181
+ onChange={onChange}
182
+ setOpenView={setOpenView}
183
+ openView={openView}
184
+ hideTabs={hideTabs}
185
+ dateRangeIcon={dateRangeIcon}
186
+ timeIcon={timeIcon}
187
+ isLandscape={isLandscape}
188
+ {...props}
189
+ />
190
+ )}
191
+
192
+ <div className={clsx(classes.pickerView, { [classes.pickerViewLandscape]: isLandscape })}>
193
+ {openView === 'year' && (
194
+ <YearSelection
195
+ date={date}
196
+ onChange={handleChangeAndOpenNext}
197
+ minDate={minDate}
198
+ maxDate={maxDate}
199
+ disablePast={disablePast}
200
+ disableFuture={disableFuture}
201
+ onYearChange={onYearChange}
202
+ animateYearScrolling={animateYearScrolling}
203
+ />
204
+ )}
205
+
206
+ {openView === 'month' && (
207
+ <MonthSelection
208
+ date={date}
209
+ onChange={handleChangeAndOpenNext}
210
+ minDate={minDate}
211
+ maxDate={maxDate}
212
+ disablePast={disablePast}
213
+ disableFuture={disableFuture}
214
+ onMonthChange={onMonthChange}
215
+ />
216
+ )}
217
+
218
+ {openView === 'date' && (
219
+ <Calendar
220
+ date={date}
221
+ onChange={handleChangeAndOpenNext}
222
+ onMonthChange={onMonthChange}
223
+ disablePast={disablePast}
224
+ disableFuture={disableFuture}
225
+ minDate={minDate}
226
+ maxDate={maxDate}
227
+ leftArrowIcon={leftArrowIcon}
228
+ leftArrowButtonProps={leftArrowButtonProps}
229
+ rightArrowIcon={rightArrowIcon}
230
+ rightArrowButtonProps={rightArrowButtonProps}
231
+ renderDay={renderDay}
232
+ shouldDisableDate={shouldDisableDate}
233
+ allowKeyboardControl={allowKeyboardControl}
234
+ loadingIndicator={loadingIndicator}
235
+ />
236
+ )}
237
+
238
+ {(openView === 'hours' || openView === 'minutes' || openView === 'seconds') && (
239
+ <TimePickerView
240
+ date={date}
241
+ ampm={ampm}
242
+ type={openView}
243
+ minutesStep={minutesStep}
244
+ onHourChange={handleChangeAndOpenNext}
245
+ onMinutesChange={handleChangeAndOpenNext}
246
+ onSecondsChange={handleChangeAndOpenNext}
247
+ />
248
+ )}
249
+ </div>
250
+
251
+ {showActionsBar && (
252
+ <DialogActions
253
+ classes={{
254
+ root: clsx({
255
+ [dialogActionsClasses.withAdditionalAction]: showTodayButton,
256
+ }),
257
+ }}
258
+ >
259
+ {showTodayButton && (
260
+ <Button color="primary" onClick={onSetToday} key="today">
261
+ {todayLabel}
262
+ </Button>
263
+ )}
264
+
265
+ {showShiftButtons && setShiftFunction && shiftButtons}
266
+ </DialogActions>
267
+ )}
268
+ </div>
269
+ );
270
+ };
271
+
272
+ Picker.defaultProps = {
273
+ ...datePickerDefaultProps,
274
+ views: Object.keys(viewsMap),
275
+ } as any;