@instructure/ui-date-input 11.6.0 → 11.6.1-snapshot-129
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 +48 -309
- package/es/DateInput/{index.js → v1/index.js} +4 -4
- package/es/DateInput/v2/index.js +407 -0
- package/es/DateInput/v2/props.js +26 -0
- package/es/DateInput/v2/styles.js +46 -0
- package/es/DateInput2/{index.js → v1/index.js} +13 -11
- package/es/{index.js → exports/a.js} +2 -2
- package/{src/index.ts → es/exports/b.js} +2 -5
- package/lib/DateInput/{index.js → v1/index.js} +9 -9
- package/lib/DateInput/v2/index.js +416 -0
- package/lib/DateInput/v2/props.js +31 -0
- package/lib/DateInput/v2/styles.js +52 -0
- package/lib/DateInput2/{index.js → v1/index.js} +19 -19
- package/lib/{index.js → exports/a.js} +4 -4
- package/lib/exports/b.js +19 -0
- package/package.json +45 -23
- package/src/DateInput/{index.tsx → v1/index.tsx} +10 -7
- package/src/DateInput/{props.ts → v1/props.ts} +2 -2
- package/src/DateInput/v2/README.md +315 -0
- package/src/DateInput/v2/index.tsx +498 -0
- package/src/DateInput/v2/props.ts +316 -0
- package/src/DateInput/v2/styles.ts +52 -0
- package/src/DateInput2/{README.md → v1/README.md} +9 -9
- package/src/DateInput2/{index.tsx → v1/index.tsx} +11 -11
- package/src/DateInput2/{props.ts → v1/props.ts} +1 -1
- package/src/exports/a.ts +28 -0
- package/src/exports/b.ts +28 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput/{index.d.ts → v1/index.d.ts} +4 -4
- package/types/DateInput/v1/index.d.ts.map +1 -0
- package/types/DateInput/{props.d.ts → v1/props.d.ts} +2 -2
- package/types/DateInput/v1/props.d.ts.map +1 -0
- package/types/DateInput/v1/styles.d.ts.map +1 -0
- package/types/DateInput/v2/index.d.ts +109 -0
- package/types/DateInput/v2/index.d.ts.map +1 -0
- package/types/DateInput/v2/props.d.ts +234 -0
- package/types/DateInput/v2/props.d.ts.map +1 -0
- package/types/DateInput/v2/styles.d.ts +13 -0
- package/types/DateInput/v2/styles.d.ts.map +1 -0
- package/types/DateInput2/{index.d.ts → v1/index.d.ts} +2 -2
- package/types/DateInput2/v1/index.d.ts.map +1 -0
- package/types/DateInput2/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/DateInput2/v1/props.d.ts.map +1 -0
- package/types/exports/a.d.ts +5 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +5 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/DateInput/index.d.ts.map +0 -1
- package/types/DateInput/props.d.ts.map +0 -1
- package/types/DateInput/styles.d.ts.map +0 -1
- package/types/DateInput2/index.d.ts.map +0 -1
- package/types/DateInput2/props.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- /package/es/DateInput/{props.js → v1/props.js} +0 -0
- /package/es/DateInput/{styles.js → v1/styles.js} +0 -0
- /package/es/DateInput2/{props.js → v1/props.js} +0 -0
- /package/lib/DateInput/{props.js → v1/props.js} +0 -0
- /package/lib/DateInput/{styles.js → v1/styles.js} +0 -0
- /package/lib/DateInput2/{props.js → v1/props.js} +0 -0
- /package/src/DateInput/{README.md → v1/README.md} +0 -0
- /package/src/DateInput/{styles.ts → v1/styles.ts} +0 -0
- /package/types/DateInput/{styles.d.ts → v1/styles.d.ts} +0 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
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, _CalendarInstUIIcon;
|
|
5
|
+
/*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
9
|
+
*
|
|
10
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
* in the Software without restriction, including without limitation the rights
|
|
13
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
* copies or substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
* SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { Children, Component } from 'react';
|
|
30
|
+
import { Calendar } from '@instructure/ui-calendar/latest';
|
|
31
|
+
import { CalendarInstUIIcon } from '@instructure/ui-icons';
|
|
32
|
+
import { Popover } from '@instructure/ui-popover/latest';
|
|
33
|
+
import { Selectable } from '@instructure/ui-selectable';
|
|
34
|
+
import { TextInput } from '@instructure/ui-text-input/latest';
|
|
35
|
+
import { createChainedFunction } from '@instructure/ui-utils';
|
|
36
|
+
import { getInteraction, callRenderProp, safeCloneElement, passthroughProps } from '@instructure/ui-react-utils';
|
|
37
|
+
import { DateTime, Locale } from '@instructure/ui-i18n';
|
|
38
|
+
import { withStyle } from '@instructure/emotion';
|
|
39
|
+
import generateStyle from "./styles.js";
|
|
40
|
+
import { allowedProps } from "./props.js";
|
|
41
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
42
|
+
/**
|
|
43
|
+
---
|
|
44
|
+
category: components
|
|
45
|
+
---
|
|
46
|
+
**/
|
|
47
|
+
let DateInput = (_dec = withStyle(generateStyle), _dec(_class = (_DateInput = class DateInput extends Component {
|
|
48
|
+
constructor(...args) {
|
|
49
|
+
super(...args);
|
|
50
|
+
this.state = {
|
|
51
|
+
hasInputRef: false,
|
|
52
|
+
isShowingCalendar: false,
|
|
53
|
+
validatedDate: void 0,
|
|
54
|
+
messages: []
|
|
55
|
+
};
|
|
56
|
+
this._input = void 0;
|
|
57
|
+
this.ref = null;
|
|
58
|
+
this.formatDateId = date => {
|
|
59
|
+
// ISO8601 strings may contain a space. Remove any spaces before using the
|
|
60
|
+
// date as the id.
|
|
61
|
+
return date.replace(/\s/g, '');
|
|
62
|
+
};
|
|
63
|
+
this.handleInputRef = el => {
|
|
64
|
+
var _this$props$inputRef, _this$props;
|
|
65
|
+
// Ensures that we position the Calendar with respect to the input correctly
|
|
66
|
+
// if the Calendar is open on mount
|
|
67
|
+
if (!this.state.hasInputRef) {
|
|
68
|
+
this.setState({
|
|
69
|
+
hasInputRef: true
|
|
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
|
+
}
|
|
176
|
+
locale() {
|
|
177
|
+
if (this.props.locale) {
|
|
178
|
+
return this.props.locale;
|
|
179
|
+
} else if (this.context && this.context.locale) {
|
|
180
|
+
return this.context.locale;
|
|
181
|
+
}
|
|
182
|
+
return Locale.browserLocale();
|
|
183
|
+
}
|
|
184
|
+
timezone() {
|
|
185
|
+
if (this.props.timezone) {
|
|
186
|
+
return this.props.timezone;
|
|
187
|
+
} else if (this.context && this.context.timezone) {
|
|
188
|
+
return this.context.timezone;
|
|
189
|
+
}
|
|
190
|
+
return DateTime.browserTimeZone();
|
|
191
|
+
}
|
|
192
|
+
componentDidMount() {
|
|
193
|
+
var _this$props$makeStyle, _this$props8;
|
|
194
|
+
(_this$props$makeStyle = (_this$props8 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props8);
|
|
195
|
+
}
|
|
196
|
+
componentDidUpdate() {
|
|
197
|
+
var _this$props$makeStyle2, _this$props9;
|
|
198
|
+
(_this$props$makeStyle2 = (_this$props9 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props9);
|
|
199
|
+
}
|
|
200
|
+
get selectedDateId() {
|
|
201
|
+
let selectedDateId;
|
|
202
|
+
Children.toArray(this.props.children).forEach(day => {
|
|
203
|
+
const _props = day.props,
|
|
204
|
+
date = _props.date,
|
|
205
|
+
isSelected = _props.isSelected;
|
|
206
|
+
if (isSelected) {
|
|
207
|
+
selectedDateId = this.formatDateId(date);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
return selectedDateId;
|
|
211
|
+
}
|
|
212
|
+
get interaction() {
|
|
213
|
+
return getInteraction({
|
|
214
|
+
props: this.props
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
renderMonthNavigationButton(type = 'prev') {
|
|
218
|
+
const _this$props0 = this.props,
|
|
219
|
+
renderPrevMonthButton = _this$props0.renderPrevMonthButton,
|
|
220
|
+
renderNextMonthButton = _this$props0.renderNextMonthButton;
|
|
221
|
+
const button = type === 'prev' ? renderPrevMonthButton : renderNextMonthButton;
|
|
222
|
+
return button && safeCloneElement(callRenderProp(button), {
|
|
223
|
+
tabIndex: -1
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
renderDays(getOptionProps) {
|
|
227
|
+
const children = this.props.children;
|
|
228
|
+
if (!children) return;
|
|
229
|
+
return Children.map(children, day => {
|
|
230
|
+
const _day$props = day.props,
|
|
231
|
+
date = _day$props.date,
|
|
232
|
+
isOutsideMonth = _day$props.isOutsideMonth;
|
|
233
|
+
const props = {
|
|
234
|
+
tabIndex: -1,
|
|
235
|
+
id: this.formatDateId(date)
|
|
236
|
+
};
|
|
237
|
+
const optionProps = getOptionProps(props);
|
|
238
|
+
const propsAdded = isOutsideMonth ? {
|
|
239
|
+
...props,
|
|
240
|
+
onClick: optionProps.onClick,
|
|
241
|
+
role: 'presentation'
|
|
242
|
+
} : optionProps;
|
|
243
|
+
return safeCloneElement(day, propsAdded);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
renderCalendar({
|
|
247
|
+
getListProps,
|
|
248
|
+
getOptionProps
|
|
249
|
+
}) {
|
|
250
|
+
const _this$props1 = this.props,
|
|
251
|
+
onRequestRenderNextMonth = _this$props1.onRequestRenderNextMonth,
|
|
252
|
+
onRequestRenderPrevMonth = _this$props1.onRequestRenderPrevMonth,
|
|
253
|
+
renderNavigationLabel = _this$props1.renderNavigationLabel,
|
|
254
|
+
renderWeekdayLabels = _this$props1.renderWeekdayLabels,
|
|
255
|
+
value = _this$props1.value,
|
|
256
|
+
onChange = _this$props1.onChange,
|
|
257
|
+
disabledDates = _this$props1.disabledDates,
|
|
258
|
+
currentDate = _this$props1.currentDate;
|
|
259
|
+
const isValidDate = value ? DateTime.parse(value, this.locale(), this.timezone()).isValid() : false;
|
|
260
|
+
const noChildrenProps = this.props.children ? {} : {
|
|
261
|
+
disabledDates,
|
|
262
|
+
currentDate,
|
|
263
|
+
selectedDate: isValidDate ? value : void 0,
|
|
264
|
+
visibleMonth: isValidDate ? value : void 0,
|
|
265
|
+
onDateSelected: (dateString, momentDate, e) => {
|
|
266
|
+
// @ts-expect-error TODO
|
|
267
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e, {
|
|
268
|
+
value: `${momentDate.format('MMMM')} ${momentDate.format('D')}, ${momentDate.format('YYYY')}`
|
|
269
|
+
});
|
|
270
|
+
this.handleHideCalendar(e, dateString);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
return _jsx(Calendar, {
|
|
274
|
+
...getListProps({
|
|
275
|
+
onRequestRenderNextMonth,
|
|
276
|
+
onRequestRenderPrevMonth,
|
|
277
|
+
renderNavigationLabel,
|
|
278
|
+
renderWeekdayLabels,
|
|
279
|
+
renderNextMonthButton: this.renderMonthNavigationButton('next'),
|
|
280
|
+
renderPrevMonthButton: this.renderMonthNavigationButton('prev')
|
|
281
|
+
}),
|
|
282
|
+
...noChildrenProps,
|
|
283
|
+
children: this.renderDays(getOptionProps)
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
renderInput({
|
|
287
|
+
getInputProps,
|
|
288
|
+
getTriggerProps
|
|
289
|
+
}) {
|
|
290
|
+
const _this$props10 = this.props,
|
|
291
|
+
renderLabel = _this$props10.renderLabel,
|
|
292
|
+
value = _this$props10.value,
|
|
293
|
+
placeholder = _this$props10.placeholder,
|
|
294
|
+
onBlur = _this$props10.onBlur,
|
|
295
|
+
isRequired = _this$props10.isRequired,
|
|
296
|
+
size = _this$props10.size,
|
|
297
|
+
isInline = _this$props10.isInline,
|
|
298
|
+
layout = _this$props10.layout,
|
|
299
|
+
width = _this$props10.width,
|
|
300
|
+
onRequestValidateDate = _this$props10.onRequestValidateDate,
|
|
301
|
+
onRequestShowCalendar = _this$props10.onRequestShowCalendar,
|
|
302
|
+
onRequestHideCalendar = _this$props10.onRequestHideCalendar,
|
|
303
|
+
onRequestSelectNextDay = _this$props10.onRequestSelectNextDay,
|
|
304
|
+
onRequestSelectPrevDay = _this$props10.onRequestSelectPrevDay,
|
|
305
|
+
onRequestRenderNextMonth = _this$props10.onRequestRenderNextMonth,
|
|
306
|
+
onRequestRenderPrevMonth = _this$props10.onRequestRenderPrevMonth,
|
|
307
|
+
rest = _objectWithoutProperties(_this$props10, _excluded);
|
|
308
|
+
const interaction = this.interaction;
|
|
309
|
+
const _getTriggerProps = getTriggerProps(),
|
|
310
|
+
ref = _getTriggerProps.ref,
|
|
311
|
+
triggerProps = _objectWithoutProperties(_getTriggerProps, _excluded2);
|
|
312
|
+
const messages = this.props.messages || this.state.messages;
|
|
313
|
+
return _jsx(TextInput, {
|
|
314
|
+
...triggerProps,
|
|
315
|
+
...passthroughProps(rest),
|
|
316
|
+
...getInputProps({
|
|
317
|
+
renderLabel: callRenderProp(renderLabel),
|
|
318
|
+
value,
|
|
319
|
+
placeholder,
|
|
320
|
+
size,
|
|
321
|
+
layout,
|
|
322
|
+
width,
|
|
323
|
+
messages,
|
|
324
|
+
onChange: this.handleInputChange,
|
|
325
|
+
onBlur: createChainedFunction(onBlur, this.handleHideCalendar),
|
|
326
|
+
inputRef: createChainedFunction(ref, this.handleInputRef),
|
|
327
|
+
interaction,
|
|
328
|
+
isRequired,
|
|
329
|
+
display: isInline ? 'inline-block' : 'block',
|
|
330
|
+
renderAfterInput: _CalendarInstUIIcon || (_CalendarInstUIIcon = _jsx(CalendarInstUIIcon, {}))
|
|
331
|
+
}),
|
|
332
|
+
onKeyDown: e => {
|
|
333
|
+
var _triggerProps$onKeyDo;
|
|
334
|
+
if (!this.props.children) {
|
|
335
|
+
if (e.key === 'Enter') {
|
|
336
|
+
// @ts-expect-error TODO
|
|
337
|
+
this.handleHideCalendar(e);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
(_triggerProps$onKeyDo = triggerProps.onKeyDown) === null || _triggerProps$onKeyDo === void 0 ? void 0 : _triggerProps$onKeyDo.call(triggerProps, e);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
render() {
|
|
345
|
+
const _this$props11 = this.props,
|
|
346
|
+
placement = _this$props11.placement,
|
|
347
|
+
assistiveText = _this$props11.assistiveText,
|
|
348
|
+
styles = _this$props11.styles;
|
|
349
|
+
const isShowingCalendar = this.shouldShowCalendar();
|
|
350
|
+
return _jsx(Selectable, {
|
|
351
|
+
isShowingOptions: isShowingCalendar,
|
|
352
|
+
onRequestShowOptions: this.handleShowCalendar,
|
|
353
|
+
onRequestHideOptions: this.handleHideCalendar,
|
|
354
|
+
onRequestHighlightOption: this.handleHighlightOption,
|
|
355
|
+
onRequestSelectOption: e => this.handleHideCalendar(e),
|
|
356
|
+
selectedOptionId: this.selectedDateId,
|
|
357
|
+
highlightedOptionId: this.selectedDateId,
|
|
358
|
+
children: ({
|
|
359
|
+
getRootProps,
|
|
360
|
+
getInputProps,
|
|
361
|
+
getTriggerProps,
|
|
362
|
+
getListProps,
|
|
363
|
+
getOptionProps,
|
|
364
|
+
getDescriptionProps
|
|
365
|
+
}) => _jsxs("span", {
|
|
366
|
+
...getRootProps({
|
|
367
|
+
css: styles === null || styles === void 0 ? void 0 : styles.dateInput
|
|
368
|
+
}),
|
|
369
|
+
ref: el => {
|
|
370
|
+
this.ref = el;
|
|
371
|
+
},
|
|
372
|
+
"data-cid": "DateInput",
|
|
373
|
+
children: [this.renderInput({
|
|
374
|
+
getInputProps,
|
|
375
|
+
getTriggerProps
|
|
376
|
+
}), _jsx("span", {
|
|
377
|
+
...getDescriptionProps(),
|
|
378
|
+
css: styles === null || styles === void 0 ? void 0 : styles.assistiveText,
|
|
379
|
+
children: assistiveText
|
|
380
|
+
}), _jsx(Popover, {
|
|
381
|
+
placement: placement,
|
|
382
|
+
isShowingContent: isShowingCalendar,
|
|
383
|
+
positionTarget: this._input,
|
|
384
|
+
shouldReturnFocus: false,
|
|
385
|
+
shouldFocusContentOnTriggerBlur: true,
|
|
386
|
+
children: this.renderCalendar({
|
|
387
|
+
getListProps,
|
|
388
|
+
getOptionProps
|
|
389
|
+
})
|
|
390
|
+
})]
|
|
391
|
+
})
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}, _DateInput.displayName = "DateInput", _DateInput.componentId = 'DateInput', _DateInput.Day = Calendar.Day, _DateInput.allowedProps = allowedProps, _DateInput.defaultProps = {
|
|
395
|
+
value: '',
|
|
396
|
+
size: 'medium',
|
|
397
|
+
onBlur: () => {},
|
|
398
|
+
// must have a default so createChainedFunction works
|
|
399
|
+
isRequired: false,
|
|
400
|
+
isInline: false,
|
|
401
|
+
layout: 'stacked',
|
|
402
|
+
display: 'inline-block',
|
|
403
|
+
placement: 'bottom center',
|
|
404
|
+
isShowingCalendar: false
|
|
405
|
+
}, _DateInput)) || _class);
|
|
406
|
+
export default DateInput;
|
|
407
|
+
export { DateInput };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const allowedProps = ['renderLabel', 'value', 'size', 'placeholder', 'onChange', 'onBlur', 'interaction', 'isRequired', 'isInline', 'assistiveText', 'layout', 'width', 'display', 'inputRef', 'messages', 'placement', 'isShowingCalendar', 'onRequestValidateDate', 'onRequestShowCalendar', 'onRequestHideCalendar', 'onRequestSelectNextDay', 'onRequestSelectPrevDay', 'onRequestRenderNextMonth', 'onRequestRenderPrevMonth', 'renderNavigationLabel', 'renderWeekdayLabels', 'renderNextMonthButton', 'renderPrevMonthButton', 'children', 'disabledDates', 'currentDate', 'disabledDateErrorMessage', 'invalidDateErrorMessage', 'locale', 'timezone'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ---
|
|
27
|
+
* private: true
|
|
28
|
+
* ---
|
|
29
|
+
* Generates the style object from the theme and provided additional information
|
|
30
|
+
* @param _componentTheme The theme variable object.
|
|
31
|
+
* @param props the props of the component, the style is applied to
|
|
32
|
+
* @return The final style object, which will be used in the component
|
|
33
|
+
*/
|
|
34
|
+
const generateStyle = (_componentTheme, props) => {
|
|
35
|
+
return {
|
|
36
|
+
dateInput: {
|
|
37
|
+
label: 'dateInput',
|
|
38
|
+
display: props.display
|
|
39
|
+
},
|
|
40
|
+
assistiveText: {
|
|
41
|
+
label: 'dateInput__assistiveText',
|
|
42
|
+
display: 'none'
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export default generateStyle;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
var
|
|
2
|
+
var _CalendarInstUIIcon, _ChevronRightInstUIIc, _ChevronLeftInstUIIco;
|
|
3
3
|
/*
|
|
4
4
|
* The MIT License (MIT)
|
|
5
5
|
*
|
|
@@ -25,11 +25,11 @@ var _IconCalendarMonthLin, _IconArrowOpenEndSoli, _IconArrowOpenStartSo;
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { useState, useEffect, forwardRef } from 'react';
|
|
28
|
-
import { Calendar } from '@instructure/ui-calendar';
|
|
29
|
-
import { IconButton } from '@instructure/ui-buttons';
|
|
30
|
-
import {
|
|
31
|
-
import { Popover } from '@instructure/ui-popover';
|
|
32
|
-
import { TextInput } from '@instructure/ui-text-input';
|
|
28
|
+
import { Calendar } from '@instructure/ui-calendar/v11_6';
|
|
29
|
+
import { IconButton } from '@instructure/ui-buttons/v11_6';
|
|
30
|
+
import { CalendarInstUIIcon, ChevronLeftInstUIIcon, ChevronRightInstUIIcon } from '@instructure/ui-icons';
|
|
31
|
+
import { Popover } from '@instructure/ui-popover/v11_6';
|
|
32
|
+
import { TextInput } from '@instructure/ui-text-input/v11_6';
|
|
33
33
|
import { callRenderProp, passthroughProps } from '@instructure/ui-react-utils';
|
|
34
34
|
import { getLocale, getTimezone } from '@instructure/ui-i18n';
|
|
35
35
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
@@ -247,7 +247,9 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
247
247
|
withBorder: false,
|
|
248
248
|
screenReaderLabel: screenReaderLabels.calendarIcon,
|
|
249
249
|
interaction: interaction,
|
|
250
|
-
children: renderCalendarIcon ? callRenderProp(renderCalendarIcon) :
|
|
250
|
+
children: renderCalendarIcon ? callRenderProp(renderCalendarIcon) : _CalendarInstUIIcon || (_CalendarInstUIIcon = _jsx(CalendarInstUIIcon, {
|
|
251
|
+
color: "baseColor"
|
|
252
|
+
}))
|
|
251
253
|
}),
|
|
252
254
|
isShowingContent: showPopover,
|
|
253
255
|
onShowContent: () => setShowPopover(true),
|
|
@@ -269,8 +271,8 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
269
271
|
size: "small",
|
|
270
272
|
withBackground: false,
|
|
271
273
|
withBorder: false,
|
|
272
|
-
renderIcon:
|
|
273
|
-
color: "
|
|
274
|
+
renderIcon: _ChevronRightInstUIIc || (_ChevronRightInstUIIc = _jsx(ChevronRightInstUIIcon, {
|
|
275
|
+
color: "baseColor"
|
|
274
276
|
})),
|
|
275
277
|
screenReaderLabel: screenReaderLabels.nextMonthButton
|
|
276
278
|
}),
|
|
@@ -278,8 +280,8 @@ const DateInput2 = /*#__PURE__*/forwardRef(({
|
|
|
278
280
|
size: "small",
|
|
279
281
|
withBackground: false,
|
|
280
282
|
withBorder: false,
|
|
281
|
-
renderIcon:
|
|
282
|
-
color: "
|
|
283
|
+
renderIcon: _ChevronLeftInstUIIco || (_ChevronLeftInstUIIco = _jsx(ChevronLeftInstUIIcon, {
|
|
284
|
+
color: "baseColor"
|
|
283
285
|
})),
|
|
284
286
|
screenReaderLabel: screenReaderLabels.prevMonthButton
|
|
285
287
|
})
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
export { DateInput } from "
|
|
25
|
-
export { DateInput2 } from "
|
|
24
|
+
export { DateInput } from "../DateInput/v1/index.js";
|
|
25
|
+
export { DateInput2 } from "../DateInput2/v1/index.js";
|
|
@@ -21,8 +21,5 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
export { DateInput2 } from './DateInput2'
|
|
27
|
-
export type { DateInputProps } from './DateInput/props'
|
|
28
|
-
export type { DateInput2Props } from './DateInput2/props'
|
|
24
|
+
export { DateInput } from "../DateInput/v2/index.js";
|
|
25
|
+
export { DateInput2 } from "../DateInput2/v1/index.js";
|
|
@@ -7,11 +7,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.DateInput = void 0;
|
|
8
8
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
9
|
var _react = require("react");
|
|
10
|
-
var
|
|
11
|
-
var _IconCalendarMonthLine = require("@instructure/ui-icons/lib/IconCalendarMonthLine.js");
|
|
12
|
-
var
|
|
10
|
+
var _v11_ = require("@instructure/ui-calendar/v11_6");
|
|
11
|
+
var _IconCalendarMonthLine = require("@instructure/ui-icons/lib/generated/IconCalendarMonthLine.js");
|
|
12
|
+
var _v11_2 = require("@instructure/ui-popover/v11_6");
|
|
13
13
|
var _Selectable = require("@instructure/ui-selectable/lib/Selectable");
|
|
14
|
-
var
|
|
14
|
+
var _v11_3 = require("@instructure/ui-text-input/v11_6");
|
|
15
15
|
var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
|
|
16
16
|
var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
|
|
17
17
|
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
@@ -54,7 +54,7 @@ var _dec, _class, _DateInput, _IconCalendarMonthLin;
|
|
|
54
54
|
category: components
|
|
55
55
|
---
|
|
56
56
|
**/
|
|
57
|
-
let DateInput = exports.DateInput = (_dec = (0, _emotion.
|
|
57
|
+
let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, null), _dec(_class = (_DateInput = class DateInput extends _react.Component {
|
|
58
58
|
constructor(...args) {
|
|
59
59
|
super(...args);
|
|
60
60
|
this.state = {
|
|
@@ -280,7 +280,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
280
280
|
this.handleHideCalendar(e, dateString);
|
|
281
281
|
}
|
|
282
282
|
};
|
|
283
|
-
return (0, _jsxRuntime.jsx)(
|
|
283
|
+
return (0, _jsxRuntime.jsx)(_v11_.Calendar, {
|
|
284
284
|
...getListProps({
|
|
285
285
|
onRequestRenderNextMonth,
|
|
286
286
|
onRequestRenderPrevMonth,
|
|
@@ -320,7 +320,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
320
320
|
ref = _getTriggerProps.ref,
|
|
321
321
|
triggerProps = (0, _objectWithoutProperties2.default)(_getTriggerProps, _excluded2);
|
|
322
322
|
const messages = this.props.messages || this.state.messages;
|
|
323
|
-
return (0, _jsxRuntime.jsx)(
|
|
323
|
+
return (0, _jsxRuntime.jsx)(_v11_3.TextInput, {
|
|
324
324
|
...triggerProps,
|
|
325
325
|
...(0, _passthroughProps.passthroughProps)(rest),
|
|
326
326
|
...getInputProps({
|
|
@@ -389,7 +389,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
389
389
|
...getDescriptionProps(),
|
|
390
390
|
css: styles === null || styles === void 0 ? void 0 : styles.assistiveText,
|
|
391
391
|
children: assistiveText
|
|
392
|
-
}), (0, _jsxRuntime.jsx)(
|
|
392
|
+
}), (0, _jsxRuntime.jsx)(_v11_2.Popover, {
|
|
393
393
|
placement: placement,
|
|
394
394
|
isShowingContent: isShowingCalendar,
|
|
395
395
|
positionTarget: this._input,
|
|
@@ -403,7 +403,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
403
403
|
})
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
|
-
}, _DateInput.displayName = "DateInput", _DateInput.componentId = 'DateInput', _DateInput.Day =
|
|
406
|
+
}, _DateInput.displayName = "DateInput", _DateInput.componentId = 'DateInput', _DateInput.Day = _v11_.Calendar.Day, _DateInput.allowedProps = _props2.allowedProps, _DateInput.defaultProps = {
|
|
407
407
|
value: '',
|
|
408
408
|
size: 'medium',
|
|
409
409
|
onBlur: () => {},
|