@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
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [11.7.3-snapshot-
|
|
6
|
+
## [11.7.3-snapshot-26](https://github.com/instructure/instructure-ui/compare/v11.7.2...v11.7.3-snapshot-26) (2026-05-05)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **many:** update dependencies, remove lots of Babel plugins, remove Webpack 4 support ([f916fca](https://github.com/instructure/instructure-ui/commit/f916fcafdddcb2d7de401f93e8ff92cfdfa47bba))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
package/es/DateInput/v1/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const _excluded = ["renderLabel", "value", "placeholder", "onBlur", "isRequired", "size", "isInline", "layout", "width", "onRequestValidateDate", "onRequestShowCalendar", "onRequestHideCalendar", "onRequestSelectNextDay", "onRequestSelectPrevDay", "onRequestRenderNextMonth", "onRequestRenderPrevMonth"],
|
|
3
|
-
_excluded2 = ["ref"];
|
|
4
|
-
var _dec, _class, _DateInput, _IconCalendarMonthLin;
|
|
1
|
+
var _dec, _class;
|
|
5
2
|
/*
|
|
6
3
|
* The MIT License (MIT)
|
|
7
4
|
*
|
|
@@ -44,135 +41,31 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
44
41
|
category: components
|
|
45
42
|
---
|
|
46
43
|
**/
|
|
47
|
-
let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this._input = el;
|
|
73
|
-
(_this$props$inputRef = (_this$props = this.props).inputRef) === null || _this$props$inputRef === void 0 ? void 0 : _this$props$inputRef.call(_this$props, el);
|
|
74
|
-
};
|
|
75
|
-
this.handleInputChange = (event, value) => {
|
|
76
|
-
var _this$props$onChange, _this$props2;
|
|
77
|
-
(_this$props$onChange = (_this$props2 = this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props2, event, {
|
|
78
|
-
value
|
|
79
|
-
});
|
|
80
|
-
this.handleShowCalendar(event);
|
|
81
|
-
};
|
|
82
|
-
this.handleShowCalendar = event => {
|
|
83
|
-
if (!this.props.children) {
|
|
84
|
-
this.setState({
|
|
85
|
-
isShowingCalendar: true
|
|
86
|
-
});
|
|
87
|
-
} else if (this.interaction === 'enabled' && this.props.children) {
|
|
88
|
-
var _this$props$onRequest, _this$props3;
|
|
89
|
-
(_this$props$onRequest = (_this$props3 = this.props).onRequestShowCalendar) === null || _this$props$onRequest === void 0 ? void 0 : _this$props$onRequest.call(_this$props3, event);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
this.validateDate = date => {
|
|
93
|
-
const invalidDateErrorMessage = this.props.invalidDateErrorMessage;
|
|
94
|
-
const disabledDateErrorMessage = this.props.disabledDateErrorMessage || invalidDateErrorMessage;
|
|
95
|
-
const messages = [];
|
|
96
|
-
// check if date is enabled
|
|
97
|
-
const disabledDates = this.props.disabledDates;
|
|
98
|
-
if (typeof disabledDates === 'function' && disabledDates(date) || Array.isArray(disabledDates) && disabledDates.find(dateString => DateTime.parse(dateString, this.locale(), this.timezone()).isSame(DateTime.parse(date, this.locale(), this.timezone()), 'day'))) {
|
|
99
|
-
messages.push(typeof disabledDateErrorMessage === 'function' ? disabledDateErrorMessage(date) : {
|
|
100
|
-
type: 'error',
|
|
101
|
-
text: disabledDateErrorMessage
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// check if date is valid
|
|
106
|
-
if (!DateTime.parse(date, this.locale(), this.timezone(), [DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], true).isValid()) {
|
|
107
|
-
messages.push(typeof invalidDateErrorMessage === 'function' ? invalidDateErrorMessage(date) : {
|
|
108
|
-
type: 'error',
|
|
109
|
-
text: invalidDateErrorMessage
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
return messages;
|
|
113
|
-
};
|
|
114
|
-
this.handleHideCalendar = (event, setectedDate) => {
|
|
115
|
-
if (!this.props.children) {
|
|
116
|
-
const dateString = setectedDate || this.props.value;
|
|
117
|
-
const messages = [];
|
|
118
|
-
if (this.props.onRequestValidateDate) {
|
|
119
|
-
var _this$props$onRequest2, _this$props4;
|
|
120
|
-
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 || ''));
|
|
121
|
-
messages.push(...(userValidatedDate || []));
|
|
122
|
-
} else {
|
|
123
|
-
if (dateString) {
|
|
124
|
-
messages.push(...this.validateDate(dateString));
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
this.setState({
|
|
128
|
-
messages,
|
|
129
|
-
isShowingCalendar: false
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
var _this$props$onRequest3, _this$props5, _this$props$onRequest4, _this$props6;
|
|
133
|
-
(_this$props$onRequest3 = (_this$props5 = this.props).onRequestValidateDate) === null || _this$props$onRequest3 === void 0 ? void 0 : _this$props$onRequest3.call(_this$props5, event);
|
|
134
|
-
(_this$props$onRequest4 = (_this$props6 = this.props).onRequestHideCalendar) === null || _this$props$onRequest4 === void 0 ? void 0 : _this$props$onRequest4.call(_this$props6, event);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
this.handleHighlightOption = (event, {
|
|
138
|
-
direction
|
|
139
|
-
}) => {
|
|
140
|
-
const _this$props7 = this.props,
|
|
141
|
-
onRequestSelectNextDay = _this$props7.onRequestSelectNextDay,
|
|
142
|
-
onRequestSelectPrevDay = _this$props7.onRequestSelectPrevDay,
|
|
143
|
-
onChange = _this$props7.onChange,
|
|
144
|
-
value = _this$props7.value,
|
|
145
|
-
currentDate = _this$props7.currentDate;
|
|
146
|
-
const isValueValid = value && DateTime.parse(value, this.locale(), this.timezone()).isValid();
|
|
147
|
-
if (direction === -1) {
|
|
148
|
-
if (onRequestSelectPrevDay) {
|
|
149
|
-
onRequestSelectPrevDay === null || onRequestSelectPrevDay === void 0 ? void 0 : onRequestSelectPrevDay(event);
|
|
150
|
-
} else {
|
|
151
|
-
// @ts-expect-error TODO
|
|
152
|
-
onChange(event, {
|
|
153
|
-
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('MMMM D, YYYY')
|
|
154
|
-
});
|
|
155
|
-
this.setState({
|
|
156
|
-
messages: []
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (direction === 1) {
|
|
161
|
-
if (onRequestSelectNextDay) {
|
|
162
|
-
onRequestSelectNextDay === null || onRequestSelectNextDay === void 0 ? void 0 : onRequestSelectNextDay(event);
|
|
163
|
-
} else {
|
|
164
|
-
// @ts-expect-error TODO
|
|
165
|
-
onChange(event, {
|
|
166
|
-
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('MMMM D, YYYY')
|
|
167
|
-
});
|
|
168
|
-
this.setState({
|
|
169
|
-
messages: []
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
this.shouldShowCalendar = () => this.props.children ? this.props.isShowingCalendar : this.state.isShowingCalendar;
|
|
175
|
-
}
|
|
44
|
+
let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = class DateInput extends Component {
|
|
45
|
+
static displayName = "DateInput";
|
|
46
|
+
static componentId = 'DateInput';
|
|
47
|
+
static Day = Calendar.Day;
|
|
48
|
+
static allowedProps = allowedProps;
|
|
49
|
+
static defaultProps = {
|
|
50
|
+
value: '',
|
|
51
|
+
size: 'medium',
|
|
52
|
+
onBlur: () => {},
|
|
53
|
+
// must have a default so createChainedFunction works
|
|
54
|
+
isRequired: false,
|
|
55
|
+
isInline: false,
|
|
56
|
+
layout: 'stacked',
|
|
57
|
+
display: 'inline-block',
|
|
58
|
+
placement: 'bottom center',
|
|
59
|
+
isShowingCalendar: false
|
|
60
|
+
};
|
|
61
|
+
state = {
|
|
62
|
+
hasInputRef: false,
|
|
63
|
+
isShowingCalendar: false,
|
|
64
|
+
validatedDate: undefined,
|
|
65
|
+
messages: []
|
|
66
|
+
};
|
|
67
|
+
_input = undefined;
|
|
68
|
+
ref = null;
|
|
176
69
|
locale() {
|
|
177
70
|
if (this.props.locale) {
|
|
178
71
|
return this.props.locale;
|
|
@@ -190,19 +83,18 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
190
83
|
return DateTime.browserTimeZone();
|
|
191
84
|
}
|
|
192
85
|
componentDidMount() {
|
|
193
|
-
|
|
194
|
-
(_this$props$makeStyle = (_this$props8 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props8);
|
|
86
|
+
this.props.makeStyles?.();
|
|
195
87
|
}
|
|
196
88
|
componentDidUpdate() {
|
|
197
|
-
|
|
198
|
-
(_this$props$makeStyle2 = (_this$props9 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props9);
|
|
89
|
+
this.props.makeStyles?.();
|
|
199
90
|
}
|
|
200
91
|
get selectedDateId() {
|
|
201
92
|
let selectedDateId;
|
|
202
93
|
Children.toArray(this.props.children).forEach(day => {
|
|
203
|
-
const
|
|
204
|
-
date
|
|
205
|
-
isSelected
|
|
94
|
+
const {
|
|
95
|
+
date,
|
|
96
|
+
isSelected
|
|
97
|
+
} = day.props;
|
|
206
98
|
if (isSelected) {
|
|
207
99
|
selectedDateId = this.formatDateId(date);
|
|
208
100
|
}
|
|
@@ -214,10 +106,127 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
214
106
|
props: this.props
|
|
215
107
|
});
|
|
216
108
|
}
|
|
109
|
+
formatDateId = date => {
|
|
110
|
+
// ISO8601 strings may contain a space. Remove any spaces before using the
|
|
111
|
+
// date as the id.
|
|
112
|
+
return date.replace(/\s/g, '');
|
|
113
|
+
};
|
|
114
|
+
handleInputRef = el => {
|
|
115
|
+
// Ensures that we position the Calendar with respect to the input correctly
|
|
116
|
+
// if the Calendar is open on mount
|
|
117
|
+
if (!this.state.hasInputRef) {
|
|
118
|
+
this.setState({
|
|
119
|
+
hasInputRef: true
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
this._input = el;
|
|
123
|
+
this.props.inputRef?.(el);
|
|
124
|
+
};
|
|
125
|
+
handleInputChange = (event, value) => {
|
|
126
|
+
this.props.onChange?.(event, {
|
|
127
|
+
value
|
|
128
|
+
});
|
|
129
|
+
this.handleShowCalendar(event);
|
|
130
|
+
};
|
|
131
|
+
handleShowCalendar = event => {
|
|
132
|
+
if (!this.props.children) {
|
|
133
|
+
this.setState({
|
|
134
|
+
isShowingCalendar: true
|
|
135
|
+
});
|
|
136
|
+
} else if (this.interaction === 'enabled' && this.props.children) {
|
|
137
|
+
this.props.onRequestShowCalendar?.(event);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
validateDate = date => {
|
|
141
|
+
const {
|
|
142
|
+
invalidDateErrorMessage
|
|
143
|
+
} = this.props;
|
|
144
|
+
const disabledDateErrorMessage = this.props.disabledDateErrorMessage || invalidDateErrorMessage;
|
|
145
|
+
const messages = [];
|
|
146
|
+
// check if date is enabled
|
|
147
|
+
const {
|
|
148
|
+
disabledDates
|
|
149
|
+
} = this.props;
|
|
150
|
+
if (typeof disabledDates === 'function' && disabledDates(date) || Array.isArray(disabledDates) && disabledDates.find(dateString => DateTime.parse(dateString, this.locale(), this.timezone()).isSame(DateTime.parse(date, this.locale(), this.timezone()), 'day'))) {
|
|
151
|
+
messages.push(typeof disabledDateErrorMessage === 'function' ? disabledDateErrorMessage(date) : {
|
|
152
|
+
type: 'error',
|
|
153
|
+
text: disabledDateErrorMessage
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// check if date is valid
|
|
158
|
+
if (!DateTime.parse(date, this.locale(), this.timezone(), [DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], true).isValid()) {
|
|
159
|
+
messages.push(typeof invalidDateErrorMessage === 'function' ? invalidDateErrorMessage(date) : {
|
|
160
|
+
type: 'error',
|
|
161
|
+
text: invalidDateErrorMessage
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return messages;
|
|
165
|
+
};
|
|
166
|
+
handleHideCalendar = (event, setectedDate) => {
|
|
167
|
+
if (!this.props.children) {
|
|
168
|
+
const dateString = setectedDate || this.props.value;
|
|
169
|
+
const messages = [];
|
|
170
|
+
if (this.props.onRequestValidateDate) {
|
|
171
|
+
const userValidatedDate = this.props.onRequestValidateDate?.(event, dateString || '', this.validateDate(dateString || ''));
|
|
172
|
+
messages.push(...(userValidatedDate || []));
|
|
173
|
+
} else {
|
|
174
|
+
if (dateString) {
|
|
175
|
+
messages.push(...this.validateDate(dateString));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
this.setState({
|
|
179
|
+
messages,
|
|
180
|
+
isShowingCalendar: false
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
this.props.onRequestValidateDate?.(event);
|
|
184
|
+
this.props.onRequestHideCalendar?.(event);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
handleHighlightOption = (event, {
|
|
188
|
+
direction
|
|
189
|
+
}) => {
|
|
190
|
+
const {
|
|
191
|
+
onRequestSelectNextDay,
|
|
192
|
+
onRequestSelectPrevDay,
|
|
193
|
+
onChange,
|
|
194
|
+
value,
|
|
195
|
+
currentDate
|
|
196
|
+
} = this.props;
|
|
197
|
+
const isValueValid = value && DateTime.parse(value, this.locale(), this.timezone()).isValid();
|
|
198
|
+
if (direction === -1) {
|
|
199
|
+
if (onRequestSelectPrevDay) {
|
|
200
|
+
onRequestSelectPrevDay?.(event);
|
|
201
|
+
} else {
|
|
202
|
+
// @ts-expect-error TODO
|
|
203
|
+
onChange(event, {
|
|
204
|
+
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('MMMM D, YYYY')
|
|
205
|
+
});
|
|
206
|
+
this.setState({
|
|
207
|
+
messages: []
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (direction === 1) {
|
|
212
|
+
if (onRequestSelectNextDay) {
|
|
213
|
+
onRequestSelectNextDay?.(event);
|
|
214
|
+
} else {
|
|
215
|
+
// @ts-expect-error TODO
|
|
216
|
+
onChange(event, {
|
|
217
|
+
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('MMMM D, YYYY')
|
|
218
|
+
});
|
|
219
|
+
this.setState({
|
|
220
|
+
messages: []
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
217
225
|
renderMonthNavigationButton(type = 'prev') {
|
|
218
|
-
const
|
|
219
|
-
renderPrevMonthButton
|
|
220
|
-
renderNextMonthButton
|
|
226
|
+
const {
|
|
227
|
+
renderPrevMonthButton,
|
|
228
|
+
renderNextMonthButton
|
|
229
|
+
} = this.props;
|
|
221
230
|
const button = type === 'prev' ? renderPrevMonthButton : renderNextMonthButton;
|
|
222
231
|
return button && safeCloneElement(callRenderProp(button), {
|
|
223
232
|
tabIndex: -1
|
|
@@ -227,9 +236,10 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
227
236
|
const children = this.props.children;
|
|
228
237
|
if (!children) return;
|
|
229
238
|
return Children.map(children, day => {
|
|
230
|
-
const
|
|
231
|
-
date
|
|
232
|
-
isOutsideMonth
|
|
239
|
+
const {
|
|
240
|
+
date,
|
|
241
|
+
isOutsideMonth
|
|
242
|
+
} = day.props;
|
|
233
243
|
const props = {
|
|
234
244
|
tabIndex: -1,
|
|
235
245
|
id: this.formatDateId(date)
|
|
@@ -247,24 +257,25 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
247
257
|
getListProps,
|
|
248
258
|
getOptionProps
|
|
249
259
|
}) {
|
|
250
|
-
const
|
|
251
|
-
onRequestRenderNextMonth
|
|
252
|
-
onRequestRenderPrevMonth
|
|
253
|
-
renderNavigationLabel
|
|
254
|
-
renderWeekdayLabels
|
|
255
|
-
value
|
|
256
|
-
onChange
|
|
257
|
-
disabledDates
|
|
258
|
-
currentDate
|
|
260
|
+
const {
|
|
261
|
+
onRequestRenderNextMonth,
|
|
262
|
+
onRequestRenderPrevMonth,
|
|
263
|
+
renderNavigationLabel,
|
|
264
|
+
renderWeekdayLabels,
|
|
265
|
+
value,
|
|
266
|
+
onChange,
|
|
267
|
+
disabledDates,
|
|
268
|
+
currentDate
|
|
269
|
+
} = this.props;
|
|
259
270
|
const isValidDate = value ? DateTime.parse(value, this.locale(), this.timezone()).isValid() : false;
|
|
260
271
|
const noChildrenProps = this.props.children ? {} : {
|
|
261
272
|
disabledDates,
|
|
262
273
|
currentDate,
|
|
263
|
-
selectedDate: isValidDate ? value :
|
|
264
|
-
visibleMonth: isValidDate ? value :
|
|
274
|
+
selectedDate: isValidDate ? value : undefined,
|
|
275
|
+
visibleMonth: isValidDate ? value : undefined,
|
|
265
276
|
onDateSelected: (dateString, momentDate, e) => {
|
|
266
277
|
// @ts-expect-error TODO
|
|
267
|
-
onChange
|
|
278
|
+
onChange?.(e, {
|
|
268
279
|
value: `${momentDate.format('MMMM')} ${momentDate.format('D')}, ${momentDate.format('YYYY')}`
|
|
269
280
|
});
|
|
270
281
|
this.handleHideCalendar(e, dateString);
|
|
@@ -287,28 +298,33 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
287
298
|
getInputProps,
|
|
288
299
|
getTriggerProps
|
|
289
300
|
}) {
|
|
290
|
-
const
|
|
291
|
-
renderLabel
|
|
292
|
-
value
|
|
293
|
-
placeholder
|
|
294
|
-
onBlur
|
|
295
|
-
isRequired
|
|
296
|
-
size
|
|
297
|
-
isInline
|
|
298
|
-
layout
|
|
299
|
-
width
|
|
300
|
-
onRequestValidateDate
|
|
301
|
-
onRequestShowCalendar
|
|
302
|
-
onRequestHideCalendar
|
|
303
|
-
onRequestSelectNextDay
|
|
304
|
-
onRequestSelectPrevDay
|
|
305
|
-
onRequestRenderNextMonth
|
|
306
|
-
onRequestRenderPrevMonth
|
|
307
|
-
rest
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
301
|
+
const {
|
|
302
|
+
renderLabel,
|
|
303
|
+
value,
|
|
304
|
+
placeholder,
|
|
305
|
+
onBlur,
|
|
306
|
+
isRequired,
|
|
307
|
+
size,
|
|
308
|
+
isInline,
|
|
309
|
+
layout,
|
|
310
|
+
width,
|
|
311
|
+
onRequestValidateDate,
|
|
312
|
+
onRequestShowCalendar,
|
|
313
|
+
onRequestHideCalendar,
|
|
314
|
+
onRequestSelectNextDay,
|
|
315
|
+
onRequestSelectPrevDay,
|
|
316
|
+
onRequestRenderNextMonth,
|
|
317
|
+
onRequestRenderPrevMonth,
|
|
318
|
+
...rest
|
|
319
|
+
} = this.props;
|
|
320
|
+
const {
|
|
321
|
+
interaction
|
|
322
|
+
} = this;
|
|
323
|
+
const {
|
|
324
|
+
ref,
|
|
325
|
+
// Apply this to the actual inputRef
|
|
326
|
+
...triggerProps
|
|
327
|
+
} = getTriggerProps();
|
|
312
328
|
const messages = this.props.messages || this.state.messages;
|
|
313
329
|
return _jsx(TextInput, {
|
|
314
330
|
...triggerProps,
|
|
@@ -327,27 +343,28 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
327
343
|
interaction,
|
|
328
344
|
isRequired,
|
|
329
345
|
display: isInline ? 'inline-block' : 'block',
|
|
330
|
-
renderAfterInput:
|
|
346
|
+
renderAfterInput: _jsx(IconCalendarMonthLine, {
|
|
331
347
|
inline: false
|
|
332
|
-
})
|
|
348
|
+
})
|
|
333
349
|
}),
|
|
334
350
|
onKeyDown: e => {
|
|
335
|
-
var _triggerProps$onKeyDo;
|
|
336
351
|
if (!this.props.children) {
|
|
337
352
|
if (e.key === 'Enter') {
|
|
338
353
|
// @ts-expect-error TODO
|
|
339
354
|
this.handleHideCalendar(e);
|
|
340
355
|
}
|
|
341
356
|
}
|
|
342
|
-
|
|
357
|
+
triggerProps.onKeyDown?.(e);
|
|
343
358
|
}
|
|
344
359
|
});
|
|
345
360
|
}
|
|
361
|
+
shouldShowCalendar = () => this.props.children ? this.props.isShowingCalendar : this.state.isShowingCalendar;
|
|
346
362
|
render() {
|
|
347
|
-
const
|
|
348
|
-
placement
|
|
349
|
-
assistiveText
|
|
350
|
-
styles
|
|
363
|
+
const {
|
|
364
|
+
placement,
|
|
365
|
+
assistiveText,
|
|
366
|
+
styles
|
|
367
|
+
} = this.props;
|
|
351
368
|
const isShowingCalendar = this.shouldShowCalendar();
|
|
352
369
|
return _jsx(Selectable, {
|
|
353
370
|
isShowingOptions: isShowingCalendar,
|
|
@@ -366,7 +383,7 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
366
383
|
getDescriptionProps
|
|
367
384
|
}) => _jsxs("span", {
|
|
368
385
|
...getRootProps({
|
|
369
|
-
css: styles
|
|
386
|
+
css: styles?.dateInput
|
|
370
387
|
}),
|
|
371
388
|
ref: el => {
|
|
372
389
|
this.ref = el;
|
|
@@ -377,7 +394,7 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
377
394
|
getTriggerProps
|
|
378
395
|
}), _jsx("span", {
|
|
379
396
|
...getDescriptionProps(),
|
|
380
|
-
css: styles
|
|
397
|
+
css: styles?.assistiveText,
|
|
381
398
|
children: assistiveText
|
|
382
399
|
}), _jsx(Popover, {
|
|
383
400
|
placement: placement,
|
|
@@ -393,17 +410,6 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec(_class = (_DateInpu
|
|
|
393
410
|
})
|
|
394
411
|
});
|
|
395
412
|
}
|
|
396
|
-
}
|
|
397
|
-
value: '',
|
|
398
|
-
size: 'medium',
|
|
399
|
-
onBlur: () => {},
|
|
400
|
-
// must have a default so createChainedFunction works
|
|
401
|
-
isRequired: false,
|
|
402
|
-
isInline: false,
|
|
403
|
-
layout: 'stacked',
|
|
404
|
-
display: 'inline-block',
|
|
405
|
-
placement: 'bottom center',
|
|
406
|
-
isShowingCalendar: false
|
|
407
|
-
}, _DateInput)) || _class);
|
|
413
|
+
}) || _class);
|
|
408
414
|
export default DateInput;
|
|
409
415
|
export { DateInput };
|
package/es/DateInput/v2/index.js
CHANGED
|
@@ -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 DateInput = /*#__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 DateInput = /*#__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 DateInput = /*#__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 DateInput = /*#__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 DateInput = /*#__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,
|
|
@@ -249,9 +234,9 @@ const DateInput = /*#__PURE__*/forwardRef(({
|
|
|
249
234
|
withBorder: false,
|
|
250
235
|
screenReaderLabel: screenReaderLabels.calendarIcon,
|
|
251
236
|
interaction: interaction,
|
|
252
|
-
children: renderCalendarIcon ? callRenderProp(renderCalendarIcon) :
|
|
237
|
+
children: renderCalendarIcon ? callRenderProp(renderCalendarIcon) : _jsx(CalendarInstUIIcon, {
|
|
253
238
|
color: "baseColor"
|
|
254
|
-
})
|
|
239
|
+
})
|
|
255
240
|
}),
|
|
256
241
|
isShowingContent: showPopover,
|
|
257
242
|
onShowContent: () => setShowPopover(true),
|
|
@@ -273,18 +258,18 @@ const DateInput = /*#__PURE__*/forwardRef(({
|
|
|
273
258
|
size: "small",
|
|
274
259
|
withBackground: false,
|
|
275
260
|
withBorder: false,
|
|
276
|
-
renderIcon:
|
|
261
|
+
renderIcon: _jsx(ChevronRightInstUIIcon, {
|
|
277
262
|
color: "baseColor"
|
|
278
|
-
})
|
|
263
|
+
}),
|
|
279
264
|
screenReaderLabel: screenReaderLabels.nextMonthButton
|
|
280
265
|
}),
|
|
281
266
|
renderPrevMonthButton: _jsx(IconButton, {
|
|
282
267
|
size: "small",
|
|
283
268
|
withBackground: false,
|
|
284
269
|
withBorder: false,
|
|
285
|
-
renderIcon:
|
|
270
|
+
renderIcon: _jsx(ChevronLeftInstUIIcon, {
|
|
286
271
|
color: "baseColor"
|
|
287
|
-
})
|
|
272
|
+
}),
|
|
288
273
|
screenReaderLabel: screenReaderLabels.prevMonthButton
|
|
289
274
|
})
|
|
290
275
|
})
|