@instructure/ui-date-input 11.7.3-snapshot-7 → 11.7.3-snapshot-26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -2
- package/es/DateInput/v1/index.js +208 -202
- package/es/DateInput/v2/index.js +19 -34
- package/es/DateInput2/v1/index.js +19 -34
- package/lib/DateInput/v1/index.js +209 -203
- package/lib/DateInput/v2/index.js +20 -35
- package/lib/DateInput2/v1/index.js +20 -35
- package/package.json +18 -18
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
var _CalendarInstUIIcon, _ChevronRightInstUIIc, _ChevronLeftInstUIIco;
|
|
3
1
|
/*
|
|
4
2
|
* The MIT License (MIT)
|
|
5
3
|
*
|
|
@@ -131,23 +129,15 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
131
129
|
}, ref) => {
|
|
132
130
|
const userLocale = locale || getLocale();
|
|
133
131
|
const userTimezone = timezone || getTimezone();
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
inputMessages = _useState2[0],
|
|
137
|
-
setInputMessages = _useState2[1];
|
|
138
|
-
const _useState3 = useState(false),
|
|
139
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
140
|
-
showPopover = _useState4[0],
|
|
141
|
-
setShowPopover = _useState4[1];
|
|
132
|
+
const [inputMessages, setInputMessages] = useState(messages || []);
|
|
133
|
+
const [showPopover, setShowPopover] = useState(false);
|
|
142
134
|
useEffect(() => {
|
|
143
135
|
// don't set input messages if there is an internal error set already
|
|
144
136
|
if (inputMessages.find(m => m.text === invalidDateErrorMessage)) return;
|
|
145
137
|
setInputMessages(messages || []);
|
|
146
138
|
}, [messages]);
|
|
147
139
|
useEffect(() => {
|
|
148
|
-
const
|
|
149
|
-
_parseDate2 = _slicedToArray(_parseDate, 2),
|
|
150
|
-
utcIsoDate = _parseDate2[1];
|
|
140
|
+
const [, utcIsoDate] = parseDate(value);
|
|
151
141
|
// clear error messages if date becomes valid
|
|
152
142
|
if (utcIsoDate || !value) {
|
|
153
143
|
setInputMessages(messages || []);
|
|
@@ -170,7 +160,7 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
170
160
|
};
|
|
171
161
|
const formatDate = (date, timeZone = userTimezone) => {
|
|
172
162
|
// use formatter function if provided
|
|
173
|
-
if (typeof dateFormat !== 'string' && dateFormat
|
|
163
|
+
if (typeof dateFormat !== 'string' && dateFormat?.formatter) {
|
|
174
164
|
return dateFormat.formatter(date);
|
|
175
165
|
}
|
|
176
166
|
// if dateFormat set to a locale, use that, otherwise default to the user's locale
|
|
@@ -196,25 +186,20 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
196
186
|
return formattedDate.replace(regex(year), match => 'Y'.repeat(match.length)).replace(regex(month), match => 'M'.repeat(match.length)).replace(regex(day), match => 'D'.repeat(match.length));
|
|
197
187
|
};
|
|
198
188
|
const handleInputChange = (e, newValue) => {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
utcIsoDate = _parseDate4[1];
|
|
202
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(e, newValue, utcIsoDate);
|
|
189
|
+
const [, utcIsoDate] = parseDate(newValue);
|
|
190
|
+
onChange?.(e, newValue, utcIsoDate);
|
|
203
191
|
};
|
|
204
192
|
const handleDateSelected = (dateString, _momentDate, e) => {
|
|
205
193
|
setShowPopover(false);
|
|
206
194
|
const newValue = formatDate(new Date(dateString));
|
|
207
|
-
onChange
|
|
208
|
-
onRequestValidateDate
|
|
195
|
+
onChange?.(e, newValue, dateString);
|
|
196
|
+
onRequestValidateDate?.(e, newValue, dateString);
|
|
209
197
|
};
|
|
210
198
|
const handleBlur = e => {
|
|
211
|
-
const
|
|
212
|
-
_parseDate6 = _slicedToArray(_parseDate5, 2),
|
|
213
|
-
localeDate = _parseDate6[0],
|
|
214
|
-
utcIsoDate = _parseDate6[1];
|
|
199
|
+
const [localeDate, utcIsoDate] = parseDate(value);
|
|
215
200
|
if (localeDate) {
|
|
216
201
|
if (localeDate !== value) {
|
|
217
|
-
onChange
|
|
202
|
+
onChange?.(e, localeDate, utcIsoDate);
|
|
218
203
|
}
|
|
219
204
|
} else if (value && invalidDateErrorMessage) {
|
|
220
205
|
setInputMessages([{
|
|
@@ -222,8 +207,8 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
222
207
|
text: invalidDateErrorMessage
|
|
223
208
|
}]);
|
|
224
209
|
}
|
|
225
|
-
onRequestValidateDate
|
|
226
|
-
onBlur
|
|
210
|
+
onRequestValidateDate?.(e, value || '', utcIsoDate);
|
|
211
|
+
onBlur?.(e, value || '', utcIsoDate);
|
|
227
212
|
};
|
|
228
213
|
const selectedDate = parseDate(value)[1];
|
|
229
214
|
return _jsx(TextInput, {
|
|
@@ -236,7 +221,7 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
236
221
|
onBlur: handleBlur,
|
|
237
222
|
isRequired: isRequired,
|
|
238
223
|
value: value,
|
|
239
|
-
placeholder: placeholder
|
|
224
|
+
placeholder: placeholder ?? getDateFormatHint(),
|
|
240
225
|
width: width,
|
|
241
226
|
display: isInline ? 'inline-block' : 'block',
|
|
242
227
|
messages: inputMessages,
|
|
@@ -248,9 +233,9 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
248
233
|
withBorder: false,
|
|
249
234
|
screenReaderLabel: screenReaderLabels.calendarIcon,
|
|
250
235
|
interaction: interaction,
|
|
251
|
-
children: renderCalendarIcon ? callRenderProp(renderCalendarIcon) :
|
|
236
|
+
children: renderCalendarIcon ? callRenderProp(renderCalendarIcon) : _jsx(CalendarInstUIIcon, {
|
|
252
237
|
color: "baseColor"
|
|
253
|
-
})
|
|
238
|
+
})
|
|
254
239
|
}),
|
|
255
240
|
isShowingContent: showPopover,
|
|
256
241
|
onShowContent: () => setShowPopover(true),
|
|
@@ -272,18 +257,18 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
272
257
|
size: "small",
|
|
273
258
|
withBackground: false,
|
|
274
259
|
withBorder: false,
|
|
275
|
-
renderIcon:
|
|
260
|
+
renderIcon: _jsx(ChevronRightInstUIIcon, {
|
|
276
261
|
color: "baseColor"
|
|
277
|
-
})
|
|
262
|
+
}),
|
|
278
263
|
screenReaderLabel: screenReaderLabels.nextMonthButton
|
|
279
264
|
}),
|
|
280
265
|
renderPrevMonthButton: _jsx(IconButton, {
|
|
281
266
|
size: "small",
|
|
282
267
|
withBackground: false,
|
|
283
268
|
withBorder: false,
|
|
284
|
-
renderIcon:
|
|
269
|
+
renderIcon: _jsx(ChevronLeftInstUIIcon, {
|
|
285
270
|
color: "baseColor"
|
|
286
|
-
})
|
|
271
|
+
}),
|
|
287
272
|
screenReaderLabel: screenReaderLabels.prevMonthButton
|
|
288
273
|
})
|
|
289
274
|
})
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.DateInput = void 0;
|
|
8
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
8
|
var _react = require("react");
|
|
10
9
|
var _v11_ = require("@instructure/ui-calendar/v11_6");
|
|
11
10
|
var _IconCalendarMonthLine = require("@instructure/ui-icons/lib/generated/IconCalendarMonthLine.js");
|
|
@@ -21,11 +20,9 @@ var _DateTime = require("@instructure/ui-i18n/lib/DateTime.js");
|
|
|
21
20
|
var _Locale = require("@instructure/ui-i18n/lib/Locale.js");
|
|
22
21
|
var _emotion = require("@instructure/emotion");
|
|
23
22
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
24
|
-
var
|
|
23
|
+
var _props = require("./props");
|
|
25
24
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
26
|
-
|
|
27
|
-
_excluded2 = ["ref"];
|
|
28
|
-
var _dec, _class, _DateInput, _IconCalendarMonthLin;
|
|
25
|
+
var _dec, _class;
|
|
29
26
|
/*
|
|
30
27
|
* The MIT License (MIT)
|
|
31
28
|
*
|
|
@@ -54,135 +51,31 @@ var _dec, _class, _DateInput, _IconCalendarMonthLin;
|
|
|
54
51
|
category: components
|
|
55
52
|
---
|
|
56
53
|
**/
|
|
57
|
-
let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, null), _dec(_class =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this._input = el;
|
|
83
|
-
(_this$props$inputRef = (_this$props = this.props).inputRef) === null || _this$props$inputRef === void 0 ? void 0 : _this$props$inputRef.call(_this$props, el);
|
|
84
|
-
};
|
|
85
|
-
this.handleInputChange = (event, value) => {
|
|
86
|
-
var _this$props$onChange, _this$props2;
|
|
87
|
-
(_this$props$onChange = (_this$props2 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props2, event, {
|
|
88
|
-
value
|
|
89
|
-
});
|
|
90
|
-
this.handleShowCalendar(event);
|
|
91
|
-
};
|
|
92
|
-
this.handleShowCalendar = event => {
|
|
93
|
-
if (!this.props.children) {
|
|
94
|
-
this.setState({
|
|
95
|
-
isShowingCalendar: true
|
|
96
|
-
});
|
|
97
|
-
} else if (this.interaction === 'enabled' && this.props.children) {
|
|
98
|
-
var _this$props$onRequest, _this$props3;
|
|
99
|
-
(_this$props$onRequest = (_this$props3 = this.props).onRequestShowCalendar) === null || _this$props$onRequest === void 0 ? void 0 : _this$props$onRequest.call(_this$props3, event);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
this.validateDate = date => {
|
|
103
|
-
const invalidDateErrorMessage = this.props.invalidDateErrorMessage;
|
|
104
|
-
const disabledDateErrorMessage = this.props.disabledDateErrorMessage || invalidDateErrorMessage;
|
|
105
|
-
const messages = [];
|
|
106
|
-
// check if date is enabled
|
|
107
|
-
const disabledDates = this.props.disabledDates;
|
|
108
|
-
if (typeof disabledDates === 'function' && disabledDates(date) || Array.isArray(disabledDates) && disabledDates.find(dateString => _DateTime.DateTime.parse(dateString, this.locale(), this.timezone()).isSame(_DateTime.DateTime.parse(date, this.locale(), this.timezone()), 'day'))) {
|
|
109
|
-
messages.push(typeof disabledDateErrorMessage === 'function' ? disabledDateErrorMessage(date) : {
|
|
110
|
-
type: 'error',
|
|
111
|
-
text: disabledDateErrorMessage
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// check if date is valid
|
|
116
|
-
if (!_DateTime.DateTime.parse(date, this.locale(), this.timezone(), [_DateTime.DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], true).isValid()) {
|
|
117
|
-
messages.push(typeof invalidDateErrorMessage === 'function' ? invalidDateErrorMessage(date) : {
|
|
118
|
-
type: 'error',
|
|
119
|
-
text: invalidDateErrorMessage
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
return messages;
|
|
123
|
-
};
|
|
124
|
-
this.handleHideCalendar = (event, setectedDate) => {
|
|
125
|
-
if (!this.props.children) {
|
|
126
|
-
const dateString = setectedDate || this.props.value;
|
|
127
|
-
const messages = [];
|
|
128
|
-
if (this.props.onRequestValidateDate) {
|
|
129
|
-
var _this$props$onRequest2, _this$props4;
|
|
130
|
-
const userValidatedDate = (_this$props$onRequest2 = (_this$props4 = this.props).onRequestValidateDate) === null || _this$props$onRequest2 === void 0 ? void 0 : _this$props$onRequest2.call(_this$props4, event, dateString || '', this.validateDate(dateString || ''));
|
|
131
|
-
messages.push(...(userValidatedDate || []));
|
|
132
|
-
} else {
|
|
133
|
-
if (dateString) {
|
|
134
|
-
messages.push(...this.validateDate(dateString));
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
this.setState({
|
|
138
|
-
messages,
|
|
139
|
-
isShowingCalendar: false
|
|
140
|
-
});
|
|
141
|
-
} else {
|
|
142
|
-
var _this$props$onRequest3, _this$props5, _this$props$onRequest4, _this$props6;
|
|
143
|
-
(_this$props$onRequest3 = (_this$props5 = this.props).onRequestValidateDate) === null || _this$props$onRequest3 === void 0 ? void 0 : _this$props$onRequest3.call(_this$props5, event);
|
|
144
|
-
(_this$props$onRequest4 = (_this$props6 = this.props).onRequestHideCalendar) === null || _this$props$onRequest4 === void 0 ? void 0 : _this$props$onRequest4.call(_this$props6, event);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
this.handleHighlightOption = (event, {
|
|
148
|
-
direction
|
|
149
|
-
}) => {
|
|
150
|
-
const _this$props7 = this.props,
|
|
151
|
-
onRequestSelectNextDay = _this$props7.onRequestSelectNextDay,
|
|
152
|
-
onRequestSelectPrevDay = _this$props7.onRequestSelectPrevDay,
|
|
153
|
-
onChange = _this$props7.onChange,
|
|
154
|
-
value = _this$props7.value,
|
|
155
|
-
currentDate = _this$props7.currentDate;
|
|
156
|
-
const isValueValid = value && _DateTime.DateTime.parse(value, this.locale(), this.timezone()).isValid();
|
|
157
|
-
if (direction === -1) {
|
|
158
|
-
if (onRequestSelectPrevDay) {
|
|
159
|
-
onRequestSelectPrevDay === null || onRequestSelectPrevDay === void 0 ? void 0 : onRequestSelectPrevDay(event);
|
|
160
|
-
} else {
|
|
161
|
-
// @ts-expect-error TODO
|
|
162
|
-
onChange(event, {
|
|
163
|
-
value: _DateTime.DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('MMMM D, YYYY')
|
|
164
|
-
});
|
|
165
|
-
this.setState({
|
|
166
|
-
messages: []
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (direction === 1) {
|
|
171
|
-
if (onRequestSelectNextDay) {
|
|
172
|
-
onRequestSelectNextDay === null || onRequestSelectNextDay === void 0 ? void 0 : onRequestSelectNextDay(event);
|
|
173
|
-
} else {
|
|
174
|
-
// @ts-expect-error TODO
|
|
175
|
-
onChange(event, {
|
|
176
|
-
value: _DateTime.DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('MMMM D, YYYY')
|
|
177
|
-
});
|
|
178
|
-
this.setState({
|
|
179
|
-
messages: []
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
this.shouldShowCalendar = () => this.props.children ? this.props.isShowingCalendar : this.state.isShowingCalendar;
|
|
185
|
-
}
|
|
54
|
+
let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, null), _dec(_class = class DateInput extends _react.Component {
|
|
55
|
+
static displayName = "DateInput";
|
|
56
|
+
static componentId = 'DateInput';
|
|
57
|
+
static Day = _v11_.Calendar.Day;
|
|
58
|
+
static allowedProps = _props.allowedProps;
|
|
59
|
+
static defaultProps = {
|
|
60
|
+
value: '',
|
|
61
|
+
size: 'medium',
|
|
62
|
+
onBlur: () => {},
|
|
63
|
+
// must have a default so createChainedFunction works
|
|
64
|
+
isRequired: false,
|
|
65
|
+
isInline: false,
|
|
66
|
+
layout: 'stacked',
|
|
67
|
+
display: 'inline-block',
|
|
68
|
+
placement: 'bottom center',
|
|
69
|
+
isShowingCalendar: false
|
|
70
|
+
};
|
|
71
|
+
state = {
|
|
72
|
+
hasInputRef: false,
|
|
73
|
+
isShowingCalendar: false,
|
|
74
|
+
validatedDate: undefined,
|
|
75
|
+
messages: []
|
|
76
|
+
};
|
|
77
|
+
_input = undefined;
|
|
78
|
+
ref = null;
|
|
186
79
|
locale() {
|
|
187
80
|
if (this.props.locale) {
|
|
188
81
|
return this.props.locale;
|
|
@@ -200,19 +93,18 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
200
93
|
return _DateTime.DateTime.browserTimeZone();
|
|
201
94
|
}
|
|
202
95
|
componentDidMount() {
|
|
203
|
-
|
|
204
|
-
(_this$props$makeStyle = (_this$props8 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props8);
|
|
96
|
+
this.props.makeStyles?.();
|
|
205
97
|
}
|
|
206
98
|
componentDidUpdate() {
|
|
207
|
-
|
|
208
|
-
(_this$props$makeStyle2 = (_this$props9 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props9);
|
|
99
|
+
this.props.makeStyles?.();
|
|
209
100
|
}
|
|
210
101
|
get selectedDateId() {
|
|
211
102
|
let selectedDateId;
|
|
212
103
|
_react.Children.toArray(this.props.children).forEach(day => {
|
|
213
|
-
const
|
|
214
|
-
date
|
|
215
|
-
isSelected
|
|
104
|
+
const {
|
|
105
|
+
date,
|
|
106
|
+
isSelected
|
|
107
|
+
} = day.props;
|
|
216
108
|
if (isSelected) {
|
|
217
109
|
selectedDateId = this.formatDateId(date);
|
|
218
110
|
}
|
|
@@ -224,10 +116,127 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
224
116
|
props: this.props
|
|
225
117
|
});
|
|
226
118
|
}
|
|
119
|
+
formatDateId = date => {
|
|
120
|
+
// ISO8601 strings may contain a space. Remove any spaces before using the
|
|
121
|
+
// date as the id.
|
|
122
|
+
return date.replace(/\s/g, '');
|
|
123
|
+
};
|
|
124
|
+
handleInputRef = el => {
|
|
125
|
+
// Ensures that we position the Calendar with respect to the input correctly
|
|
126
|
+
// if the Calendar is open on mount
|
|
127
|
+
if (!this.state.hasInputRef) {
|
|
128
|
+
this.setState({
|
|
129
|
+
hasInputRef: true
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
this._input = el;
|
|
133
|
+
this.props.inputRef?.(el);
|
|
134
|
+
};
|
|
135
|
+
handleInputChange = (event, value) => {
|
|
136
|
+
this.props.onChange?.(event, {
|
|
137
|
+
value
|
|
138
|
+
});
|
|
139
|
+
this.handleShowCalendar(event);
|
|
140
|
+
};
|
|
141
|
+
handleShowCalendar = event => {
|
|
142
|
+
if (!this.props.children) {
|
|
143
|
+
this.setState({
|
|
144
|
+
isShowingCalendar: true
|
|
145
|
+
});
|
|
146
|
+
} else if (this.interaction === 'enabled' && this.props.children) {
|
|
147
|
+
this.props.onRequestShowCalendar?.(event);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
validateDate = date => {
|
|
151
|
+
const {
|
|
152
|
+
invalidDateErrorMessage
|
|
153
|
+
} = this.props;
|
|
154
|
+
const disabledDateErrorMessage = this.props.disabledDateErrorMessage || invalidDateErrorMessage;
|
|
155
|
+
const messages = [];
|
|
156
|
+
// check if date is enabled
|
|
157
|
+
const {
|
|
158
|
+
disabledDates
|
|
159
|
+
} = this.props;
|
|
160
|
+
if (typeof disabledDates === 'function' && disabledDates(date) || Array.isArray(disabledDates) && disabledDates.find(dateString => _DateTime.DateTime.parse(dateString, this.locale(), this.timezone()).isSame(_DateTime.DateTime.parse(date, this.locale(), this.timezone()), 'day'))) {
|
|
161
|
+
messages.push(typeof disabledDateErrorMessage === 'function' ? disabledDateErrorMessage(date) : {
|
|
162
|
+
type: 'error',
|
|
163
|
+
text: disabledDateErrorMessage
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// check if date is valid
|
|
168
|
+
if (!_DateTime.DateTime.parse(date, this.locale(), this.timezone(), [_DateTime.DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], true).isValid()) {
|
|
169
|
+
messages.push(typeof invalidDateErrorMessage === 'function' ? invalidDateErrorMessage(date) : {
|
|
170
|
+
type: 'error',
|
|
171
|
+
text: invalidDateErrorMessage
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return messages;
|
|
175
|
+
};
|
|
176
|
+
handleHideCalendar = (event, setectedDate) => {
|
|
177
|
+
if (!this.props.children) {
|
|
178
|
+
const dateString = setectedDate || this.props.value;
|
|
179
|
+
const messages = [];
|
|
180
|
+
if (this.props.onRequestValidateDate) {
|
|
181
|
+
const userValidatedDate = this.props.onRequestValidateDate?.(event, dateString || '', this.validateDate(dateString || ''));
|
|
182
|
+
messages.push(...(userValidatedDate || []));
|
|
183
|
+
} else {
|
|
184
|
+
if (dateString) {
|
|
185
|
+
messages.push(...this.validateDate(dateString));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
this.setState({
|
|
189
|
+
messages,
|
|
190
|
+
isShowingCalendar: false
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
this.props.onRequestValidateDate?.(event);
|
|
194
|
+
this.props.onRequestHideCalendar?.(event);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
handleHighlightOption = (event, {
|
|
198
|
+
direction
|
|
199
|
+
}) => {
|
|
200
|
+
const {
|
|
201
|
+
onRequestSelectNextDay,
|
|
202
|
+
onRequestSelectPrevDay,
|
|
203
|
+
onChange,
|
|
204
|
+
value,
|
|
205
|
+
currentDate
|
|
206
|
+
} = this.props;
|
|
207
|
+
const isValueValid = value && _DateTime.DateTime.parse(value, this.locale(), this.timezone()).isValid();
|
|
208
|
+
if (direction === -1) {
|
|
209
|
+
if (onRequestSelectPrevDay) {
|
|
210
|
+
onRequestSelectPrevDay?.(event);
|
|
211
|
+
} else {
|
|
212
|
+
// @ts-expect-error TODO
|
|
213
|
+
onChange(event, {
|
|
214
|
+
value: _DateTime.DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('MMMM D, YYYY')
|
|
215
|
+
});
|
|
216
|
+
this.setState({
|
|
217
|
+
messages: []
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (direction === 1) {
|
|
222
|
+
if (onRequestSelectNextDay) {
|
|
223
|
+
onRequestSelectNextDay?.(event);
|
|
224
|
+
} else {
|
|
225
|
+
// @ts-expect-error TODO
|
|
226
|
+
onChange(event, {
|
|
227
|
+
value: _DateTime.DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('MMMM D, YYYY')
|
|
228
|
+
});
|
|
229
|
+
this.setState({
|
|
230
|
+
messages: []
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
227
235
|
renderMonthNavigationButton(type = 'prev') {
|
|
228
|
-
const
|
|
229
|
-
renderPrevMonthButton
|
|
230
|
-
renderNextMonthButton
|
|
236
|
+
const {
|
|
237
|
+
renderPrevMonthButton,
|
|
238
|
+
renderNextMonthButton
|
|
239
|
+
} = this.props;
|
|
231
240
|
const button = type === 'prev' ? renderPrevMonthButton : renderNextMonthButton;
|
|
232
241
|
return button && (0, _safeCloneElement.safeCloneElement)((0, _callRenderProp.callRenderProp)(button), {
|
|
233
242
|
tabIndex: -1
|
|
@@ -237,9 +246,10 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
237
246
|
const children = this.props.children;
|
|
238
247
|
if (!children) return;
|
|
239
248
|
return _react.Children.map(children, day => {
|
|
240
|
-
const
|
|
241
|
-
date
|
|
242
|
-
isOutsideMonth
|
|
249
|
+
const {
|
|
250
|
+
date,
|
|
251
|
+
isOutsideMonth
|
|
252
|
+
} = day.props;
|
|
243
253
|
const props = {
|
|
244
254
|
tabIndex: -1,
|
|
245
255
|
id: this.formatDateId(date)
|
|
@@ -257,24 +267,25 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
257
267
|
getListProps,
|
|
258
268
|
getOptionProps
|
|
259
269
|
}) {
|
|
260
|
-
const
|
|
261
|
-
onRequestRenderNextMonth
|
|
262
|
-
onRequestRenderPrevMonth
|
|
263
|
-
renderNavigationLabel
|
|
264
|
-
renderWeekdayLabels
|
|
265
|
-
value
|
|
266
|
-
onChange
|
|
267
|
-
disabledDates
|
|
268
|
-
currentDate
|
|
270
|
+
const {
|
|
271
|
+
onRequestRenderNextMonth,
|
|
272
|
+
onRequestRenderPrevMonth,
|
|
273
|
+
renderNavigationLabel,
|
|
274
|
+
renderWeekdayLabels,
|
|
275
|
+
value,
|
|
276
|
+
onChange,
|
|
277
|
+
disabledDates,
|
|
278
|
+
currentDate
|
|
279
|
+
} = this.props;
|
|
269
280
|
const isValidDate = value ? _DateTime.DateTime.parse(value, this.locale(), this.timezone()).isValid() : false;
|
|
270
281
|
const noChildrenProps = this.props.children ? {} : {
|
|
271
282
|
disabledDates,
|
|
272
283
|
currentDate,
|
|
273
|
-
selectedDate: isValidDate ? value :
|
|
274
|
-
visibleMonth: isValidDate ? value :
|
|
284
|
+
selectedDate: isValidDate ? value : undefined,
|
|
285
|
+
visibleMonth: isValidDate ? value : undefined,
|
|
275
286
|
onDateSelected: (dateString, momentDate, e) => {
|
|
276
287
|
// @ts-expect-error TODO
|
|
277
|
-
onChange
|
|
288
|
+
onChange?.(e, {
|
|
278
289
|
value: `${momentDate.format('MMMM')} ${momentDate.format('D')}, ${momentDate.format('YYYY')}`
|
|
279
290
|
});
|
|
280
291
|
this.handleHideCalendar(e, dateString);
|
|
@@ -297,28 +308,33 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
297
308
|
getInputProps,
|
|
298
309
|
getTriggerProps
|
|
299
310
|
}) {
|
|
300
|
-
const
|
|
301
|
-
renderLabel
|
|
302
|
-
value
|
|
303
|
-
placeholder
|
|
304
|
-
onBlur
|
|
305
|
-
isRequired
|
|
306
|
-
size
|
|
307
|
-
isInline
|
|
308
|
-
layout
|
|
309
|
-
width
|
|
310
|
-
onRequestValidateDate
|
|
311
|
-
onRequestShowCalendar
|
|
312
|
-
onRequestHideCalendar
|
|
313
|
-
onRequestSelectNextDay
|
|
314
|
-
onRequestSelectPrevDay
|
|
315
|
-
onRequestRenderNextMonth
|
|
316
|
-
onRequestRenderPrevMonth
|
|
317
|
-
rest
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
311
|
+
const {
|
|
312
|
+
renderLabel,
|
|
313
|
+
value,
|
|
314
|
+
placeholder,
|
|
315
|
+
onBlur,
|
|
316
|
+
isRequired,
|
|
317
|
+
size,
|
|
318
|
+
isInline,
|
|
319
|
+
layout,
|
|
320
|
+
width,
|
|
321
|
+
onRequestValidateDate,
|
|
322
|
+
onRequestShowCalendar,
|
|
323
|
+
onRequestHideCalendar,
|
|
324
|
+
onRequestSelectNextDay,
|
|
325
|
+
onRequestSelectPrevDay,
|
|
326
|
+
onRequestRenderNextMonth,
|
|
327
|
+
onRequestRenderPrevMonth,
|
|
328
|
+
...rest
|
|
329
|
+
} = this.props;
|
|
330
|
+
const {
|
|
331
|
+
interaction
|
|
332
|
+
} = this;
|
|
333
|
+
const {
|
|
334
|
+
ref,
|
|
335
|
+
// Apply this to the actual inputRef
|
|
336
|
+
...triggerProps
|
|
337
|
+
} = getTriggerProps();
|
|
322
338
|
const messages = this.props.messages || this.state.messages;
|
|
323
339
|
return (0, _jsxRuntime.jsx)(_v11_3.TextInput, {
|
|
324
340
|
...triggerProps,
|
|
@@ -337,27 +353,28 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
337
353
|
interaction,
|
|
338
354
|
isRequired,
|
|
339
355
|
display: isInline ? 'inline-block' : 'block',
|
|
340
|
-
renderAfterInput:
|
|
356
|
+
renderAfterInput: (0, _jsxRuntime.jsx)(_IconCalendarMonthLine.IconCalendarMonthLine, {
|
|
341
357
|
inline: false
|
|
342
|
-
})
|
|
358
|
+
})
|
|
343
359
|
}),
|
|
344
360
|
onKeyDown: e => {
|
|
345
|
-
var _triggerProps$onKeyDo;
|
|
346
361
|
if (!this.props.children) {
|
|
347
362
|
if (e.key === 'Enter') {
|
|
348
363
|
// @ts-expect-error TODO
|
|
349
364
|
this.handleHideCalendar(e);
|
|
350
365
|
}
|
|
351
366
|
}
|
|
352
|
-
|
|
367
|
+
triggerProps.onKeyDown?.(e);
|
|
353
368
|
}
|
|
354
369
|
});
|
|
355
370
|
}
|
|
371
|
+
shouldShowCalendar = () => this.props.children ? this.props.isShowingCalendar : this.state.isShowingCalendar;
|
|
356
372
|
render() {
|
|
357
|
-
const
|
|
358
|
-
placement
|
|
359
|
-
assistiveText
|
|
360
|
-
styles
|
|
373
|
+
const {
|
|
374
|
+
placement,
|
|
375
|
+
assistiveText,
|
|
376
|
+
styles
|
|
377
|
+
} = this.props;
|
|
361
378
|
const isShowingCalendar = this.shouldShowCalendar();
|
|
362
379
|
return (0, _jsxRuntime.jsx)(_Selectable.Selectable, {
|
|
363
380
|
isShowingOptions: isShowingCalendar,
|
|
@@ -376,7 +393,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
376
393
|
getDescriptionProps
|
|
377
394
|
}) => (0, _jsxRuntime.jsxs)("span", {
|
|
378
395
|
...getRootProps({
|
|
379
|
-
css: styles
|
|
396
|
+
css: styles?.dateInput
|
|
380
397
|
}),
|
|
381
398
|
ref: el => {
|
|
382
399
|
this.ref = el;
|
|
@@ -387,7 +404,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
387
404
|
getTriggerProps
|
|
388
405
|
}), (0, _jsxRuntime.jsx)("span", {
|
|
389
406
|
...getDescriptionProps(),
|
|
390
|
-
css: styles
|
|
407
|
+
css: styles?.assistiveText,
|
|
391
408
|
children: assistiveText
|
|
392
409
|
}), (0, _jsxRuntime.jsx)(_v11_2.Popover, {
|
|
393
410
|
placement: placement,
|
|
@@ -403,16 +420,5 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_style
|
|
|
403
420
|
})
|
|
404
421
|
});
|
|
405
422
|
}
|
|
406
|
-
}
|
|
407
|
-
value: '',
|
|
408
|
-
size: 'medium',
|
|
409
|
-
onBlur: () => {},
|
|
410
|
-
// must have a default so createChainedFunction works
|
|
411
|
-
isRequired: false,
|
|
412
|
-
isInline: false,
|
|
413
|
-
layout: 'stacked',
|
|
414
|
-
display: 'inline-block',
|
|
415
|
-
placement: 'bottom center',
|
|
416
|
-
isShowingCalendar: false
|
|
417
|
-
}, _DateInput)) || _class);
|
|
423
|
+
}) || _class);
|
|
418
424
|
var _default = exports.default = DateInput;
|