grommet 2.25.0 → 2.25.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.
- package/components/Anchor/Anchor.js +14 -1
- package/components/Button/Button.js +81 -8
- package/components/Button/StyledButtonKind.js +9 -3
- package/components/Button/index.d.ts +1 -1
- package/components/Button/propTypes.js +1 -1
- package/components/Calendar/Calendar.js +232 -292
- package/components/Calendar/utils.js +16 -129
- package/components/Chart/calcs.js +44 -27
- package/components/Chart/stories/Scan.js +11 -9
- package/components/Chart/stories/data.js +16 -17
- package/components/CheckBox/CheckBox.js +3 -2
- package/components/DataChart/DataChart.js +14 -28
- package/components/DataChart/Detail.js +18 -11
- package/components/DataChart/XAxis.js +29 -18
- package/components/DataChart/stories/Pad.js +54 -0
- package/components/DataTable/DataTable.js +13 -9
- package/components/DataTable/buildState.js +2 -2
- package/components/DataTable/index.d.ts +4 -1
- package/components/DataTable/stories/SpaceX.js +3 -1
- package/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/components/DateInput/DateInput.js +60 -68
- package/components/DateInput/utils.js +30 -5
- package/components/FileInput/FileInput.js +2 -1
- package/components/FileInput/StyledFileInput.js +1 -1
- package/components/Form/Form.js +78 -5
- package/components/FormField/FormField.js +29 -29
- package/components/Grommet/Grommet.js +7 -2
- package/components/Grommet/index.d.ts +1 -0
- package/components/Grommet/propTypes.js +2 -1
- package/components/Heading/Heading.js +4 -2
- package/components/Heading/StyledHeading.js +1 -1
- package/components/Heading/index.d.ts +1 -0
- package/components/Heading/propTypes.js +2 -1
- package/components/Image/Image.js +4 -2
- package/components/Layer/LayerContainer.js +25 -0
- package/components/List/List.js +17 -0
- package/components/Menu/Menu.js +7 -4
- package/components/Menu/index.d.ts +2 -2
- package/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/components/Meter/Circle.js +5 -1
- package/components/PageHeader/PageHeader.js +22 -13
- package/components/PageHeader/index.d.ts +10 -1
- package/components/PageHeader/propTypes.js +1 -0
- package/components/PageHeader/stories/Size.js +55 -0
- package/components/Select/SelectContainer.js +96 -75
- package/components/Select/stories/Clear.js +7 -1
- package/components/Select/utils.js +1 -0
- package/components/Spinner/Spinner.js +1 -0
- package/components/Tab/Tab.js +1 -1
- package/components/Tabs/Tabs.js +11 -2
- package/components/Video/StyledVideo.js +2 -2
- package/contexts/AnalyticsContext/AnalyticsContext.js +65 -0
- package/contexts/AnalyticsContext/index.d.ts +7 -0
- package/contexts/AnalyticsContext/index.js +11 -0
- package/contexts/index.js +8 -0
- package/es6/components/Anchor/Anchor.js +15 -3
- package/es6/components/Button/Button.js +83 -11
- package/es6/components/Button/StyledButtonKind.js +9 -3
- package/es6/components/Button/index.d.ts +1 -1
- package/es6/components/Button/propTypes.js +1 -1
- package/es6/components/Calendar/Calendar.js +230 -292
- package/es6/components/Calendar/utils.js +13 -114
- package/es6/components/Chart/calcs.js +44 -27
- package/es6/components/Chart/stories/Scan.js +10 -9
- package/es6/components/Chart/stories/data.js +16 -17
- package/es6/components/CheckBox/CheckBox.js +3 -2
- package/es6/components/DataChart/DataChart.js +15 -28
- package/es6/components/DataChart/Detail.js +20 -10
- package/es6/components/DataChart/XAxis.js +29 -19
- package/es6/components/DataChart/stories/Pad.js +42 -0
- package/es6/components/DataTable/DataTable.js +13 -9
- package/es6/components/DataTable/buildState.js +2 -2
- package/es6/components/DataTable/index.d.ts +4 -1
- package/es6/components/DataTable/stories/SpaceX.js +3 -1
- package/es6/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/es6/components/DateInput/DateInput.js +57 -64
- package/es6/components/DateInput/utils.js +29 -7
- package/es6/components/FileInput/FileInput.js +2 -1
- package/es6/components/FileInput/StyledFileInput.js +1 -1
- package/es6/components/Form/Form.js +76 -5
- package/es6/components/FormField/FormField.js +29 -30
- package/es6/components/Grommet/Grommet.js +6 -2
- package/es6/components/Grommet/index.d.ts +1 -0
- package/es6/components/Grommet/propTypes.js +2 -1
- package/es6/components/Heading/Heading.js +4 -2
- package/es6/components/Heading/StyledHeading.js +1 -1
- package/es6/components/Heading/index.d.ts +1 -0
- package/es6/components/Heading/propTypes.js +2 -1
- package/es6/components/Image/Image.js +4 -2
- package/es6/components/Layer/LayerContainer.js +24 -0
- package/es6/components/List/List.js +16 -0
- package/es6/components/Menu/Menu.js +7 -4
- package/es6/components/Menu/index.d.ts +2 -2
- package/es6/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/es6/components/Meter/Circle.js +5 -1
- package/es6/components/PageHeader/PageHeader.js +24 -14
- package/es6/components/PageHeader/index.d.ts +10 -1
- package/es6/components/PageHeader/propTypes.js +1 -0
- package/es6/components/PageHeader/stories/Size.js +43 -0
- package/es6/components/Select/SelectContainer.js +96 -77
- package/es6/components/Select/stories/Clear.js +7 -1
- package/es6/components/Select/utils.js +1 -0
- package/es6/components/Spinner/Spinner.js +1 -0
- package/es6/components/Tab/Tab.js +1 -1
- package/es6/components/Tabs/Tabs.js +10 -2
- package/es6/components/Video/StyledVideo.js +2 -2
- package/es6/contexts/AnalyticsContext/AnalyticsContext.js +47 -0
- package/es6/contexts/AnalyticsContext/index.d.ts +7 -0
- package/es6/contexts/AnalyticsContext/index.js +1 -0
- package/es6/contexts/index.js +1 -0
- package/es6/themes/base.d.ts +51 -33
- package/es6/themes/base.js +49 -1
- package/es6/utils/DOM.js +4 -0
- package/es6/utils/mixins.js +3 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +56 -48
- package/themes/base.d.ts +51 -33
- package/themes/base.js +49 -1
- package/tools/pack.js +20 -13
- package/tools/release-stable.js +2 -4
- package/utils/DOM.js +9 -2
- package/utils/mixins.js +7 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, DataChart } from 'grommet';
|
|
3
|
+
var data = [];
|
|
4
|
+
|
|
5
|
+
for (var i = 1; i < 3; i += 1) {
|
|
6
|
+
var v = Math.sin(i / 2.0);
|
|
7
|
+
data.push({
|
|
8
|
+
percent: Math.abs(v * 100)
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export var Pad = function Pad() {
|
|
13
|
+
return (
|
|
14
|
+
/*#__PURE__*/
|
|
15
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
16
|
+
// <Grommet theme={grommet}>
|
|
17
|
+
React.createElement(Box, {
|
|
18
|
+
align: "center",
|
|
19
|
+
justify: "start",
|
|
20
|
+
pad: "large"
|
|
21
|
+
}, /*#__PURE__*/React.createElement(DataChart, {
|
|
22
|
+
bounds: {
|
|
23
|
+
y: [0, 100]
|
|
24
|
+
},
|
|
25
|
+
guide: true,
|
|
26
|
+
detail: true,
|
|
27
|
+
pad: {
|
|
28
|
+
horizontal: 'xlarge'
|
|
29
|
+
},
|
|
30
|
+
data: data,
|
|
31
|
+
series: ['percent', {}],
|
|
32
|
+
chart: [{
|
|
33
|
+
property: 'percent',
|
|
34
|
+
thickness: 'medium'
|
|
35
|
+
}]
|
|
36
|
+
})) // </Grommet>
|
|
37
|
+
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
export default {
|
|
41
|
+
title: 'Visualizations/DataChart/Pad'
|
|
42
|
+
};
|
|
@@ -110,11 +110,14 @@ var DataTable = function DataTable(_ref) {
|
|
|
110
110
|
|
|
111
111
|
var _useState5 = useState(sortProp || {}),
|
|
112
112
|
sort = _useState5[0],
|
|
113
|
-
setSort = _useState5[1];
|
|
113
|
+
setSort = _useState5[1];
|
|
114
|
+
|
|
115
|
+
useEffect(function () {
|
|
116
|
+
if (sortProp) setSort(sortProp);
|
|
117
|
+
}, [sortProp]); // the data filtered and sorted, if needed
|
|
114
118
|
// Note: onUpdate mode expects the data to be passed
|
|
115
119
|
// in completely filtered and sorted already.
|
|
116
120
|
|
|
117
|
-
|
|
118
121
|
var adjustedData = useMemo(function () {
|
|
119
122
|
return onUpdate ? data : filterAndSortData(data, filters, onSearch, sort);
|
|
120
123
|
}, [data, filters, onSearch, onUpdate, sort]); // the values to put in the footer cells
|
|
@@ -368,6 +371,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
368
371
|
items = _usePagination[0],
|
|
369
372
|
paginationProps = _usePagination[1];
|
|
370
373
|
|
|
374
|
+
var paginationStep = paginationProps.step;
|
|
371
375
|
var Container = paginate ? StyledContainer : Fragment;
|
|
372
376
|
var containterProps = paginate ? _extends({}, theme.dataTable.container, {
|
|
373
377
|
fill: fill
|
|
@@ -421,13 +425,13 @@ var DataTable = function DataTable(_ref) {
|
|
|
421
425
|
expanded: Object.keys(groupState).filter(function (k) {
|
|
422
426
|
return groupState[k].expanded;
|
|
423
427
|
}),
|
|
424
|
-
count: limit +
|
|
428
|
+
count: limit + paginationStep
|
|
425
429
|
};
|
|
426
430
|
if (sort != null && sort.property) opts.sort = sort;
|
|
427
431
|
if (showProp) opts.show = showProp;
|
|
428
432
|
onUpdate(opts);
|
|
429
433
|
setLimit(function (prev) {
|
|
430
|
-
return prev +
|
|
434
|
+
return prev + paginationStep;
|
|
431
435
|
});
|
|
432
436
|
}
|
|
433
437
|
} : onMore,
|
|
@@ -441,7 +445,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
441
445
|
rowProps: rowProps,
|
|
442
446
|
selected: selected,
|
|
443
447
|
size: size,
|
|
444
|
-
step:
|
|
448
|
+
step: paginationStep,
|
|
445
449
|
verticalAlign: typeof verticalAlign === 'string' ? verticalAlign : verticalAlign == null ? void 0 : verticalAlign.body
|
|
446
450
|
}) : /*#__PURE__*/React.createElement(Body, {
|
|
447
451
|
ref: bodyRef,
|
|
@@ -452,13 +456,13 @@ var DataTable = function DataTable(_ref) {
|
|
|
452
456
|
onMore: onUpdate ? function () {
|
|
453
457
|
if (adjustedData.length === limit) {
|
|
454
458
|
var opts = {
|
|
455
|
-
count: limit +
|
|
459
|
+
count: limit + paginationStep
|
|
456
460
|
};
|
|
457
461
|
if (sort != null && sort.property) opts.sort = sort;
|
|
458
462
|
if (showProp) opts.show = showProp;
|
|
459
463
|
onUpdate(opts);
|
|
460
464
|
setLimit(function (prev) {
|
|
461
|
-
return prev +
|
|
465
|
+
return prev + paginationStep;
|
|
462
466
|
});
|
|
463
467
|
}
|
|
464
468
|
} : onMore,
|
|
@@ -475,7 +479,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
475
479
|
selected: selected,
|
|
476
480
|
show: !paginate ? showProp : undefined,
|
|
477
481
|
size: size,
|
|
478
|
-
step:
|
|
482
|
+
step: paginationStep,
|
|
479
483
|
rowDetails: rowDetails,
|
|
480
484
|
rowExpand: rowExpand,
|
|
481
485
|
setRowExpand: setRowExpand,
|
|
@@ -537,7 +541,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
537
541
|
}), placeholder && items && items.length > 0 && /*#__PURE__*/React.createElement(StyledPlaceholder, {
|
|
538
542
|
top: headerHeight,
|
|
539
543
|
bottom: footerHeight
|
|
540
|
-
}, placeholderContent))), paginate && adjustedData.length >
|
|
544
|
+
}, placeholderContent))), paginate && adjustedData.length > paginationStep && items && items.length ? /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
541
545
|
alignSelf: "end"
|
|
542
546
|
}, paginationProps)) : null);
|
|
543
547
|
};
|
|
@@ -93,8 +93,8 @@ export var filterAndSortData = function filterAndSortData(data, filters, onSearc
|
|
|
93
93
|
var d1Val = datumValue(d1, property);
|
|
94
94
|
var d2Val = datumValue(d2, property);
|
|
95
95
|
|
|
96
|
-
if (typeof d1Val === 'string' && typeof d2Val === 'string') {
|
|
97
|
-
var sortResult = d1Val.localeCompare(d2Val, undefined, {
|
|
96
|
+
if (typeof d1Val === 'string' && typeof d2Val === 'string' || typeof d1Val === 'string' && !d2Val || typeof d2Val === 'string' && !d1Val) {
|
|
97
|
+
var sortResult = (d1Val || '').localeCompare(d2Val || '', undefined, {
|
|
98
98
|
sensitivity: 'base'
|
|
99
99
|
});
|
|
100
100
|
return sortAsc ? sortResult : -sortResult;
|
|
@@ -129,7 +129,10 @@ export interface DataTableProps<TRowType = any> {
|
|
|
129
129
|
|
|
130
130
|
export interface DataTableExtendedProps<TRowType = any>
|
|
131
131
|
extends DataTableProps<TRowType>,
|
|
132
|
-
Omit<
|
|
132
|
+
Omit<
|
|
133
|
+
JSX.IntrinsicElements['table'],
|
|
134
|
+
'onSelect' | 'placeholder' | 'border'
|
|
135
|
+
> {}
|
|
133
136
|
|
|
134
137
|
declare class DataTable<TRowType = any> extends React.Component<
|
|
135
138
|
DataTableExtendedProps<TRowType>
|
|
@@ -29,7 +29,9 @@ var columns = [{
|
|
|
29
29
|
}
|
|
30
30
|
}, (_datum$failures = datum.failures) == null ? void 0 : _datum$failures.map(function (_ref) {
|
|
31
31
|
var reason = _ref.reason;
|
|
32
|
-
return /*#__PURE__*/React.createElement(Text,
|
|
32
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
33
|
+
key: reason
|
|
34
|
+
}, reason);
|
|
33
35
|
}));
|
|
34
36
|
return /*#__PURE__*/React.createElement(Tip, {
|
|
35
37
|
plain: true,
|
|
@@ -16,7 +16,9 @@ var columns = [{
|
|
|
16
16
|
header: 'Rocket',
|
|
17
17
|
size: 'small',
|
|
18
18
|
render: function render(datum) {
|
|
19
|
-
return /*#__PURE__*/React.createElement(Text,
|
|
19
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
20
|
+
key: datum.rocket.name
|
|
21
|
+
}, datum.rocket.name);
|
|
20
22
|
}
|
|
21
23
|
}, {
|
|
22
24
|
property: 'success',
|
|
@@ -32,7 +34,9 @@ var columns = [{
|
|
|
32
34
|
}
|
|
33
35
|
}, (_datum$failures = datum.failures) == null ? void 0 : _datum$failures.map(function (_ref) {
|
|
34
36
|
var reason = _ref.reason;
|
|
35
|
-
return /*#__PURE__*/React.createElement(Text,
|
|
37
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
38
|
+
key: reason
|
|
39
|
+
}, reason);
|
|
36
40
|
}));
|
|
37
41
|
return /*#__PURE__*/React.createElement(Tip, {
|
|
38
42
|
plain: true,
|
|
@@ -20,9 +20,34 @@ import { FormContext } from '../Form';
|
|
|
20
20
|
import { Keyboard } from '../Keyboard';
|
|
21
21
|
import { MaskedInput } from '../MaskedInput';
|
|
22
22
|
import { useForwardedRef } from '../../utils';
|
|
23
|
-
import { getTimestamp, normalizeForTimezone } from '../Calendar/utils';
|
|
24
23
|
import { formatToSchema, schemaToMask, valuesAreEqual, valueToText, textToValue } from './utils';
|
|
25
24
|
import { DateInputPropTypes } from './propTypes';
|
|
25
|
+
import { getOutputFormat } from '../Calendar/Calendar';
|
|
26
|
+
|
|
27
|
+
var getReference = function getReference(value) {
|
|
28
|
+
var adjustedDate;
|
|
29
|
+
var res;
|
|
30
|
+
if (typeof value === 'string') res = value;else if (Array.isArray(value) && Array.isArray(value[0])) res = value[0].find(function (date) {
|
|
31
|
+
return date;
|
|
32
|
+
});else if (Array.isArray(value) && value.length) {
|
|
33
|
+
res = value[0];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (res) {
|
|
37
|
+
var _res;
|
|
38
|
+
|
|
39
|
+
adjustedDate = new Date(res); // if time is not specified in ISOstring, normalize to midnight
|
|
40
|
+
|
|
41
|
+
if (((_res = res) == null ? void 0 : _res.indexOf('T')) === -1) {
|
|
42
|
+
var offset = adjustedDate.getTimezoneOffset();
|
|
43
|
+
var hour = adjustedDate.getHours();
|
|
44
|
+
adjustedDate.setHours(hour, offset);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return adjustedDate;
|
|
49
|
+
};
|
|
50
|
+
|
|
26
51
|
var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
27
52
|
var buttonProps = _ref.buttonProps,
|
|
28
53
|
calendarProps = _ref.calendarProps,
|
|
@@ -67,25 +92,24 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
67
92
|
value = _useFormInput[0],
|
|
68
93
|
setValue = _useFormInput[1];
|
|
69
94
|
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (Array.isArray(value) && value.length) return getTimestamp(value[0]); // check to see if value is not an empty string
|
|
74
|
-
// empty string should behave like undefined
|
|
95
|
+
var _useState = useState(getOutputFormat(value)),
|
|
96
|
+
outputFormat = _useState[0],
|
|
97
|
+
setOutputFormat = _useState[1];
|
|
75
98
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// will just rely on the UTC timestamp and don't need to normalize.
|
|
99
|
+
useEffect(function () {
|
|
100
|
+
setOutputFormat(function (previousFormat) {
|
|
101
|
+
var nextFormat = getOutputFormat(value); // when user types, date could become something like 07//2020
|
|
102
|
+
// and value becomes undefined. don't lose the format from the
|
|
103
|
+
// previous valid date
|
|
82
104
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
105
|
+
return previousFormat !== nextFormat ? previousFormat : nextFormat;
|
|
106
|
+
});
|
|
107
|
+
}, [value]); // keep track of timestamp from original date(s)
|
|
86
108
|
|
|
109
|
+
var _useState2 = useState(getReference(value)),
|
|
110
|
+
reference = _useState2[0],
|
|
111
|
+
setReference = _useState2[1]; // do we expect multiple dates?
|
|
87
112
|
|
|
88
|
-
var normalizedDate = normalizeForTimezone(value, timestamp, normalize); // do we expect multiple dates?
|
|
89
113
|
|
|
90
114
|
var range = Array.isArray(value) || format && format.includes('-'); // parse format and build a formal schema we can use elsewhere
|
|
91
115
|
|
|
@@ -97,9 +121,9 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
97
121
|
return schemaToMask(schema);
|
|
98
122
|
}, [schema]); // textValue is only used when a format is provided
|
|
99
123
|
|
|
100
|
-
var
|
|
101
|
-
textValue =
|
|
102
|
-
setTextValue =
|
|
124
|
+
var _useState3 = useState(schema ? valueToText(value, schema) : undefined),
|
|
125
|
+
textValue = _useState3[0],
|
|
126
|
+
setTextValue = _useState3[1]; // Setting the icon through `inputProps` is deprecated.
|
|
103
127
|
// The `icon` prop should be used instead.
|
|
104
128
|
|
|
105
129
|
|
|
@@ -124,17 +148,17 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
124
148
|
|
|
125
149
|
useEffect(function () {
|
|
126
150
|
if (schema && value !== undefined) {
|
|
127
|
-
var nextTextValue = valueToText(
|
|
151
|
+
var nextTextValue = valueToText(value, schema);
|
|
128
152
|
|
|
129
|
-
if (!valuesAreEqual(textToValue(textValue, schema, range,
|
|
153
|
+
if (!valuesAreEqual(textToValue(textValue, schema, range, reference), textToValue(nextTextValue, schema, range, reference)) || textValue === '' && nextTextValue !== '') {
|
|
130
154
|
setTextValue(nextTextValue);
|
|
131
155
|
}
|
|
132
156
|
}
|
|
133
|
-
}, [range, schema, textValue,
|
|
157
|
+
}, [range, schema, textValue, reference, value]); // when format and not inline, whether to show the Calendar in a Drop
|
|
134
158
|
|
|
135
|
-
var
|
|
136
|
-
open =
|
|
137
|
-
setOpen =
|
|
159
|
+
var _useState4 = useState(),
|
|
160
|
+
open = _useState4[0],
|
|
161
|
+
setOpen = _useState4[1];
|
|
138
162
|
|
|
139
163
|
var openCalendar = useCallback(function () {
|
|
140
164
|
setOpen(true);
|
|
@@ -154,33 +178,23 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
154
178
|
ref: inline ? ref : undefined,
|
|
155
179
|
id: inline && !format ? id : undefined,
|
|
156
180
|
range: range,
|
|
157
|
-
date: range ? undefined :
|
|
181
|
+
date: range ? undefined : value // when caller initializes with empty array, dates should be undefined
|
|
158
182
|
// allowing the user to select both begin and end of the range
|
|
159
183
|
,
|
|
160
|
-
dates: range && value.length ? [
|
|
184
|
+
dates: range && value.length ? [value] : undefined // places focus on days grid when Calendar opens
|
|
161
185
|
,
|
|
162
186
|
initialFocus: open ? 'days' : undefined,
|
|
163
|
-
normalize: normalize,
|
|
164
187
|
onSelect: disabled ? undefined : function (nextValue) {
|
|
165
188
|
var normalizedValue;
|
|
166
189
|
|
|
167
190
|
if (range && Array.isArray(nextValue)) {
|
|
168
191
|
normalizedValue = nextValue[0];
|
|
169
192
|
} // clicking an edge date removes it
|
|
170
|
-
else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
171
|
-
// been passed in, indicating that we should stay local if the
|
|
172
|
-
// user first picks a date via the Calendar.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var nextNormalize = normalize;
|
|
193
|
+
else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
|
|
176
194
|
|
|
177
|
-
if (
|
|
178
|
-
nextNormalize = false;
|
|
179
|
-
setNormalize(nextNormalize);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (schema) setTextValue(valueToText(normalizeForTimezone(normalizedValue, undefined, nextNormalize), schema));
|
|
195
|
+
if (schema) setTextValue(valueToText(normalizedValue, schema));
|
|
183
196
|
setValue(normalizedValue);
|
|
197
|
+
setReference(getReference(nextValue));
|
|
184
198
|
if (_onChange) _onChange({
|
|
185
199
|
value: normalizedValue
|
|
186
200
|
});
|
|
@@ -192,9 +206,7 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
192
206
|
}, 1);
|
|
193
207
|
}
|
|
194
208
|
}
|
|
195
|
-
},
|
|
196
|
-
timestamp: timestamp
|
|
197
|
-
})));
|
|
209
|
+
}, calendarProps));
|
|
198
210
|
var formContextValue = useMemo(function () {
|
|
199
211
|
return {
|
|
200
212
|
useFormInput: function useFormInput(_ref3) {
|
|
@@ -263,27 +275,8 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
263
275
|
onChange: function onChange(event) {
|
|
264
276
|
var nextTextValue = event.target.value;
|
|
265
277
|
setTextValue(nextTextValue);
|
|
266
|
-
var
|
|
267
|
-
//
|
|
268
|
-
|
|
269
|
-
if (timestamp === undefined && Date.parse(nextTextValue)) {
|
|
270
|
-
var _Date$toISOString$spl = new Date(nextTextValue).toISOString().split('T');
|
|
271
|
-
|
|
272
|
-
localTimestamp = _Date$toISOString$spl[1];
|
|
273
|
-
} // timestamp will be undefined if no defaultValue or value have
|
|
274
|
-
// been passed in, indicating that we should stay local
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var nextNormalize = normalize;
|
|
278
|
-
|
|
279
|
-
if (timestamp === undefined) {
|
|
280
|
-
nextNormalize = false;
|
|
281
|
-
setNormalize(nextNormalize);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
var nextValue = textToValue(nextTextValue, schema, range, timestamp || localTimestamp, nextNormalize); // reset to original state
|
|
285
|
-
|
|
286
|
-
if (nextValue === undefined) setNormalize(true); // update value even when undefined
|
|
278
|
+
var nextValue = textToValue(nextTextValue, schema, range, reference, outputFormat);
|
|
279
|
+
if (nextValue !== undefined) setReference(getReference(nextValue)); // update value even when undefined
|
|
287
280
|
|
|
288
281
|
setValue(nextValue);
|
|
289
282
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
2
|
+
|
|
3
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
4
|
+
|
|
5
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
6
|
+
|
|
1
7
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
8
|
|
|
3
|
-
// Converting between Date and String types is handled via a "schema".
|
|
9
|
+
import { handleOffset } from '../Calendar/utils'; // Converting between Date and String types is handled via a "schema".
|
|
4
10
|
// The schema is an array of strings, split into strings with identical
|
|
5
11
|
// characters. So, 'mm/dd/yyyy' will be ['mm', '/', 'dd', '/', 'yyyyy'].
|
|
6
|
-
|
|
12
|
+
|
|
7
13
|
export var formatToSchema = function formatToSchema(format) {
|
|
8
14
|
if (!format) return undefined;
|
|
9
15
|
var result = [];
|
|
@@ -70,7 +76,16 @@ export var valueToText = function valueToText(value, schema) {
|
|
|
70
76
|
|
|
71
77
|
if (!value || Array.isArray(value) && !value.length) return text;
|
|
72
78
|
var dates = (Array.isArray(value) ? value : [value]).map(function (v) {
|
|
73
|
-
|
|
79
|
+
// TO DO should we extract this to a reusable function?
|
|
80
|
+
var adjustedDate = new Date(v); // if time is not specified in ISOstring, normalize to midnight
|
|
81
|
+
|
|
82
|
+
if (v.indexOf('T') === -1) {
|
|
83
|
+
var offset = adjustedDate.getTimezoneOffset();
|
|
84
|
+
var hour = adjustedDate.getHours();
|
|
85
|
+
adjustedDate.setHours(hour, offset);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return adjustedDate;
|
|
74
89
|
});
|
|
75
90
|
var dateIndex = 0;
|
|
76
91
|
var parts = {};
|
|
@@ -126,7 +141,7 @@ var pullDigits = function pullDigits(text, index) {
|
|
|
126
141
|
return text.slice(index, end);
|
|
127
142
|
};
|
|
128
143
|
|
|
129
|
-
export var textToValue = function textToValue(text, schema, range,
|
|
144
|
+
export var textToValue = function textToValue(text, schema, range, reference, outputFormat) {
|
|
130
145
|
if (!text) return range ? [] : undefined;
|
|
131
146
|
var result;
|
|
132
147
|
|
|
@@ -134,10 +149,17 @@ export var textToValue = function textToValue(text, schema, range, timestamp, no
|
|
|
134
149
|
var leapYear = parts.y % 4 === 0 && parts.y % 100 !== 0 || parts.y % 400 === 0; // Do a little sanity checking on the parts first.
|
|
135
150
|
// If not valid, leave as is.
|
|
136
151
|
|
|
137
|
-
if (!parts.m || !parts.d || !parts.y || parts.y.length < 4 || parts.m.length > 2 || parts.d.length > 2 || parts.m > 12 || parts.d > 31 || (parts.m === "02" || parts.m === "2") && parts.d > (leapYear ? 29 : 28)) return parts;
|
|
138
|
-
|
|
152
|
+
if (!parts.m || !parts.d || !parts.y || parts.y.length < 4 || parts.m.length > 2 || parts.d.length > 2 || parts.m > 12 || parts.d > 31 || (parts.m === "02" || parts.m === "2") && parts.d > (leapYear ? 29 : 28)) return parts; // use time info from reference date
|
|
153
|
+
|
|
154
|
+
var time = reference ? [reference.getHours(), reference.getMinutes(), reference.getSeconds(), reference.getMilliseconds()] : null;
|
|
155
|
+
|
|
156
|
+
var date = _construct(Date, [parts.y, parts.m - 1, parts.d].concat(time)).toISOString();
|
|
139
157
|
|
|
140
|
-
if (
|
|
158
|
+
if (date && outputFormat === 'no timezone') {
|
|
159
|
+
var _handleOffset$toISOSt = handleOffset(date).toISOString().split('T');
|
|
160
|
+
|
|
161
|
+
date = _handleOffset$toISOSt[0];
|
|
162
|
+
}
|
|
141
163
|
|
|
142
164
|
if (!range) {
|
|
143
165
|
if (!result) result = date;
|
|
@@ -42,7 +42,7 @@ var formatBytes = function formatBytes(size) {
|
|
|
42
42
|
var ContentsBox = styled(Box).withConfig({
|
|
43
43
|
displayName: "FileInput__ContentsBox",
|
|
44
44
|
componentId: "sc-1jzq7im-0"
|
|
45
|
-
})(["position:relative;", " ", ";", ";", ";"], function (props) {
|
|
45
|
+
})(["cursor:pointer;position:relative;", " ", ";", ";", ";"], function (props) {
|
|
46
46
|
return props.disabled && disabledStyle();
|
|
47
47
|
}, function (props) {
|
|
48
48
|
return props.theme.fileInput && props.theme.fileInput.extend;
|
|
@@ -292,6 +292,7 @@ var FileInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
292
292
|
justify: "between"
|
|
293
293
|
}, files.length <= aggregateThreshold && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Message, theme.fileInput.message, message), /*#__PURE__*/React.createElement(Keyboard, {
|
|
294
294
|
onSpace: function onSpace(event) {
|
|
295
|
+
event.preventDefault();
|
|
295
296
|
if (controlRef.current === event.target) inputRef.current.click();
|
|
296
297
|
},
|
|
297
298
|
onEnter: function onEnter(event) {
|
|
@@ -4,7 +4,7 @@ import { defaultProps } from '../../default-props';
|
|
|
4
4
|
var StyledFileInput = styled.input.withConfig({
|
|
5
5
|
displayName: "StyledFileInput",
|
|
6
6
|
componentId: "sc-rl7ywv-0"
|
|
7
|
-
})(["position:absolute;height:100%;width:100%;", " opacity:0;border:none;", " ", " &::-moz-focus-inner{border:none;outline:none;}"], inputStyle, function (props) {
|
|
7
|
+
})(["position:absolute;height:100%;width:100%;", " font-size:0;opacity:0;border:none;", " ", " &::-moz-focus-inner{border:none;outline:none;}&::-webkit-file-upload-button{cursor:pointer;}"], inputStyle, function (props) {
|
|
8
8
|
return !props.disabled && 'cursor: pointer;';
|
|
9
9
|
}, function (props) {
|
|
10
10
|
return props.rightOffset && "\n width: calc(100% - " + props.rightOffset + "px);\n right: " + props.rightOffset + "px;\n ";
|
|
@@ -5,7 +5,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
5
5
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
6
6
|
|
|
7
7
|
import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import { useAnalytics } from '../../contexts';
|
|
8
9
|
import { MessageContext } from '../../contexts/MessageContext';
|
|
10
|
+
import { useForwardedRef } from '../../utils';
|
|
9
11
|
import { FormContext } from './FormContext';
|
|
10
12
|
import { FormPropTypes } from './propTypes';
|
|
11
13
|
var defaultValue = {};
|
|
@@ -182,6 +184,8 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
182
184
|
valueProp = _ref2.value,
|
|
183
185
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
184
186
|
|
|
187
|
+
var formRef = useForwardedRef(ref);
|
|
188
|
+
|
|
185
189
|
var _useContext = useContext(MessageContext),
|
|
186
190
|
format = _useContext.format;
|
|
187
191
|
|
|
@@ -225,6 +229,11 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
225
229
|
|
|
226
230
|
var validationRulesRef = useRef({});
|
|
227
231
|
var requiredFields = useRef([]);
|
|
232
|
+
var analyticsRef = useRef({
|
|
233
|
+
start: new Date(),
|
|
234
|
+
errors: {}
|
|
235
|
+
});
|
|
236
|
+
var sendAnalytics = useAnalytics();
|
|
228
237
|
var buildValid = useCallback(function (nextErrors) {
|
|
229
238
|
var valid = false;
|
|
230
239
|
valid = requiredFields.current.filter(function (n) {
|
|
@@ -247,6 +256,19 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
247
256
|
});
|
|
248
257
|
};
|
|
249
258
|
|
|
259
|
+
var updateAnalytics = function updateAnalytics() {
|
|
260
|
+
var _validationResultsRef;
|
|
261
|
+
|
|
262
|
+
var errorFields = Object.keys((_validationResultsRef = validationResultsRef.current) == null ? void 0 : _validationResultsRef.errors);
|
|
263
|
+
var errorCounts = analyticsRef.current.errors;
|
|
264
|
+
|
|
265
|
+
if (errorFields.length > 0) {
|
|
266
|
+
errorFields.forEach(function (key) {
|
|
267
|
+
errorCounts[key] = (errorCounts[key] || 0) + 1;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
250
272
|
var applyValidationRules = useCallback(function (validationRules) {
|
|
251
273
|
var _validateForm = validateForm(validationRules, value, format, messages),
|
|
252
274
|
validatedErrors = _validateForm[0],
|
|
@@ -271,6 +293,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
271
293
|
valid: buildValid(nextErrors)
|
|
272
294
|
}));
|
|
273
295
|
validationResultsRef.current = nextValidationResults;
|
|
296
|
+
updateAnalytics();
|
|
274
297
|
return nextValidationResults;
|
|
275
298
|
});
|
|
276
299
|
}, [buildValid, format, messages, onValidate, value]); // Validate all fields holding values onMount if set to
|
|
@@ -318,17 +341,38 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
318
341
|
// as the user fixes them (basically act like validate=change for that)
|
|
319
342
|
|
|
320
343
|
useEffect(function () {
|
|
321
|
-
var
|
|
344
|
+
var _validationResultsRef2;
|
|
322
345
|
|
|
323
346
|
var validationRules = Object.entries(validationRulesRef.current);
|
|
324
347
|
|
|
325
|
-
if ((
|
|
348
|
+
if ((_validationResultsRef2 = validationResultsRef.current) != null && _validationResultsRef2.errors && Object.keys(validationResultsRef.current.errors).length > 0) {
|
|
326
349
|
applyValidationRules(validationRules.filter(function (_ref6) {
|
|
327
350
|
var n = _ref6[0];
|
|
328
351
|
return touched[n] && validationResultsRef.current.errors[n];
|
|
329
352
|
}));
|
|
330
353
|
}
|
|
331
|
-
}, [applyValidationRules, touched]);
|
|
354
|
+
}, [applyValidationRules, touched]);
|
|
355
|
+
useEffect(function () {
|
|
356
|
+
var element = formRef.current;
|
|
357
|
+
analyticsRef.current = {
|
|
358
|
+
start: new Date(),
|
|
359
|
+
errors: {}
|
|
360
|
+
};
|
|
361
|
+
sendAnalytics({
|
|
362
|
+
type: 'formOpen',
|
|
363
|
+
element: element
|
|
364
|
+
});
|
|
365
|
+
return function () {
|
|
366
|
+
if (!analyticsRef.current.submitted) {
|
|
367
|
+
sendAnalytics({
|
|
368
|
+
type: 'formClose',
|
|
369
|
+
element: element,
|
|
370
|
+
errors: analyticsRef.current.errors,
|
|
371
|
+
elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}, [sendAnalytics, formRef]); // There are three basic patterns of handling form input value state:
|
|
332
376
|
//
|
|
333
377
|
// 1 - form controlled
|
|
334
378
|
//
|
|
@@ -486,7 +530,12 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
486
530
|
|
|
487
531
|
validationRulesRef.current[name].field = validateName(validateArg, required);
|
|
488
532
|
return function () {
|
|
489
|
-
|
|
533
|
+
delete validationRulesRef.current[name].field;
|
|
534
|
+
var requiredFieldIndex = requiredFields.current.indexOf(name);
|
|
535
|
+
|
|
536
|
+
if (requiredFieldIndex !== -1) {
|
|
537
|
+
requiredFields.current.splice(requiredFieldIndex, 1);
|
|
538
|
+
}
|
|
490
539
|
};
|
|
491
540
|
}
|
|
492
541
|
|
|
@@ -511,9 +560,16 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
511
560
|
};
|
|
512
561
|
}, [onChange, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp]);
|
|
513
562
|
return /*#__PURE__*/React.createElement("form", _extends({
|
|
514
|
-
ref:
|
|
563
|
+
ref: formRef
|
|
515
564
|
}, rest, {
|
|
516
565
|
onReset: function onReset(event) {
|
|
566
|
+
sendAnalytics({
|
|
567
|
+
type: 'formReset',
|
|
568
|
+
element: formRef.current,
|
|
569
|
+
data: event,
|
|
570
|
+
errors: analyticsRef.current.errors,
|
|
571
|
+
elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
|
|
572
|
+
});
|
|
517
573
|
setPendingValidation(undefined);
|
|
518
574
|
|
|
519
575
|
if (!valueProp) {
|
|
@@ -525,6 +581,10 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
525
581
|
|
|
526
582
|
setTouched(defaultTouched);
|
|
527
583
|
setValidationResults(defaultValidationResults);
|
|
584
|
+
analyticsRef.current = {
|
|
585
|
+
start: new Date(),
|
|
586
|
+
errors: {}
|
|
587
|
+
};
|
|
528
588
|
|
|
529
589
|
if (_onReset) {
|
|
530
590
|
event.persist(); // extract from React's synthetic event pool
|
|
@@ -555,6 +615,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
555
615
|
};
|
|
556
616
|
if (onValidate) onValidate(nextValidationResults);
|
|
557
617
|
validationResultsRef.current = nextValidationResults;
|
|
618
|
+
updateAnalytics();
|
|
558
619
|
return nextValidationResults;
|
|
559
620
|
});
|
|
560
621
|
|
|
@@ -566,6 +627,16 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
566
627
|
adjustedEvent.touched = touched;
|
|
567
628
|
|
|
568
629
|
_onSubmit(adjustedEvent);
|
|
630
|
+
|
|
631
|
+
sendAnalytics({
|
|
632
|
+
type: 'formSubmit',
|
|
633
|
+
element: formRef.current,
|
|
634
|
+
data: adjustedEvent,
|
|
635
|
+
errors: analyticsRef.current.errors,
|
|
636
|
+
elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
|
|
637
|
+
});
|
|
638
|
+
analyticsRef.current.errors = {};
|
|
639
|
+
analyticsRef.current.submitted = true;
|
|
569
640
|
}
|
|
570
641
|
}
|
|
571
642
|
}), /*#__PURE__*/React.createElement(FormContext.Provider, {
|