@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,75 @@
1
+ import {window} from 'ssr-window';
2
+ import isString from 'lodash/isString';
3
+ import DOMUtils from './dom';
4
+
5
+ // t = current time, b = start value, c = change in value, d = duration
6
+ // http://stackoverflow.com/questions/8917921/cross-browser-javascript-not-jquery-scroll-to-top-animation
7
+ Math.easeInOutQuad = (t, b, c, d) => {
8
+ /* eslint-disable no-param-reassign, no-mixed-operators */
9
+ t /= d / 2;
10
+
11
+ if (t < 1) {
12
+ return (c / 2) * t * t + b;
13
+ }
14
+
15
+ t--;
16
+
17
+ return (-c / 2) * (t * (t - 2) - 1) + b;
18
+ /* eslint-enable no-param-reassign, no-mixed-operators */
19
+ };
20
+
21
+ /**
22
+ * Utilities for working with animations.
23
+ * @module AnimationUtils
24
+ */
25
+ const AnimationUtils = {
26
+ /**
27
+ * Scrolls the specified element to the specified position.
28
+ * @static
29
+ * @function scrollTo
30
+ * @param {String|Element} el - The selector or element to scroll to.
31
+ * @param {Number} [position=0] - The position to scroll the element to.
32
+ * @param {Number} [duration=400] - The time (in milliseconds) to scroll.
33
+ * @param {String} [axis='y'] - The axis to scroll on.
34
+ * @param {Function} [cb] - A callback function to call when the animation finishes.
35
+ * @example
36
+ * AnimationUtils.scrollTo(window, 0, 1000);
37
+ * @returns {void}
38
+ */
39
+ scrollTo(el, position = 0, duration = 400, axis = 'y', cb = null) {
40
+ const element = isString(el) ? DOMUtils.el(el) : el;
41
+ const start = axis === 'y' ? element.scrollTop : element.scrollLeft;
42
+ const change = position - start;
43
+ const increment = 20;
44
+ let currentTime = 0;
45
+
46
+ const animateScroll = () => {
47
+ currentTime += increment;
48
+
49
+ const val = Math.easeInOutQuad(
50
+ currentTime,
51
+ start,
52
+ change,
53
+ duration
54
+ );
55
+
56
+ if (axis === 'y') {
57
+ element.scrollTop = val;
58
+ } else {
59
+ element.scrollLeft = val;
60
+ }
61
+
62
+ if (currentTime < duration) {
63
+ window.setTimeout(animateScroll, increment);
64
+ } else {
65
+ if (cb) {
66
+ cb();
67
+ }
68
+ }
69
+ };
70
+
71
+ animateScroll();
72
+ },
73
+ };
74
+
75
+ export default AnimationUtils;
@@ -0,0 +1,226 @@
1
+ import {window} from 'ssr-window';
2
+ import isDate from 'lodash/isDate';
3
+ import isObject from 'lodash/isObject';
4
+ import isString from 'lodash/isString';
5
+ import moment from 'moment-timezone';
6
+
7
+ const splitTextDate = (date, delimeter) => {
8
+ const d = date.split(delimeter);
9
+
10
+ return new Date(d[2], d[0] - 1, d[1]);
11
+ };
12
+
13
+ const splitMobileDate = date => {
14
+ const d = date.split('-');
15
+
16
+ return new Date(d[0], d[1] - 1, d[2]);
17
+ };
18
+
19
+ /**
20
+ * Utilities for working with dates.
21
+ * @module DateUtils
22
+ */
23
+ const DateUtils = {
24
+ // /**
25
+ // * Check whether input type of 'date' is supported in the current browser.
26
+ // * @static
27
+ // * @function supportsDateInput
28
+ // * @example
29
+ // * DateUtils.supportsDateInput();
30
+ // * @returns {Boolean} - Whether the input type is supported.
31
+ // */
32
+ // supportsDateInput() {
33
+ // const fakeValue = 'not-a-date';
34
+ // const input = document.createElement('input');
35
+ //
36
+ // input.setAttribute('type', 'date');
37
+ // input.setAttribute('value', fakeValue);
38
+ //
39
+ // return input.value !== fakeValue;
40
+ // },
41
+
42
+ // /**
43
+ // * Gets the closest match to the user's current time zone.
44
+ // * @static
45
+ // * @function getTimeZone
46
+ // * @example
47
+ // * DateUtils.getTimeZone(); // 'America/Chicago'
48
+ // * @returns {String} - The user's current time zone.
49
+ // */
50
+ // getTimeZone() {
51
+ // if (
52
+ // window.Intl &&
53
+ // isObject(window.Intl) &&
54
+ // window.Intl.DateTimeFormat().resolvedOptions().timeZone
55
+ // ) {
56
+ // return window.Intl.DateTimeFormat().resolvedOptions().timeZone;
57
+ // } else {
58
+ // return moment.tz.guess();
59
+ // }
60
+ // },
61
+
62
+ // /**
63
+ // * Converts a mobile input date to a string using the specified format.
64
+ // * @static
65
+ // * @function convertToDesktop
66
+ // * @param {String} date - The input value in the format YYYY-MM-DD.
67
+ // * @param {String} [format='MM/DD/YYYY'] - The output format.
68
+ // * @example
69
+ // * DateUtils.convertToDesktop('1983-01-19');
70
+ // * @returns {String} - The formatted date.
71
+ // */
72
+ // convertToDesktop(date, format = 'MM/DD/YYYY') {
73
+ // if (!isString(date)) {
74
+ // throw new Error('The supplied date is not a string.');
75
+ // }
76
+ //
77
+ // if (date.indexOf('-') !== -1) {
78
+ // return moment(splitMobileDate(date)).format(format);
79
+ // } else {
80
+ // return date;
81
+ // }
82
+ // },
83
+
84
+ // /**
85
+ // * Converts a desktop input date to the native mobile date format.
86
+ // * @static
87
+ // * @function convertToMobile
88
+ // * @param {String} date - The input value in the format MM/DD/YYYY.
89
+ // * @example
90
+ // * DateUtils.convertToMobile('01/19/1983');
91
+ // * @returns {String} - The mobile formatted date.
92
+ // */
93
+ // convertToMobile(date) {
94
+ // if (!isString(date)) {
95
+ // throw new Error('The supplied date is not a string.');
96
+ // }
97
+ //
98
+ // if (date.indexOf('/') !== -1) {
99
+ // return moment(splitTextDate(date, '/')).format('YYYY-MM-DD');
100
+ // } else {
101
+ // return date;
102
+ // }
103
+ // },
104
+
105
+ /**
106
+ * Converts a string date from a text or date input to a date object.
107
+ * @static
108
+ * @function getAsDate
109
+ * @param {String} date - The date in the format MM/DD/YYYY (text input) or YYYY-MM-DD (date input).
110
+ * @example
111
+ * DateUtils.getAsDate('1983-01-19');
112
+ * DateUtils.getAsDate('01/19/1983');
113
+ * @returns {Date} - The date object.
114
+ */
115
+ getAsDate(date) {
116
+ if (!isString(date)) {
117
+ throw new Error('The supplied date is not a string.');
118
+ }
119
+
120
+ if (date.indexOf('-') !== -1) {
121
+ // date input
122
+ return splitMobileDate(date);
123
+ } else {
124
+ // text input
125
+ return splitTextDate(date, '/');
126
+ }
127
+ },
128
+
129
+ /**
130
+ * Converts a string date from a text or date input to a moment instance.
131
+ * @static
132
+ * @function getAsMoment
133
+ * @param {String} date - The date in the format MM/DD/YYYY (text input) or YYYY-MM-DD (date input).
134
+ * @example
135
+ * DateUtils.getAsMoment('1983-01-19');
136
+ * DateUtils.getAsMoment('01/19/1983');
137
+ * @returns {Moment} - The moment instance.
138
+ */
139
+ getAsMoment(date) {
140
+ if (!isString(date)) {
141
+ throw new Error('The supplied date is not a string.');
142
+ }
143
+
144
+ if (date.indexOf('-') !== -1) {
145
+ // date input
146
+ return moment(splitMobileDate(date));
147
+ } else {
148
+ // text input
149
+ return moment(splitTextDate(date, '/'));
150
+ }
151
+ },
152
+
153
+ /**
154
+ * Combines a date moment with a time moment to return one moment instance.
155
+ * @static
156
+ * @function combineDateAndTime
157
+ * @param {Moment} date - The date as a moment instance.
158
+ * @param {Moment} time - The time as a moment instance.
159
+ * @example
160
+ * DateUtils.combineDateAndTime(moment(), moment().add(7, 'hours').add(23, 'minutes'));
161
+ * @returns {Moment} - The combined moment instance.
162
+ */
163
+ combineDateAndTime(date, time) {
164
+ if (!moment.isMoment(date) || !moment.isMoment(time)) {
165
+ throw new Error(
166
+ 'The date and/or time supplied was not an instance of Moment.'
167
+ );
168
+ }
169
+
170
+ return date.hours(time.hours()).minutes(time.minutes());
171
+ },
172
+
173
+ /**
174
+ * Checks if one date is before another.
175
+ * @static
176
+ * @function isBefore
177
+ * @param {Date} dateToCheck - The date to check.
178
+ * @param {Date} dateToCompare - The date to check against.
179
+ * @param {Boolean} [useTime=false] - Whether to use the time in the comparison.
180
+ * @example
181
+ * DateUtils.isBefore(new Date(2016, 1, 19), new Date(2016, 3, 14));
182
+ * @returns {Boolean} - Whether the provided date is before the one being checked against.
183
+ */
184
+ isBefore(dateToCheck, dateToCompare, useTime = false) {
185
+ if (!isDate(dateToCheck) || !isDate(dateToCompare)) {
186
+ throw new Error(
187
+ 'The dates supplied must be instances of the Date object.'
188
+ );
189
+ }
190
+
191
+ if (!useTime) {
192
+ dateToCheck.setHours(0, 0, 0, 0);
193
+ dateToCompare.setHours(0, 0, 0, 0);
194
+ }
195
+
196
+ return dateToCheck < dateToCompare;
197
+ },
198
+
199
+ /**
200
+ * Checks if one date is after another.
201
+ * @static
202
+ * @function isAfter
203
+ * @param {Date} dateToCheck - The date to check.
204
+ * @param {Date} dateToCompare - The date to check against.
205
+ * @param {Boolean} [useTime=false] - Whether to use the time in the comparison.
206
+ * @example
207
+ * DateUtils.isAfter(new Date(2016, 1, 19), new Date(2016, 3, 14));
208
+ * @returns {Boolean} - Whether the provided date is after the one being checked against.
209
+ */
210
+ isAfter(dateToCheck, dateToCompare, useTime = false) {
211
+ if (!isDate(dateToCheck) || !isDate(dateToCompare)) {
212
+ throw new Error(
213
+ 'The dates supplied must be instances of the Date object.'
214
+ );
215
+ }
216
+
217
+ if (!useTime) {
218
+ dateToCheck.setHours(0, 0, 0, 0);
219
+ dateToCompare.setHours(0, 0, 0, 0);
220
+ }
221
+
222
+ return dateToCheck > dateToCompare;
223
+ },
224
+ };
225
+
226
+ export default DateUtils;