superdesk-ui-framework 4.0.48 → 4.0.49

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.
@@ -7,7 +7,7 @@
7
7
  var a = typeof exports === 'object' ? factory(require("react"), require("react-dom"), require("angular")) : factory(root["react"], root["react-dom"], root["angular"]);
8
8
  for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
9
9
  }
10
- })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_824__) {
10
+ })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_0__, __WEBPACK_EXTERNAL_MODULE_9__, __WEBPACK_EXTERNAL_MODULE_826__) {
11
11
  return /******/ (function(modules) { // webpackBootstrap
12
12
  /******/ // The module cache
13
13
  /******/ var installedModules = {};
@@ -70,7 +70,7 @@ return /******/ (function(modules) { // webpackBootstrap
70
70
  /******/ __webpack_require__.p = "";
71
71
  /******/
72
72
  /******/ // Load entry module and return exports
73
- /******/ return __webpack_require__(__webpack_require__.s = 821);
73
+ /******/ return __webpack_require__(__webpack_require__.s = 823);
74
74
  /******/ })
75
75
  /************************************************************************/
76
76
  /******/ ({
@@ -82,7 +82,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
82
82
 
83
83
  /***/ }),
84
84
 
85
- /***/ 19:
85
+ /***/ 18:
86
86
  /***/ (function(module, exports, __webpack_require__) {
87
87
 
88
88
  /* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_RESULT__;/**
@@ -17296,11 +17296,11 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_0__;
17296
17296
  }
17297
17297
  }.call(this));
17298
17298
 
17299
- /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(42), __webpack_require__(59)(module)))
17299
+ /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(43), __webpack_require__(59)(module)))
17300
17300
 
17301
17301
  /***/ }),
17302
17302
 
17303
- /***/ 42:
17303
+ /***/ 43:
17304
17304
  /***/ (function(module, exports) {
17305
17305
 
17306
17306
  var g;
@@ -28246,21 +28246,21 @@ return jQuery;
28246
28246
 
28247
28247
  /***/ }),
28248
28248
 
28249
- /***/ 821:
28249
+ /***/ 823:
28250
28250
  /***/ (function(module, exports, __webpack_require__) {
28251
28251
 
28252
28252
  "use strict";
28253
28253
 
28254
28254
 
28255
- __webpack_require__(19);
28255
+ __webpack_require__(18);
28256
28256
 
28257
28257
  __webpack_require__(74);
28258
28258
 
28259
- __webpack_require__(822);
28260
-
28261
28259
  __webpack_require__(824);
28262
28260
 
28263
- __webpack_require__(825);
28261
+ __webpack_require__(826);
28262
+
28263
+ __webpack_require__(827);
28264
28264
 
28265
28265
  __webpack_require__(0);
28266
28266
 
@@ -28268,7 +28268,7 @@ __webpack_require__(9);
28268
28268
 
28269
28269
  /***/ }),
28270
28270
 
28271
- /***/ 822:
28271
+ /***/ 824:
28272
28272
  /***/ (function(module, exports, __webpack_require__) {
28273
28273
 
28274
28274
  var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
@@ -28292,7 +28292,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
28292
28292
  if ( true ) {
28293
28293
 
28294
28294
  // AMD. Register as an anonymous module.
28295
- !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(74), __webpack_require__(823) ], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
28295
+ !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(74), __webpack_require__(825) ], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
28296
28296
  __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
28297
28297
  (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
28298
28298
  __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
@@ -29030,7 +29030,7 @@ return $.widget;
29030
29030
 
29031
29031
  /***/ }),
29032
29032
 
29033
- /***/ 823:
29033
+ /***/ 825:
29034
29034
  /***/ (function(module, exports, __webpack_require__) {
29035
29035
 
29036
29036
  var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;( function( factory ) {
@@ -29060,23 +29060,23 @@ return $.ui.version = "1.13.0";
29060
29060
 
29061
29061
  /***/ }),
29062
29062
 
29063
- /***/ 824:
29063
+ /***/ 826:
29064
29064
  /***/ (function(module, exports) {
29065
29065
 
29066
- module.exports = __WEBPACK_EXTERNAL_MODULE_824__;
29066
+ module.exports = __WEBPACK_EXTERNAL_MODULE_826__;
29067
29067
 
29068
29068
  /***/ }),
29069
29069
 
29070
- /***/ 825:
29070
+ /***/ 827:
29071
29071
  /***/ (function(module, exports, __webpack_require__) {
29072
29072
 
29073
- __webpack_require__(826);
29073
+ __webpack_require__(828);
29074
29074
  module.exports = 'ngAnimate';
29075
29075
 
29076
29076
 
29077
29077
  /***/ }),
29078
29078
 
29079
- /***/ 826:
29079
+ /***/ 828:
29080
29080
  /***/ (function(module, exports) {
29081
29081
 
29082
29082
  /**
@@ -7,7 +7,7 @@ class DateTimePickerExample extends React.PureComponent<{}, {dateTime: Date | nu
7
7
  super(props);
8
8
 
9
9
  this.state = {
10
- dateTime: new Date(),
10
+ dateTime: null,
11
11
  };
12
12
  }
13
13
 
@@ -17,6 +17,8 @@ class DateTimePickerExample extends React.PureComponent<{}, {dateTime: Date | nu
17
17
  label="Planning date"
18
18
  labelHidden
19
19
  inlineLabel
20
+ fullWidth
21
+ valueType="date"
20
22
  value={this.state.dateTime}
21
23
  dateFormat="YYYY-MM-DD"
22
24
  fullWidth
@@ -7,12 +7,12 @@ import {TimePickerV2} from '../../../app-typescript/components/TimePickerV2';
7
7
  let minutes = Array.from(Array(60).keys());
8
8
  let changedMinutes = minutes.filter((num) => num % 15 !== 0);
9
9
 
10
- class TimePickerExample extends React.PureComponent<{}, {time: string}> {
10
+ class TimePickerExample extends React.PureComponent<{}, {time: string | null}> {
11
11
  constructor(props) {
12
12
  super(props);
13
13
 
14
14
  this.state = {
15
- time: '',
15
+ time: null,
16
16
  };
17
17
  }
18
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superdesk-ui-framework",
3
- "version": "4.0.48",
3
+ "version": "4.0.49",
4
4
  "license": "AGPL-3.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,6 +13,8 @@ interface IPropsValueDate extends IInputWrapper {
13
13
  disabled?: boolean;
14
14
  ref?: React.LegacyRef<InputWrapper>;
15
15
  'data-test-id'?: string;
16
+ timeHeaderTemplate?: React.ReactNode;
17
+ timeFooterTemplate?: React.ReactNode;
16
18
  }
17
19
  type IValue = {
18
20
  date?: string;
@@ -30,6 +32,8 @@ interface IPropsValueObject extends IInputWrapper {
30
32
  disabled?: boolean;
31
33
  ref?: React.LegacyRef<InputWrapper>;
32
34
  'data-test-id'?: string;
35
+ timeHeaderTemplate?: React.ReactNode;
36
+ timeFooterTemplate?: React.ReactNode;
33
37
  }
34
38
  type IProps = IPropsValueDate | IPropsValueObject;
35
39
  export declare class DateTimePicker extends React.PureComponent<IProps> {
@@ -37,7 +41,7 @@ export declare class DateTimePicker extends React.PureComponent<IProps> {
37
41
  handleTimeChange: (time: string) => void;
38
42
  handleDateChange: (date: Date | null) => void;
39
43
  prepareFormat(unitOfTime: number): string;
40
- getTimeValue(): string;
44
+ getTimeValue(): string | null;
41
45
  getDateValue(): Date | null;
42
46
  handleClear: () => void;
43
47
  render(): JSX.Element;
@@ -132,10 +132,10 @@ var DateTimePicker = /** @class */ (function (_super) {
132
132
  if (this.props.valueType === 'date') {
133
133
  return this.props.value != null
134
134
  ? "".concat(this.prepareFormat(this.props.value.getHours()), ":").concat(this.prepareFormat(this.props.value.getMinutes()))
135
- : '';
135
+ : null;
136
136
  }
137
137
  else if (this.props.valueType === 'object') {
138
- return (_a = this.props.value.time) !== null && _a !== void 0 ? _a : '';
138
+ return (_a = this.props.value.time) !== null && _a !== void 0 ? _a : null;
139
139
  }
140
140
  else {
141
141
  (0, helpers_1.assertNever)(this.props);
@@ -160,7 +160,7 @@ var DateTimePicker = /** @class */ (function (_super) {
160
160
  React.createElement("div", { style: { flexGrow: 1 } },
161
161
  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 })),
162
162
  React.createElement("div", { style: { flexGrow: 1 } },
163
- 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 })),
163
+ 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, headerTemplate: this.props.timeHeaderTemplate, footerTemplate: this.props.timeFooterTemplate })),
164
164
  this.props.preview !== true && (React.createElement(IconButton_1.IconButton, { disabled: this.props.disabled, icon: "remove-sign", onClick: this.handleClear, ariaValue: "Clear" })))));
165
165
  };
166
166
  return DateTimePicker;
@@ -5,6 +5,7 @@ interface IPropsPopupPositioner {
5
5
  placement: Placement;
6
6
  onClose(): void;
7
7
  closeOnHoverEnd?: boolean;
8
+ 'data-test-id'?: string;
8
9
  }
9
10
  export declare class PopupPositioner extends React.PureComponent<IPropsPopupPositioner> {
10
11
  private wrapperEl;
@@ -150,7 +150,7 @@ var PopupPositioner = /** @class */ (function (_super) {
150
150
  left: '-100vw',
151
151
  display: 'flex',
152
152
  zIndex: this.zIndex,
153
- } }, this.props.children), document.body)));
153
+ }, "data-test-id": this.props['data-test-id'] }, this.props.children), document.body)));
154
154
  };
155
155
  return PopupPositioner;
156
156
  }(React.PureComponent));
@@ -1,13 +1,20 @@
1
1
  import * as React from 'react';
2
2
  import { IInputWrapper } from './Form/InputWrapper';
3
3
  interface IProps extends IInputWrapper {
4
- value: string;
4
+ value: string | null;
5
5
  onChange(valueNext: string): void;
6
6
  allowSeconds?: boolean;
7
+ headerTemplate?: React.ReactNode;
8
+ footerTemplate?: React.ReactNode;
7
9
  'data-test-id'?: string;
8
10
  }
9
- export declare class TimePicker extends React.PureComponent<IProps> {
11
+ interface IState {
12
+ popupOpen: boolean;
13
+ }
14
+ export declare class TimePicker extends React.PureComponent<IProps, IState> {
10
15
  private htmlId;
16
+ private timeInputRef;
17
+ constructor(props: IProps);
11
18
  render(): JSX.Element;
12
19
  }
13
20
  export {};
@@ -55,21 +55,46 @@ exports.TimePicker = void 0;
55
55
  var React = __importStar(require("react"));
56
56
  var react_id_generator_1 = __importDefault(require("react-id-generator"));
57
57
  var Form_1 = require("./Form");
58
+ var TimePickerPopover_1 = require("./TimePickerPopover");
59
+ var ShowPopup_1 = require("./ShowPopup");
58
60
  var TimePicker = /** @class */ (function (_super) {
59
61
  __extends(TimePicker, _super);
60
- function TimePicker() {
61
- var _this = _super !== null && _super.apply(this, arguments) || this;
62
+ function TimePicker(props) {
63
+ var _this = _super.call(this, props) || this;
62
64
  _this.htmlId = (0, react_id_generator_1.default)();
65
+ _this.timeInputRef = React.createRef();
66
+ _this.state = {
67
+ popupOpen: false,
68
+ };
63
69
  return _this;
64
70
  }
65
71
  TimePicker.prototype.render = function () {
66
72
  var _this = this;
73
+ var _a;
67
74
  if (this.props.preview) {
68
75
  return (React.createElement("div", null,
69
76
  React.createElement("span", null, this.props.value)));
70
77
  }
71
- 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, inputWrapper: this.props.inputWrapper },
72
- React.createElement("input", { value: this.props.value, type: "time", className: "sd-input__input", id: this.htmlId, "aria-labelledby": this.htmlId + 'label', step: this.props.allowSeconds ? 1 : undefined, required: this.props.required, disabled: this.props.disabled, onChange: function (event) {
78
+ 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 },
79
+ this.state.popupOpen && (React.createElement(ShowPopup_1.PopupPositioner, { getReferenceElement: function () { return _this.timeInputRef.current; }, placement: "bottom-start", onClose: function () {
80
+ _this.setState({
81
+ popupOpen: false,
82
+ });
83
+ }, "data-test-id": "time-picker-popover" },
84
+ React.createElement(TimePickerPopover_1.TimePickerPopover, { value: this.props.value, onChange: this.props.onChange, closePopup: function () {
85
+ _this.setState({
86
+ popupOpen: false,
87
+ });
88
+ }, allowSeconds: this.props.allowSeconds, headerTemplate: this.props.headerTemplate, footerTemplate: this.props.footerTemplate }))),
89
+ React.createElement("input", { style: {
90
+ cursor: 'pointer',
91
+ }, ref: this.timeInputRef, value: (_a = this.props.value) !== null && _a !== void 0 ? _a : undefined, type: "time", onClick: function (e) {
92
+ // don't show default popup
93
+ e.preventDefault();
94
+ _this.setState({
95
+ popupOpen: true,
96
+ });
97
+ }, className: "sd-input__input", id: this.htmlId, "aria-labelledby": this.htmlId + 'label', step: this.props.allowSeconds ? 1 : undefined, required: this.props.required, disabled: this.props.disabled, onChange: function (event) {
73
98
  _this.props.onChange(event.target.value);
74
99
  }, "data-test-id": this.props['data-test-id'] })));
75
100
  };
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { ITimeUnit } from '../utils/time';
3
+ interface IProps {
4
+ closePopup: () => void;
5
+ headerTemplate?: React.ReactNode;
6
+ footerTemplate?: React.ReactNode;
7
+ allowSeconds?: boolean;
8
+ onChange: (nextValue: string) => void;
9
+ value: string | null;
10
+ }
11
+ export declare class TimePickerPopover extends React.PureComponent<IProps> {
12
+ private is12HourFormat;
13
+ private inputRefs;
14
+ constructor(props: IProps);
15
+ handleChange(unit: ITimeUnit, value: string): void;
16
+ componentDidMount(): void;
17
+ render(): React.ReactNode;
18
+ }
19
+ export {};
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || (function () {
34
+ var ownKeys = function(o) {
35
+ ownKeys = Object.getOwnPropertyNames || function (o) {
36
+ var ar = [];
37
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
+ return ar;
39
+ };
40
+ return ownKeys(o);
41
+ };
42
+ return function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
+ __setModuleDefault(result, mod);
47
+ return result;
48
+ };
49
+ })();
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ exports.TimePickerPopover = void 0;
52
+ var React = __importStar(require("react"));
53
+ var common_1 = require("@sourcefabric/common");
54
+ var ContentDivider_1 = require("./ContentDivider");
55
+ var RadioButtonGroup_1 = require("./RadioButtonGroup");
56
+ var time_1 = require("../utils/time");
57
+ var helpers_1 = require("../helpers");
58
+ var TimeValueHolder = /** @class */ (function (_super) {
59
+ __extends(TimeValueHolder, _super);
60
+ function TimeValueHolder(props) {
61
+ var _this = _super.call(this, props) || this;
62
+ _this.spanEl = React.createRef();
63
+ return _this;
64
+ }
65
+ TimeValueHolder.prototype.scrollToValue = function () {
66
+ var _a;
67
+ (_a = this.spanEl.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView();
68
+ };
69
+ TimeValueHolder.prototype.render = function () {
70
+ var _a;
71
+ return (React.createElement("span", { ref: this.props.isActive ? this.spanEl : undefined, onClick: this.props.onClick, className: (0, common_1.classnames)('p-1 time-unit', {
72
+ 'time-unit-highlight': (_a = this.props.isActive) !== null && _a !== void 0 ? _a : false,
73
+ }) }, this.props.value));
74
+ };
75
+ return TimeValueHolder;
76
+ }(React.PureComponent));
77
+ function parseUnitOfTime(unit, value, is12HourFormat) {
78
+ var _a = (value !== null && value !== void 0 ? value : '').split(':'), hour = _a[0], minutes = _a[1], seconds = _a[2];
79
+ var valueForUnit = (function () {
80
+ if (unit === 'hours') {
81
+ /**
82
+ * Hour value is always in 24-hour format, so we need to adjust it
83
+ * to 12-hour if needed.
84
+ */
85
+ if (is12HourFormat) {
86
+ return hour === '00' ? '12' : hour;
87
+ }
88
+ else {
89
+ return hour;
90
+ }
91
+ }
92
+ else if (unit === 'minutes') {
93
+ return minutes;
94
+ }
95
+ else if (unit === 'seconds') {
96
+ return seconds;
97
+ }
98
+ else {
99
+ (0, helpers_1.assertNever)(unit);
100
+ }
101
+ })();
102
+ var valueParsed = is12HourFormat && unit === 'hours' && valueForUnit !== '12'
103
+ ? parseInt(valueForUnit, 10) % 12
104
+ : parseInt(valueForUnit, 10);
105
+ return (0, time_1.padValue)(valueParsed);
106
+ }
107
+ var TimePickerPopover = /** @class */ (function (_super) {
108
+ __extends(TimePickerPopover, _super);
109
+ function TimePickerPopover(props) {
110
+ var _this = _super.call(this, props) || this;
111
+ _this.inputRefs = [React.createRef(), React.createRef(), React.createRef()];
112
+ _this.handleChange = _this.handleChange.bind(_this);
113
+ var hour = new Date().toLocaleTimeString([]);
114
+ _this.is12HourFormat = hour.includes('AM') || hour.includes('PM');
115
+ return _this;
116
+ }
117
+ TimePickerPopover.prototype.handleChange = function (unit, value) {
118
+ var fallbackDate = new Date();
119
+ var _a = this.props.value == null
120
+ ? [
121
+ (0, time_1.padValue)(fallbackDate.getHours()),
122
+ (0, time_1.padValue)(fallbackDate.getMinutes()),
123
+ (0, time_1.padValue)(fallbackDate.getSeconds()),
124
+ ]
125
+ : this.props.value.split(':'), hour = _a[0], minutes = _a[1], seconds = _a[2];
126
+ var nextValue = '';
127
+ if (unit === 'hours') {
128
+ nextValue = "".concat(value, ":").concat(minutes);
129
+ }
130
+ else if (unit === 'minutes') {
131
+ nextValue = "".concat(hour, ":").concat(value);
132
+ }
133
+ else if (unit === 'seconds') {
134
+ nextValue = "".concat(hour, ":").concat(minutes, ":").concat(value);
135
+ }
136
+ else {
137
+ (0, helpers_1.assertNever)(unit);
138
+ }
139
+ if (this.props.allowSeconds && unit !== 'seconds') {
140
+ nextValue += ":".concat(seconds);
141
+ }
142
+ this.props.onChange(nextValue);
143
+ };
144
+ TimePickerPopover.prototype.componentDidMount = function () {
145
+ this.inputRefs.forEach(function (unitOfTime) { var _a, _b; return (_b = (_a = unitOfTime === null || unitOfTime === void 0 ? void 0 : unitOfTime.current) === null || _a === void 0 ? void 0 : _a.scrollToValue) === null || _b === void 0 ? void 0 : _b.call(_a); });
146
+ };
147
+ TimePickerPopover.prototype.render = function () {
148
+ var _this = this;
149
+ var _a;
150
+ var styleForColumnOfUnit = {
151
+ maxHeight: 190,
152
+ overflowY: 'auto',
153
+ scrollbarWidth: 'none',
154
+ marginTop: 'var(--gap-1)',
155
+ };
156
+ return (React.createElement("div", { className: "sd-shadow--z2 radius-md", onBlur: this.props.closePopup },
157
+ React.createElement(common_1.Spacer, { v: true, gap: "0", style: {
158
+ width: 200,
159
+ padding: 'var(--gap-1)',
160
+ backgroundColor: 'var(--color-bg-00)',
161
+ borderRadius: 'var(--b-radius--small)',
162
+ } },
163
+ this.props.headerTemplate && (React.createElement(React.Fragment, null,
164
+ this.props.headerTemplate,
165
+ React.createElement(ContentDivider_1.ContentDivider, { border: true, type: "solid", orientation: "horizontal", margin: "none" }))),
166
+ React.createElement(common_1.Spacer, { h: true, gap: "4", noWrap: true, justifyContent: "center", alignItems: "start" },
167
+ React.createElement(common_1.Spacer, { v: true, gap: "4", style: styleForColumnOfUnit, alignItems: "center", noWrap: true }, (0, time_1.getOptionsForTimeUnit)('hours', this.is12HourFormat).map(function (hour) {
168
+ var isActiveHour = hour === parseUnitOfTime('hours', _this.props.value, _this.is12HourFormat);
169
+ return (React.createElement(TimeValueHolder, { ref: isActiveHour ? _this.inputRefs[0] : undefined, onClick: function () {
170
+ _this.handleChange('hours', hour);
171
+ }, isActive: isActiveHour, value: hour }));
172
+ })),
173
+ React.createElement(ContentDivider_1.ContentDivider, { align: "center", border: true, type: "solid", orientation: "vertical", margin: "none" }),
174
+ React.createElement(common_1.Spacer, { v: true, gap: "4", style: styleForColumnOfUnit, alignItems: "center", noWrap: true }, (0, time_1.getOptionsForTimeUnit)('minutes', this.is12HourFormat).map(function (minute) {
175
+ var isActiveMinute = minute === parseUnitOfTime('minutes', _this.props.value, _this.is12HourFormat);
176
+ return (React.createElement(TimeValueHolder, { ref: isActiveMinute ? _this.inputRefs[1] : undefined, isActive: isActiveMinute, value: minute, onClick: function () {
177
+ _this.handleChange('minutes', minute);
178
+ } }));
179
+ })),
180
+ this.props.allowSeconds && (React.createElement(React.Fragment, null,
181
+ React.createElement(ContentDivider_1.ContentDivider, { align: "center", border: true, type: "solid", orientation: "vertical", margin: "none" }),
182
+ React.createElement(common_1.Spacer, { v: true, gap: "4", style: styleForColumnOfUnit, alignItems: "center", noWrap: true }, (0, time_1.getOptionsForTimeUnit)('seconds', this.is12HourFormat).map(function (second) {
183
+ var isActiveMinute = second ===
184
+ parseUnitOfTime('seconds', _this.props.value, _this.is12HourFormat);
185
+ return (React.createElement(TimeValueHolder, { ref: isActiveMinute ? _this.inputRefs[2] : undefined, onClick: function () {
186
+ _this.handleChange('seconds', second);
187
+ }, isActive: isActiveMinute, value: second }));
188
+ })))),
189
+ this.is12HourFormat && (React.createElement("div", { style: {
190
+ marginTop: 'var(--gap-1)',
191
+ } },
192
+ React.createElement(RadioButtonGroup_1.RadioButtonGroup, { onChange: function (nextValue) {
193
+ var _a;
194
+ var _b = ((_a = _this.props.value) !== null && _a !== void 0 ? _a : '').split(':'), hour = _b[0], minutes = _b[1], seconds = _b[2];
195
+ if (nextValue === 'PM') {
196
+ var newValue = "".concat((0, time_1.padValue)(parseInt(hour, 10) + 12), ":").concat(minutes);
197
+ if (_this.props.allowSeconds) {
198
+ newValue += ":".concat(seconds);
199
+ }
200
+ _this.props.onChange(newValue);
201
+ }
202
+ else {
203
+ var newValue = "".concat((0, time_1.padValue)(parseInt(hour, 10) - 12), ":").concat(minutes);
204
+ if (_this.props.allowSeconds) {
205
+ newValue += ":".concat(seconds);
206
+ }
207
+ _this.props.onChange(newValue);
208
+ }
209
+ }, options: [
210
+ {
211
+ label: 'AM',
212
+ value: 'AM',
213
+ },
214
+ {
215
+ label: 'PM',
216
+ value: 'PM',
217
+ },
218
+ ], value: parseInt(((_a = this.props.value) !== null && _a !== void 0 ? _a : '').split(':')[0], 10) < 12 ? 'AM' : 'PM' })))),
219
+ this.props.footerTemplate && (React.createElement(React.Fragment, null,
220
+ React.createElement(ContentDivider_1.ContentDivider, { border: true, type: "solid", orientation: "horizontal", margin: "none" }),
221
+ this.props.footerTemplate)))));
222
+ };
223
+ return TimePickerPopover;
224
+ }(React.PureComponent));
225
+ exports.TimePickerPopover = TimePickerPopover;
@@ -0,0 +1,5 @@
1
+ export type ITimeUnit = 'hours' | 'minutes' | 'seconds';
2
+ export declare function getOptionsForTimeUnit(timeUnit: ITimeUnit, is12HourFormat?: boolean, disabledOptions?: {
3
+ [key: string]: Array<number>;
4
+ }): Array<string>;
5
+ export declare function padValue(value: number): string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getOptionsForTimeUnit = getOptionsForTimeUnit;
13
+ exports.padValue = padValue;
14
+ var lodash_1 = require("lodash");
15
+ function getOptionsForTimeUnit(timeUnit, is12HourFormat, disabledOptions) {
16
+ var format12HourArr = __spreadArray([12], (0, lodash_1.range)(1, 12), true);
17
+ var timeUnitArray = (function () {
18
+ if (timeUnit === 'hours') {
19
+ if (is12HourFormat) {
20
+ return format12HourArr;
21
+ }
22
+ else {
23
+ return (0, lodash_1.range)(24);
24
+ }
25
+ }
26
+ else {
27
+ return (0, lodash_1.range)(60);
28
+ }
29
+ })();
30
+ return timeUnitArray
31
+ .filter(function (item) { var _a; return !((_a = disabledOptions === null || disabledOptions === void 0 ? void 0 : disabledOptions[timeUnit]) !== null && _a !== void 0 ? _a : []).includes(item); })
32
+ .map(function (value) { return value.toString().padStart(2, '0'); });
33
+ }
34
+ function padValue(value) {
35
+ return value.toString().padStart(2, '0');
36
+ }