superdesk-ui-framework 4.0.46 → 4.0.47

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.
@@ -82,7 +82,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
82
82
 
83
83
  /***/ }),
84
84
 
85
- /***/ 18:
85
+ /***/ 19:
86
86
  /***/ (function(module, exports, __webpack_require__) {
87
87
 
88
88
  /* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_RESULT__;/**
@@ -28252,7 +28252,7 @@ return jQuery;
28252
28252
  "use strict";
28253
28253
 
28254
28254
 
28255
- __webpack_require__(18);
28255
+ __webpack_require__(19);
28256
28256
 
28257
28257
  __webpack_require__(74);
28258
28258
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superdesk-ui-framework",
3
- "version": "4.0.46",
3
+ "version": "4.0.47",
4
4
  "license": "AGPL-3.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,7 +1,8 @@
1
1
  import * as React from "react";
2
2
  import { InputWrapper } from "./Form";
3
3
  import { IInputWrapper } from "./Form/InputWrapper";
4
- interface IProps extends IInputWrapper {
4
+ interface IPropsValueDate extends IInputWrapper {
5
+ valueType: 'date';
5
6
  value: Date | null;
6
7
  dateFormat: string;
7
8
  onChange: (value: Date | null) => void;
@@ -13,11 +14,32 @@ interface IProps extends IInputWrapper {
13
14
  ref?: React.LegacyRef<InputWrapper>;
14
15
  'data-test-id'?: string;
15
16
  }
17
+ type IValue = {
18
+ date?: string;
19
+ time?: string;
20
+ };
21
+ interface IPropsValueObject extends IInputWrapper {
22
+ valueType: 'object';
23
+ value: IValue;
24
+ dateFormat: string;
25
+ onChange: (value: IValue) => void;
26
+ preview?: boolean;
27
+ fullWidth?: boolean;
28
+ allowSeconds?: boolean;
29
+ required?: boolean;
30
+ disabled?: boolean;
31
+ ref?: React.LegacyRef<InputWrapper>;
32
+ 'data-test-id'?: string;
33
+ }
34
+ type IProps = IPropsValueDate | IPropsValueObject;
16
35
  export declare class DateTimePicker extends React.PureComponent<IProps> {
17
36
  private htmlId;
18
37
  handleTimeChange: (time: string) => void;
19
38
  handleDateChange: (date: Date | null) => void;
20
39
  prepareFormat(unitOfTime: number): string;
40
+ getTimeValue(): string;
41
+ getDateValue(): Date | null;
42
+ handleClear: () => void;
21
43
  render(): JSX.Element;
22
44
  }
23
45
  export {};
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
29
  if (k2 === undefined) k2 = k;
19
30
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -60,53 +71,99 @@ var TimePicker_1 = require("./TimePicker");
60
71
  var IconButton_1 = require("./IconButton");
61
72
  var Form_1 = require("./Form");
62
73
  var react_id_generator_1 = __importDefault(require("react-id-generator"));
74
+ var date_fns_1 = require("date-fns");
75
+ var helpers_1 = require("../helpers");
63
76
  var DateTimePicker = /** @class */ (function (_super) {
64
77
  __extends(DateTimePicker, _super);
65
78
  function DateTimePicker() {
66
79
  var _this = _super !== null && _super.apply(this, arguments) || this;
67
80
  _this.htmlId = (0, react_id_generator_1.default)();
68
81
  _this.handleTimeChange = function (time) {
69
- var _a = time
70
- .split(":")
71
- .map(function (x) { return (0, lodash_1.defaultTo)(parseInt(x, 10), 0); }), hours = _a[0], minutes = _a[1]; // handle NaN value
72
- var origDate = _this.props.value ? new Date(_this.props.value) : new Date();
73
- origDate.setHours(hours, minutes);
74
- _this.props.onChange(origDate);
82
+ if (_this.props.valueType === 'date') {
83
+ var _a = time
84
+ .split(":")
85
+ .map(function (x) { return (0, lodash_1.defaultTo)(parseInt(x, 10), 0); }), hours = _a[0], minutes = _a[1];
86
+ var origDate = _this.props.value ? new Date(_this.props.value) : new Date();
87
+ origDate.setHours(hours, minutes);
88
+ _this.props.onChange(origDate);
89
+ }
90
+ else if (_this.props.valueType === 'object') {
91
+ _this.props.onChange(__assign(__assign({}, _this.props.value), { time: time }));
92
+ }
93
+ else {
94
+ (0, helpers_1.assertNever)(_this.props);
95
+ }
75
96
  };
76
97
  _this.handleDateChange = function (date) {
77
98
  var _a;
78
- if (date == null) {
99
+ if (_this.props.valueType === 'date') {
100
+ if (date == null) {
101
+ _this.props.onChange(null);
102
+ return;
103
+ }
104
+ var origDate = (_a = _this.props.value) !== null && _a !== void 0 ? _a : new Date();
105
+ var selectedDate = new Date(date);
106
+ selectedDate.setHours(origDate.getHours(), origDate.getMinutes());
107
+ _this.props.onChange(selectedDate);
108
+ }
109
+ else if (_this.props.valueType === 'object') {
110
+ _this.props.onChange(__assign(__assign({}, _this.props.value), { date: date ? (0, date_fns_1.format)(date, 'yyyy-MM-dd') : undefined }));
111
+ }
112
+ else {
113
+ (0, helpers_1.assertNever)(_this.props);
114
+ }
115
+ };
116
+ _this.handleClear = function () {
117
+ if (_this.props.valueType === 'date') {
79
118
  _this.props.onChange(null);
80
- return;
81
119
  }
82
- var origDate = (_a = _this.props.value) !== null && _a !== void 0 ? _a : new Date();
83
- var selectedDate = new Date(date);
84
- selectedDate.setHours(origDate.getHours(), origDate.getMinutes());
85
- _this.props.onChange(selectedDate);
120
+ else if (_this.props.valueType === 'object') {
121
+ _this.props.onChange({ date: undefined, time: undefined });
122
+ }
123
+ else {
124
+ (0, helpers_1.assertNever)(_this.props);
125
+ }
86
126
  };
87
127
  return _this;
88
128
  }
89
129
  DateTimePicker.prototype.prepareFormat = function (unitOfTime) {
90
130
  return unitOfTime.toString().padStart(2, "0");
91
131
  };
132
+ DateTimePicker.prototype.getTimeValue = function () {
133
+ var _a;
134
+ if (this.props.valueType === 'date') {
135
+ return this.props.value != null
136
+ ? "".concat(this.prepareFormat(this.props.value.getHours()), ":").concat(this.prepareFormat(this.props.value.getMinutes()))
137
+ : "";
138
+ }
139
+ else if (this.props.valueType === 'object') {
140
+ return (_a = this.props.value.time) !== null && _a !== void 0 ? _a : '';
141
+ }
142
+ else {
143
+ (0, helpers_1.assertNever)(this.props);
144
+ }
145
+ };
146
+ DateTimePicker.prototype.getDateValue = function () {
147
+ if (this.props.valueType === 'date') {
148
+ return this.props.value;
149
+ }
150
+ else if (this.props.valueType === 'object') {
151
+ return this.props.value.date ? new Date(this.props.value.date) : null;
152
+ }
153
+ else {
154
+ (0, helpers_1.assertNever)(this.props);
155
+ }
156
+ };
92
157
  DateTimePicker.prototype.render = function () {
93
- var _this = this;
94
- var convertedTimeValue = this.props.value != null
95
- ? "".concat(this.prepareFormat(this.props.value.getHours()), ":").concat(this.prepareFormat(this.props.value.getMinutes()))
96
- : "";
158
+ var timeValue = this.getTimeValue();
159
+ var dateValue = this.getDateValue();
97
160
  return (React.createElement(Form_1.InputWrapper, { label: this.props.label, error: this.props.error, invalid: this.props.error != null, required: this.props.required, disabled: this.props.disabled, info: this.props.info, inlineLabel: this.props.inlineLabel, labelHidden: this.props.labelHidden, htmlId: this.htmlId, tabindex: this.props.tabindex, fullWidth: this.props.fullWidth, inputWrapper: this.props.inputWrapper, "data-test-id": this.props["data-test-id"], ref: this.props.ref },
98
161
  React.createElement(common_1.Spacer, { h: true, gap: "8", alignItems: "end", noWrap: true },
99
162
  React.createElement("div", { style: { flexGrow: 1 } },
100
- React.createElement(DatePicker_1.DatePicker, { disabled: this.props.disabled, preview: this.props.preview, required: this.props.required, hideClearButton: true, value: this.props.value, onChange: function (val) {
101
- _this.handleDateChange(val);
102
- }, dateFormat: this.props.dateFormat, inlineLabel: true, labelHidden: true, fullWidth: this.props.fullWidth })),
163
+ React.createElement(DatePicker_1.DatePicker, { disabled: this.props.disabled, preview: this.props.preview, required: this.props.required, hideClearButton: true, value: dateValue, onChange: this.handleDateChange, dateFormat: this.props.dateFormat, inlineLabel: true, labelHidden: true, fullWidth: this.props.fullWidth })),
103
164
  React.createElement("div", { style: { flexGrow: 1 } },
104
- React.createElement(TimePicker_1.TimePicker, { disabled: this.props.disabled, preview: this.props.preview, value: convertedTimeValue, onChange: function (val) {
105
- _this.handleTimeChange(val);
106
- }, inlineLabel: true, labelHidden: true, allowSeconds: this.props.allowSeconds, fullWidth: this.props.fullWidth, required: this.props.required })),
107
- this.props.preview !== true && (React.createElement(IconButton_1.IconButton, { disabled: this.props.disabled, icon: "remove-sign", onClick: function () {
108
- _this.props.onChange(null);
109
- }, ariaValue: "Clear" })))));
165
+ React.createElement(TimePicker_1.TimePicker, { disabled: this.props.disabled, preview: this.props.preview, value: timeValue, onChange: this.handleTimeChange, inlineLabel: true, labelHidden: true, allowSeconds: this.props.allowSeconds, fullWidth: this.props.fullWidth, required: this.props.required })),
166
+ this.props.preview !== true && (React.createElement(IconButton_1.IconButton, { disabled: this.props.disabled, icon: "remove-sign", onClick: this.handleClear, ariaValue: "Clear" })))));
110
167
  };
111
168
  return DateTimePicker;
112
169
  }(React.PureComponent));