@synerise/ds-date-picker 0.5.69 → 0.6.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.
@@ -1,24 +1,8 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
6
-
7
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
8
-
9
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
-
11
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
12
-
13
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
-
15
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
16
-
17
1
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
2
 
19
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
3
+ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
20
4
 
21
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
22
6
 
23
7
  import * as React from 'react';
24
8
  import { FormattedMessage } from 'react-intl';
@@ -35,18 +19,14 @@ import { fnsStartOfMonth, fnsSetYear, fnsSetMonth, fnsSetDate, fnsStartOfDay, fn
35
19
  import { changeDayWithHoursPreserved } from '../utils';
36
20
 
37
21
  var RawDatePicker = /*#__PURE__*/function (_React$Component) {
38
- _inherits(RawDatePicker, _React$Component);
39
-
40
- var _super = _createSuper(RawDatePicker);
22
+ _inheritsLoose(RawDatePicker, _React$Component);
41
23
 
42
24
  function RawDatePicker(props) {
43
25
  var _this;
44
26
 
45
- _classCallCheck(this, RawDatePicker);
27
+ _this = _React$Component.call(this, props) || this; // eslint-disable-next-line react/state-in-constructor
46
28
 
47
- _this = _super.call(this, props); // eslint-disable-next-line react/state-in-constructor
48
-
49
- _this.handleChange = function (value) {
29
+ _defineProperty(_assertThisInitialized(_this), "handleChange", function (value) {
50
30
  var onValueChange = _this.props.onValueChange;
51
31
  var _this$state = _this.state,
52
32
  mode = _this$state.mode,
@@ -69,21 +49,21 @@ var RawDatePicker = /*#__PURE__*/function (_React$Component) {
69
49
 
70
50
  onValueChange && onValueChange(value);
71
51
  }
72
- };
52
+ });
73
53
 
74
- _this.handleDayMouseEnter = function (day) {
54
+ _defineProperty(_assertThisInitialized(_this), "handleDayMouseEnter", function (day) {
75
55
  return _this.setState({
76
56
  enteredTo: day
77
57
  });
78
- };
58
+ });
79
59
 
80
- _this.handleDayMouseLeave = function () {
60
+ _defineProperty(_assertThisInitialized(_this), "handleDayMouseLeave", function () {
81
61
  return _this.setState({
82
62
  enteredTo: undefined
83
63
  });
84
- };
64
+ });
85
65
 
86
- _this.handleDayClick = function (day, modifiers) {
66
+ _defineProperty(_assertThisInitialized(_this), "handleDayClick", function (day, modifiers) {
87
67
  var _this$state2 = _this.state,
88
68
  isChanged = _this$state2.changed,
89
69
  value = _this$state2.value;
@@ -106,15 +86,15 @@ var RawDatePicker = /*#__PURE__*/function (_React$Component) {
106
86
  }
107
87
 
108
88
  !!showTime && _this.handleModeSwitch('time');
109
- };
89
+ });
110
90
 
111
- _this.handleModeSwitch = function (mode) {
91
+ _defineProperty(_assertThisInitialized(_this), "handleModeSwitch", function (mode) {
112
92
  return _this.setState({
113
93
  mode: mode
114
94
  });
115
- };
95
+ });
116
96
 
117
- _this.handleApply = function (date) {
97
+ _defineProperty(_assertThisInitialized(_this), "handleApply", function (date) {
118
98
  var onApply = _this.props.onApply;
119
99
  if (!onApply) return;
120
100
  var value = _this.state.value;
@@ -130,43 +110,43 @@ var RawDatePicker = /*#__PURE__*/function (_React$Component) {
130
110
  }
131
111
 
132
112
  _this.handleModeSwitch('date');
133
- };
113
+ });
134
114
 
135
- _this.handleMonthChange = function (month, mode) {
115
+ _defineProperty(_assertThisInitialized(_this), "handleMonthChange", function (month, mode) {
136
116
  return _this.setState({
137
117
  month: month,
138
118
  mode: mode
139
119
  });
140
- };
120
+ });
141
121
 
142
- _this.renderDay = function (day) {
122
+ _defineProperty(_assertThisInitialized(_this), "renderDay", function (day) {
143
123
  var text = day.getDate();
144
- return React.createElement(React.Fragment, null, React.createElement(DayBackground, null), React.createElement(DayText, {
124
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DayBackground, null), /*#__PURE__*/React.createElement(DayText, {
145
125
  "data-attr": text
146
- }, text), React.createElement(DayForeground, null));
147
- };
126
+ }, text), /*#__PURE__*/React.createElement(DayForeground, null));
127
+ });
148
128
 
149
- _this.renderYearPicker = function () {
129
+ _defineProperty(_assertThisInitialized(_this), "renderYearPicker", function () {
150
130
  var month = _this.state.month;
151
- return React.createElement(YearPicker, {
131
+ return /*#__PURE__*/React.createElement(YearPicker, {
152
132
  value: month,
153
133
  onChange: function onChange(changedMonth) {
154
134
  return changedMonth && _this.handleMonthChange(changedMonth, 'date');
155
135
  }
156
136
  });
157
- };
137
+ });
158
138
 
159
- _this.renderMonthPicker = function () {
139
+ _defineProperty(_assertThisInitialized(_this), "renderMonthPicker", function () {
160
140
  var month = _this.state.month;
161
- return React.createElement(MonthPicker, {
141
+ return /*#__PURE__*/React.createElement(MonthPicker, {
162
142
  value: month,
163
143
  onChange: function onChange(changedMonth) {
164
144
  return changedMonth && _this.handleMonthChange(changedMonth, 'date');
165
145
  }
166
146
  });
167
- };
147
+ });
168
148
 
169
- _this.renderDayPicker = function () {
149
+ _defineProperty(_assertThisInitialized(_this), "renderDayPicker", function () {
170
150
  var _this$state3 = _this.state,
171
151
  value = _this$state3.value,
172
152
  enteredTo = _this$state3.enteredTo;
@@ -180,7 +160,7 @@ var RawDatePicker = /*#__PURE__*/function (_React$Component) {
180
160
  };
181
161
  var selectedDays = value ? [value] : [];
182
162
  var month = _this.state.month;
183
- return React.createElement(DayPicker, {
163
+ return /*#__PURE__*/React.createElement(DayPicker, {
184
164
  fixedWeeks: true,
185
165
  showOutsideDays: true,
186
166
  canChangeMonth: false,
@@ -203,24 +183,24 @@ var RawDatePicker = /*#__PURE__*/function (_React$Component) {
203
183
  },
204
184
  modifiers: modifiers
205
185
  });
206
- };
186
+ });
207
187
 
208
- _this.handleDaySwitch = function (day) {
188
+ _defineProperty(_assertThisInitialized(_this), "handleDaySwitch", function (day) {
209
189
  var disabledDates = _this.props.disabledDates; // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
210
190
  // @ts-ignore
211
191
 
212
192
  _this.handleDayClick(day, {
213
193
  disabled: disabledDates ? disabledDates(day) : false
214
194
  });
215
- };
195
+ });
216
196
 
217
- _this.renderTimePicker = function () {
197
+ _defineProperty(_assertThisInitialized(_this), "renderTimePicker", function () {
218
198
  var value = _this.state.value;
219
199
  var _this$props2 = _this.props,
220
200
  disabledHours = _this$props2.disabledHours,
221
201
  disabledMinutes = _this$props2.disabledMinutes,
222
202
  disabledSeconds = _this$props2.disabledSeconds;
223
- return React.createElement(TimePicker, {
203
+ return /*#__PURE__*/React.createElement(TimePicker, {
224
204
  value: value,
225
205
  onChange: _this.handleChange,
226
206
  disabledHours: disabledHours,
@@ -233,7 +213,7 @@ var RawDatePicker = /*#__PURE__*/function (_React$Component) {
233
213
  return _this.handleDaySwitch(fnsAddDays(legacyParse(value), -1));
234
214
  }
235
215
  });
236
- };
216
+ });
237
217
 
238
218
  _this.state = {
239
219
  mode: 'date',
@@ -246,102 +226,100 @@ var RawDatePicker = /*#__PURE__*/function (_React$Component) {
246
226
  return _this;
247
227
  }
248
228
 
249
- _createClass(RawDatePicker, [{
250
- key: "getTexts",
251
- value: function getTexts() {
252
- var _this$props3 = this.props,
253
- texts = _this$props3.texts,
254
- intl = _this$props3.intl;
255
- var updatedTexts = {
256
- apply: (texts === null || texts === void 0 ? void 0 : texts.apply) || React.createElement(FormattedMessage, {
257
- id: "DS.DATE-PICKER.APPLY"
258
- }),
259
- now: (texts === null || texts === void 0 ? void 0 : texts.now) || React.createElement(FormattedMessage, {
260
- id: "DS.DATE-PICKER.NOW"
261
- }),
262
- inputPlaceholder: (texts === null || texts === void 0 ? void 0 : texts.inputPlaceholder) || (intl === null || intl === void 0 ? void 0 : intl.formatMessage({
263
- id: 'DS.DATE-PICKER.SELECT-DATE'
264
- })) || ''
265
- };
266
- return updatedTexts;
267
- }
268
- }, {
269
- key: "getSnapshotBeforeUpdate",
270
- value: function getSnapshotBeforeUpdate(prevProps) {
271
- var value = this.props.value;
272
- var mode = this.state.mode;
273
-
274
- if ((prevProps === null || prevProps === void 0 ? void 0 : prevProps.value) !== value) {
275
- this.setState({
276
- value: value,
277
- month: fnsStartOfMonth(value || new Date()),
278
- changed: true,
279
- mode: value === undefined ? 'date' : mode
280
- });
281
- }
229
+ var _proto = RawDatePicker.prototype;
230
+
231
+ _proto.getTexts = function getTexts() {
232
+ var _this$props3 = this.props,
233
+ texts = _this$props3.texts,
234
+ intl = _this$props3.intl;
235
+ var updatedTexts = {
236
+ apply: (texts == null ? void 0 : texts.apply) || /*#__PURE__*/React.createElement(FormattedMessage, {
237
+ id: "DS.DATE-PICKER.APPLY"
238
+ }),
239
+ now: (texts == null ? void 0 : texts.now) || /*#__PURE__*/React.createElement(FormattedMessage, {
240
+ id: "DS.DATE-PICKER.NOW"
241
+ }),
242
+ inputPlaceholder: (texts == null ? void 0 : texts.inputPlaceholder) || (intl == null ? void 0 : intl.formatMessage({
243
+ id: 'DS.DATE-PICKER.SELECT-DATE'
244
+ })) || ''
245
+ };
246
+ return updatedTexts;
247
+ };
248
+
249
+ _proto.getSnapshotBeforeUpdate = function getSnapshotBeforeUpdate(prevProps) {
250
+ var value = this.props.value;
251
+ var mode = this.state.mode;
282
252
 
283
- return null;
253
+ if ((prevProps == null ? void 0 : prevProps.value) !== value) {
254
+ this.setState({
255
+ value: value,
256
+ month: fnsStartOfMonth(value || new Date()),
257
+ changed: true,
258
+ mode: value === undefined ? 'date' : mode
259
+ });
284
260
  }
285
- }, {
286
- key: "render",
287
- value: function render() {
288
- var _this2 = this;
289
-
290
- var _this$state4 = this.state,
291
- mode = _this$state4.mode,
292
- changed = _this$state4.changed,
293
- value = _this$state4.value,
294
- texts = _this$state4.texts;
295
- var _this$props4 = this.props,
296
- showTime = _this$props4.showTime,
297
- hideNow = _this$props4.hideNow;
298
- var isValid = !!value;
299
- var picker;
300
-
301
- switch (mode) {
302
- case 'time':
303
- picker = this.renderTimePicker();
304
- break;
305
-
306
- case 'date':
307
- picker = this.renderDayPicker();
308
- break;
309
-
310
- case 'month':
311
- picker = this.renderMonthPicker();
312
- break;
313
-
314
- case 'year':
315
- picker = this.renderYearPicker();
316
- break;
317
-
318
- default:
319
- picker = null;
320
- break;
321
- }
322
261
 
323
- return React.createElement(S.Container, null, picker, React.createElement(Footer, {
324
- canApply: isValid && changed,
325
- onApply: this.handleApply,
326
- dateOnly: !showTime,
327
- mode: mode,
328
- canSwitchMode: isValid,
329
- onSwitchMode: function onSwitchMode() {
330
- return _this2.handleModeSwitch(mode === 'time' ? 'date' : 'time');
331
- },
332
- texts: texts,
333
- hideNow: hideNow
334
- }));
262
+ return null;
263
+ };
264
+
265
+ _proto.render = function render() {
266
+ var _this2 = this;
267
+
268
+ var _this$state4 = this.state,
269
+ mode = _this$state4.mode,
270
+ changed = _this$state4.changed,
271
+ value = _this$state4.value,
272
+ texts = _this$state4.texts;
273
+ var _this$props4 = this.props,
274
+ showTime = _this$props4.showTime,
275
+ hideNow = _this$props4.hideNow;
276
+ var isValid = !!value;
277
+ var picker;
278
+
279
+ switch (mode) {
280
+ case 'time':
281
+ picker = this.renderTimePicker();
282
+ break;
283
+
284
+ case 'date':
285
+ picker = this.renderDayPicker();
286
+ break;
287
+
288
+ case 'month':
289
+ picker = this.renderMonthPicker();
290
+ break;
291
+
292
+ case 'year':
293
+ picker = this.renderYearPicker();
294
+ break;
295
+
296
+ default:
297
+ picker = null;
298
+ break;
335
299
  }
336
- }]);
300
+
301
+ return /*#__PURE__*/React.createElement(S.Container, null, picker, /*#__PURE__*/React.createElement(Footer, {
302
+ canApply: isValid && changed,
303
+ onApply: this.handleApply,
304
+ dateOnly: !showTime,
305
+ mode: mode,
306
+ canSwitchMode: isValid,
307
+ onSwitchMode: function onSwitchMode() {
308
+ return _this2.handleModeSwitch(mode === 'time' ? 'date' : 'time');
309
+ },
310
+ texts: texts,
311
+ hideNow: hideNow
312
+ }));
313
+ };
337
314
 
338
315
  return RawDatePicker;
339
316
  }(React.Component);
340
317
 
341
- RawDatePicker.defaultProps = {
318
+ _defineProperty(RawDatePicker, "defaultProps", {
342
319
  showTime: false,
343
320
  disabledHours: [],
344
321
  disabledMinutes: [],
345
322
  disabledSeconds: []
346
- };
323
+ });
324
+
347
325
  export default RawDatePicker;
@@ -0,0 +1 @@
1
+ export {};
package/dist/format.js CHANGED
@@ -6,8 +6,11 @@ var locales = {
6
6
  es: es
7
7
  };
8
8
  var defaultLocale = 'en';
9
- export default function (date, formatStr) {
10
- var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultLocale;
9
+ export default function (date, formatStr, locale) {
10
+ if (locale === void 0) {
11
+ locale = defaultLocale;
12
+ }
13
+
11
14
  return fnsFormat(date, formatStr, {
12
15
  locale: locales[locale.substring(0, 2)]
13
16
  });
@@ -15,14 +15,20 @@ var FIRST_DAY = {
15
15
  pl: 1
16
16
  };
17
17
 
18
- function formatDay(d) {
19
- var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
20
- return "".concat(WEEKDAYS_LONG[locale][d.getDay()], ", ").concat(d.getDate(), " ").concat(MONTHS[locale][d.getMonth()], " ").concat(d.getFullYear());
18
+ function formatDay(d, locale) {
19
+ if (locale === void 0) {
20
+ locale = 'en';
21
+ }
22
+
23
+ return WEEKDAYS_LONG[locale][d.getDay()] + ", " + d.getDate() + " " + MONTHS[locale][d.getMonth()] + " " + d.getFullYear();
21
24
  }
22
25
 
23
- function formatMonthTitle(d) {
24
- var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
25
- return "".concat(MONTHS[locale][d.getMonth()], " ").concat(d.getFullYear());
26
+ function formatMonthTitle(d, locale) {
27
+ if (locale === void 0) {
28
+ locale = 'en';
29
+ }
30
+
31
+ return MONTHS[locale][d.getMonth()] + " " + d.getFullYear();
26
32
  }
27
33
 
28
34
  function formatWeekdayShort(i, locale) {
package/dist/utils.js CHANGED
@@ -1,15 +1,3 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
8
-
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
13
1
  import { differenceInCalendarDays } from 'date-fns';
14
2
  import { legacyParse } from "@date-fns/upgrade/v2";
15
3
  import { fnsAddSeconds, fnsDifferenceInSeconds, fnsGetYear } from './fns';
@@ -19,7 +7,7 @@ export var range = function range(start, end) {
19
7
  }
20
8
 
21
9
  var size = end - start;
22
- return _toConsumableArray(Array(size).keys()).map(function (i) {
10
+ return [].concat(Array(size).keys()).map(function (i) {
23
11
  return i + start;
24
12
  });
25
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-date-picker",
3
- "version": "0.5.69",
3
+ "version": "0.6.3",
4
4
  "description": "DatePicker UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,11 +33,11 @@
33
33
  "types": "dist/index.d.ts",
34
34
  "dependencies": {
35
35
  "@date-fns/upgrade": "^1.0.3",
36
- "@synerise/ds-button": "^0.15.0",
37
- "@synerise/ds-core": "^0.30.14",
38
- "@synerise/ds-icon": "^0.45.2",
39
- "@synerise/ds-time-picker": "^0.5.48",
40
- "@synerise/ds-tooltip": "^0.10.56",
36
+ "@synerise/ds-button": "^0.16.2",
37
+ "@synerise/ds-core": "^0.31.2",
38
+ "@synerise/ds-icon": "^0.46.2",
39
+ "@synerise/ds-time-picker": "^0.6.3",
40
+ "@synerise/ds-tooltip": "^0.11.2",
41
41
  "classnames": "^2.2.6",
42
42
  "date-fns": "2.16.1",
43
43
  "lodash": "^4.17.20",
@@ -48,5 +48,5 @@
48
48
  "@synerise/ds-core": "*",
49
49
  "react": ">=16.9.0 < 17.0.0"
50
50
  },
51
- "gitHead": "bf865b6d1967c42effb68dc794f34dd18ddebe27"
51
+ "gitHead": "2468359677783819939fb9f1ef5acc36667ecd1a"
52
52
  }