@birdnet/advanced-react-dates 0.0.0-stage → 1.0.0
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/.babelrc +67 -0
- package/.eslintrc +66 -0
- package/.nvmrc +1 -0
- package/.nyc_output/4d8efcd220c2aec1f2b4ffd49d875001.json +1 -0
- package/.nyc_output/66d34779498a5d49bcf9d757dfc7fdb5.json +1 -0
- package/.nyc_output/8ca7e04140934515928bc7d4ae476b73.json +1 -0
- package/.nyc_output/afc270bb597bfc50e690436959c2ae54.json +1 -0
- package/.nycrc +19 -0
- package/.travis.yml +13 -0
- package/CHANGELOG.md +665 -0
- package/CLAUDE.md +56 -0
- package/INTHEWILD.md +9 -0
- package/LICENSE +21 -0
- package/README.md +421 -2
- package/constants.js +2 -0
- package/esm/components/CalendarDay.js +321 -0
- package/esm/components/CalendarIcon.js +11 -0
- package/esm/components/CalendarMonth.js +254 -0
- package/esm/components/CalendarMonthGrid.js +365 -0
- package/esm/components/CalendarWeek.js +11 -0
- package/esm/components/ChevronDown.js +11 -0
- package/esm/components/ChevronUp.js +11 -0
- package/esm/components/CloseButton.js +12 -0
- package/esm/components/CustomizableCalendarDay.js +341 -0
- package/esm/components/DateInput.js +344 -0
- package/esm/components/DateRangePicker.js +647 -0
- package/esm/components/DateRangePickerInput.js +341 -0
- package/esm/components/DateRangePickerInputController.js +348 -0
- package/esm/components/DayPicker.js +1167 -0
- package/esm/components/DayPickerKeyboardShortcuts.js +364 -0
- package/esm/components/DayPickerNavigation.js +314 -0
- package/esm/components/DayPickerRangeController.js +1202 -0
- package/esm/components/DayPickerSingleDateController.js +690 -0
- package/esm/components/KeyboardShortcutRow.js +69 -0
- package/esm/components/LeftArrow.js +11 -0
- package/esm/components/RightArrow.js +11 -0
- package/esm/components/SingleDatePicker.js +605 -0
- package/esm/components/SingleDatePickerInput.js +264 -0
- package/esm/components/SingleDatePickerInputController.js +260 -0
- package/esm/constants.js +28 -0
- package/esm/defaultPhrases.js +225 -0
- package/esm/index.js +20 -0
- package/esm/initialize.js +2 -0
- package/esm/shapes/AnchorDirectionShape.js +3 -0
- package/esm/shapes/CalendarInfoPositionShape.js +3 -0
- package/esm/shapes/DateRangePickerShape.js +101 -0
- package/esm/shapes/DayOfWeekShape.js +3 -0
- package/esm/shapes/DisabledShape.js +3 -0
- package/esm/shapes/FocusedInputShape.js +3 -0
- package/esm/shapes/IconPositionShape.js +3 -0
- package/esm/shapes/ModifiersShape.js +18 -0
- package/esm/shapes/NavPositionShape.js +3 -0
- package/esm/shapes/OpenDirectionShape.js +3 -0
- package/esm/shapes/OrientationShape.js +3 -0
- package/esm/shapes/ScrollableOrientationShape.js +3 -0
- package/esm/shapes/SingleDatePickerShape.js +90 -0
- package/esm/theme/DefaultTheme.js +176 -0
- package/esm/utils/calculateDimension.js +28 -0
- package/esm/utils/disableScroll.js +67 -0
- package/esm/utils/getActiveElement.js +3 -0
- package/esm/utils/getCalendarDaySettings.js +48 -0
- package/esm/utils/getCalendarMonthWeeks.js +37 -0
- package/esm/utils/getCalendarMonthWidth.js +4 -0
- package/esm/utils/getDetachedContainerStyles.js +36 -0
- package/esm/utils/getInputHeight.js +42 -0
- package/esm/utils/getNumberOfCalendarMonthWeeks.js +11 -0
- package/esm/utils/getPhrase.js +7 -0
- package/esm/utils/getPhrasePropTypes.js +9 -0
- package/esm/utils/getPooledMoment.js +8 -0
- package/esm/utils/getPreviousMonthMemoLast.js +9 -0
- package/esm/utils/getResponsiveContainerStyles.js +8 -0
- package/esm/utils/getSelectedDateOffset.js +8 -0
- package/esm/utils/getTransformStyles.js +8 -0
- package/esm/utils/getVisibleDays.js +42 -0
- package/esm/utils/isAfterDay.js +7 -0
- package/esm/utils/isBeforeDay.js +13 -0
- package/esm/utils/isDayVisible.js +38 -0
- package/esm/utils/isInclusivelyAfterDay.js +6 -0
- package/esm/utils/isInclusivelyBeforeDay.js +6 -0
- package/esm/utils/isNextDay.js +7 -0
- package/esm/utils/isNextMonth.js +6 -0
- package/esm/utils/isPrevMonth.js +6 -0
- package/esm/utils/isPreviousDay.js +7 -0
- package/esm/utils/isSameDay.js +7 -0
- package/esm/utils/isSameMonth.js +7 -0
- package/esm/utils/isTransitionEndSupported.js +3 -0
- package/esm/utils/modifiers.js +94 -0
- package/esm/utils/noflip.js +10 -0
- package/esm/utils/registerCSSInterfaceWithDefaultTheme.js +5 -0
- package/esm/utils/registerInterfaceWithDefaultTheme.js +6 -0
- package/esm/utils/toISODateString.js +12 -0
- package/esm/utils/toISOMonthString.js +12 -0
- package/esm/utils/toLocalizedDateString.js +8 -0
- package/esm/utils/toMomentObject.js +7 -0
- package/index.js +2 -0
- package/initialize.js +2 -0
- package/karma.conf.js +82 -0
- package/lib/components/CalendarDay.js +327 -0
- package/lib/components/CalendarIcon.js +18 -0
- package/lib/components/CalendarMonth.js +259 -0
- package/lib/components/CalendarMonthGrid.js +372 -0
- package/lib/components/CalendarWeek.js +18 -0
- package/lib/components/ChevronDown.js +18 -0
- package/lib/components/ChevronUp.js +18 -0
- package/lib/components/CloseButton.js +19 -0
- package/lib/components/CustomizableCalendarDay.js +347 -0
- package/lib/components/DateInput.js +351 -0
- package/lib/components/DateRangePicker.js +653 -0
- package/lib/components/DateRangePickerInput.js +348 -0
- package/lib/components/DateRangePickerInputController.js +354 -0
- package/lib/components/DayPicker.js +1175 -0
- package/lib/components/DayPickerKeyboardShortcuts.js +371 -0
- package/lib/components/DayPickerNavigation.js +321 -0
- package/lib/components/DayPickerRangeController.js +1208 -0
- package/lib/components/DayPickerSingleDateController.js +695 -0
- package/lib/components/KeyboardShortcutRow.js +76 -0
- package/lib/components/LeftArrow.js +18 -0
- package/lib/components/RightArrow.js +18 -0
- package/lib/components/SingleDatePicker.js +611 -0
- package/lib/components/SingleDatePickerInput.js +271 -0
- package/lib/components/SingleDatePickerInputController.js +266 -0
- package/lib/constants.js +34 -0
- package/lib/css/_datepicker.css +886 -0
- package/lib/defaultPhrases.js +231 -0
- package/lib/index.js +146 -0
- package/lib/initialize.js +5 -0
- package/lib/shapes/AnchorDirectionShape.js +10 -0
- package/lib/shapes/CalendarInfoPositionShape.js +10 -0
- package/lib/shapes/DateRangePickerShape.js +108 -0
- package/lib/shapes/DayOfWeekShape.js +10 -0
- package/lib/shapes/DisabledShape.js +10 -0
- package/lib/shapes/FocusedInputShape.js +10 -0
- package/lib/shapes/IconPositionShape.js +10 -0
- package/lib/shapes/ModifiersShape.js +25 -0
- package/lib/shapes/NavPositionShape.js +10 -0
- package/lib/shapes/OpenDirectionShape.js +10 -0
- package/lib/shapes/OrientationShape.js +10 -0
- package/lib/shapes/ScrollableOrientationShape.js +10 -0
- package/lib/shapes/SingleDatePickerShape.js +97 -0
- package/lib/theme/DefaultTheme.js +182 -0
- package/lib/utils/calculateDimension.js +34 -0
- package/lib/utils/disableScroll.js +75 -0
- package/lib/utils/getActiveElement.js +9 -0
- package/lib/utils/getCalendarDaySettings.js +55 -0
- package/lib/utils/getCalendarMonthWeeks.js +44 -0
- package/lib/utils/getCalendarMonthWidth.js +10 -0
- package/lib/utils/getDetachedContainerStyles.js +41 -0
- package/lib/utils/getInputHeight.js +48 -0
- package/lib/utils/getNumberOfCalendarMonthWeeks.js +18 -0
- package/lib/utils/getPhrase.js +13 -0
- package/lib/utils/getPhrasePropTypes.js +16 -0
- package/lib/utils/getPooledMoment.js +15 -0
- package/lib/utils/getPreviousMonthMemoLast.js +15 -0
- package/lib/utils/getResponsiveContainerStyles.js +15 -0
- package/lib/utils/getSelectedDateOffset.js +14 -0
- package/lib/utils/getTransformStyles.js +14 -0
- package/lib/utils/getVisibleDays.js +49 -0
- package/lib/utils/isAfterDay.js +14 -0
- package/lib/utils/isBeforeDay.js +20 -0
- package/lib/utils/isDayVisible.js +45 -0
- package/lib/utils/isInclusivelyAfterDay.js +13 -0
- package/lib/utils/isInclusivelyBeforeDay.js +13 -0
- package/lib/utils/isNextDay.js +14 -0
- package/lib/utils/isNextMonth.js +13 -0
- package/lib/utils/isPrevMonth.js +13 -0
- package/lib/utils/isPreviousDay.js +14 -0
- package/lib/utils/isSameDay.js +14 -0
- package/lib/utils/isSameMonth.js +14 -0
- package/lib/utils/isTransitionEndSupported.js +9 -0
- package/lib/utils/modifiers.js +102 -0
- package/lib/utils/noflip.js +16 -0
- package/lib/utils/registerCSSInterfaceWithDefaultTheme.js +12 -0
- package/lib/utils/registerInterfaceWithDefaultTheme.js +13 -0
- package/lib/utils/toISODateString.js +19 -0
- package/lib/utils/toISOMonthString.js +19 -0
- package/lib/utils/toLocalizedDateString.js +15 -0
- package/lib/utils/toMomentObject.js +14 -0
- package/package.json +141 -4
- package/scripts/.eslintrc +7 -0
- package/scripts/buildCSS.js +37 -0
- package/scripts/pure-component-fallback.js +70 -0
- package/scripts/renderAllComponents.jsx +25 -0
- package/src/components/CalendarDay.jsx +366 -0
- package/src/components/CalendarIcon.jsx +3 -0
- package/src/components/CalendarMonth.jsx +300 -0
- package/src/components/CalendarMonthGrid.jsx +427 -0
- package/src/components/CalendarWeek.jsx +17 -0
- package/src/components/ChevronDown.jsx +3 -0
- package/src/components/ChevronUp.jsx +3 -0
- package/src/components/CloseButton.jsx +3 -0
- package/src/components/CustomizableCalendarDay.jsx +382 -0
- package/src/components/DateInput.jsx +401 -0
- package/src/components/DateRangePicker.jsx +777 -0
- package/src/components/DateRangePickerInput.jsx +434 -0
- package/src/components/DateRangePickerInputController.jsx +379 -0
- package/src/components/DayPicker.jsx +1407 -0
- package/src/components/DayPickerKeyboardShortcuts.jsx +443 -0
- package/src/components/DayPickerNavigation.jsx +445 -0
- package/src/components/DayPickerRangeController.jsx +1409 -0
- package/src/components/DayPickerSingleDateController.jsx +769 -0
- package/src/components/KeyboardShortcutRow.jsx +93 -0
- package/src/components/LeftArrow.jsx +3 -0
- package/src/components/RightArrow.jsx +3 -0
- package/src/components/SingleDatePicker.jsx +731 -0
- package/src/components/SingleDatePickerInput.jsx +329 -0
- package/src/components/SingleDatePickerInputController.jsx +280 -0
- package/src/constants.js +37 -0
- package/src/defaultPhrases.js +215 -0
- package/src/index.js +20 -0
- package/src/initialize.js +3 -0
- package/src/shapes/AnchorDirectionShape.js +8 -0
- package/src/shapes/CalendarInfoPositionShape.js +15 -0
- package/src/shapes/DateRangePickerShape.js +111 -0
- package/src/shapes/DayOfWeekShape.js +5 -0
- package/src/shapes/DisabledShape.js +5 -0
- package/src/shapes/FocusedInputShape.js +8 -0
- package/src/shapes/IconPositionShape.js +8 -0
- package/src/shapes/ModifiersShape.js +20 -0
- package/src/shapes/NavPositionShape.js +8 -0
- package/src/shapes/OpenDirectionShape.js +8 -0
- package/src/shapes/OrientationShape.js +8 -0
- package/src/shapes/ScrollableOrientationShape.js +13 -0
- package/src/shapes/SingleDatePickerShape.js +100 -0
- package/src/svg/arrow-left.svg +1 -0
- package/src/svg/arrow-right.svg +1 -0
- package/src/svg/calendar.svg +1 -0
- package/src/svg/chevron-down.svg +1 -0
- package/src/svg/chevron-up.svg +1 -0
- package/src/svg/close.svg +1 -0
- package/src/theme/DefaultTheme.js +196 -0
- package/src/utils/calculateDimension.js +32 -0
- package/src/utils/disableScroll.js +65 -0
- package/src/utils/getActiveElement.js +3 -0
- package/src/utils/getCalendarDaySettings.js +61 -0
- package/src/utils/getCalendarMonthWeeks.js +49 -0
- package/src/utils/getCalendarMonthWidth.js +3 -0
- package/src/utils/getDetachedContainerStyles.js +39 -0
- package/src/utils/getInputHeight.js +67 -0
- package/src/utils/getNumberOfCalendarMonthWeeks.js +15 -0
- package/src/utils/getPhrase.jsx +9 -0
- package/src/utils/getPhrasePropTypes.js +9 -0
- package/src/utils/getPooledMoment.js +10 -0
- package/src/utils/getPreviousMonthMemoLast.js +11 -0
- package/src/utils/getResponsiveContainerStyles.js +18 -0
- package/src/utils/getSelectedDateOffset.js +6 -0
- package/src/utils/getTransformStyles.js +8 -0
- package/src/utils/getVisibleDays.js +54 -0
- package/src/utils/isAfterDay.js +9 -0
- package/src/utils/isBeforeDay.js +18 -0
- package/src/utils/isDayVisible.js +57 -0
- package/src/utils/isInclusivelyAfterDay.js +8 -0
- package/src/utils/isInclusivelyBeforeDay.js +8 -0
- package/src/utils/isNextDay.js +9 -0
- package/src/utils/isNextMonth.js +8 -0
- package/src/utils/isPrevMonth.js +8 -0
- package/src/utils/isPreviousDay.js +9 -0
- package/src/utils/isSameDay.js +10 -0
- package/src/utils/isSameMonth.js +9 -0
- package/src/utils/isTransitionEndSupported.js +3 -0
- package/src/utils/modifiers.js +116 -0
- package/src/utils/noflip.js +11 -0
- package/src/utils/registerCSSInterfaceWithDefaultTheme.js +7 -0
- package/src/utils/registerInterfaceWithDefaultTheme.js +7 -0
- package/src/utils/toISODateString.js +14 -0
- package/src/utils/toISOMonthString.js +14 -0
- package/src/utils/toLocalizedDateString.js +12 -0
- package/src/utils/toMomentObject.js +12 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _enzymeShallowEqual = _interopRequireDefault(require("enzyme-shallow-equal"));
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _readOnlyError2 = _interopRequireDefault(require("@babel/runtime/helpers/readOnlyError"));
|
|
11
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
var _react = _interopRequireDefault(require("react"));
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
var _airbnbPropTypes = require("airbnb-prop-types");
|
|
16
|
+
var _reactWithStyles = require("react-with-styles");
|
|
17
|
+
var _throttle = _interopRequireDefault(require("lodash/throttle"));
|
|
18
|
+
var _isTouchDevice = _interopRequireDefault(require("is-touch-device"));
|
|
19
|
+
var _noflip = _interopRequireDefault(require("../utils/noflip"));
|
|
20
|
+
var _getInputHeight = _interopRequireDefault(require("../utils/getInputHeight"));
|
|
21
|
+
var _OpenDirectionShape = _interopRequireDefault(require("../shapes/OpenDirectionShape"));
|
|
22
|
+
var _constants = require("../constants");
|
|
23
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
24
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
25
|
+
var FANG_PATH_TOP = "M0,".concat(_constants.FANG_HEIGHT_PX, " ").concat(_constants.FANG_WIDTH_PX, ",").concat(_constants.FANG_HEIGHT_PX, " ").concat(_constants.FANG_WIDTH_PX / 2, ",0z");
|
|
26
|
+
var FANG_STROKE_TOP = "M0,".concat(_constants.FANG_HEIGHT_PX, " ").concat(_constants.FANG_WIDTH_PX / 2, ",0 ").concat(_constants.FANG_WIDTH_PX, ",").concat(_constants.FANG_HEIGHT_PX);
|
|
27
|
+
var FANG_PATH_BOTTOM = "M0,0 ".concat(_constants.FANG_WIDTH_PX, ",0 ").concat(_constants.FANG_WIDTH_PX / 2, ",").concat(_constants.FANG_HEIGHT_PX, "z");
|
|
28
|
+
var FANG_STROKE_BOTTOM = "M0,0 ".concat(_constants.FANG_WIDTH_PX / 2, ",").concat(_constants.FANG_HEIGHT_PX, " ").concat(_constants.FANG_WIDTH_PX, ",0");
|
|
29
|
+
var propTypes = process.env.NODE_ENV !== "production" ? (0, _airbnbPropTypes.forbidExtraProps)(_objectSpread(_objectSpread({}, _reactWithStyles.withStylesPropTypes), {}, {
|
|
30
|
+
id: _propTypes["default"].string.isRequired,
|
|
31
|
+
placeholder: _propTypes["default"].string,
|
|
32
|
+
displayValue: _propTypes["default"].string,
|
|
33
|
+
ariaLabel: _propTypes["default"].string,
|
|
34
|
+
autoComplete: _propTypes["default"].string,
|
|
35
|
+
titleText: _propTypes["default"].string,
|
|
36
|
+
screenReaderMessage: _propTypes["default"].string,
|
|
37
|
+
focused: _propTypes["default"].bool,
|
|
38
|
+
disabled: _propTypes["default"].bool,
|
|
39
|
+
required: _propTypes["default"].bool,
|
|
40
|
+
readOnly: _propTypes["default"].bool,
|
|
41
|
+
openDirection: _OpenDirectionShape["default"],
|
|
42
|
+
showCaret: _propTypes["default"].bool,
|
|
43
|
+
verticalSpacing: _airbnbPropTypes.nonNegativeInteger,
|
|
44
|
+
small: _propTypes["default"].bool,
|
|
45
|
+
block: _propTypes["default"].bool,
|
|
46
|
+
regular: _propTypes["default"].bool,
|
|
47
|
+
onChange: _propTypes["default"].func,
|
|
48
|
+
onFocus: _propTypes["default"].func,
|
|
49
|
+
onKeyDownShiftTab: _propTypes["default"].func,
|
|
50
|
+
onKeyDownTab: _propTypes["default"].func,
|
|
51
|
+
onKeyDownArrowDown: _propTypes["default"].func,
|
|
52
|
+
onKeyDownQuestionMark: _propTypes["default"].func,
|
|
53
|
+
// accessibility
|
|
54
|
+
isFocused: _propTypes["default"].bool // describes actual DOM focus
|
|
55
|
+
})) : {};
|
|
56
|
+
var defaultProps = {
|
|
57
|
+
placeholder: 'Select Date',
|
|
58
|
+
displayValue: '',
|
|
59
|
+
ariaLabel: undefined,
|
|
60
|
+
autoComplete: 'off',
|
|
61
|
+
titleText: undefined,
|
|
62
|
+
screenReaderMessage: '',
|
|
63
|
+
focused: false,
|
|
64
|
+
disabled: false,
|
|
65
|
+
required: false,
|
|
66
|
+
readOnly: null,
|
|
67
|
+
openDirection: _constants.OPEN_DOWN,
|
|
68
|
+
showCaret: false,
|
|
69
|
+
verticalSpacing: _constants.DEFAULT_VERTICAL_SPACING,
|
|
70
|
+
small: false,
|
|
71
|
+
block: false,
|
|
72
|
+
regular: false,
|
|
73
|
+
onChange: function onChange() {},
|
|
74
|
+
onFocus: function onFocus() {},
|
|
75
|
+
onKeyDownShiftTab: function onKeyDownShiftTab() {},
|
|
76
|
+
onKeyDownTab: function onKeyDownTab() {},
|
|
77
|
+
onKeyDownArrowDown: function onKeyDownArrowDown() {},
|
|
78
|
+
onKeyDownQuestionMark: function onKeyDownQuestionMark() {},
|
|
79
|
+
// accessibility
|
|
80
|
+
isFocused: false
|
|
81
|
+
};
|
|
82
|
+
var DateInput = /*#__PURE__*/function (_ref2, _ref) {
|
|
83
|
+
function DateInput(props) {
|
|
84
|
+
var _this;
|
|
85
|
+
_this = _ref2.call(this, props) || this;
|
|
86
|
+
_this.state = {
|
|
87
|
+
dateString: '',
|
|
88
|
+
isTouchDevice: false,
|
|
89
|
+
lastDisplayValue: props.displayValue
|
|
90
|
+
};
|
|
91
|
+
_this.onChange = _this.onChange.bind(_this);
|
|
92
|
+
_this.onKeyDown = _this.onKeyDown.bind(_this);
|
|
93
|
+
_this.setInputRef = _this.setInputRef.bind(_this);
|
|
94
|
+
_this.throttledKeyDown = (0, _throttle["default"])(_this.onFinalKeyDown, 300, {
|
|
95
|
+
trailing: false
|
|
96
|
+
});
|
|
97
|
+
return _this;
|
|
98
|
+
}
|
|
99
|
+
(0, _inheritsLoose2["default"])(DateInput, _ref2);
|
|
100
|
+
var _proto = DateInput.prototype;
|
|
101
|
+
_proto[_ref] = function (nextProps, nextState) {
|
|
102
|
+
return !(0, _enzymeShallowEqual["default"])(this.props, nextProps) || !(0, _enzymeShallowEqual["default"])(this.state, nextState);
|
|
103
|
+
};
|
|
104
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
105
|
+
this.setState({
|
|
106
|
+
isTouchDevice: (0, _isTouchDevice["default"])()
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
DateInput.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
|
|
110
|
+
var displayValue = props.displayValue;
|
|
111
|
+
// Only react to displayValue changes that arrive via props, not to our own
|
|
112
|
+
// state updates (e.g. the user typing), so a typed draft is never wiped mid-edit.
|
|
113
|
+
if (displayValue !== state.lastDisplayValue) {
|
|
114
|
+
var nextState = {
|
|
115
|
+
lastDisplayValue: displayValue
|
|
116
|
+
};
|
|
117
|
+
if (state.dateString && displayValue) {
|
|
118
|
+
nextState.dateString = '';
|
|
119
|
+
}
|
|
120
|
+
return nextState;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
124
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
125
|
+
var _this$props = this.props,
|
|
126
|
+
focused = _this$props.focused,
|
|
127
|
+
isFocused = _this$props.isFocused;
|
|
128
|
+
if (prevProps.focused === focused && prevProps.isFocused === isFocused) return;
|
|
129
|
+
if (focused && isFocused) {
|
|
130
|
+
this.inputRef.focus();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
_proto.onChange = function onChange(e) {
|
|
134
|
+
var _this$props2 = this.props,
|
|
135
|
+
onChange = _this$props2.onChange,
|
|
136
|
+
onKeyDownQuestionMark = _this$props2.onKeyDownQuestionMark;
|
|
137
|
+
var dateString = e.target.value;
|
|
138
|
+
|
|
139
|
+
// In Safari, onKeyDown does not consistently fire ahead of onChange. As a result, we need to
|
|
140
|
+
// special case the `?` key so that it always triggers the appropriate callback, instead of
|
|
141
|
+
// modifying the input value
|
|
142
|
+
if (dateString[dateString.length - 1] === '?') {
|
|
143
|
+
onKeyDownQuestionMark(e);
|
|
144
|
+
} else {
|
|
145
|
+
this.setState({
|
|
146
|
+
dateString: dateString
|
|
147
|
+
}, function () {
|
|
148
|
+
return onChange(dateString);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
_proto.onKeyDown = function onKeyDown(e) {
|
|
153
|
+
e.stopPropagation();
|
|
154
|
+
if (!_constants.MODIFIER_KEY_NAMES.has(e.key)) {
|
|
155
|
+
this.throttledKeyDown(e);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
_proto.onFinalKeyDown = function onFinalKeyDown(e) {
|
|
159
|
+
var _this$props3 = this.props,
|
|
160
|
+
onKeyDownShiftTab = _this$props3.onKeyDownShiftTab,
|
|
161
|
+
onKeyDownTab = _this$props3.onKeyDownTab,
|
|
162
|
+
onKeyDownArrowDown = _this$props3.onKeyDownArrowDown,
|
|
163
|
+
onKeyDownQuestionMark = _this$props3.onKeyDownQuestionMark;
|
|
164
|
+
var key = e.key;
|
|
165
|
+
if (key === 'Tab') {
|
|
166
|
+
if (e.shiftKey) {
|
|
167
|
+
onKeyDownShiftTab(e);
|
|
168
|
+
} else {
|
|
169
|
+
onKeyDownTab(e);
|
|
170
|
+
}
|
|
171
|
+
} else if (key === 'ArrowDown') {
|
|
172
|
+
onKeyDownArrowDown(e);
|
|
173
|
+
} else if (key === '?') {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
onKeyDownQuestionMark(e);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
_proto.setInputRef = function setInputRef(ref) {
|
|
179
|
+
this.inputRef = ref;
|
|
180
|
+
};
|
|
181
|
+
_proto.render = function render() {
|
|
182
|
+
var _this$state = this.state,
|
|
183
|
+
dateString = _this$state.dateString,
|
|
184
|
+
isTouch = _this$state.isTouchDevice;
|
|
185
|
+
var _this$props4 = this.props,
|
|
186
|
+
id = _this$props4.id,
|
|
187
|
+
placeholder = _this$props4.placeholder,
|
|
188
|
+
ariaLabel = _this$props4.ariaLabel,
|
|
189
|
+
autoComplete = _this$props4.autoComplete,
|
|
190
|
+
titleText = _this$props4.titleText,
|
|
191
|
+
displayValue = _this$props4.displayValue,
|
|
192
|
+
screenReaderMessage = _this$props4.screenReaderMessage,
|
|
193
|
+
focused = _this$props4.focused,
|
|
194
|
+
showCaret = _this$props4.showCaret,
|
|
195
|
+
onFocus = _this$props4.onFocus,
|
|
196
|
+
disabled = _this$props4.disabled,
|
|
197
|
+
required = _this$props4.required,
|
|
198
|
+
readOnly = _this$props4.readOnly,
|
|
199
|
+
openDirection = _this$props4.openDirection,
|
|
200
|
+
verticalSpacing = _this$props4.verticalSpacing,
|
|
201
|
+
small = _this$props4.small,
|
|
202
|
+
regular = _this$props4.regular,
|
|
203
|
+
block = _this$props4.block,
|
|
204
|
+
css = _this$props4.css,
|
|
205
|
+
styles = _this$props4.styles,
|
|
206
|
+
reactDates = _this$props4.theme.reactDates;
|
|
207
|
+
var value = dateString || displayValue || '';
|
|
208
|
+
var screenReaderMessageId = "DateInput__screen-reader-message-".concat(id);
|
|
209
|
+
var withFang = showCaret && focused;
|
|
210
|
+
var inputHeight = (0, _getInputHeight["default"])(reactDates, small);
|
|
211
|
+
return /*#__PURE__*/_react["default"].createElement("div", css(styles.DateInput, small && styles.DateInput__small, block && styles.DateInput__block, withFang && styles.DateInput__withFang, disabled && styles.DateInput__disabled, withFang && openDirection === _constants.OPEN_DOWN && styles.DateInput__openDown, withFang && openDirection === _constants.OPEN_UP && styles.DateInput__openUp), /*#__PURE__*/_react["default"].createElement("input", (0, _extends2["default"])({}, css(styles.DateInput_input, small && styles.DateInput_input__small, regular && styles.DateInput_input__regular, readOnly && styles.DateInput_input__readOnly, focused && styles.DateInput_input__focused, disabled && styles.DateInput_input__disabled), {
|
|
212
|
+
"aria-label": ariaLabel === undefined ? placeholder : ariaLabel,
|
|
213
|
+
title: titleText,
|
|
214
|
+
type: "text",
|
|
215
|
+
id: id,
|
|
216
|
+
name: id,
|
|
217
|
+
ref: this.setInputRef,
|
|
218
|
+
value: value,
|
|
219
|
+
onChange: this.onChange,
|
|
220
|
+
onKeyDown: this.onKeyDown,
|
|
221
|
+
onFocus: onFocus,
|
|
222
|
+
placeholder: placeholder,
|
|
223
|
+
autoComplete: autoComplete,
|
|
224
|
+
disabled: disabled,
|
|
225
|
+
readOnly: typeof readOnly === 'boolean' ? readOnly : isTouch,
|
|
226
|
+
required: required,
|
|
227
|
+
"aria-describedby": screenReaderMessage && screenReaderMessageId
|
|
228
|
+
})), withFang && /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
|
|
229
|
+
role: "presentation",
|
|
230
|
+
focusable: "false"
|
|
231
|
+
}, css(styles.DateInput_fang, openDirection === _constants.OPEN_DOWN && {
|
|
232
|
+
top: inputHeight + verticalSpacing - _constants.FANG_HEIGHT_PX - 1
|
|
233
|
+
}, openDirection === _constants.OPEN_UP && {
|
|
234
|
+
bottom: inputHeight + verticalSpacing - _constants.FANG_HEIGHT_PX - 1
|
|
235
|
+
})), /*#__PURE__*/_react["default"].createElement("path", (0, _extends2["default"])({}, css(styles.DateInput_fangShape), {
|
|
236
|
+
d: openDirection === _constants.OPEN_DOWN ? FANG_PATH_TOP : FANG_PATH_BOTTOM
|
|
237
|
+
})), /*#__PURE__*/_react["default"].createElement("path", (0, _extends2["default"])({}, css(styles.DateInput_fangStroke), {
|
|
238
|
+
d: openDirection === _constants.OPEN_DOWN ? FANG_STROKE_TOP : FANG_STROKE_BOTTOM
|
|
239
|
+
}))), screenReaderMessage && /*#__PURE__*/_react["default"].createElement("p", (0, _extends2["default"])({}, css(styles.DateInput_screenReaderMessage), {
|
|
240
|
+
id: screenReaderMessageId
|
|
241
|
+
}), screenReaderMessage));
|
|
242
|
+
};
|
|
243
|
+
return DateInput;
|
|
244
|
+
}(_react["default"].PureComponent || _react["default"].Component, !_react["default"].PureComponent && "shouldComponentUpdate");
|
|
245
|
+
DateInput.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
|
|
246
|
+
DateInput.defaultProps = defaultProps;
|
|
247
|
+
var _default = exports["default"] = (0, _reactWithStyles.withStyles)(function (_ref3) {
|
|
248
|
+
var _ref3$reactDates = _ref3.reactDates,
|
|
249
|
+
border = _ref3$reactDates.border,
|
|
250
|
+
color = _ref3$reactDates.color,
|
|
251
|
+
sizing = _ref3$reactDates.sizing,
|
|
252
|
+
spacing = _ref3$reactDates.spacing,
|
|
253
|
+
font = _ref3$reactDates.font,
|
|
254
|
+
zIndex = _ref3$reactDates.zIndex;
|
|
255
|
+
return {
|
|
256
|
+
DateInput: {
|
|
257
|
+
margin: 0,
|
|
258
|
+
padding: spacing.inputPadding,
|
|
259
|
+
background: color.background,
|
|
260
|
+
position: 'relative',
|
|
261
|
+
display: 'inline-block',
|
|
262
|
+
width: sizing.inputWidth,
|
|
263
|
+
verticalAlign: 'middle'
|
|
264
|
+
},
|
|
265
|
+
DateInput__small: {
|
|
266
|
+
width: sizing.inputWidth_small
|
|
267
|
+
},
|
|
268
|
+
DateInput__block: {
|
|
269
|
+
width: '100%'
|
|
270
|
+
},
|
|
271
|
+
DateInput__disabled: {
|
|
272
|
+
background: color.disabled,
|
|
273
|
+
color: color.textDisabled
|
|
274
|
+
},
|
|
275
|
+
DateInput_input: {
|
|
276
|
+
fontWeight: font.input.weight,
|
|
277
|
+
fontSize: font.input.size,
|
|
278
|
+
lineHeight: font.input.lineHeight,
|
|
279
|
+
color: color.text,
|
|
280
|
+
backgroundColor: color.background,
|
|
281
|
+
width: '100%',
|
|
282
|
+
padding: "".concat(spacing.displayTextPaddingVertical, "px ").concat(spacing.displayTextPaddingHorizontal, "px"),
|
|
283
|
+
paddingTop: spacing.displayTextPaddingTop,
|
|
284
|
+
paddingBottom: spacing.displayTextPaddingBottom,
|
|
285
|
+
paddingLeft: (0, _noflip["default"])(spacing.displayTextPaddingLeft),
|
|
286
|
+
paddingRight: (0, _noflip["default"])(spacing.displayTextPaddingRight),
|
|
287
|
+
border: border.input.border,
|
|
288
|
+
borderTop: border.input.borderTop,
|
|
289
|
+
borderRight: (0, _noflip["default"])(border.input.borderRight),
|
|
290
|
+
borderBottom: border.input.borderBottom,
|
|
291
|
+
borderLeft: (0, _noflip["default"])(border.input.borderLeft),
|
|
292
|
+
borderRadius: border.input.borderRadius
|
|
293
|
+
},
|
|
294
|
+
DateInput_input__small: {
|
|
295
|
+
fontSize: font.input.size_small,
|
|
296
|
+
lineHeight: font.input.lineHeight_small,
|
|
297
|
+
letterSpacing: font.input.letterSpacing_small,
|
|
298
|
+
padding: "".concat(spacing.displayTextPaddingVertical_small, "px ").concat(spacing.displayTextPaddingHorizontal_small, "px"),
|
|
299
|
+
paddingTop: spacing.displayTextPaddingTop_small,
|
|
300
|
+
paddingBottom: spacing.displayTextPaddingBottom_small,
|
|
301
|
+
paddingLeft: (0, _noflip["default"])(spacing.displayTextPaddingLeft_small),
|
|
302
|
+
paddingRight: (0, _noflip["default"])(spacing.displayTextPaddingRight_small)
|
|
303
|
+
},
|
|
304
|
+
DateInput_input__regular: {
|
|
305
|
+
fontWeight: 'inherit'
|
|
306
|
+
},
|
|
307
|
+
DateInput_input__readOnly: {
|
|
308
|
+
userSelect: 'none'
|
|
309
|
+
},
|
|
310
|
+
DateInput_input__focused: {
|
|
311
|
+
outline: border.input.outlineFocused,
|
|
312
|
+
background: color.backgroundFocused,
|
|
313
|
+
border: border.input.borderFocused,
|
|
314
|
+
borderTop: border.input.borderTopFocused,
|
|
315
|
+
borderRight: (0, _noflip["default"])(border.input.borderRightFocused),
|
|
316
|
+
borderBottom: border.input.borderBottomFocused,
|
|
317
|
+
borderLeft: (0, _noflip["default"])(border.input.borderLeftFocused)
|
|
318
|
+
},
|
|
319
|
+
DateInput_input__disabled: {
|
|
320
|
+
background: color.disabled,
|
|
321
|
+
fontStyle: font.input.styleDisabled
|
|
322
|
+
},
|
|
323
|
+
DateInput_screenReaderMessage: {
|
|
324
|
+
border: 0,
|
|
325
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
326
|
+
height: 1,
|
|
327
|
+
margin: -1,
|
|
328
|
+
overflow: 'hidden',
|
|
329
|
+
padding: 0,
|
|
330
|
+
position: 'absolute',
|
|
331
|
+
width: 1
|
|
332
|
+
},
|
|
333
|
+
DateInput_fang: {
|
|
334
|
+
position: 'absolute',
|
|
335
|
+
width: _constants.FANG_WIDTH_PX,
|
|
336
|
+
height: _constants.FANG_HEIGHT_PX,
|
|
337
|
+
left: 22,
|
|
338
|
+
// TODO: should be noflip wrapped and handled by an isRTL prop
|
|
339
|
+
zIndex: zIndex + 2
|
|
340
|
+
},
|
|
341
|
+
DateInput_fangShape: {
|
|
342
|
+
fill: color.background
|
|
343
|
+
},
|
|
344
|
+
DateInput_fangStroke: {
|
|
345
|
+
stroke: color.core.border,
|
|
346
|
+
fill: 'transparent'
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}, {
|
|
350
|
+
pureComponent: typeof _react["default"].PureComponent !== 'undefined'
|
|
351
|
+
})(DateInput);
|