@instructure/ui-date-input 9.2.1-snapshot-14 → 9.2.1-snapshot-16

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 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
- ## [9.2.1-snapshot-14](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.2.1-snapshot-14) (2024-07-16)
6
+ ## [9.2.1-snapshot-16](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.2.1-snapshot-16) (2024-07-16)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-date-input
8
+
9
+ ### Features
10
+
11
+ * **ui,ui-date-input:** add new DateInput2 component ([9c893fc](https://github.com/instructure/instructure-ui/commit/9c893fc6ac1ae5ef4648f573b648cad78997ac86))
9
12
 
10
13
 
11
14
 
@@ -44,8 +44,6 @@ import { propTypes, allowedProps } from './props';
44
44
  ---
45
45
  category: components
46
46
  ---
47
- The `DateInput` component provides a visual interface for inputting date data.
48
- See <https://instructure.design/#DateInput/>
49
47
  **/
50
48
  let DateInput = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec(_class = _dec2(_class = (_DateInput = class DateInput extends Component {
51
49
  constructor(...args) {
@@ -62,7 +62,8 @@ const propTypes = {
62
62
  disabledDateErrorMessage: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
63
63
  invalidDateErrorMessage: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
64
64
  locale: PropTypes.string,
65
- timezone: PropTypes.string
65
+ timezone: PropTypes.string,
66
+ withYearPicker: PropTypes.object
66
67
  };
67
68
  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'];
68
69
  export { propTypes, allowedProps };
@@ -0,0 +1,208 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ var _IconCalendarMonthLin, _IconArrowOpenEndSoli, _IconArrowOpenStartSo;
3
+ /*
4
+ * The MIT License (MIT)
5
+ *
6
+ * Copyright (c) 2015 - present Instructure, Inc.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in all
16
+ * copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ * SOFTWARE.
25
+ */
26
+
27
+ /** @jsx jsx */
28
+ import { useState, useEffect, useContext } from 'react';
29
+ import moment from 'moment-timezone';
30
+ import { Calendar } from '@instructure/ui-calendar';
31
+ import { IconButton } from '@instructure/ui-buttons';
32
+ import { IconCalendarMonthLine, IconArrowOpenEndSolid, IconArrowOpenStartSolid } from '@instructure/ui-icons';
33
+ import { Popover } from '@instructure/ui-popover';
34
+ import { TextInput } from '@instructure/ui-text-input';
35
+ import { passthroughProps } from '@instructure/ui-react-utils';
36
+ import { ApplyLocaleContext, Locale } from '@instructure/ui-i18n';
37
+ import { jsx } from '@instructure/emotion';
38
+ import { propTypes } from './props';
39
+ function isValidDate(dateString) {
40
+ return !isNaN(new Date(dateString).getTime());
41
+ }
42
+ function isValidMomentDate(dateString, locale, timezone) {
43
+ return moment.tz(dateString, [moment.ISO_8601, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], locale, true, timezone).isValid();
44
+ }
45
+
46
+ /**
47
+ ---
48
+ category: components
49
+ ---
50
+ **/
51
+ const DateInput2 = ({
52
+ renderLabel,
53
+ screenReaderLabels,
54
+ isRequired = false,
55
+ interaction = 'enabled',
56
+ size = 'medium',
57
+ isInline = false,
58
+ value,
59
+ messages,
60
+ width,
61
+ onChange,
62
+ onBlur,
63
+ withYearPicker,
64
+ invalidDateErrorMessage,
65
+ locale,
66
+ timezone,
67
+ placeholder,
68
+ ...rest
69
+ }) => {
70
+ const _useState = useState(''),
71
+ _useState2 = _slicedToArray(_useState, 2),
72
+ selectedDate = _useState2[0],
73
+ setSelectedDate = _useState2[1];
74
+ const _useState3 = useState(messages || []),
75
+ _useState4 = _slicedToArray(_useState3, 2),
76
+ inputMessages = _useState4[0],
77
+ setInputMessages = _useState4[1];
78
+ const _useState5 = useState(false),
79
+ _useState6 = _slicedToArray(_useState5, 2),
80
+ showPopover = _useState6[0],
81
+ setShowPopover = _useState6[1];
82
+ const localeContext = useContext(ApplyLocaleContext);
83
+ useEffect(() => {
84
+ validateInput(true);
85
+ }, [value]);
86
+ useEffect(() => {
87
+ setInputMessages(messages || []);
88
+ }, [messages]);
89
+ const handleInputChange = (e, value) => {
90
+ onChange === null || onChange === void 0 ? void 0 : onChange(e, value);
91
+ };
92
+ const handleDateSelected = (dateString, _momentDate, e) => {
93
+ const formattedDate = new Date(dateString).toLocaleDateString(getLocale(), {
94
+ month: 'long',
95
+ year: 'numeric',
96
+ day: 'numeric',
97
+ timeZone: getTimezone()
98
+ });
99
+ handleInputChange(e, formattedDate);
100
+ setShowPopover(false);
101
+ };
102
+ const validateInput = (onlyRemoveError = false) => {
103
+ // TODO `isValidDate` and `isValidMomentDate` basically have the same functionality but the latter is a bit more strict (e.g.: `33` is only valid in `isValidMomentDate`)
104
+ // in the future we should get rid of moment but currently Calendar is using it for validation too so we can only remove it simultaneously
105
+ // otherwise DateInput could pass invalid dates to Calendar and break it
106
+ if (isValidDate(value || '') && isValidMomentDate(value || '', getLocale(), getTimezone()) || value === '') {
107
+ setSelectedDate(value || '');
108
+ setInputMessages(messages || []);
109
+ return true;
110
+ }
111
+ if (!onlyRemoveError) {
112
+ setInputMessages([{
113
+ type: 'error',
114
+ text: invalidDateErrorMessage || ''
115
+ }]);
116
+ }
117
+ return false;
118
+ };
119
+ const getLocale = () => {
120
+ if (locale) {
121
+ return locale;
122
+ } else if (localeContext.locale) {
123
+ return localeContext.locale;
124
+ }
125
+ return Locale.browserLocale();
126
+ };
127
+ const getTimezone = () => {
128
+ if (timezone) {
129
+ return timezone;
130
+ } else if (localeContext.timezone) {
131
+ return localeContext.timezone;
132
+ }
133
+ // default to the system's timezone
134
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
135
+ };
136
+ const handleBlur = e => {
137
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
138
+ const isInputValid = validateInput(false);
139
+ if (isInputValid && value) {
140
+ const formattedDate = new Date(value).toLocaleDateString(getLocale(), {
141
+ month: 'long',
142
+ year: 'numeric',
143
+ day: 'numeric',
144
+ timeZone: getTimezone()
145
+ });
146
+ handleInputChange(e, formattedDate);
147
+ }
148
+ };
149
+ return jsx(TextInput, Object.assign({}, passthroughProps(rest), {
150
+ renderLabel: renderLabel,
151
+ onChange: handleInputChange,
152
+ onBlur: handleBlur,
153
+ isRequired: isRequired,
154
+ value: value,
155
+ placeholder: placeholder,
156
+ width: width,
157
+ size: size,
158
+ display: isInline ? 'inline-block' : 'block',
159
+ messages: inputMessages,
160
+ interaction: interaction,
161
+ renderAfterInput: jsx(Popover, {
162
+ renderTrigger: jsx(IconButton, {
163
+ withBackground: false,
164
+ withBorder: false,
165
+ screenReaderLabel: screenReaderLabels.calendarIcon,
166
+ shape: "circle",
167
+ size: size,
168
+ interaction: interaction
169
+ }, _IconCalendarMonthLin || (_IconCalendarMonthLin = jsx(IconCalendarMonthLine, null))),
170
+ isShowingContent: showPopover,
171
+ onShowContent: () => setShowPopover(true),
172
+ onHideContent: () => setShowPopover(false),
173
+ on: "click",
174
+ shouldContainFocus: true,
175
+ shouldReturnFocus: true,
176
+ shouldCloseOnDocumentClick: true
177
+ }, jsx(Calendar, {
178
+ withYearPicker: withYearPicker,
179
+ onDateSelected: handleDateSelected,
180
+ selectedDate: selectedDate,
181
+ visibleMonth: selectedDate,
182
+ locale: locale,
183
+ timezone: timezone,
184
+ role: "listbox",
185
+ renderNextMonthButton: jsx(IconButton, {
186
+ size: "small",
187
+ withBackground: false,
188
+ withBorder: false,
189
+ renderIcon: _IconArrowOpenEndSoli || (_IconArrowOpenEndSoli = jsx(IconArrowOpenEndSolid, {
190
+ color: "primary"
191
+ })),
192
+ screenReaderLabel: screenReaderLabels.nextMonthButton
193
+ }),
194
+ renderPrevMonthButton: jsx(IconButton, {
195
+ size: "small",
196
+ withBackground: false,
197
+ withBorder: false,
198
+ renderIcon: _IconArrowOpenStartSo || (_IconArrowOpenStartSo = jsx(IconArrowOpenStartSolid, {
199
+ color: "primary"
200
+ })),
201
+ screenReaderLabel: screenReaderLabels.prevMonthButton
202
+ })
203
+ }))
204
+ }));
205
+ };
206
+ DateInput2.propTypes = propTypes;
207
+ export default DateInput2;
208
+ export { DateInput2 };
@@ -0,0 +1,48 @@
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
+ import PropTypes from 'prop-types';
26
+ import { controllable } from '@instructure/ui-prop-types';
27
+ import { FormPropTypes } from '@instructure/ui-form-field';
28
+ const propTypes = {
29
+ renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
30
+ screenReaderLabels: PropTypes.object.isRequired,
31
+ value: controllable(PropTypes.string),
32
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
33
+ placeholder: PropTypes.string,
34
+ onChange: PropTypes.func,
35
+ onBlur: PropTypes.func,
36
+ interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
37
+ isRequired: PropTypes.bool,
38
+ isInline: PropTypes.bool,
39
+ width: PropTypes.string,
40
+ messages: PropTypes.arrayOf(FormPropTypes.message),
41
+ onRequestShowCalendar: PropTypes.func,
42
+ onRequestHideCalendar: PropTypes.func,
43
+ invalidDateErrorMessage: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
44
+ locale: PropTypes.string,
45
+ timezone: PropTypes.string,
46
+ withYearPicker: PropTypes.object
47
+ };
48
+ export { propTypes };
package/es/index.js CHANGED
@@ -22,4 +22,5 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export { DateInput } from './DateInput';
25
+ export { DateInput } from './DateInput';
26
+ export { DateInput2 } from './DateInput2';
@@ -55,8 +55,6 @@ var _dec, _dec2, _class, _DateInput, _IconCalendarMonthLin;
55
55
  ---
56
56
  category: components
57
57
  ---
58
- The `DateInput` component provides a visual interface for inputting date data.
59
- See <https://instructure.design/#DateInput/>
60
58
  **/
61
59
  let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_DateInput = class DateInput extends _react.Component {
62
60
  constructor(...args) {
@@ -70,6 +70,7 @@ const propTypes = exports.propTypes = {
70
70
  disabledDateErrorMessage: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
71
71
  invalidDateErrorMessage: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
72
72
  locale: _propTypes.default.string,
73
- timezone: _propTypes.default.string
73
+ timezone: _propTypes.default.string,
74
+ withYearPicker: _propTypes.default.object
74
75
  };
75
76
  const allowedProps = exports.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'];
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.DateInput2 = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
11
+ var _Calendar = require("@instructure/ui-calendar/lib/Calendar");
12
+ var _IconButton = require("@instructure/ui-buttons/lib/IconButton");
13
+ var _IconCalendarMonthLine = require("@instructure/ui-icons/lib/IconCalendarMonthLine.js");
14
+ var _IconArrowOpenEndSolid = require("@instructure/ui-icons/lib/IconArrowOpenEndSolid.js");
15
+ var _IconArrowOpenStartSolid = require("@instructure/ui-icons/lib/IconArrowOpenStartSolid.js");
16
+ var _Popover = require("@instructure/ui-popover/lib/Popover");
17
+ var _TextInput = require("@instructure/ui-text-input/lib/TextInput");
18
+ var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
19
+ var _ApplyLocaleContext = require("@instructure/ui-i18n/lib/ApplyLocale/ApplyLocaleContext.js");
20
+ var _Locale = require("@instructure/ui-i18n/lib/Locale.js");
21
+ var _emotion = require("@instructure/emotion");
22
+ var _props = require("./props");
23
+ var _IconCalendarMonthLin, _IconArrowOpenEndSoli, _IconArrowOpenStartSo;
24
+ /*
25
+ * The MIT License (MIT)
26
+ *
27
+ * Copyright (c) 2015 - present Instructure, Inc.
28
+ *
29
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ * of this software and associated documentation files (the "Software"), to deal
31
+ * in the Software without restriction, including without limitation the rights
32
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ * copies of the Software, and to permit persons to whom the Software is
34
+ * furnished to do so, subject to the following conditions:
35
+ *
36
+ * The above copyright notice and this permission notice shall be included in all
37
+ * copies or substantial portions of the Software.
38
+ *
39
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ * SOFTWARE.
46
+ */
47
+ /** @jsx jsx */
48
+ function isValidDate(dateString) {
49
+ return !isNaN(new Date(dateString).getTime());
50
+ }
51
+ function isValidMomentDate(dateString, locale, timezone) {
52
+ return _momentTimezone.default.tz(dateString, [_momentTimezone.default.ISO_8601, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], locale, true, timezone).isValid();
53
+ }
54
+
55
+ /**
56
+ ---
57
+ category: components
58
+ ---
59
+ **/
60
+ const DateInput2 = ({
61
+ renderLabel,
62
+ screenReaderLabels,
63
+ isRequired = false,
64
+ interaction = 'enabled',
65
+ size = 'medium',
66
+ isInline = false,
67
+ value,
68
+ messages,
69
+ width,
70
+ onChange,
71
+ onBlur,
72
+ withYearPicker,
73
+ invalidDateErrorMessage,
74
+ locale,
75
+ timezone,
76
+ placeholder,
77
+ ...rest
78
+ }) => {
79
+ const _useState = (0, _react.useState)(''),
80
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
81
+ selectedDate = _useState2[0],
82
+ setSelectedDate = _useState2[1];
83
+ const _useState3 = (0, _react.useState)(messages || []),
84
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
85
+ inputMessages = _useState4[0],
86
+ setInputMessages = _useState4[1];
87
+ const _useState5 = (0, _react.useState)(false),
88
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
89
+ showPopover = _useState6[0],
90
+ setShowPopover = _useState6[1];
91
+ const localeContext = (0, _react.useContext)(_ApplyLocaleContext.ApplyLocaleContext);
92
+ (0, _react.useEffect)(() => {
93
+ validateInput(true);
94
+ }, [value]);
95
+ (0, _react.useEffect)(() => {
96
+ setInputMessages(messages || []);
97
+ }, [messages]);
98
+ const handleInputChange = (e, value) => {
99
+ onChange === null || onChange === void 0 ? void 0 : onChange(e, value);
100
+ };
101
+ const handleDateSelected = (dateString, _momentDate, e) => {
102
+ const formattedDate = new Date(dateString).toLocaleDateString(getLocale(), {
103
+ month: 'long',
104
+ year: 'numeric',
105
+ day: 'numeric',
106
+ timeZone: getTimezone()
107
+ });
108
+ handleInputChange(e, formattedDate);
109
+ setShowPopover(false);
110
+ };
111
+ const validateInput = (onlyRemoveError = false) => {
112
+ // TODO `isValidDate` and `isValidMomentDate` basically have the same functionality but the latter is a bit more strict (e.g.: `33` is only valid in `isValidMomentDate`)
113
+ // in the future we should get rid of moment but currently Calendar is using it for validation too so we can only remove it simultaneously
114
+ // otherwise DateInput could pass invalid dates to Calendar and break it
115
+ if (isValidDate(value || '') && isValidMomentDate(value || '', getLocale(), getTimezone()) || value === '') {
116
+ setSelectedDate(value || '');
117
+ setInputMessages(messages || []);
118
+ return true;
119
+ }
120
+ if (!onlyRemoveError) {
121
+ setInputMessages([{
122
+ type: 'error',
123
+ text: invalidDateErrorMessage || ''
124
+ }]);
125
+ }
126
+ return false;
127
+ };
128
+ const getLocale = () => {
129
+ if (locale) {
130
+ return locale;
131
+ } else if (localeContext.locale) {
132
+ return localeContext.locale;
133
+ }
134
+ return _Locale.Locale.browserLocale();
135
+ };
136
+ const getTimezone = () => {
137
+ if (timezone) {
138
+ return timezone;
139
+ } else if (localeContext.timezone) {
140
+ return localeContext.timezone;
141
+ }
142
+ // default to the system's timezone
143
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
144
+ };
145
+ const handleBlur = e => {
146
+ onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
147
+ const isInputValid = validateInput(false);
148
+ if (isInputValid && value) {
149
+ const formattedDate = new Date(value).toLocaleDateString(getLocale(), {
150
+ month: 'long',
151
+ year: 'numeric',
152
+ day: 'numeric',
153
+ timeZone: getTimezone()
154
+ });
155
+ handleInputChange(e, formattedDate);
156
+ }
157
+ };
158
+ return (0, _emotion.jsx)(_TextInput.TextInput, Object.assign({}, (0, _passthroughProps.passthroughProps)(rest), {
159
+ renderLabel: renderLabel,
160
+ onChange: handleInputChange,
161
+ onBlur: handleBlur,
162
+ isRequired: isRequired,
163
+ value: value,
164
+ placeholder: placeholder,
165
+ width: width,
166
+ size: size,
167
+ display: isInline ? 'inline-block' : 'block',
168
+ messages: inputMessages,
169
+ interaction: interaction,
170
+ renderAfterInput: (0, _emotion.jsx)(_Popover.Popover, {
171
+ renderTrigger: (0, _emotion.jsx)(_IconButton.IconButton, {
172
+ withBackground: false,
173
+ withBorder: false,
174
+ screenReaderLabel: screenReaderLabels.calendarIcon,
175
+ shape: "circle",
176
+ size: size,
177
+ interaction: interaction
178
+ }, _IconCalendarMonthLin || (_IconCalendarMonthLin = (0, _emotion.jsx)(_IconCalendarMonthLine.IconCalendarMonthLine, null))),
179
+ isShowingContent: showPopover,
180
+ onShowContent: () => setShowPopover(true),
181
+ onHideContent: () => setShowPopover(false),
182
+ on: "click",
183
+ shouldContainFocus: true,
184
+ shouldReturnFocus: true,
185
+ shouldCloseOnDocumentClick: true
186
+ }, (0, _emotion.jsx)(_Calendar.Calendar, {
187
+ withYearPicker: withYearPicker,
188
+ onDateSelected: handleDateSelected,
189
+ selectedDate: selectedDate,
190
+ visibleMonth: selectedDate,
191
+ locale: locale,
192
+ timezone: timezone,
193
+ role: "listbox",
194
+ renderNextMonthButton: (0, _emotion.jsx)(_IconButton.IconButton, {
195
+ size: "small",
196
+ withBackground: false,
197
+ withBorder: false,
198
+ renderIcon: _IconArrowOpenEndSoli || (_IconArrowOpenEndSoli = (0, _emotion.jsx)(_IconArrowOpenEndSolid.IconArrowOpenEndSolid, {
199
+ color: "primary"
200
+ })),
201
+ screenReaderLabel: screenReaderLabels.nextMonthButton
202
+ }),
203
+ renderPrevMonthButton: (0, _emotion.jsx)(_IconButton.IconButton, {
204
+ size: "small",
205
+ withBackground: false,
206
+ withBorder: false,
207
+ renderIcon: _IconArrowOpenStartSo || (_IconArrowOpenStartSo = (0, _emotion.jsx)(_IconArrowOpenStartSolid.IconArrowOpenStartSolid, {
208
+ color: "primary"
209
+ })),
210
+ screenReaderLabel: screenReaderLabels.prevMonthButton
211
+ })
212
+ }))
213
+ }));
214
+ };
215
+ exports.DateInput2 = DateInput2;
216
+ DateInput2.propTypes = _props.propTypes;
217
+ var _default = exports.default = DateInput2;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.propTypes = void 0;
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
10
+ var _FormPropTypes = require("@instructure/ui-form-field/lib/FormPropTypes.js");
11
+ /*
12
+ * The MIT License (MIT)
13
+ *
14
+ * Copyright (c) 2015 - present Instructure, Inc.
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ * of this software and associated documentation files (the "Software"), to deal
18
+ * in the Software without restriction, including without limitation the rights
19
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ * copies of the Software, and to permit persons to whom the Software is
21
+ * furnished to do so, subject to the following conditions:
22
+ *
23
+ * The above copyright notice and this permission notice shall be included in all
24
+ * copies or substantial portions of the Software.
25
+ *
26
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ * SOFTWARE.
33
+ */
34
+
35
+ const propTypes = exports.propTypes = {
36
+ renderLabel: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
37
+ screenReaderLabels: _propTypes.default.object.isRequired,
38
+ value: (0, _controllable.controllable)(_propTypes.default.string),
39
+ size: _propTypes.default.oneOf(['small', 'medium', 'large']),
40
+ placeholder: _propTypes.default.string,
41
+ onChange: _propTypes.default.func,
42
+ onBlur: _propTypes.default.func,
43
+ interaction: _propTypes.default.oneOf(['enabled', 'disabled', 'readonly']),
44
+ isRequired: _propTypes.default.bool,
45
+ isInline: _propTypes.default.bool,
46
+ width: _propTypes.default.string,
47
+ messages: _propTypes.default.arrayOf(_FormPropTypes.FormPropTypes.message),
48
+ onRequestShowCalendar: _propTypes.default.func,
49
+ onRequestHideCalendar: _propTypes.default.func,
50
+ invalidDateErrorMessage: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
51
+ locale: _propTypes.default.string,
52
+ timezone: _propTypes.default.string,
53
+ withYearPicker: _propTypes.default.object
54
+ };
package/lib/index.js CHANGED
@@ -9,4 +9,11 @@ Object.defineProperty(exports, "DateInput", {
9
9
  return _DateInput.DateInput;
10
10
  }
11
11
  });
12
- var _DateInput = require("./DateInput");
12
+ Object.defineProperty(exports, "DateInput2", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _DateInput2.DateInput2;
16
+ }
17
+ });
18
+ var _DateInput = require("./DateInput");
19
+ var _DateInput2 = require("./DateInput2");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-date-input",
3
- "version": "9.2.1-snapshot-14",
3
+ "version": "9.2.1-snapshot-16",
4
4
  "description": "A UI component library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,10 +23,11 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-axe-check": "9.2.1-snapshot-14",
27
- "@instructure/ui-babel-preset": "9.2.1-snapshot-14",
28
- "@instructure/ui-scripts": "9.2.1-snapshot-14",
29
- "@instructure/ui-test-utils": "9.2.1-snapshot-14",
26
+ "@instructure/ui-axe-check": "9.2.1-snapshot-16",
27
+ "@instructure/ui-babel-preset": "9.2.1-snapshot-16",
28
+ "@instructure/ui-buttons": "9.2.1-snapshot-16",
29
+ "@instructure/ui-scripts": "9.2.1-snapshot-16",
30
+ "@instructure/ui-test-utils": "9.2.1-snapshot-16",
30
31
  "@testing-library/jest-dom": "^6.4.6",
31
32
  "@testing-library/react": "^15.0.7",
32
33
  "@testing-library/user-event": "^14.5.2",
@@ -34,20 +35,21 @@
34
35
  },
35
36
  "dependencies": {
36
37
  "@babel/runtime": "^7.24.5",
37
- "@instructure/emotion": "9.2.1-snapshot-14",
38
- "@instructure/shared-types": "9.2.1-snapshot-14",
39
- "@instructure/ui-calendar": "9.2.1-snapshot-14",
40
- "@instructure/ui-form-field": "9.2.1-snapshot-14",
41
- "@instructure/ui-i18n": "9.2.1-snapshot-14",
42
- "@instructure/ui-icons": "9.2.1-snapshot-14",
43
- "@instructure/ui-popover": "9.2.1-snapshot-14",
44
- "@instructure/ui-position": "9.2.1-snapshot-14",
45
- "@instructure/ui-prop-types": "9.2.1-snapshot-14",
46
- "@instructure/ui-react-utils": "9.2.1-snapshot-14",
47
- "@instructure/ui-selectable": "9.2.1-snapshot-14",
48
- "@instructure/ui-testable": "9.2.1-snapshot-14",
49
- "@instructure/ui-text-input": "9.2.1-snapshot-14",
50
- "@instructure/ui-utils": "9.2.1-snapshot-14",
38
+ "@instructure/emotion": "9.2.1-snapshot-16",
39
+ "@instructure/shared-types": "9.2.1-snapshot-16",
40
+ "@instructure/ui-calendar": "9.2.1-snapshot-16",
41
+ "@instructure/ui-form-field": "9.2.1-snapshot-16",
42
+ "@instructure/ui-i18n": "9.2.1-snapshot-16",
43
+ "@instructure/ui-icons": "9.2.1-snapshot-16",
44
+ "@instructure/ui-popover": "9.2.1-snapshot-16",
45
+ "@instructure/ui-position": "9.2.1-snapshot-16",
46
+ "@instructure/ui-prop-types": "9.2.1-snapshot-16",
47
+ "@instructure/ui-react-utils": "9.2.1-snapshot-16",
48
+ "@instructure/ui-selectable": "9.2.1-snapshot-16",
49
+ "@instructure/ui-testable": "9.2.1-snapshot-16",
50
+ "@instructure/ui-text-input": "9.2.1-snapshot-16",
51
+ "@instructure/ui-utils": "9.2.1-snapshot-16",
52
+ "moment-timezone": "^0.5.45",
51
53
  "prop-types": "^15.8.1"
52
54
  },
53
55
  "peerDependencies": {