@spothero/ui 15.0.0-beta.1 → 15.0.0-beta.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.
Files changed (61) hide show
  1. package/.eslintignore +2 -1
  2. package/README.md +2 -2
  3. package/backlog/Chart/Chart.js +2 -2
  4. package/backlog/DateTime/DatePicker.js +4 -4
  5. package/backlog/DateTime/DatePickerCalendar.js +8 -8
  6. package/backlog/DateTime/DatePickerCalendarWithRange.js +6 -6
  7. package/backlog/DateTime/DateTimeRangePicker.js +6 -4
  8. package/backlog/DateTime/TimePicker.js +3 -3
  9. package/backlog/ErrorBoundary/ErrorBoundary.js +7 -9
  10. package/backlog/Flyout/Flyout.js +5 -5
  11. package/backlog/Form/Form.js +5 -3
  12. package/backlog/GooglePlacesSearchInput/GooglePlacesSearchInput.js +1 -4
  13. package/backlog/Notification/Notification.js +4 -4
  14. package/backlog/Portal/Portal.js +3 -3
  15. package/backlog/RenderInBody/RenderInBody.js +2 -2
  16. package/backlog/Select/Select.js +3 -3
  17. package/backlog/SelectControlled/SelectControlled.js +3 -3
  18. package/backlog/Tooltip/Tooltip.js +6 -6
  19. package/backlog/utils/animation.js +84 -0
  20. package/backlog/utils/date.js +233 -0
  21. package/backlog/utils/dom.js +441 -0
  22. package/backlog/utils/environment.js +422 -0
  23. package/backlog/utils/number.js +43 -0
  24. package/backlog/utils/time.js +282 -0
  25. package/backlog/v1/components/Image/Image.js +2 -2
  26. package/backlog/v1/components/Modal/Modal.js +12 -12
  27. package/backlog/v1/components/Modal/ModalContent.js +3 -3
  28. package/package.json +1 -2
  29. package/styles/Chart/Chart.jsx +1 -1
  30. package/styles/DateTime/DatePicker.jsx +1 -1
  31. package/styles/DateTime/DatePickerCalendar.jsx +1 -1
  32. package/styles/DateTime/DatePickerCalendarWithRange.jsx +1 -1
  33. package/styles/DateTime/DateTimeRangePicker.jsx +2 -1
  34. package/styles/DateTime/TimePicker.jsx +1 -1
  35. package/styles/ErrorBoundary/ErrorBoundary.jsx +7 -6
  36. package/styles/Flyout/Flyout.jsx +1 -1
  37. package/styles/Form/Form.jsx +2 -1
  38. package/styles/GooglePlacesSearchInput/GooglePlacesSearchInput.jsx +2 -2
  39. package/styles/Notification/Notification.jsx +1 -1
  40. package/styles/Portal/Portal.jsx +1 -1
  41. package/styles/RenderInBody/RenderInBody.jsx +1 -1
  42. package/styles/Select/Select.jsx +1 -1
  43. package/styles/SelectControlled/SelectControlled.jsx +1 -1
  44. package/styles/Tooltip/Tooltip.jsx +1 -1
  45. package/styles/utils/animation.js +75 -0
  46. package/styles/utils/date.js +226 -0
  47. package/styles/utils/dom.js +428 -0
  48. package/styles/utils/environment.js +425 -0
  49. package/styles/utils/number.js +33 -0
  50. package/styles/utils/time.js +268 -0
  51. package/styles/v1/components/Image/Image.jsx +1 -1
  52. package/styles/v1/components/Modal/Modal.jsx +1 -1
  53. package/styles/v1/components/Modal/ModalContent.jsx +1 -1
  54. package/styles/v1/components/Modal/stories/Content.stories.js +1 -1
  55. package/styles/v2/components/Image/Image.jsx +1 -1
  56. package/v1/index.js +1 -1
  57. package/v1/index.js.LICENSE.txt +0 -29
  58. package/v1/index.js.map +1 -1
  59. package/v2/index.js +1 -1
  60. package/v2/index.js.LICENSE.txt +0 -29
  61. package/v2/index.js.map +1 -1
@@ -0,0 +1,268 @@
1
+ import isEmpty from 'lodash/isEmpty';
2
+ import isNumber from 'lodash/isNumber';
3
+ import isString from 'lodash/isString';
4
+ import moment from 'moment-timezone';
5
+ import NumberUtils from './number';
6
+ // import StringUtils from '../string/string';
7
+
8
+ /**
9
+ * Utilities for working with times.
10
+ * @module TimeUtils
11
+ */
12
+ const TimeUtils = {
13
+ // /**
14
+ // * Normalizes the provided time down to the provided step.
15
+ // * @static
16
+ // * @function normalizeToStep
17
+ // * @param {String} time - The input value in the format hh:mm A.
18
+ // * @param {Number} [step=1] - The step to round down to.
19
+ // * @example
20
+ // * TimeUtils.normalizeToStep('07:07 PM', 15); // '07:00 PM'
21
+ // * @returns {String} - The normalized time.
22
+ // */
23
+ // normalizeToStep(time, step = 1) {
24
+ // if (isEmpty(time)) {
25
+ // return time;
26
+ // }
27
+ //
28
+ // if (!isString(time)) {
29
+ // throw new Error('The supplied time is not a string.');
30
+ // }
31
+ //
32
+ // const {hours, mins} = TimeUtils.getValuesFromString(time, step);
33
+ //
34
+ // return TimeUtils.getFromValuesAsString(hours, mins);
35
+ // },
36
+ //
37
+ /**
38
+ * Provides the hours, minutes, and meridiem from a time string.
39
+ * @static
40
+ * @function getValuesFromString
41
+ * @param {String} time - The input value in the format hh:mm A.
42
+ * @param {Number} [step=1] - The step to round down to.
43
+ * @example
44
+ * TimeUtils.getValuesFromString('10:19 AM');
45
+ * @returns {Object} - The object containing the hours, minutes, and meridiem.
46
+ */
47
+ getValuesFromString(time, step = 1) {
48
+ if (isEmpty(time)) {
49
+ return time;
50
+ }
51
+
52
+ if (!isString(time)) {
53
+ throw new Error('The supplied time is not a string.');
54
+ }
55
+
56
+ const firstPartials = time.split(':');
57
+ const secondPartials = firstPartials[1].split(' ');
58
+ const isAM = secondPartials[1] === 'AM';
59
+ const mins = parseInt(secondPartials[0], 10);
60
+ const minsRounded = NumberUtils.roundDownToNearestStep(mins, step);
61
+ let hours = parseInt(firstPartials[0], 10);
62
+
63
+ if (isAM && hours === 12) {
64
+ hours = 0;
65
+ } else if (!isAM && hours !== 12) {
66
+ hours += 12;
67
+ }
68
+
69
+ return {
70
+ hours,
71
+ mins: minsRounded,
72
+ isAM,
73
+ };
74
+ },
75
+ //
76
+ // /**
77
+ // * Provides the formatted time from hours and minutes values.
78
+ // * @static
79
+ // * @function getFromValuesAsString
80
+ // * @param {Number} hours - The hours in a 24 hour format.
81
+ // * @param {Number} minutes - The minutes from 0 - 60.
82
+ // * @param {Boolean} [roundMinutesDown=false] - Whether to round the minutes down to the provided step.
83
+ // * @param {Number} [step=1] - The step to round minutes down to.
84
+ // * @example
85
+ // * TimeUtils.getFromValuesAsString(20, 35); // '08:35 PM'
86
+ // * @returns {String} - The formatted time.
87
+ // */
88
+ // getFromValuesAsString(hours, minutes, roundMinutesDown = false, step = 1) {
89
+ // const meridiem = hours < 12 ? 'AM' : 'PM';
90
+ // let newHours = hours;
91
+ // let newMinutes = minutes;
92
+ //
93
+ // if (newHours > 12) {
94
+ // newHours -= 12;
95
+ // } else if (newHours === 0) {
96
+ // newHours = 12;
97
+ // }
98
+ //
99
+ // if (roundMinutesDown) {
100
+ // newMinutes = NumberUtils.roundDownToNearestStep(newMinutes, step);
101
+ // }
102
+ //
103
+ // return `${StringUtils.padWith(newHours)}:${StringUtils.padWith(
104
+ // newMinutes
105
+ // )} ${meridiem}`;
106
+ // },
107
+ //
108
+ // /**
109
+ // * Converts a mobile input time to a string in the format hh:mm A.
110
+ // * @static
111
+ // * @function getMobileAsString
112
+ // * @param {String} time - The input value in the format HH:mm (24 hour format).
113
+ // * @param {Number} [step=1] - The step to round down to.
114
+ // * @example
115
+ // * TimeUtils.getMobileAsString('22:19'); // 10:19 PM
116
+ // * @returns {String} - The formatted time.
117
+ // */
118
+ // getMobileAsString(time, step = 1) {
119
+ // if (!isString(time)) {
120
+ // throw new Error('The supplied time is not a string.');
121
+ // }
122
+ //
123
+ // const frags = time.split(':');
124
+ // const mins = parseInt(frags[1], 10);
125
+ // const minsRounded = NumberUtils.roundDownToNearestStep(mins, step);
126
+ // const hours = parseInt(frags[0], 10);
127
+ // const meridiem = hours < 12 ? 'AM' : 'PM';
128
+ // let hh = hours;
129
+ //
130
+ // if (hours > 12) {
131
+ // hh -= 12;
132
+ // } else if (hours === 0) {
133
+ // hh = 12;
134
+ // }
135
+ //
136
+ // return `${StringUtils.padWith(hh)}:${StringUtils.padWith(
137
+ // minsRounded
138
+ // )} ${meridiem}`;
139
+ // },
140
+ //
141
+ // /**
142
+ // * Converts a time to a date object.
143
+ // * @static
144
+ // * @function getAsDate
145
+ // * @param {String} time - The input value in the format hh:mm A.
146
+ // * @example
147
+ // * TimeUtils.getAsDate('10:19 PM');
148
+ // * @returns {Date} - The time inside of a date object.
149
+ // */
150
+ // getAsDate(time) {
151
+ // if (isEmpty(time)) {
152
+ // return null;
153
+ // }
154
+ //
155
+ // if (!isString(time)) {
156
+ // throw new Error('The supplied time is not a string.');
157
+ // }
158
+ //
159
+ // const {hours, mins} = TimeUtils.getValuesFromString(time);
160
+ // const d = new Date();
161
+ //
162
+ // d.setHours(hours);
163
+ // d.setMinutes(mins);
164
+ // d.setSeconds(0);
165
+ //
166
+ // return d;
167
+ // },
168
+
169
+ /**
170
+ * Converts a time to a moment instance.
171
+ * @static
172
+ * @function getAsMoment
173
+ * @param {String} time - The input value in the format hh:mm A.
174
+ * @example
175
+ * TimeUtils.getAsMoment('10:19 PM');
176
+ * @returns {Moment} - The time inside of a moment instance.
177
+ */
178
+ getAsMoment(time) {
179
+ if (isEmpty(time)) {
180
+ return null;
181
+ }
182
+
183
+ if (!isString(time)) {
184
+ throw new Error('The supplied time is not a string.');
185
+ }
186
+
187
+ const {hours, mins} = TimeUtils.getValuesFromString(time);
188
+
189
+ return moment([1, 1])
190
+ .startOf('day')
191
+ .add(hours, 'hours')
192
+ .add(mins, 'minutes');
193
+ },
194
+
195
+ /**
196
+ * Generate an array of times.
197
+ * @static
198
+ * @function getTimes
199
+ * @param {Object} data - The data to pass to the function.
200
+ * @param {Number} [data.step=30] - Increment times by this many minutes.
201
+ * @param {String} [data.format='hh:mm A'] - Moment.js format (http://momentjs.com/docs/#/displaying/format/).
202
+ * @param {String} [data.ignoreBefore] - Number of minutes to ignore times before in the output.
203
+ * @param {String} [data.ignoreAfter] - Number of minutes to ignore times after in the output.
204
+ * @example
205
+ * TimeUtils.getTimes({
206
+ * step: 30,
207
+ * format: 'hh:mm A'
208
+ * });
209
+ * @returns {Array} times - An array of times.
210
+ */
211
+ getTimes({step = 30, format = 'hh:mm A', ignoreBefore, ignoreAfter} = {}) {
212
+ if (ignoreBefore && !isNumber(ignoreBefore)) {
213
+ throw new Error('The ignoreBefore value passed was not a number.');
214
+ }
215
+
216
+ if (ignoreAfter && !isNumber(ignoreAfter)) {
217
+ throw new Error('The ignoreAfter value passed was not a number.');
218
+ }
219
+
220
+ if (ignoreBefore && ignoreAfter && ignoreBefore > ignoreAfter) {
221
+ throw new Error(
222
+ 'The value of ignoreBefore should be less than the value of ignoreAfter.'
223
+ );
224
+ }
225
+
226
+ const dateTime = moment([0, 0]);
227
+ const total = 1440;
228
+ const len = total / step;
229
+ const times = [];
230
+ const beforeMoment = ignoreBefore
231
+ ? dateTime.clone().startOf('day').add(ignoreBefore, 'minutes')
232
+ : null;
233
+ const afterMoment = ignoreAfter
234
+ ? dateTime.clone().startOf('day').add(ignoreAfter, 'minutes')
235
+ : null;
236
+ let i = 0;
237
+ let id = 0;
238
+ let shouldAdd = true;
239
+ let time;
240
+
241
+ for (i; i < len; i++) {
242
+ id = i * step;
243
+
244
+ time = dateTime.clone().startOf('day').add(id, 'minutes');
245
+
246
+ shouldAdd = beforeMoment
247
+ ? time.isSameOrAfter(beforeMoment)
248
+ : shouldAdd;
249
+
250
+ if (shouldAdd) {
251
+ shouldAdd = afterMoment
252
+ ? time.isSameOrBefore(afterMoment)
253
+ : shouldAdd;
254
+ }
255
+
256
+ if (shouldAdd) {
257
+ times.push({
258
+ id,
259
+ formatted: time.format(format),
260
+ });
261
+ }
262
+ }
263
+
264
+ return times;
265
+ },
266
+ };
267
+
268
+ export default TimeUtils;
@@ -4,7 +4,7 @@ import React, {Component} from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import classNames from 'classnames';
6
6
  import LazyLoad from 'react-lazy-load';
7
- import {EnvironmentUtils} from '@spothero/utils';
7
+ import EnvironmentUtils from '../../../utils/environment';
8
8
  import PulseLoader from '../../../PulseLoader/PulseLoader';
9
9
 
10
10
  export default class Image extends Component {
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
5
5
  import classNames from 'classnames';
6
6
  import IconChevronLeft from '@spothero/icons/chevron-left';
7
7
  import IconTimes from '@spothero/icons/times';
8
- import {DOMUtils} from '@spothero/utils';
8
+ import DOMUtils from '../../../utils/dom';
9
9
  import Button from 'v1/components/Button/Button';
10
10
  import Portal from '../../../Portal/Portal';
11
11
 
@@ -5,7 +5,7 @@ import React, {Component} from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import classNames from 'classnames';
7
7
  import {document, window} from 'ssr-window';
8
- import {DOMUtils} from '@spothero/utils';
8
+ import DOMUtils from '../../../utils/dom';
9
9
 
10
10
  export default class ModalContent extends Component {
11
11
  static propTypes = {
@@ -3,7 +3,7 @@ import Button from 'v1/components/Button/Button';
3
3
  import Modal from '../Modal';
4
4
  import ModalContent from '../ModalContent';
5
5
  import ErrorBoundary from '../../../../ErrorBoundary/ErrorBoundary';
6
- import {DOMUtils} from '@spothero/utils';
6
+ import DOMUtils from '../../../../utils/dom';
7
7
 
8
8
  export default {
9
9
  component: Modal,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import {Image as ChakraImage, Img as ChakraImg} from '@chakra-ui/react';
4
- import {EnvironmentUtils} from '@spothero/utils';
4
+ import EnvironmentUtils from '../../../utils/environment';
5
5
  import template from 'lodash/template';
6
6
 
7
7
  const buildCloudinarySrc = ({