@atlaskit/datetime-picker 14.0.1 → 14.0.3
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 +17 -0
- package/dist/cjs/components/date-picker.js +1 -7
- package/dist/cjs/components/date-time-picker.js +1 -1
- package/dist/cjs/components/time-picker.js +284 -312
- package/dist/cjs/internal/menu.js +0 -1
- package/dist/es2019/components/date-picker.js +1 -7
- package/dist/es2019/components/date-time-picker.js +1 -1
- package/dist/es2019/components/time-picker.js +246 -297
- package/dist/es2019/internal/menu.js +0 -1
- package/dist/esm/components/date-picker.js +1 -7
- package/dist/esm/components/date-time-picker.js +1 -1
- package/dist/esm/components/time-picker.js +283 -313
- package/dist/esm/internal/menu.js +0 -1
- package/dist/types/components/date-picker.d.ts +0 -3
- package/dist/types/components/time-picker.d.ts +2 -104
- package/dist/types/types.d.ts +4 -0
- package/dist/types-ts4.5/components/date-picker.d.ts +0 -3
- package/dist/types-ts4.5/components/time-picker.d.ts +2 -104
- package/dist/types-ts4.5/types.d.ts +4 -0
- package/package.json +3 -8
|
@@ -5,19 +5,15 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = void 0;
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
10
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
16
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
17
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
|
-
var
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
19
14
|
var _dateFns = require("date-fns");
|
|
20
15
|
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
16
|
+
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
21
17
|
var _locale = require("@atlaskit/locale");
|
|
22
18
|
var _select = _interopRequireWildcard(require("@atlaskit/select"));
|
|
23
19
|
var _constants = require("@atlaskit/theme/constants");
|
|
@@ -30,12 +26,10 @@ var _excluded = ["styles"];
|
|
|
30
26
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
31
27
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
32
28
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
33
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
34
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
35
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } // eslint-disable-next-line no-restricted-imports
|
|
29
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // eslint-disable-next-line no-restricted-imports
|
|
36
30
|
// eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
|
|
37
31
|
var packageName = "@atlaskit/datetime-picker";
|
|
38
|
-
var packageVersion = "14.0.
|
|
32
|
+
var packageVersion = "14.0.3";
|
|
39
33
|
var menuStyles = {
|
|
40
34
|
/* Need to remove default absolute positioning as that causes issues with position fixed */
|
|
41
35
|
position: 'static',
|
|
@@ -44,295 +38,12 @@ var menuStyles = {
|
|
|
44
38
|
/* React-Popper has already offset the menu so we need to reset the margin, otherwise the offset value is doubled */
|
|
45
39
|
margin: 0
|
|
46
40
|
};
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
defaultValue: '',
|
|
52
|
-
hideIcon: false,
|
|
53
|
-
id: '',
|
|
54
|
-
innerProps: {},
|
|
55
|
-
isDisabled: false,
|
|
56
|
-
isInvalid: false,
|
|
57
|
-
label: '',
|
|
58
|
-
name: '',
|
|
59
|
-
// These disables are here for proper typing when used as defaults. They
|
|
60
|
-
// should *not* use the `noop` function.
|
|
61
|
-
/* eslint-disable @repo/internal/react/use-noop */
|
|
62
|
-
onBlur: function onBlur(_event) {},
|
|
63
|
-
onChange: function onChange(_value) {},
|
|
64
|
-
onFocus: function onFocus(_event) {},
|
|
65
|
-
/* eslint-enable @repo/internal/react/use-noop */
|
|
66
|
-
parseInputValue: function parseInputValue(time, _timeFormat) {
|
|
67
|
-
return (0, _parseTime.default)(time);
|
|
68
|
-
},
|
|
69
|
-
selectProps: {},
|
|
70
|
-
spacing: 'default',
|
|
71
|
-
times: _internal.defaultTimes,
|
|
72
|
-
timeIsEditable: false,
|
|
73
|
-
locale: 'en-US'
|
|
74
|
-
// Not including a default prop for value as it will
|
|
75
|
-
// Make the component a controlled component
|
|
41
|
+
var analyticsAttributes = {
|
|
42
|
+
componentName: 'timePicker',
|
|
43
|
+
packageName: packageName,
|
|
44
|
+
packageVersion: packageVersion
|
|
76
45
|
};
|
|
77
|
-
var TimePickerComponent = exports.TimePickerWithoutAnalytics = /*#__PURE__*/function (_React$Component) {
|
|
78
|
-
(0, _inherits2.default)(TimePickerComponent, _React$Component);
|
|
79
|
-
var _super = _createSuper(TimePickerComponent);
|
|
80
|
-
function TimePickerComponent() {
|
|
81
|
-
var _this;
|
|
82
|
-
(0, _classCallCheck2.default)(this, TimePickerComponent);
|
|
83
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
84
|
-
args[_key] = arguments[_key];
|
|
85
|
-
}
|
|
86
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
87
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "containerRef", null);
|
|
88
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
|
|
89
|
-
isOpen: _this.props.defaultIsOpen,
|
|
90
|
-
clearingFromIcon: false,
|
|
91
|
-
value: _this.props.defaultValue,
|
|
92
|
-
isFocused: false
|
|
93
|
-
});
|
|
94
|
-
// All state needs to be accessed via this function so that the state is mapped from props
|
|
95
|
-
// correctly to allow controlled/uncontrolled usage.
|
|
96
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getValue", function () {
|
|
97
|
-
var _this$props$value;
|
|
98
|
-
return (_this$props$value = _this.props.value) !== null && _this$props$value !== void 0 ? _this$props$value : _this.state.value;
|
|
99
|
-
});
|
|
100
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getIsOpen", function () {
|
|
101
|
-
var _this$props$isOpen;
|
|
102
|
-
return (_this$props$isOpen = _this.props.isOpen) !== null && _this$props$isOpen !== void 0 ? _this$props$isOpen : _this.state.isOpen;
|
|
103
|
-
});
|
|
104
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onChange", function (newValue, action) {
|
|
105
|
-
var rawValue = newValue ? newValue.value || newValue : '';
|
|
106
|
-
var value = rawValue.toString();
|
|
107
|
-
var changedState = {
|
|
108
|
-
value: value
|
|
109
|
-
};
|
|
110
|
-
if (action && action.action === 'clear') {
|
|
111
|
-
changedState = _objectSpread(_objectSpread({}, changedState), {}, {
|
|
112
|
-
clearingFromIcon: true
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
_this.setState(changedState);
|
|
116
|
-
_this.props.onChange(value);
|
|
117
|
-
});
|
|
118
|
-
/**
|
|
119
|
-
* Only allow custom times if timeIsEditable prop is true
|
|
120
|
-
*/
|
|
121
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onCreateOption", function (inputValue) {
|
|
122
|
-
if (_this.props.timeIsEditable) {
|
|
123
|
-
var _this$props = _this.props,
|
|
124
|
-
parseInputValue = _this$props.parseInputValue,
|
|
125
|
-
timeFormat = _this$props.timeFormat;
|
|
126
|
-
var sanitizedInput;
|
|
127
|
-
try {
|
|
128
|
-
sanitizedInput = parseInputValue(inputValue, timeFormat || _internal.defaultTimeFormat);
|
|
129
|
-
} catch (e) {
|
|
130
|
-
return; // do nothing, the main validation should happen in the form
|
|
131
|
-
}
|
|
132
|
-
var includesSeconds = !!(timeFormat && /[:.]?(s|ss)/.test(timeFormat));
|
|
133
|
-
var formatFormat = includesSeconds ? 'HH:mm:ss' : 'HH:mm';
|
|
134
|
-
var formattedValue = (0, _dateFns.format)(sanitizedInput, formatFormat) || '';
|
|
135
|
-
_this.setState({
|
|
136
|
-
value: formattedValue
|
|
137
|
-
});
|
|
138
|
-
_this.props.onChange(formattedValue);
|
|
139
|
-
} else {
|
|
140
|
-
_this.onChange(inputValue);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMenuOpen", function () {
|
|
144
|
-
// Don't open menu after the user has clicked clear
|
|
145
|
-
if (_this.state.clearingFromIcon) {
|
|
146
|
-
_this.setState({
|
|
147
|
-
clearingFromIcon: false
|
|
148
|
-
});
|
|
149
|
-
} else {
|
|
150
|
-
_this.setState({
|
|
151
|
-
isOpen: true
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMenuClose", function () {
|
|
156
|
-
// Don't close menu after the user has clicked clear
|
|
157
|
-
if (_this.state.clearingFromIcon) {
|
|
158
|
-
_this.setState({
|
|
159
|
-
clearingFromIcon: false
|
|
160
|
-
});
|
|
161
|
-
} else {
|
|
162
|
-
_this.setState({
|
|
163
|
-
isOpen: false
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setContainerRef", function (ref) {
|
|
168
|
-
var oldRef = _this.containerRef;
|
|
169
|
-
_this.containerRef = ref;
|
|
170
|
-
// Cause a re-render if we're getting the container ref for the first time
|
|
171
|
-
// as the layered menu requires it for dimension calculation
|
|
172
|
-
if (oldRef == null && ref != null) {
|
|
173
|
-
_this.forceUpdate();
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onBlur", function (event) {
|
|
177
|
-
_this.setState({
|
|
178
|
-
isFocused: false
|
|
179
|
-
});
|
|
180
|
-
_this.props.onBlur(event);
|
|
181
|
-
});
|
|
182
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onFocus", function (event) {
|
|
183
|
-
_this.setState({
|
|
184
|
-
isFocused: true
|
|
185
|
-
});
|
|
186
|
-
_this.props.onFocus(event);
|
|
187
|
-
});
|
|
188
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSelectKeyDown", function (event) {
|
|
189
|
-
var key = event.key;
|
|
190
|
-
var keyPressed = key.toLowerCase();
|
|
191
|
-
if (_this.state.clearingFromIcon && (keyPressed === 'backspace' || keyPressed === 'delete')) {
|
|
192
|
-
// If being cleared from keyboard, don't change behaviour
|
|
193
|
-
_this.setState({
|
|
194
|
-
clearingFromIcon: false
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
return _this;
|
|
199
|
-
}
|
|
200
|
-
(0, _createClass2.default)(TimePickerComponent, [{
|
|
201
|
-
key: "render",
|
|
202
|
-
value: function render() {
|
|
203
|
-
var _this2 = this;
|
|
204
|
-
var _this$props2 = this.props,
|
|
205
|
-
appearance = _this$props2.appearance,
|
|
206
|
-
ariaDescribedBy = _this$props2['aria-describedby'],
|
|
207
|
-
autoFocus = _this$props2.autoFocus,
|
|
208
|
-
formatDisplayLabel = _this$props2.formatDisplayLabel,
|
|
209
|
-
hideIcon = _this$props2.hideIcon,
|
|
210
|
-
id = _this$props2.id,
|
|
211
|
-
innerProps = _this$props2.innerProps,
|
|
212
|
-
isDisabled = _this$props2.isDisabled,
|
|
213
|
-
label = _this$props2.label,
|
|
214
|
-
locale = _this$props2.locale,
|
|
215
|
-
name = _this$props2.name,
|
|
216
|
-
placeholder = _this$props2.placeholder,
|
|
217
|
-
selectProps = _this$props2.selectProps,
|
|
218
|
-
spacing = _this$props2.spacing,
|
|
219
|
-
testId = _this$props2.testId,
|
|
220
|
-
isInvalid = _this$props2.isInvalid,
|
|
221
|
-
timeIsEditable = _this$props2.timeIsEditable,
|
|
222
|
-
timeFormat = _this$props2.timeFormat,
|
|
223
|
-
times = _this$props2.times;
|
|
224
|
-
var ICON_PADDING = 2;
|
|
225
|
-
var l10n = (0, _locale.createLocalizationProvider)(locale);
|
|
226
|
-
var value = this.getValue() || '';
|
|
227
|
-
var isOpen = this.getIsOpen();
|
|
228
|
-
var _selectProps$styles = selectProps.styles,
|
|
229
|
-
selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles,
|
|
230
|
-
otherSelectProps = (0, _objectWithoutProperties2.default)(selectProps, _excluded);
|
|
231
|
-
var SelectComponent = timeIsEditable ? _select.CreatableSelect : _select.default;
|
|
232
46
|
|
|
233
|
-
/**
|
|
234
|
-
* There are multiple props that can change how the time is formatted.
|
|
235
|
-
* The priority of props used is:
|
|
236
|
-
* 1. formatDisplayLabel
|
|
237
|
-
* 2. timeFormat
|
|
238
|
-
* 3. locale
|
|
239
|
-
*/
|
|
240
|
-
var formatTime = function formatTime(time) {
|
|
241
|
-
if (formatDisplayLabel) {
|
|
242
|
-
return formatDisplayLabel(time, timeFormat || _internal.defaultTimeFormat);
|
|
243
|
-
}
|
|
244
|
-
var date = (0, _parseTime.default)(time);
|
|
245
|
-
if (!(date instanceof Date)) {
|
|
246
|
-
return '';
|
|
247
|
-
}
|
|
248
|
-
if (!(0, _dateFns.isValid)(date)) {
|
|
249
|
-
return time;
|
|
250
|
-
}
|
|
251
|
-
if (timeFormat) {
|
|
252
|
-
return (0, _dateFns.format)(date, (0, _parseTokens.convertTokens)(timeFormat));
|
|
253
|
-
}
|
|
254
|
-
return l10n.formatTime(date);
|
|
255
|
-
};
|
|
256
|
-
var options = times.map(function (time) {
|
|
257
|
-
return {
|
|
258
|
-
label: formatTime(time),
|
|
259
|
-
value: time
|
|
260
|
-
};
|
|
261
|
-
});
|
|
262
|
-
var initialValue = value ? {
|
|
263
|
-
label: formatTime(value),
|
|
264
|
-
value: value
|
|
265
|
-
} : null;
|
|
266
|
-
var SingleValue = (0, _singleValue.makeSingleValue)({
|
|
267
|
-
lang: this.props.locale
|
|
268
|
-
});
|
|
269
|
-
var selectComponents = _objectSpread({
|
|
270
|
-
DropdownIndicator: _internal.EmptyComponent,
|
|
271
|
-
Menu: _fixedLayerMenu.FixedLayerMenu,
|
|
272
|
-
SingleValue: SingleValue
|
|
273
|
-
}, hideIcon && {
|
|
274
|
-
ClearIndicator: _internal.EmptyComponent
|
|
275
|
-
});
|
|
276
|
-
var renderIconContainer = Boolean(!hideIcon && value);
|
|
277
|
-
var mergedStyles = (0, _select.mergeStyles)(selectStyles, {
|
|
278
|
-
control: function control(base) {
|
|
279
|
-
return _objectSpread({}, base);
|
|
280
|
-
},
|
|
281
|
-
menu: function menu(base) {
|
|
282
|
-
return _objectSpread(_objectSpread(_objectSpread({}, base), menuStyles), {}, {
|
|
283
|
-
// Fixed positioned elements no longer inherit width from their parent, so we must explicitly set the
|
|
284
|
-
// menu width to the width of our container
|
|
285
|
-
width: _this2.containerRef ? _this2.containerRef.getBoundingClientRect().width : 'auto'
|
|
286
|
-
});
|
|
287
|
-
},
|
|
288
|
-
indicatorsContainer: function indicatorsContainer(base) {
|
|
289
|
-
return _objectSpread(_objectSpread({}, base), {}, {
|
|
290
|
-
paddingLeft: renderIconContainer ? ICON_PADDING : 0,
|
|
291
|
-
paddingRight: renderIconContainer ? (0, _constants.gridSize)() - ICON_PADDING : 0
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, innerProps, {
|
|
296
|
-
ref: this.setContainerRef,
|
|
297
|
-
"data-testid": testId && "".concat(testId, "--container")
|
|
298
|
-
}), /*#__PURE__*/_react.default.createElement("input", {
|
|
299
|
-
name: name,
|
|
300
|
-
type: "hidden",
|
|
301
|
-
value: value,
|
|
302
|
-
"data-testid": testId && "".concat(testId, "--input"),
|
|
303
|
-
onKeyDown: this.onSelectKeyDown
|
|
304
|
-
}), /*#__PURE__*/_react.default.createElement(SelectComponent, (0, _extends2.default)({
|
|
305
|
-
"aria-describedby": ariaDescribedBy,
|
|
306
|
-
"aria-label": label || undefined,
|
|
307
|
-
appearance: appearance,
|
|
308
|
-
autoFocus: autoFocus,
|
|
309
|
-
components: selectComponents,
|
|
310
|
-
inputId: id,
|
|
311
|
-
isClearable: true,
|
|
312
|
-
isDisabled: isDisabled,
|
|
313
|
-
menuIsOpen: isOpen && !isDisabled,
|
|
314
|
-
menuPlacement: "auto",
|
|
315
|
-
openMenuOnFocus: true,
|
|
316
|
-
onBlur: this.onBlur,
|
|
317
|
-
onCreateOption: this.onCreateOption,
|
|
318
|
-
onChange: this.onChange,
|
|
319
|
-
options: options,
|
|
320
|
-
onFocus: this.onFocus,
|
|
321
|
-
onMenuOpen: this.onMenuOpen,
|
|
322
|
-
onMenuClose: this.onMenuClose,
|
|
323
|
-
placeholder: placeholder || l10n.formatTime(_internal.placeholderDatetime),
|
|
324
|
-
styles: mergedStyles,
|
|
325
|
-
value: initialValue,
|
|
326
|
-
spacing: spacing,
|
|
327
|
-
fixedLayerRef: this.containerRef,
|
|
328
|
-
isInvalid: isInvalid,
|
|
329
|
-
testId: testId
|
|
330
|
-
}, otherSelectProps)));
|
|
331
|
-
}
|
|
332
|
-
}]);
|
|
333
|
-
return TimePickerComponent;
|
|
334
|
-
}(_react.default.Component);
|
|
335
|
-
(0, _defineProperty2.default)(TimePickerComponent, "defaultProps", timePickerDefaultProps);
|
|
336
47
|
/**
|
|
337
48
|
* __Time picker__
|
|
338
49
|
*
|
|
@@ -342,19 +53,280 @@ var TimePickerComponent = exports.TimePickerWithoutAnalytics = /*#__PURE__*/func
|
|
|
342
53
|
* - [Code](https://atlassian.design/components/datetime-picker/time-picker/code)
|
|
343
54
|
* - [Usage](https://atlassian.design/components/datetime-picker/time-picker/usage)
|
|
344
55
|
*/
|
|
345
|
-
var TimePicker = (0,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
56
|
+
var TimePicker = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
57
|
+
var ariaDescribedBy = _ref['aria-describedby'],
|
|
58
|
+
analyticsContext = _ref.analyticsContext,
|
|
59
|
+
_ref$appearance = _ref.appearance,
|
|
60
|
+
appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
|
|
61
|
+
_ref$autoFocus = _ref.autoFocus,
|
|
62
|
+
autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
|
|
63
|
+
_ref$defaultIsOpen = _ref.defaultIsOpen,
|
|
64
|
+
defaultIsOpen = _ref$defaultIsOpen === void 0 ? false : _ref$defaultIsOpen,
|
|
65
|
+
_ref$defaultValue = _ref.defaultValue,
|
|
66
|
+
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
|
67
|
+
formatDisplayLabel = _ref.formatDisplayLabel,
|
|
68
|
+
_ref$hideIcon = _ref.hideIcon,
|
|
69
|
+
hideIcon = _ref$hideIcon === void 0 ? false : _ref$hideIcon,
|
|
70
|
+
_ref$id = _ref.id,
|
|
71
|
+
id = _ref$id === void 0 ? '' : _ref$id,
|
|
72
|
+
_ref$innerProps = _ref.innerProps,
|
|
73
|
+
innerProps = _ref$innerProps === void 0 ? {} : _ref$innerProps,
|
|
74
|
+
_ref$isDisabled = _ref.isDisabled,
|
|
75
|
+
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
|
|
76
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
77
|
+
isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
|
|
78
|
+
providedIsOpen = _ref.isOpen,
|
|
79
|
+
_ref$label = _ref.label,
|
|
80
|
+
label = _ref$label === void 0 ? '' : _ref$label,
|
|
81
|
+
_ref$locale = _ref.locale,
|
|
82
|
+
locale = _ref$locale === void 0 ? 'en-US' : _ref$locale,
|
|
83
|
+
_ref$name = _ref.name,
|
|
84
|
+
name = _ref$name === void 0 ? '' : _ref$name,
|
|
85
|
+
_ref$onBlur = _ref.onBlur,
|
|
86
|
+
providedOnBlur = _ref$onBlur === void 0 ? _noop.default : _ref$onBlur,
|
|
87
|
+
_ref$onChange = _ref.onChange,
|
|
88
|
+
providedOnChange = _ref$onChange === void 0 ? _noop.default : _ref$onChange,
|
|
89
|
+
_ref$onFocus = _ref.onFocus,
|
|
90
|
+
providedOnFocus = _ref$onFocus === void 0 ? _noop.default : _ref$onFocus,
|
|
91
|
+
_ref$parseInputValue = _ref.parseInputValue,
|
|
92
|
+
parseInputValue = _ref$parseInputValue === void 0 ? function (time, _timeFormat) {
|
|
93
|
+
return (0, _parseTime.default)(time);
|
|
94
|
+
} : _ref$parseInputValue,
|
|
95
|
+
placeholder = _ref.placeholder,
|
|
96
|
+
_ref$selectProps = _ref.selectProps,
|
|
97
|
+
selectProps = _ref$selectProps === void 0 ? {} : _ref$selectProps,
|
|
98
|
+
_ref$spacing = _ref.spacing,
|
|
99
|
+
spacing = _ref$spacing === void 0 ? 'default' : _ref$spacing,
|
|
100
|
+
testId = _ref.testId,
|
|
101
|
+
timeFormat = _ref.timeFormat,
|
|
102
|
+
_ref$timeIsEditable = _ref.timeIsEditable,
|
|
103
|
+
timeIsEditable = _ref$timeIsEditable === void 0 ? false : _ref$timeIsEditable,
|
|
104
|
+
_ref$times = _ref.times,
|
|
105
|
+
times = _ref$times === void 0 ? _internal.defaultTimes : _ref$times,
|
|
106
|
+
providedValue = _ref.value;
|
|
107
|
+
var _useState = (0, _react.useState)(null),
|
|
108
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
109
|
+
containerRef = _useState2[0],
|
|
110
|
+
setContainerRef = _useState2[1];
|
|
111
|
+
/**
|
|
112
|
+
* When being cleared from the icon the TimePicker is blurred.
|
|
113
|
+
* This variable defines whether the default onMenuOpen or onMenuClose
|
|
114
|
+
* events should behave as normal
|
|
115
|
+
*/
|
|
116
|
+
var _useState3 = (0, _react.useState)(false),
|
|
117
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
118
|
+
clearingFromIcon = _useState4[0],
|
|
119
|
+
setClearingFromIcon = _useState4[1];
|
|
120
|
+
// TODO: Remove isFocused? Does it do anything?
|
|
121
|
+
var _useState5 = (0, _react.useState)(false),
|
|
122
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
123
|
+
_ = _useState6[0],
|
|
124
|
+
setIsFocused = _useState6[1];
|
|
125
|
+
var _useState7 = (0, _react.useState)(providedIsOpen || defaultIsOpen),
|
|
126
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
127
|
+
isOpen = _useState8[0],
|
|
128
|
+
setIsOpen = _useState8[1];
|
|
129
|
+
var _useState9 = (0, _react.useState)(providedValue || defaultValue),
|
|
130
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
|
131
|
+
value = _useState10[0],
|
|
132
|
+
setValue = _useState10[1];
|
|
133
|
+
|
|
134
|
+
// Hack to force update: https://legacy.reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
|
|
135
|
+
var _useReducer = (0, _react.useReducer)(function (x) {
|
|
136
|
+
return x + 1;
|
|
137
|
+
}, 0),
|
|
138
|
+
_useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
|
|
139
|
+
forceUpdate = _useReducer2[1];
|
|
140
|
+
var providedOnChangeWithAnalytics = (0, _analyticsNext.usePlatformLeafEventHandler)(_objectSpread({
|
|
141
|
+
fn: providedOnChange,
|
|
351
142
|
action: 'selectedTime',
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
143
|
+
analyticsData: analyticsContext
|
|
144
|
+
}, analyticsAttributes));
|
|
145
|
+
var onChange = function onChange(newValue, action) {
|
|
146
|
+
var rawValue = newValue ? newValue.value || newValue : '';
|
|
147
|
+
var finalValue = rawValue.toString();
|
|
148
|
+
setValue(finalValue);
|
|
149
|
+
if (action && action.action === 'clear') {
|
|
150
|
+
setClearingFromIcon(true);
|
|
151
|
+
}
|
|
152
|
+
providedOnChangeWithAnalytics(finalValue);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Only allow custom times if timeIsEditable prop is true
|
|
157
|
+
*/
|
|
158
|
+
var onCreateOption = function onCreateOption(inputValue) {
|
|
159
|
+
if (timeIsEditable) {
|
|
160
|
+
var sanitizedInput;
|
|
161
|
+
try {
|
|
162
|
+
sanitizedInput = parseInputValue(inputValue, timeFormat || _internal.defaultTimeFormat);
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return; // do nothing, the main validation should happen in the form
|
|
165
|
+
}
|
|
166
|
+
var includesSeconds = !!(timeFormat && /[:.]?(s|ss)/.test(timeFormat));
|
|
167
|
+
var formatFormat = includesSeconds ? 'HH:mm:ss' : 'HH:mm';
|
|
168
|
+
var formattedValue = (0, _dateFns.format)(sanitizedInput, formatFormat) || '';
|
|
169
|
+
setValue(formattedValue);
|
|
170
|
+
providedOnChange(formattedValue);
|
|
171
|
+
} else {
|
|
172
|
+
providedOnChange(inputValue);
|
|
357
173
|
}
|
|
358
|
-
}
|
|
359
|
-
|
|
174
|
+
};
|
|
175
|
+
var onMenuOpen = function onMenuOpen() {
|
|
176
|
+
// Don't open menu after the user has clicked clear
|
|
177
|
+
if (clearingFromIcon) {
|
|
178
|
+
setClearingFromIcon(false);
|
|
179
|
+
} else {
|
|
180
|
+
setIsOpen(true);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
var onMenuClose = function onMenuClose() {
|
|
184
|
+
// Don't close menu after the user has clicked clear
|
|
185
|
+
if (clearingFromIcon) {
|
|
186
|
+
setClearingFromIcon(false);
|
|
187
|
+
} else {
|
|
188
|
+
setIsOpen(false);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var setInternalContainerRef = function setInternalContainerRef(ref) {
|
|
192
|
+
var oldRef = containerRef;
|
|
193
|
+
setContainerRef(ref);
|
|
194
|
+
// Cause a re-render if we're getting the container ref for the first time
|
|
195
|
+
// as the layered menu requires it for dimension calculation
|
|
196
|
+
if (oldRef === null && ref !== null) {
|
|
197
|
+
forceUpdate();
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var onBlur = function onBlur(event) {
|
|
201
|
+
setIsFocused(false);
|
|
202
|
+
providedOnBlur(event);
|
|
203
|
+
};
|
|
204
|
+
var onFocus = function onFocus(event) {
|
|
205
|
+
setIsFocused(true);
|
|
206
|
+
providedOnFocus(event);
|
|
207
|
+
};
|
|
208
|
+
var onSelectKeyDown = function onSelectKeyDown(event) {
|
|
209
|
+
var key = event.key;
|
|
210
|
+
var keyPressed = key.toLowerCase();
|
|
211
|
+
if (clearingFromIcon && (keyPressed === 'backspace' || keyPressed === 'delete')) {
|
|
212
|
+
// If being cleared from keyboard, don't change behaviour
|
|
213
|
+
setClearingFromIcon(false);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var ICON_PADDING = 2;
|
|
217
|
+
var l10n = (0, _locale.createLocalizationProvider)(locale);
|
|
218
|
+
var _selectProps$styles = selectProps.styles,
|
|
219
|
+
selectStyles = _selectProps$styles === void 0 ? {} : _selectProps$styles,
|
|
220
|
+
otherSelectProps = (0, _objectWithoutProperties2.default)(selectProps, _excluded);
|
|
221
|
+
var SelectComponent = timeIsEditable ? _select.CreatableSelect : _select.default;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* There are multiple props that can change how the time is formatted.
|
|
225
|
+
* The priority of props used is:
|
|
226
|
+
* 1. formatDisplayLabel
|
|
227
|
+
* 2. timeFormat
|
|
228
|
+
* 3. locale
|
|
229
|
+
*/
|
|
230
|
+
var formatTime = function formatTime(time) {
|
|
231
|
+
if (formatDisplayLabel) {
|
|
232
|
+
return formatDisplayLabel(time, timeFormat || _internal.defaultTimeFormat);
|
|
233
|
+
}
|
|
234
|
+
var date = (0, _parseTime.default)(time);
|
|
235
|
+
if (!(date instanceof Date)) {
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
if (!(0, _dateFns.isValid)(date)) {
|
|
239
|
+
return time;
|
|
240
|
+
}
|
|
241
|
+
if (timeFormat) {
|
|
242
|
+
return (0, _dateFns.format)(date, (0, _parseTokens.convertTokens)(timeFormat));
|
|
243
|
+
}
|
|
244
|
+
return l10n.formatTime(date);
|
|
245
|
+
};
|
|
246
|
+
var options = times.map(function (time) {
|
|
247
|
+
return {
|
|
248
|
+
label: formatTime(time),
|
|
249
|
+
value: time
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
var initialValue;
|
|
253
|
+
if (providedValue !== null && providedValue !== undefined && providedValue !== '') {
|
|
254
|
+
initialValue = {
|
|
255
|
+
label: formatTime(providedValue),
|
|
256
|
+
value: providedValue
|
|
257
|
+
};
|
|
258
|
+
} else if (providedValue !== '' && value) {
|
|
259
|
+
initialValue = {
|
|
260
|
+
label: formatTime(value),
|
|
261
|
+
value: value
|
|
262
|
+
};
|
|
263
|
+
} else {
|
|
264
|
+
initialValue = null;
|
|
265
|
+
}
|
|
266
|
+
var SingleValue = (0, _singleValue.makeSingleValue)({
|
|
267
|
+
lang: locale
|
|
268
|
+
});
|
|
269
|
+
var selectComponents = _objectSpread({
|
|
270
|
+
DropdownIndicator: _internal.EmptyComponent,
|
|
271
|
+
Menu: _fixedLayerMenu.FixedLayerMenu,
|
|
272
|
+
SingleValue: SingleValue
|
|
273
|
+
}, hideIcon && {
|
|
274
|
+
ClearIndicator: _internal.EmptyComponent
|
|
275
|
+
});
|
|
276
|
+
var renderIconContainer = Boolean(!hideIcon && value);
|
|
277
|
+
var mergedStyles = (0, _select.mergeStyles)(selectStyles, {
|
|
278
|
+
control: function control(base) {
|
|
279
|
+
return _objectSpread({}, base);
|
|
280
|
+
},
|
|
281
|
+
menu: function menu(base) {
|
|
282
|
+
return _objectSpread(_objectSpread(_objectSpread({}, base), menuStyles), {}, {
|
|
283
|
+
// Fixed positioned elements no longer inherit width from their parent, so we must explicitly set the
|
|
284
|
+
// menu width to the width of our container
|
|
285
|
+
width: containerRef ? containerRef.getBoundingClientRect().width : 'auto'
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
indicatorsContainer: function indicatorsContainer(base) {
|
|
289
|
+
return _objectSpread(_objectSpread({}, base), {}, {
|
|
290
|
+
paddingLeft: renderIconContainer ? ICON_PADDING : 0,
|
|
291
|
+
paddingRight: renderIconContainer ? (0, _constants.gridSize)() - ICON_PADDING : 0
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, innerProps, {
|
|
296
|
+
ref: setInternalContainerRef,
|
|
297
|
+
"data-testid": testId && "".concat(testId, "--container")
|
|
298
|
+
}), /*#__PURE__*/_react.default.createElement("input", {
|
|
299
|
+
name: name,
|
|
300
|
+
type: "hidden",
|
|
301
|
+
value: value,
|
|
302
|
+
"data-testid": testId && "".concat(testId, "--input"),
|
|
303
|
+
onKeyDown: onSelectKeyDown
|
|
304
|
+
}), /*#__PURE__*/_react.default.createElement(SelectComponent, (0, _extends2.default)({
|
|
305
|
+
"aria-describedby": ariaDescribedBy,
|
|
306
|
+
"aria-label": label || undefined,
|
|
307
|
+
appearance: appearance,
|
|
308
|
+
autoFocus: autoFocus,
|
|
309
|
+
components: selectComponents,
|
|
310
|
+
inputId: id,
|
|
311
|
+
isClearable: true,
|
|
312
|
+
isDisabled: isDisabled,
|
|
313
|
+
menuIsOpen: isOpen && !isDisabled,
|
|
314
|
+
menuPlacement: "auto",
|
|
315
|
+
openMenuOnFocus: true,
|
|
316
|
+
onBlur: onBlur,
|
|
317
|
+
onCreateOption: onCreateOption,
|
|
318
|
+
onChange: onChange,
|
|
319
|
+
options: options,
|
|
320
|
+
onFocus: onFocus,
|
|
321
|
+
onMenuOpen: onMenuOpen,
|
|
322
|
+
onMenuClose: onMenuClose,
|
|
323
|
+
placeholder: placeholder || l10n.formatTime(_internal.placeholderDatetime),
|
|
324
|
+
styles: mergedStyles,
|
|
325
|
+
value: initialValue,
|
|
326
|
+
spacing: spacing,
|
|
327
|
+
fixedLayerRef: containerRef,
|
|
328
|
+
isInvalid: isInvalid,
|
|
329
|
+
testId: testId
|
|
330
|
+
}, otherSelectProps)));
|
|
331
|
+
});
|
|
360
332
|
var _default = exports.default = TimePicker;
|
|
@@ -72,7 +72,6 @@ var Menu = exports.Menu = function Menu(_ref) {
|
|
|
72
72
|
onChange: selectProps.onCalendarChange,
|
|
73
73
|
onSelect: selectProps.onCalendarSelect,
|
|
74
74
|
previousMonthLabel: selectProps.previousMonthLabel,
|
|
75
|
-
calendarRef: selectProps.calendarRef,
|
|
76
75
|
selected: [selectProps.calendarValue],
|
|
77
76
|
shouldSetFocusOnCurrentDay: selectProps.shouldSetFocusOnCurrentDay,
|
|
78
77
|
locale: selectProps.calendarLocale,
|
|
@@ -19,7 +19,7 @@ import { getSafeCalendarValue, getShortISOString } from '../internal/parse-date'
|
|
|
19
19
|
import { convertTokens } from '../internal/parse-tokens';
|
|
20
20
|
import { makeSingleValue } from '../internal/single-value';
|
|
21
21
|
const packageName = "@atlaskit/datetime-picker";
|
|
22
|
-
const packageVersion = "14.0.
|
|
22
|
+
const packageVersion = "14.0.3";
|
|
23
23
|
const datePickerDefaultProps = {
|
|
24
24
|
appearance: 'default',
|
|
25
25
|
autoFocus: false,
|
|
@@ -51,7 +51,6 @@ const datePickerDefaultProps = {
|
|
|
51
51
|
class DatePickerComponent extends Component {
|
|
52
52
|
constructor(props) {
|
|
53
53
|
super(props);
|
|
54
|
-
_defineProperty(this, "calendarRef", null);
|
|
55
54
|
_defineProperty(this, "containerRef", null);
|
|
56
55
|
// All state needs to be accessed via this function so that the state is mapped from props
|
|
57
56
|
// correctly to allow controlled/uncontrolled usage.
|
|
@@ -284,9 +283,6 @@ class DatePickerComponent extends Component {
|
|
|
284
283
|
this.onClear();
|
|
285
284
|
}
|
|
286
285
|
});
|
|
287
|
-
_defineProperty(this, "refCalendar", ref => {
|
|
288
|
-
this.calendarRef = ref;
|
|
289
|
-
});
|
|
290
286
|
_defineProperty(this, "handleSelectInputChange", (selectInputValue, actionMeta) => {
|
|
291
287
|
const {
|
|
292
288
|
onInputChange
|
|
@@ -436,7 +432,6 @@ class DatePickerComponent extends Component {
|
|
|
436
432
|
} : {};
|
|
437
433
|
const calendarProps = {
|
|
438
434
|
calendarContainerRef: this.containerRef,
|
|
439
|
-
calendarRef: this.refCalendar,
|
|
440
435
|
calendarDisabled: disabled,
|
|
441
436
|
calendarDisabledDateFilter: disabledDateFilter,
|
|
442
437
|
calendarMaxDate: maxDate,
|
|
@@ -516,7 +511,6 @@ class DatePickerComponent extends Component {
|
|
|
516
511
|
calendarLocale: calendarProps.calendarLocale,
|
|
517
512
|
calendarMaxDate: calendarProps.calendarMaxDate,
|
|
518
513
|
calendarMinDate: calendarProps.calendarMinDate,
|
|
519
|
-
calendarRef: calendarProps.calendarRef,
|
|
520
514
|
calendarValue: calendarProps.calendarValue,
|
|
521
515
|
calendarView: calendarProps.calendarView,
|
|
522
516
|
calendarWeekStartDay: calendarProps.calendarWeekStartDay,
|