@instructure/ui-date-input 9.1.0 → 9.1.1-pr-snapshot-1720090208194
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 +11 -0
- package/es/DateInput/index.js +0 -2
- package/es/DateInput/props.js +2 -1
- package/es/DateInput2/index.js +154 -0
- package/es/DateInput2/props.js +47 -0
- package/es/index.js +2 -1
- package/lib/DateInput/index.js +0 -2
- package/lib/DateInput/props.js +2 -1
- package/lib/DateInput2/index.js +162 -0
- package/lib/DateInput2/props.js +53 -0
- package/lib/index.js +8 -1
- package/package.json +21 -19
- package/src/DateInput/README.md +2 -0
- package/src/DateInput/index.tsx +0 -2
- package/src/DateInput/props.ts +20 -1
- package/src/DateInput2/README.md +94 -0
- package/src/DateInput2/index.tsx +202 -0
- package/src/DateInput2/props.ts +176 -0
- package/src/index.ts +1 -0
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DateInput/index.d.ts +12 -2
- package/types/DateInput/index.d.ts.map +1 -1
- package/types/DateInput/props.d.ts +17 -0
- package/types/DateInput/props.d.ts.map +1 -1
- package/types/DateInput2/index.d.ts +14 -0
- package/types/DateInput2/index.d.ts.map +1 -0
- package/types/DateInput2/props.d.ts +123 -0
- package/types/DateInput2/props.d.ts.map +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.1.1-pr-snapshot-1720090208194](https://github.com/instructure/instructure-ui/compare/v9.1.0...v9.1.1-pr-snapshot-1720090208194) (2024-07-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **ui-date-input:** add year picker to DateInput and note to use the new api ([71de6b4](https://github.com/instructure/instructure-ui/commit/71de6b44cd38ba021cb977fdfaf75a039cf1c342))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [9.1.0](https://github.com/instructure/instructure-ui/compare/v9.0.1...v9.1.0) (2024-06-14)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @instructure/ui-date-input
|
package/es/DateInput/index.js
CHANGED
|
@@ -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) {
|
package/es/DateInput/props.js
CHANGED
|
@@ -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,154 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
var _IconCalendarMonthLin;
|
|
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 } from '@instructure/ui-icons';
|
|
33
|
+
import { Popover } from '@instructure/ui-popover';
|
|
34
|
+
import { TextInput } from '@instructure/ui-text-input';
|
|
35
|
+
import { DateTime, ApplyLocaleContext, Locale } from '@instructure/ui-i18n';
|
|
36
|
+
import { jsx } from '@instructure/emotion';
|
|
37
|
+
import { propTypes } from './props';
|
|
38
|
+
/**
|
|
39
|
+
---
|
|
40
|
+
category: components
|
|
41
|
+
---
|
|
42
|
+
**/
|
|
43
|
+
const DateInput2 = ({
|
|
44
|
+
renderLabel,
|
|
45
|
+
isRequired = false,
|
|
46
|
+
interaction = 'enabled',
|
|
47
|
+
value = '',
|
|
48
|
+
size = 'medium',
|
|
49
|
+
isInline = false,
|
|
50
|
+
messages = [],
|
|
51
|
+
width,
|
|
52
|
+
onChange,
|
|
53
|
+
onBlur,
|
|
54
|
+
withYearPicker,
|
|
55
|
+
invalidDateErrorMessage,
|
|
56
|
+
locale,
|
|
57
|
+
timezone,
|
|
58
|
+
placeholder
|
|
59
|
+
}) => {
|
|
60
|
+
const _useState = useState(''),
|
|
61
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
62
|
+
selectedDate = _useState2[0],
|
|
63
|
+
setSelectedDate = _useState2[1];
|
|
64
|
+
const _useState3 = useState(messages),
|
|
65
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
66
|
+
inputMessages = _useState4[0],
|
|
67
|
+
setInputMessages = _useState4[1];
|
|
68
|
+
const _useState5 = useState(false),
|
|
69
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
70
|
+
showPopover = _useState6[0],
|
|
71
|
+
setShowPopover = _useState6[1];
|
|
72
|
+
const localeContext = useContext(ApplyLocaleContext);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
validateInput(true);
|
|
75
|
+
}, [value]);
|
|
76
|
+
const handleInputChange = (e, value) => {
|
|
77
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e, value);
|
|
78
|
+
};
|
|
79
|
+
const handleDateSelected = (dateString, momentDate, e) => {
|
|
80
|
+
setSelectedDate(dateString);
|
|
81
|
+
handleInputChange(e, `${momentDate.format('MMMM')} ${momentDate.format('D')}, ${momentDate.format('YYYY')}`);
|
|
82
|
+
setShowPopover(false);
|
|
83
|
+
};
|
|
84
|
+
const validateInput = (onlyRemoveError = false) => {
|
|
85
|
+
if (moment.tz(value ? value : '', [DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], getLocale(), true, getTimezone()).isValid() || value === '') {
|
|
86
|
+
setSelectedDate(value || '');
|
|
87
|
+
setInputMessages(messages);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (typeof invalidDateErrorMessage !== 'function' && !onlyRemoveError) {
|
|
91
|
+
setInputMessages([{
|
|
92
|
+
type: 'error',
|
|
93
|
+
text: invalidDateErrorMessage
|
|
94
|
+
}]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const getLocale = () => {
|
|
98
|
+
if (locale) {
|
|
99
|
+
return locale;
|
|
100
|
+
} else if (localeContext.locale) {
|
|
101
|
+
return localeContext.locale;
|
|
102
|
+
}
|
|
103
|
+
return Locale.browserLocale();
|
|
104
|
+
};
|
|
105
|
+
const getTimezone = () => {
|
|
106
|
+
if (timezone) {
|
|
107
|
+
return timezone;
|
|
108
|
+
} else if (localeContext.timezone) {
|
|
109
|
+
return localeContext.timezone;
|
|
110
|
+
}
|
|
111
|
+
return DateTime.browserTimeZone();
|
|
112
|
+
};
|
|
113
|
+
const handleBlur = e => {
|
|
114
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
115
|
+
validateInput(false);
|
|
116
|
+
};
|
|
117
|
+
return jsx(TextInput, {
|
|
118
|
+
renderLabel: renderLabel,
|
|
119
|
+
onChange: handleInputChange,
|
|
120
|
+
onBlur: handleBlur,
|
|
121
|
+
isRequired: isRequired,
|
|
122
|
+
value: value,
|
|
123
|
+
placeholder: placeholder,
|
|
124
|
+
width: width,
|
|
125
|
+
size: size,
|
|
126
|
+
display: isInline ? 'inline-block' : 'block',
|
|
127
|
+
messages: inputMessages,
|
|
128
|
+
interaction: interaction,
|
|
129
|
+
renderAfterInput: jsx(Popover, {
|
|
130
|
+
renderTrigger: jsx(IconButton, {
|
|
131
|
+
withBackground: false,
|
|
132
|
+
withBorder: false,
|
|
133
|
+
screenReaderLabel: "Calendar",
|
|
134
|
+
shape: "circle",
|
|
135
|
+
interaction: interaction
|
|
136
|
+
}, _IconCalendarMonthLin || (_IconCalendarMonthLin = jsx(IconCalendarMonthLine, null))),
|
|
137
|
+
isShowingContent: showPopover,
|
|
138
|
+
onShowContent: () => setShowPopover(true),
|
|
139
|
+
onHideContent: () => setShowPopover(false),
|
|
140
|
+
on: "click",
|
|
141
|
+
shouldContainFocus: true,
|
|
142
|
+
shouldReturnFocus: true,
|
|
143
|
+
shouldCloseOnDocumentClick: true
|
|
144
|
+
}, jsx(Calendar, {
|
|
145
|
+
withYearPicker: withYearPicker,
|
|
146
|
+
onDateSelected: handleDateSelected,
|
|
147
|
+
selectedDate: selectedDate,
|
|
148
|
+
visibleMonth: selectedDate
|
|
149
|
+
}))
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
DateInput2.propTypes = propTypes;
|
|
153
|
+
export default DateInput2;
|
|
154
|
+
export { DateInput2 };
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
value: controllable(PropTypes.string),
|
|
31
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
32
|
+
placeholder: PropTypes.string,
|
|
33
|
+
onChange: PropTypes.func,
|
|
34
|
+
onBlur: PropTypes.func,
|
|
35
|
+
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
36
|
+
isRequired: PropTypes.bool,
|
|
37
|
+
isInline: PropTypes.bool,
|
|
38
|
+
width: PropTypes.string,
|
|
39
|
+
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
40
|
+
onRequestShowCalendar: PropTypes.func,
|
|
41
|
+
onRequestHideCalendar: PropTypes.func,
|
|
42
|
+
invalidDateErrorMessage: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
43
|
+
locale: PropTypes.string,
|
|
44
|
+
timezone: PropTypes.string,
|
|
45
|
+
withYearPicker: PropTypes.object
|
|
46
|
+
};
|
|
47
|
+
export { propTypes };
|
package/es/index.js
CHANGED
package/lib/DateInput/index.js
CHANGED
|
@@ -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) {
|
package/lib/DateInput/props.js
CHANGED
|
@@ -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,162 @@
|
|
|
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 _Popover = require("@instructure/ui-popover/lib/Popover");
|
|
15
|
+
var _TextInput = require("@instructure/ui-text-input/lib/TextInput");
|
|
16
|
+
var _DateTime = require("@instructure/ui-i18n/lib/DateTime.js");
|
|
17
|
+
var _ApplyLocaleContext = require("@instructure/ui-i18n/lib/ApplyLocale/ApplyLocaleContext.js");
|
|
18
|
+
var _Locale = require("@instructure/ui-i18n/lib/Locale.js");
|
|
19
|
+
var _emotion = require("@instructure/emotion");
|
|
20
|
+
var _props = require("./props");
|
|
21
|
+
var _IconCalendarMonthLin;
|
|
22
|
+
/*
|
|
23
|
+
* The MIT License (MIT)
|
|
24
|
+
*
|
|
25
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
26
|
+
*
|
|
27
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
* in the Software without restriction, including without limitation the rights
|
|
30
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
* furnished to do so, subject to the following conditions:
|
|
33
|
+
*
|
|
34
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
* copies or substantial portions of the Software.
|
|
36
|
+
*
|
|
37
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
* SOFTWARE.
|
|
44
|
+
*/
|
|
45
|
+
/** @jsx jsx */
|
|
46
|
+
/**
|
|
47
|
+
---
|
|
48
|
+
category: components
|
|
49
|
+
---
|
|
50
|
+
**/
|
|
51
|
+
const DateInput2 = ({
|
|
52
|
+
renderLabel,
|
|
53
|
+
isRequired = false,
|
|
54
|
+
interaction = 'enabled',
|
|
55
|
+
value = '',
|
|
56
|
+
size = 'medium',
|
|
57
|
+
isInline = false,
|
|
58
|
+
messages = [],
|
|
59
|
+
width,
|
|
60
|
+
onChange,
|
|
61
|
+
onBlur,
|
|
62
|
+
withYearPicker,
|
|
63
|
+
invalidDateErrorMessage,
|
|
64
|
+
locale,
|
|
65
|
+
timezone,
|
|
66
|
+
placeholder
|
|
67
|
+
}) => {
|
|
68
|
+
const _useState = (0, _react.useState)(''),
|
|
69
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
70
|
+
selectedDate = _useState2[0],
|
|
71
|
+
setSelectedDate = _useState2[1];
|
|
72
|
+
const _useState3 = (0, _react.useState)(messages),
|
|
73
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
74
|
+
inputMessages = _useState4[0],
|
|
75
|
+
setInputMessages = _useState4[1];
|
|
76
|
+
const _useState5 = (0, _react.useState)(false),
|
|
77
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
78
|
+
showPopover = _useState6[0],
|
|
79
|
+
setShowPopover = _useState6[1];
|
|
80
|
+
const localeContext = (0, _react.useContext)(_ApplyLocaleContext.ApplyLocaleContext);
|
|
81
|
+
(0, _react.useEffect)(() => {
|
|
82
|
+
validateInput(true);
|
|
83
|
+
}, [value]);
|
|
84
|
+
const handleInputChange = (e, value) => {
|
|
85
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e, value);
|
|
86
|
+
};
|
|
87
|
+
const handleDateSelected = (dateString, momentDate, e) => {
|
|
88
|
+
setSelectedDate(dateString);
|
|
89
|
+
handleInputChange(e, `${momentDate.format('MMMM')} ${momentDate.format('D')}, ${momentDate.format('YYYY')}`);
|
|
90
|
+
setShowPopover(false);
|
|
91
|
+
};
|
|
92
|
+
const validateInput = (onlyRemoveError = false) => {
|
|
93
|
+
if (_momentTimezone.default.tz(value ? value : '', [_DateTime.DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], getLocale(), true, getTimezone()).isValid() || value === '') {
|
|
94
|
+
setSelectedDate(value || '');
|
|
95
|
+
setInputMessages(messages);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (typeof invalidDateErrorMessage !== 'function' && !onlyRemoveError) {
|
|
99
|
+
setInputMessages([{
|
|
100
|
+
type: 'error',
|
|
101
|
+
text: invalidDateErrorMessage
|
|
102
|
+
}]);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const getLocale = () => {
|
|
106
|
+
if (locale) {
|
|
107
|
+
return locale;
|
|
108
|
+
} else if (localeContext.locale) {
|
|
109
|
+
return localeContext.locale;
|
|
110
|
+
}
|
|
111
|
+
return _Locale.Locale.browserLocale();
|
|
112
|
+
};
|
|
113
|
+
const getTimezone = () => {
|
|
114
|
+
if (timezone) {
|
|
115
|
+
return timezone;
|
|
116
|
+
} else if (localeContext.timezone) {
|
|
117
|
+
return localeContext.timezone;
|
|
118
|
+
}
|
|
119
|
+
return _DateTime.DateTime.browserTimeZone();
|
|
120
|
+
};
|
|
121
|
+
const handleBlur = e => {
|
|
122
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
123
|
+
validateInput(false);
|
|
124
|
+
};
|
|
125
|
+
return (0, _emotion.jsx)(_TextInput.TextInput, {
|
|
126
|
+
renderLabel: renderLabel,
|
|
127
|
+
onChange: handleInputChange,
|
|
128
|
+
onBlur: handleBlur,
|
|
129
|
+
isRequired: isRequired,
|
|
130
|
+
value: value,
|
|
131
|
+
placeholder: placeholder,
|
|
132
|
+
width: width,
|
|
133
|
+
size: size,
|
|
134
|
+
display: isInline ? 'inline-block' : 'block',
|
|
135
|
+
messages: inputMessages,
|
|
136
|
+
interaction: interaction,
|
|
137
|
+
renderAfterInput: (0, _emotion.jsx)(_Popover.Popover, {
|
|
138
|
+
renderTrigger: (0, _emotion.jsx)(_IconButton.IconButton, {
|
|
139
|
+
withBackground: false,
|
|
140
|
+
withBorder: false,
|
|
141
|
+
screenReaderLabel: "Calendar",
|
|
142
|
+
shape: "circle",
|
|
143
|
+
interaction: interaction
|
|
144
|
+
}, _IconCalendarMonthLin || (_IconCalendarMonthLin = (0, _emotion.jsx)(_IconCalendarMonthLine.IconCalendarMonthLine, null))),
|
|
145
|
+
isShowingContent: showPopover,
|
|
146
|
+
onShowContent: () => setShowPopover(true),
|
|
147
|
+
onHideContent: () => setShowPopover(false),
|
|
148
|
+
on: "click",
|
|
149
|
+
shouldContainFocus: true,
|
|
150
|
+
shouldReturnFocus: true,
|
|
151
|
+
shouldCloseOnDocumentClick: true
|
|
152
|
+
}, (0, _emotion.jsx)(_Calendar.Calendar, {
|
|
153
|
+
withYearPicker: withYearPicker,
|
|
154
|
+
onDateSelected: handleDateSelected,
|
|
155
|
+
selectedDate: selectedDate,
|
|
156
|
+
visibleMonth: selectedDate
|
|
157
|
+
}))
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
exports.DateInput2 = DateInput2;
|
|
161
|
+
DateInput2.propTypes = _props.propTypes;
|
|
162
|
+
var _default = exports.default = DateInput2;
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
value: (0, _controllable.controllable)(_propTypes.default.string),
|
|
38
|
+
size: _propTypes.default.oneOf(['small', 'medium', 'large']),
|
|
39
|
+
placeholder: _propTypes.default.string,
|
|
40
|
+
onChange: _propTypes.default.func,
|
|
41
|
+
onBlur: _propTypes.default.func,
|
|
42
|
+
interaction: _propTypes.default.oneOf(['enabled', 'disabled', 'readonly']),
|
|
43
|
+
isRequired: _propTypes.default.bool,
|
|
44
|
+
isInline: _propTypes.default.bool,
|
|
45
|
+
width: _propTypes.default.string,
|
|
46
|
+
messages: _propTypes.default.arrayOf(_FormPropTypes.FormPropTypes.message),
|
|
47
|
+
onRequestShowCalendar: _propTypes.default.func,
|
|
48
|
+
onRequestHideCalendar: _propTypes.default.func,
|
|
49
|
+
invalidDateErrorMessage: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
|
|
50
|
+
locale: _propTypes.default.string,
|
|
51
|
+
timezone: _propTypes.default.string,
|
|
52
|
+
withYearPicker: _propTypes.default.object
|
|
53
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -9,4 +9,11 @@ Object.defineProperty(exports, "DateInput", {
|
|
|
9
9
|
return _DateInput.DateInput;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
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.1.
|
|
3
|
+
"version": "9.1.1-pr-snapshot-1720090208194",
|
|
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,30 +23,32 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "9.1.
|
|
27
|
-
"@instructure/ui-babel-preset": "9.1.
|
|
28
|
-
"@instructure/ui-
|
|
29
|
-
"@instructure/ui-
|
|
26
|
+
"@instructure/ui-axe-check": "9.1.1-pr-snapshot-1720090208194",
|
|
27
|
+
"@instructure/ui-babel-preset": "9.1.1-pr-snapshot-1720090208194",
|
|
28
|
+
"@instructure/ui-buttons": "9.1.1-pr-snapshot-1720090208194",
|
|
29
|
+
"@instructure/ui-scripts": "9.1.1-pr-snapshot-1720090208194",
|
|
30
|
+
"@instructure/ui-test-utils": "9.1.1-pr-snapshot-1720090208194",
|
|
30
31
|
"@testing-library/jest-dom": "^6.4.5",
|
|
31
32
|
"@testing-library/react": "^15.0.7",
|
|
32
33
|
"@testing-library/user-event": "^14.5.2"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@babel/runtime": "^7.24.5",
|
|
36
|
-
"@instructure/emotion": "9.1.
|
|
37
|
-
"@instructure/shared-types": "9.1.
|
|
38
|
-
"@instructure/ui-calendar": "9.1.
|
|
39
|
-
"@instructure/ui-form-field": "9.1.
|
|
40
|
-
"@instructure/ui-i18n": "9.1.
|
|
41
|
-
"@instructure/ui-icons": "9.1.
|
|
42
|
-
"@instructure/ui-popover": "9.1.
|
|
43
|
-
"@instructure/ui-position": "9.1.
|
|
44
|
-
"@instructure/ui-prop-types": "9.1.
|
|
45
|
-
"@instructure/ui-react-utils": "9.1.
|
|
46
|
-
"@instructure/ui-selectable": "9.1.
|
|
47
|
-
"@instructure/ui-testable": "9.1.
|
|
48
|
-
"@instructure/ui-text-input": "9.1.
|
|
49
|
-
"@instructure/ui-utils": "9.1.
|
|
37
|
+
"@instructure/emotion": "9.1.1-pr-snapshot-1720090208194",
|
|
38
|
+
"@instructure/shared-types": "9.1.1-pr-snapshot-1720090208194",
|
|
39
|
+
"@instructure/ui-calendar": "9.1.1-pr-snapshot-1720090208194",
|
|
40
|
+
"@instructure/ui-form-field": "9.1.1-pr-snapshot-1720090208194",
|
|
41
|
+
"@instructure/ui-i18n": "9.1.1-pr-snapshot-1720090208194",
|
|
42
|
+
"@instructure/ui-icons": "9.1.1-pr-snapshot-1720090208194",
|
|
43
|
+
"@instructure/ui-popover": "9.1.1-pr-snapshot-1720090208194",
|
|
44
|
+
"@instructure/ui-position": "9.1.1-pr-snapshot-1720090208194",
|
|
45
|
+
"@instructure/ui-prop-types": "9.1.1-pr-snapshot-1720090208194",
|
|
46
|
+
"@instructure/ui-react-utils": "9.1.1-pr-snapshot-1720090208194",
|
|
47
|
+
"@instructure/ui-selectable": "9.1.1-pr-snapshot-1720090208194",
|
|
48
|
+
"@instructure/ui-testable": "9.1.1-pr-snapshot-1720090208194",
|
|
49
|
+
"@instructure/ui-text-input": "9.1.1-pr-snapshot-1720090208194",
|
|
50
|
+
"@instructure/ui-utils": "9.1.1-pr-snapshot-1720090208194",
|
|
51
|
+
"moment-timezone": "^0.5.45",
|
|
50
52
|
"prop-types": "^15.8.1"
|
|
51
53
|
},
|
|
52
54
|
"peerDependencies": {
|
package/src/DateInput/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
describes: DateInput
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
> **Important:** You can now use are updated version [`DateInput2`](/#DateInput2) which is easier to configure for devs, has a better UX for end users, better accessibility features and a year picker. In our next major update (v10) this component will be deprecated and renamed.
|
|
6
|
+
|
|
5
7
|
The `DateInput` component provides a visual interface for inputting date data.
|
|
6
8
|
|
|
7
9
|
### Default config
|
package/src/DateInput/index.tsx
CHANGED
|
@@ -59,8 +59,6 @@ import type { FormMessage } from '@instructure/ui-form-field'
|
|
|
59
59
|
---
|
|
60
60
|
category: components
|
|
61
61
|
---
|
|
62
|
-
The `DateInput` component provides a visual interface for inputting date data.
|
|
63
|
-
See <https://instructure.design/#DateInput/>
|
|
64
62
|
**/
|
|
65
63
|
@withStyle(generateStyle, null)
|
|
66
64
|
@testable()
|
package/src/DateInput/props.ts
CHANGED
|
@@ -250,6 +250,24 @@ type DateInputOwnProps = {
|
|
|
250
250
|
* property or a context property.
|
|
251
251
|
**/
|
|
252
252
|
timezone?: string
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* If set, years can be picked from a dropdown.
|
|
256
|
+
* It accepts an object.
|
|
257
|
+
* screenReaderLabel: string // e.g.: i18n("pick a year")
|
|
258
|
+
*
|
|
259
|
+
* onRequestYearChange?:(e: React.MouseEvent,requestedYear: number): void // if set, on year change, only this will be called and no internal change will take place
|
|
260
|
+
*
|
|
261
|
+
* startYear: number // e.g.: 2001, sets the start year of the selectable list
|
|
262
|
+
*
|
|
263
|
+
* endYear: number // e.g.: 2030, sets the end year of the selectable list
|
|
264
|
+
*/
|
|
265
|
+
withYearPicker?: {
|
|
266
|
+
screenReaderLabel: string
|
|
267
|
+
onRequestYearChange?: (e: any, requestedYear: number) => void
|
|
268
|
+
startYear: number
|
|
269
|
+
endYear: number
|
|
270
|
+
}
|
|
253
271
|
}
|
|
254
272
|
|
|
255
273
|
type PropKeys = keyof DateInputOwnProps
|
|
@@ -308,7 +326,8 @@ const propTypes: PropValidators<PropKeys> = {
|
|
|
308
326
|
PropTypes.string
|
|
309
327
|
]),
|
|
310
328
|
locale: PropTypes.string,
|
|
311
|
-
timezone: PropTypes.string
|
|
329
|
+
timezone: PropTypes.string,
|
|
330
|
+
withYearPicker: PropTypes.object
|
|
312
331
|
}
|
|
313
332
|
|
|
314
333
|
const allowedProps: AllowedPropKeys = [
|