@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,63 @@
1
+ import * as React from 'react';
2
+ import * as PropTypes from 'prop-types';
3
+ import clsx from 'clsx';
4
+ import ToolbarText from './ToolbarText';
5
+ import Button, { ButtonProps } from '@material-ui/core/Button';
6
+ import { ExtendMui } from '../typings/extendMui';
7
+ import { TypographyProps } from '@material-ui/core/Typography';
8
+ import { createStyles, withStyles, WithStyles } from '@material-ui/core/styles';
9
+
10
+ export interface ToolbarButtonProps
11
+ extends ExtendMui<ButtonProps, 'variant'>,
12
+ WithStyles<typeof styles> {
13
+ variant: TypographyProps['variant'];
14
+ selected: boolean;
15
+ label: string;
16
+ align?: TypographyProps['align'];
17
+ typographyClassName?: string;
18
+ }
19
+
20
+ const ToolbarButton: React.FunctionComponent<ToolbarButtonProps> = ({
21
+ classes,
22
+ className = null,
23
+ label,
24
+ selected,
25
+ variant,
26
+ align,
27
+ typographyClassName,
28
+ ...other
29
+ }) => {
30
+ return (
31
+ <Button variant="text" className={clsx(classes.toolbarBtn, className)} {...other}>
32
+ <ToolbarText
33
+ align={align}
34
+ className={typographyClassName}
35
+ variant={variant}
36
+ label={label}
37
+ selected={selected}
38
+ />
39
+ </Button>
40
+ );
41
+ };
42
+
43
+ (ToolbarButton as any).propTypes = {
44
+ selected: PropTypes.bool.isRequired,
45
+ label: PropTypes.string.isRequired,
46
+ classes: PropTypes.any.isRequired,
47
+ className: PropTypes.string,
48
+ innerRef: PropTypes.any,
49
+ };
50
+
51
+ ToolbarButton.defaultProps = {
52
+ className: '',
53
+ };
54
+
55
+ export const styles = createStyles({
56
+ toolbarBtn: {
57
+ padding: 0,
58
+ minWidth: '16px',
59
+ textTransform: 'none',
60
+ },
61
+ });
62
+
63
+ export default withStyles(styles, { name: 'MuiPickersToolbarButton' })(ToolbarButton);
@@ -0,0 +1,49 @@
1
+ import * as React from 'react';
2
+ import clsx from 'clsx';
3
+ import Typography, { TypographyProps } from '@material-ui/core/Typography';
4
+ import { ExtendMui } from '../typings/extendMui';
5
+ import { makeStyles, fade } from '@material-ui/core/styles';
6
+
7
+ export interface ToolbarTextProps extends ExtendMui<TypographyProps> {
8
+ selected?: boolean;
9
+ label: string;
10
+ }
11
+
12
+ export const useStyles = makeStyles(
13
+ theme => {
14
+ const textColor =
15
+ theme.palette.type === 'light'
16
+ ? theme.palette.primary.contrastText
17
+ : theme.palette.getContrastText(theme.palette.background.default);
18
+
19
+ return {
20
+ toolbarTxt: {
21
+ color: fade(textColor, 0.54),
22
+ },
23
+ toolbarBtnSelected: {
24
+ color: textColor,
25
+ },
26
+ };
27
+ },
28
+ { name: 'MuiPickersToolbarText' }
29
+ );
30
+
31
+ const ToolbarText: React.FunctionComponent<ToolbarTextProps> = ({
32
+ selected,
33
+ label,
34
+ className = null,
35
+ ...other
36
+ }) => {
37
+ const classes = useStyles();
38
+ return (
39
+ <Typography
40
+ children={label}
41
+ className={clsx(classes.toolbarTxt, className, {
42
+ [classes.toolbarBtnSelected]: selected,
43
+ })}
44
+ {...other}
45
+ />
46
+ );
47
+ };
48
+
49
+ export default ToolbarText;
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { Omit } from '@material-ui/core';
3
+ import { useUtils } from './hooks/useUtils';
4
+ import { IUtils } from '@date-io/core/IUtils';
5
+ import { MaterialUiPickersDate } from '../typings/date';
6
+
7
+ export interface WithUtilsProps {
8
+ utils: IUtils<MaterialUiPickersDate>;
9
+ }
10
+
11
+ export const withUtils = () => <P extends WithUtilsProps>(Component: React.ComponentType<P>) => {
12
+ const WithUtils: React.SFC<Omit<P, keyof WithUtilsProps>> = props => {
13
+ const utils = useUtils();
14
+ return <Component utils={utils} {...(props as any)} />;
15
+ };
16
+
17
+ WithUtils.displayName = `WithUtils(${Component.displayName || Component.name})`;
18
+ return WithUtils;
19
+ };
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import { useIsomorphicEffect } from './useKeyDown';
3
+ import { BasePickerProps } from '../../typings/BasePicker';
4
+
5
+ const getOrientation = () =>
6
+ typeof window !== 'undefined' &&
7
+ window.screen &&
8
+ window.screen.orientation &&
9
+ Math.abs(window.screen.orientation.angle) === 90
10
+ ? 'landscape'
11
+ : 'portrait';
12
+
13
+ export function useIsLandscape(customOrientation?: BasePickerProps['orientation']) {
14
+ const [orientation, setOrientation] = React.useState<BasePickerProps['orientation']>(
15
+ getOrientation()
16
+ );
17
+
18
+ const eventHandler = React.useCallback(() => setOrientation(getOrientation()), []);
19
+
20
+ useIsomorphicEffect(() => {
21
+ window.addEventListener('orientationchange', eventHandler);
22
+ return () => window.removeEventListener('orientationchange', eventHandler);
23
+ }, [eventHandler]);
24
+
25
+ const orientationToUse = customOrientation || orientation;
26
+ return orientationToUse === 'landscape';
27
+ }
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+
3
+ export const useIsomorphicEffect =
4
+ typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;
5
+
6
+ type KeyHandlers = Record<KeyboardEvent['key'], () => void>;
7
+
8
+ export function runKeyHandler(e: KeyboardEvent, keyHandlers: KeyHandlers) {
9
+ const handler = keyHandlers[e.key];
10
+ if (handler) {
11
+ handler();
12
+ // if event was handled prevent other side effects (e.g. page scroll)
13
+ e.preventDefault();
14
+ }
15
+ }
16
+
17
+ export function useKeyDown(active: boolean, keyHandlers: KeyHandlers) {
18
+ const keyHandlersRef = React.useRef(keyHandlers);
19
+ useIsomorphicEffect(() => {
20
+ keyHandlersRef.current = keyHandlers;
21
+ });
22
+
23
+ React.useEffect(() => {
24
+ if (active) {
25
+ const handleKeyDown = (event: KeyboardEvent) => {
26
+ runKeyHandler(event, keyHandlers);
27
+ };
28
+ window.addEventListener('keydown', handleKeyDown);
29
+ return () => {
30
+ window.removeEventListener('keydown', handleKeyDown);
31
+ };
32
+ }
33
+ }, [active, keyHandlers]);
34
+ }
@@ -0,0 +1,72 @@
1
+ import { useUtils } from './useUtils';
2
+ import { Omit } from '@material-ui/core';
3
+ import { IUtils } from '@date-io/core/IUtils';
4
+ import { BasePickerProps } from '../../typings/BasePicker';
5
+ import { MaterialUiPickersDate } from '../../typings/date';
6
+ import { useCallback, useEffect, useMemo, useState } from 'react';
7
+ import { getDisplayDate } from '../../_helpers/text-field-helper';
8
+ import { StateHookOptions, usePickerState } from './usePickerState';
9
+
10
+ export interface BaseKeyboardPickerProps extends Omit<BasePickerProps, 'onChange'> {
11
+ /** String value for controlling value with pure input string. Overrides value prop */
12
+ inputValue?: string;
13
+ /** Keyboard onChange callback */
14
+ onChange: (date: MaterialUiPickersDate | null, value?: string | null) => void;
15
+ }
16
+
17
+ function parseInputString(value: string, utils: IUtils<any>, format: string) {
18
+ try {
19
+ return utils.parse(value, format);
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+
25
+ export function useKeyboardPickerState(props: BaseKeyboardPickerProps, options: StateHookOptions) {
26
+ const { format = options.getDefaultFormat(), inputValue, onChange, value } = props;
27
+ const utils = useUtils();
28
+
29
+ const displayDate = getDisplayDate(value, format, utils, value === null, props);
30
+ const [innerInputValue, setInnerInputValue] = useState(displayDate);
31
+ const dateValue = inputValue ? parseInputString(inputValue, utils, format) : value;
32
+
33
+ useEffect(() => {
34
+ if (value === null || utils.isValid(value)) {
35
+ setInnerInputValue(displayDate);
36
+ }
37
+ }, [displayDate, setInnerInputValue, utils, value]);
38
+
39
+ const handleKeyboardChange = useCallback(
40
+ (date: MaterialUiPickersDate) => {
41
+ onChange(date, date === null ? null : utils.format(date, format));
42
+ },
43
+ [format, onChange, utils]
44
+ );
45
+
46
+ const { inputProps: innerInputProps, wrapperProps, pickerProps } = usePickerState(
47
+ // Extend props interface
48
+ { ...props, value: dateValue, onChange: handleKeyboardChange },
49
+ options
50
+ );
51
+
52
+ const inputProps = useMemo(
53
+ () => ({
54
+ ...innerInputProps, // reuse validation and open/close logic
55
+ format: wrapperProps.format,
56
+ inputValue: inputValue || innerInputValue,
57
+ onChange: (value: string | null) => {
58
+ setInnerInputValue(value || '');
59
+ const date = value === null ? null : utils.parse(value, wrapperProps.format);
60
+
61
+ onChange(date, value);
62
+ },
63
+ }),
64
+ [innerInputProps, innerInputValue, inputValue, onChange, utils, wrapperProps.format]
65
+ );
66
+
67
+ return {
68
+ inputProps,
69
+ wrapperProps,
70
+ pickerProps,
71
+ };
72
+ }
@@ -0,0 +1,22 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
2
+ import { BasePickerProps } from '../../typings/BasePicker';
3
+ import { useCallback, useState, Dispatch, SetStateAction } from 'react';
4
+
5
+ export function useOpenState({ open, onOpen, onClose }: BasePickerProps) {
6
+ let setIsOpenState: null | Dispatch<SetStateAction<boolean>> = null;
7
+ if (open === undefined || open === null) {
8
+ // The component is uncontrolled, so we need to give it its own state.
9
+ [open, setIsOpenState] = useState<boolean>(false);
10
+ }
11
+
12
+ // prettier-ignore
13
+ const setIsOpen = useCallback((newIsOpen: boolean) => {
14
+ setIsOpenState && setIsOpenState(newIsOpen);
15
+
16
+ return newIsOpen
17
+ ? onOpen && onOpen()
18
+ : onClose && onClose();
19
+ }, [onOpen, onClose, setIsOpenState]);
20
+
21
+ return { isOpen: open, setIsOpen };
22
+ }
@@ -0,0 +1,134 @@
1
+ import { useUtils } from './useUtils';
2
+ import { IUtils } from '@date-io/core/IUtils';
3
+ import { MaterialUiPickersDate } from '../..';
4
+ import { useOpenState } from './useOpenState';
5
+ import { BasePickerProps } from '../../typings/BasePicker';
6
+ import { getDisplayDate, validate } from '../../_helpers/text-field-helper';
7
+ import { useCallback, useDebugValue, useEffect, useMemo, useState, useRef } from 'react';
8
+
9
+ export interface StateHookOptions {
10
+ getDefaultFormat: () => string;
11
+ }
12
+
13
+ const useValueToDate = (
14
+ utils: IUtils<MaterialUiPickersDate>,
15
+ { value, initialFocusedDate }: BasePickerProps
16
+ ) => {
17
+ const nowRef = useRef(utils.date());
18
+ const date = utils.date(value || initialFocusedDate || nowRef.current);
19
+
20
+ return date && utils.isValid(date) ? date : nowRef.current;
21
+ };
22
+
23
+ function useDateValues(props: BasePickerProps, options: StateHookOptions) {
24
+ const utils = useUtils();
25
+ const date = useValueToDate(utils, props);
26
+ const format = props.format || options.getDefaultFormat();
27
+
28
+ return { date, format };
29
+ }
30
+
31
+ export function usePickerState(props: BasePickerProps, options: StateHookOptions) {
32
+ const { autoOk, disabled, onAccept, onChange, onError, value, variant } = props;
33
+
34
+ const utils = useUtils();
35
+ const { isOpen, setIsOpen } = useOpenState(props);
36
+ const { date, format } = useDateValues(props, options);
37
+ const [pickerDate, setPickerDate] = useState(date);
38
+
39
+ useEffect(() => {
40
+ // if value was changed in closed state - treat it as accepted
41
+ if (!isOpen && !utils.isEqual(pickerDate, date)) {
42
+ setPickerDate(date);
43
+ }
44
+ }, [date, isOpen, pickerDate, utils]);
45
+
46
+ const acceptDate = useCallback(
47
+ (acceptedDate: MaterialUiPickersDate) => {
48
+ setIsOpen(false);
49
+ onChange(acceptedDate);
50
+
51
+ if (onAccept) {
52
+ onAccept(acceptedDate);
53
+ }
54
+ },
55
+ [onAccept, onChange, setIsOpen]
56
+ );
57
+
58
+ const wrapperProps = useMemo(
59
+ () => ({
60
+ format,
61
+ open: isOpen,
62
+ onClear: () => acceptDate(null),
63
+ onAccept: () => acceptDate(pickerDate),
64
+ onSetToday: () => setPickerDate(utils.date()),
65
+ onDismiss: () => {
66
+ setIsOpen(false);
67
+ },
68
+ }),
69
+ [acceptDate, format, isOpen, pickerDate, setIsOpen, utils]
70
+ );
71
+
72
+ const pickerProps = useMemo(
73
+ () => ({
74
+ date: pickerDate,
75
+ onChange: (newDate: MaterialUiPickersDate, isFinish = true) => {
76
+ setPickerDate(newDate);
77
+
78
+ if (variant === 'inline' || variant === 'static') {
79
+ onChange(newDate);
80
+ }
81
+
82
+ if (isFinish && autoOk) {
83
+ acceptDate(newDate);
84
+ }
85
+ },
86
+ onSetToday: () => {
87
+ let newDate = utils.date();
88
+ setPickerDate(newDate);
89
+
90
+ if (variant === 'inline' || variant === 'static') {
91
+ onChange(newDate);
92
+ }
93
+
94
+ if (autoOk) {
95
+ acceptDate(newDate);
96
+ }
97
+ },
98
+ onSetShift: (shiftDate: Date) => {
99
+ let newDate = utils.date(shiftDate);
100
+
101
+ if (variant === 'inline' || variant === 'static') {
102
+ onChange(newDate);
103
+ }
104
+
105
+ if (autoOk) {
106
+ acceptDate(newDate);
107
+ }
108
+ },
109
+ }),
110
+ [acceptDate, autoOk, onChange, pickerDate, variant]
111
+ );
112
+
113
+ const validationError = validate(value, utils, props);
114
+ useEffect(() => {
115
+ if (validationError && onError) {
116
+ onError(validationError, value);
117
+ }
118
+ }, [onError, validationError, value]);
119
+
120
+ const inputValue = getDisplayDate(date, format, utils, value === null, props);
121
+ const inputProps = useMemo(
122
+ () => ({
123
+ inputValue,
124
+ validationError,
125
+ onClick: () => !disabled && setIsOpen(true),
126
+ }),
127
+ [disabled, inputValue, setIsOpen, validationError]
128
+ );
129
+
130
+ const pickerState = { pickerProps, inputProps, wrapperProps };
131
+
132
+ useDebugValue(pickerState);
133
+ return pickerState;
134
+ }
@@ -0,0 +1,20 @@
1
+ import { useContext } from 'react';
2
+ import { IUtils } from '@date-io/core/IUtils';
3
+ import { MaterialUiPickersDate } from '../../typings/date';
4
+ import { MuiPickersContext } from '../../MuiPickersUtilsProvider';
5
+
6
+ export const checkUtils = (utils: IUtils<MaterialUiPickersDate> | null | undefined) => {
7
+ if (!utils) {
8
+ // tslint:disable-next-line
9
+ throw new Error(
10
+ 'Can not find utils in context. You either a) forgot to wrap your component tree in MuiPickersUtilsProvider; or b) mixed named and direct file imports. Recommendation: use named imports from the module index.'
11
+ );
12
+ }
13
+ };
14
+
15
+ export function useUtils() {
16
+ const utils = useContext(MuiPickersContext);
17
+ checkUtils(utils);
18
+
19
+ return utils!;
20
+ }
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ import { MaterialUiPickersDate } from '../..';
3
+ import { PickerView } from '../../Picker/Picker';
4
+ import { arrayIncludes } from '../../_helpers/utils';
5
+
6
+ export function useViews(
7
+ views: PickerView[],
8
+ openTo: PickerView,
9
+ onChange: (date: MaterialUiPickersDate, isFinish?: boolean) => void
10
+ ) {
11
+ const [openView, setOpenView] = React.useState(
12
+ openTo && arrayIncludes(views, openTo) ? openTo : views[0]
13
+ );
14
+
15
+ const handleChangeAndOpenNext = React.useCallback(
16
+ (date: MaterialUiPickersDate, isFinish?: boolean) => {
17
+ const nextViewToOpen = views[views.indexOf(openView!) + 1];
18
+ if (isFinish && nextViewToOpen) {
19
+ // do not close picker if needs to show next view
20
+ onChange(date, false);
21
+ setOpenView(nextViewToOpen);
22
+ return;
23
+ }
24
+
25
+ onChange(date, Boolean(isFinish));
26
+ },
27
+ [onChange, openView, views]
28
+ );
29
+
30
+ return { handleChangeAndOpenNext, openView, setOpenView };
31
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
3
+
4
+ export const ArrowLeftIcon: React.SFC<SvgIconProps> = props => {
5
+ return (
6
+ <SvgIcon {...props}>
7
+ <path d="M15.41 16.59L10.83 12l4.58-4.59L14 6l-6 6 6 6 1.41-1.41z" />
8
+ <path fill="none" d="M0 0h24v24H0V0z" />
9
+ </SvgIcon>
10
+ );
11
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
3
+
4
+ export const ArrowRightIcon: React.SFC<SvgIconProps> = props => {
5
+ return (
6
+ <SvgIcon {...props}>
7
+ <path d="M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z" />
8
+ <path fill="none" d="M0 0h24v24H0V0z" />
9
+ </SvgIcon>
10
+ );
11
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
3
+
4
+ export const DateRangeIcon: React.SFC<SvgIconProps> = props => {
5
+ return (
6
+ <SvgIcon {...props}>
7
+ <path d="M9 11H7v2h2v-2zm4 0h-2v2h2v-2zm4 0h-2v2h2v-2zm2-7h-1V2h-2v2H8V2H6v2H5c-1.11 0-1.99.9-1.99 2L3 20c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 16H5V9h14v11z" />
8
+ <path fill="none" d="M0 0h24v24H0z" />
9
+ </SvgIcon>
10
+ );
11
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
3
+
4
+ export const KeyboardIcon: React.SFC<SvgIconProps> = props => {
5
+ return (
6
+ <SvgIcon {...props}>
7
+ <path d="M17 12h-5v5h5v-5zM16 1v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2h-1V1h-2zm3 18H5V8h14v11z" />
8
+ <path fill="none" d="M0 0h24v24H0z" />
9
+ </SvgIcon>
10
+ );
11
+ };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';
3
+
4
+ export const TimeIcon: React.SFC<SvgIconProps> = props => {
5
+ return (
6
+ <SvgIcon {...props}>
7
+ <path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" />
8
+ <path fill="none" d="M0 0h24v24H0z" />
9
+ <path d="M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z" />
10
+ </SvgIcon>
11
+ );
12
+ };
@@ -0,0 +1,11 @@
1
+ enum ClockType {
2
+ HOURS = 'hours',
3
+
4
+ MINUTES = 'minutes',
5
+
6
+ SECONDS = 'seconds',
7
+ }
8
+
9
+ export type ClockViewType = 'hours' | 'minutes' | 'seconds';
10
+
11
+ export default ClockType;
@@ -0,0 +1,5 @@
1
+ export const DIALOG_WIDTH = 310;
2
+
3
+ export const DIALOG_WIDTH_WIDER = 325;
4
+
5
+ export const VIEW_HEIGHT = 305;
@@ -0,0 +1,37 @@
1
+ import * as PropTypes from 'prop-types';
2
+ import { BaseTimePickerProps } from '../TimePicker/TimePicker';
3
+ import { BaseDatePickerProps } from '../DatePicker/DatePicker';
4
+
5
+ const date = PropTypes.oneOfType([
6
+ PropTypes.object,
7
+ PropTypes.string,
8
+ PropTypes.number,
9
+ PropTypes.instanceOf(Date),
10
+ ]);
11
+
12
+ const datePickerView = PropTypes.oneOf(['year', 'month', 'day']);
13
+
14
+ export type ParsableDate = object | string | number | Date | null | undefined;
15
+
16
+ export const DomainPropTypes = { date, datePickerView };
17
+
18
+ /* eslint-disable @typescript-eslint/no-object-literal-type-assertion */
19
+ export const timePickerDefaultProps = {
20
+ ampm: true,
21
+ invalidDateMessage: 'Invalid Time Format',
22
+ } as BaseTimePickerProps;
23
+
24
+ export const datePickerDefaultProps = {
25
+ minDate: new Date('1900-01-01'),
26
+ maxDate: new Date('2200-01-01'),
27
+ invalidDateMessage: 'Invalid Date Format',
28
+ minDateMessage: 'Date should not be before minimal date',
29
+ maxDateMessage: 'Date should not be after maximal date',
30
+ allowKeyboardControl: true,
31
+ } as BaseDatePickerProps;
32
+
33
+ export const dateTimePickerDefaultProps = {
34
+ ...timePickerDefaultProps,
35
+ ...datePickerDefaultProps,
36
+ showTabs: true,
37
+ } as BaseTimePickerProps & BaseDatePickerProps;
package/src/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { MaterialUiPickersDate } from './typings/date';
2
+ import { KeyboardTimePickerProps } from './TimePicker';
3
+ import { DatePickerProps, KeyboardDatePickerProps } from './DatePicker';
4
+ import { DateTimePickerProps, KeyboardDateTimePickerProps } from './DateTimePicker';
5
+
6
+ export type TimePickerProps = KeyboardTimePickerProps;
7
+
8
+ export type KeyboardTimePickerProps = KeyboardTimePickerProps;
9
+
10
+ export type DatePickerProps = DatePickerProps;
11
+
12
+ export type KeyboardDatePickerProps = KeyboardDatePickerProps;
13
+
14
+ export type DateTimePickerProps = DateTimePickerProps;
15
+
16
+ export type KeyboardDateTimePickerProps = KeyboardDateTimePickerProps;
17
+
18
+ export type MaterialUiPickersDate = MaterialUiPickersDate;
19
+
20
+ export { DatePicker, KeyboardDatePicker } from './DatePicker';
21
+
22
+ export { TimePicker, KeyboardTimePicker } from './TimePicker';
23
+
24
+ export { DateTimePicker, KeyboardDateTimePicker } from './DateTimePicker';
25
+
26
+ export { default as Calendar } from './views/Calendar/Calendar';
27
+
28
+ export { default as Day } from './views/Calendar/Day';
29
+
30
+ export { default as TimePickerView } from './views/Clock/ClockView';
31
+
32
+ export { default as Clock } from './views/Clock/Clock';
33
+
34
+ export { Picker } from './Picker/Picker';
35
+
36
+ export { makePurePicker } from './Picker/WrappedPurePicker';
37
+
38
+ export { makeKeyboardPicker } from './Picker/WrappedKeyboardPicker';
39
+
40
+ export { validate } from './_helpers/text-field-helper';
41
+
42
+ export { useUtils } from './_shared/hooks/useUtils';
43
+
44
+ export { usePickerState } from './_shared/hooks/usePickerState';
45
+
46
+ export { useKeyboardPickerState } from './_shared/hooks/useKeyboardPickerState';
47
+
48
+ export { default as MuiPickersUtilsProvider, MuiPickersContext } from './MuiPickersUtilsProvider';