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.
Files changed (123) hide show
  1. package/components/Anchor/Anchor.js +14 -1
  2. package/components/Button/Button.js +81 -8
  3. package/components/Button/StyledButtonKind.js +9 -3
  4. package/components/Button/index.d.ts +1 -1
  5. package/components/Button/propTypes.js +1 -1
  6. package/components/Calendar/Calendar.js +232 -292
  7. package/components/Calendar/utils.js +16 -129
  8. package/components/Chart/calcs.js +44 -27
  9. package/components/Chart/stories/Scan.js +11 -9
  10. package/components/Chart/stories/data.js +16 -17
  11. package/components/CheckBox/CheckBox.js +3 -2
  12. package/components/DataChart/DataChart.js +14 -28
  13. package/components/DataChart/Detail.js +18 -11
  14. package/components/DataChart/XAxis.js +29 -18
  15. package/components/DataChart/stories/Pad.js +54 -0
  16. package/components/DataTable/DataTable.js +13 -9
  17. package/components/DataTable/buildState.js +2 -2
  18. package/components/DataTable/index.d.ts +4 -1
  19. package/components/DataTable/stories/SpaceX.js +3 -1
  20. package/components/DataTable/stories/SpaceXUngrouped.js +6 -2
  21. package/components/DateInput/DateInput.js +60 -68
  22. package/components/DateInput/utils.js +30 -5
  23. package/components/FileInput/FileInput.js +2 -1
  24. package/components/FileInput/StyledFileInput.js +1 -1
  25. package/components/Form/Form.js +78 -5
  26. package/components/FormField/FormField.js +29 -29
  27. package/components/Grommet/Grommet.js +7 -2
  28. package/components/Grommet/index.d.ts +1 -0
  29. package/components/Grommet/propTypes.js +2 -1
  30. package/components/Heading/Heading.js +4 -2
  31. package/components/Heading/StyledHeading.js +1 -1
  32. package/components/Heading/index.d.ts +1 -0
  33. package/components/Heading/propTypes.js +2 -1
  34. package/components/Image/Image.js +4 -2
  35. package/components/Layer/LayerContainer.js +25 -0
  36. package/components/List/List.js +17 -0
  37. package/components/Menu/Menu.js +7 -4
  38. package/components/Menu/index.d.ts +2 -2
  39. package/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
  40. package/components/Meter/Circle.js +5 -1
  41. package/components/PageHeader/PageHeader.js +22 -13
  42. package/components/PageHeader/index.d.ts +10 -1
  43. package/components/PageHeader/propTypes.js +1 -0
  44. package/components/PageHeader/stories/Size.js +55 -0
  45. package/components/Select/SelectContainer.js +96 -75
  46. package/components/Select/stories/Clear.js +7 -1
  47. package/components/Select/utils.js +1 -0
  48. package/components/Spinner/Spinner.js +1 -0
  49. package/components/Tab/Tab.js +1 -1
  50. package/components/Tabs/Tabs.js +11 -2
  51. package/components/Video/StyledVideo.js +2 -2
  52. package/contexts/AnalyticsContext/AnalyticsContext.js +65 -0
  53. package/contexts/AnalyticsContext/index.d.ts +7 -0
  54. package/contexts/AnalyticsContext/index.js +11 -0
  55. package/contexts/index.js +8 -0
  56. package/es6/components/Anchor/Anchor.js +15 -3
  57. package/es6/components/Button/Button.js +83 -11
  58. package/es6/components/Button/StyledButtonKind.js +9 -3
  59. package/es6/components/Button/index.d.ts +1 -1
  60. package/es6/components/Button/propTypes.js +1 -1
  61. package/es6/components/Calendar/Calendar.js +230 -292
  62. package/es6/components/Calendar/utils.js +13 -114
  63. package/es6/components/Chart/calcs.js +44 -27
  64. package/es6/components/Chart/stories/Scan.js +10 -9
  65. package/es6/components/Chart/stories/data.js +16 -17
  66. package/es6/components/CheckBox/CheckBox.js +3 -2
  67. package/es6/components/DataChart/DataChart.js +15 -28
  68. package/es6/components/DataChart/Detail.js +20 -10
  69. package/es6/components/DataChart/XAxis.js +29 -19
  70. package/es6/components/DataChart/stories/Pad.js +42 -0
  71. package/es6/components/DataTable/DataTable.js +13 -9
  72. package/es6/components/DataTable/buildState.js +2 -2
  73. package/es6/components/DataTable/index.d.ts +4 -1
  74. package/es6/components/DataTable/stories/SpaceX.js +3 -1
  75. package/es6/components/DataTable/stories/SpaceXUngrouped.js +6 -2
  76. package/es6/components/DateInput/DateInput.js +57 -64
  77. package/es6/components/DateInput/utils.js +29 -7
  78. package/es6/components/FileInput/FileInput.js +2 -1
  79. package/es6/components/FileInput/StyledFileInput.js +1 -1
  80. package/es6/components/Form/Form.js +76 -5
  81. package/es6/components/FormField/FormField.js +29 -30
  82. package/es6/components/Grommet/Grommet.js +6 -2
  83. package/es6/components/Grommet/index.d.ts +1 -0
  84. package/es6/components/Grommet/propTypes.js +2 -1
  85. package/es6/components/Heading/Heading.js +4 -2
  86. package/es6/components/Heading/StyledHeading.js +1 -1
  87. package/es6/components/Heading/index.d.ts +1 -0
  88. package/es6/components/Heading/propTypes.js +2 -1
  89. package/es6/components/Image/Image.js +4 -2
  90. package/es6/components/Layer/LayerContainer.js +24 -0
  91. package/es6/components/List/List.js +16 -0
  92. package/es6/components/Menu/Menu.js +7 -4
  93. package/es6/components/Menu/index.d.ts +2 -2
  94. package/es6/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
  95. package/es6/components/Meter/Circle.js +5 -1
  96. package/es6/components/PageHeader/PageHeader.js +24 -14
  97. package/es6/components/PageHeader/index.d.ts +10 -1
  98. package/es6/components/PageHeader/propTypes.js +1 -0
  99. package/es6/components/PageHeader/stories/Size.js +43 -0
  100. package/es6/components/Select/SelectContainer.js +96 -77
  101. package/es6/components/Select/stories/Clear.js +7 -1
  102. package/es6/components/Select/utils.js +1 -0
  103. package/es6/components/Spinner/Spinner.js +1 -0
  104. package/es6/components/Tab/Tab.js +1 -1
  105. package/es6/components/Tabs/Tabs.js +10 -2
  106. package/es6/components/Video/StyledVideo.js +2 -2
  107. package/es6/contexts/AnalyticsContext/AnalyticsContext.js +47 -0
  108. package/es6/contexts/AnalyticsContext/index.d.ts +7 -0
  109. package/es6/contexts/AnalyticsContext/index.js +1 -0
  110. package/es6/contexts/index.js +1 -0
  111. package/es6/themes/base.d.ts +51 -33
  112. package/es6/themes/base.js +49 -1
  113. package/es6/utils/DOM.js +4 -0
  114. package/es6/utils/mixins.js +3 -0
  115. package/grommet.min.js +1 -1
  116. package/grommet.min.js.map +1 -1
  117. package/package.json +56 -48
  118. package/themes/base.d.ts +51 -33
  119. package/themes/base.js +49 -1
  120. package/tools/pack.js +20 -13
  121. package/tools/release-stable.js +2 -4
  122. package/utils/DOM.js +9 -2
  123. package/utils/mixins.js +7 -1
@@ -5,9 +5,11 @@ exports.XAxis = void 0;
5
5
 
6
6
  var _react = _interopRequireWildcard(require("react"));
7
7
 
8
+ var _utils = require("../../utils");
9
+
8
10
  var _Box = require("../Box");
9
11
 
10
- var _excluded = ["values", "pad", "renderValue", "serie"];
12
+ var _excluded = ["values", "pad", "renderValue", "serie", "theme", "thickness"];
11
13
 
12
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
15
 
@@ -19,40 +21,49 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
19
21
 
20
22
  var XAxis = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
21
23
  var values = _ref.values,
22
- pad = _ref.pad,
24
+ padProp = _ref.pad,
23
25
  renderValue = _ref.renderValue,
24
26
  serie = _ref.serie,
27
+ theme = _ref.theme,
28
+ thickness = _ref.thickness,
25
29
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
26
30
 
27
- // When there are only labels at the end of the axis, let them take as much
28
- // space as they like. If there are more, align their container to the
31
+ // pad to the edge of the thickness, for when padding is more than half
32
+ // the thickness
33
+ var pad = (0, _react.useMemo)(function () {
34
+ return {
35
+ start: (0, _utils.edgeToNum)(padProp.start || padProp.horizontal, theme) - (0, _utils.edgeToNum)(thickness, theme) / 2 + "px",
36
+ end: (0, _utils.edgeToNum)(padProp.end || padProp.horizontal, theme) - (0, _utils.edgeToNum)(thickness, theme) / 2 + "px"
37
+ };
38
+ }, [padProp, theme, thickness]); // When there are only labels at the end of the axis and there isn't
39
+ // much space for them, let them take as much space as they like
40
+ // flowing in from the edges.
41
+ // Otherwise, align their container to the
29
42
  // data/guide lines and then let their content overflow that.
30
- var itemProps = values.length === 2 ? {} : {
31
- width: '1px',
32
- overflow: 'visible',
33
- align: 'center'
34
- };
35
- var horizontal = pad.horizontal,
36
- start = pad.start,
37
- end = pad.end; // ignore vertical parts
38
43
 
44
+ var labelContainerProps = (0, _react.useMemo)(function () {
45
+ // 24px was chosen empirically as 48px is enough to show some simple text
46
+ var centered = values.length !== 2 || (0, _utils.edgeToNum)(padProp.start || padProp.horizontal, theme) >= 24;
47
+ if (centered) return {
48
+ width: thickness,
49
+ overflow: 'visible',
50
+ align: 'center'
51
+ };
52
+ return {};
53
+ }, [padProp, theme, thickness, values]);
39
54
  return /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({
40
55
  ref: ref,
41
56
  gridArea: "xAxis",
42
57
  direction: "row",
43
58
  justify: "between",
44
- pad: {
45
- horizontal: horizontal,
46
- start: start,
47
- end: end
48
- }
59
+ pad: pad
49
60
  }, rest), values.map(function (dataIndex, i) {
50
61
  return (
51
62
  /*#__PURE__*/
52
63
  // eslint-disable-next-line react/no-array-index-key
53
64
  _react["default"].createElement(_Box.Box, _extends({
54
65
  key: i
55
- }, itemProps), serie ? renderValue(serie, dataIndex) : dataIndex)
66
+ }, labelContainerProps), serie ? renderValue(serie, dataIndex) : dataIndex)
56
67
  );
57
68
  }));
58
69
  });
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports["default"] = exports.Pad = void 0;
5
+
6
+ var _react = _interopRequireDefault(require("react"));
7
+
8
+ var _grommet = require("grommet");
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ var data = [];
13
+
14
+ for (var i = 1; i < 3; i += 1) {
15
+ var v = Math.sin(i / 2.0);
16
+ data.push({
17
+ percent: Math.abs(v * 100)
18
+ });
19
+ }
20
+
21
+ var Pad = function Pad() {
22
+ return (
23
+ /*#__PURE__*/
24
+ // Uncomment <Grommet> lines when using outside of storybook
25
+ // <Grommet theme={grommet}>
26
+ _react["default"].createElement(_grommet.Box, {
27
+ align: "center",
28
+ justify: "start",
29
+ pad: "large"
30
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.DataChart, {
31
+ bounds: {
32
+ y: [0, 100]
33
+ },
34
+ guide: true,
35
+ detail: true,
36
+ pad: {
37
+ horizontal: 'xlarge'
38
+ },
39
+ data: data,
40
+ series: ['percent', {}],
41
+ chart: [{
42
+ property: 'percent',
43
+ thickness: 'medium'
44
+ }]
45
+ })) // </Grommet>
46
+
47
+ );
48
+ };
49
+
50
+ exports.Pad = Pad;
51
+ var _default = {
52
+ title: 'Visualizations/DataChart/Pad'
53
+ };
54
+ exports["default"] = _default;
@@ -135,11 +135,14 @@ var DataTable = function DataTable(_ref) {
135
135
 
136
136
  var _useState5 = (0, _react.useState)(sortProp || {}),
137
137
  sort = _useState5[0],
138
- setSort = _useState5[1]; // the data filtered and sorted, if needed
138
+ setSort = _useState5[1];
139
+
140
+ (0, _react.useEffect)(function () {
141
+ if (sortProp) setSort(sortProp);
142
+ }, [sortProp]); // the data filtered and sorted, if needed
139
143
  // Note: onUpdate mode expects the data to be passed
140
144
  // in completely filtered and sorted already.
141
145
 
142
-
143
146
  var adjustedData = (0, _react.useMemo)(function () {
144
147
  return onUpdate ? data : (0, _buildState.filterAndSortData)(data, filters, onSearch, sort);
145
148
  }, [data, filters, onSearch, onUpdate, sort]); // the values to put in the footer cells
@@ -393,6 +396,7 @@ var DataTable = function DataTable(_ref) {
393
396
  items = _usePagination[0],
394
397
  paginationProps = _usePagination[1];
395
398
 
399
+ var paginationStep = paginationProps.step;
396
400
  var Container = paginate ? _StyledDataTable.StyledContainer : _react.Fragment;
397
401
  var containterProps = paginate ? _extends({}, theme.dataTable.container, {
398
402
  fill: fill
@@ -446,13 +450,13 @@ var DataTable = function DataTable(_ref) {
446
450
  expanded: Object.keys(groupState).filter(function (k) {
447
451
  return groupState[k].expanded;
448
452
  }),
449
- count: limit + step
453
+ count: limit + paginationStep
450
454
  };
451
455
  if (sort != null && sort.property) opts.sort = sort;
452
456
  if (showProp) opts.show = showProp;
453
457
  onUpdate(opts);
454
458
  setLimit(function (prev) {
455
- return prev + step;
459
+ return prev + paginationStep;
456
460
  });
457
461
  }
458
462
  } : onMore,
@@ -466,7 +470,7 @@ var DataTable = function DataTable(_ref) {
466
470
  rowProps: rowProps,
467
471
  selected: selected,
468
472
  size: size,
469
- step: step,
473
+ step: paginationStep,
470
474
  verticalAlign: typeof verticalAlign === 'string' ? verticalAlign : verticalAlign == null ? void 0 : verticalAlign.body
471
475
  }) : /*#__PURE__*/_react["default"].createElement(_Body.Body, {
472
476
  ref: bodyRef,
@@ -477,13 +481,13 @@ var DataTable = function DataTable(_ref) {
477
481
  onMore: onUpdate ? function () {
478
482
  if (adjustedData.length === limit) {
479
483
  var opts = {
480
- count: limit + step
484
+ count: limit + paginationStep
481
485
  };
482
486
  if (sort != null && sort.property) opts.sort = sort;
483
487
  if (showProp) opts.show = showProp;
484
488
  onUpdate(opts);
485
489
  setLimit(function (prev) {
486
- return prev + step;
490
+ return prev + paginationStep;
487
491
  });
488
492
  }
489
493
  } : onMore,
@@ -500,7 +504,7 @@ var DataTable = function DataTable(_ref) {
500
504
  selected: selected,
501
505
  show: !paginate ? showProp : undefined,
502
506
  size: size,
503
- step: step,
507
+ step: paginationStep,
504
508
  rowDetails: rowDetails,
505
509
  rowExpand: rowExpand,
506
510
  setRowExpand: setRowExpand,
@@ -562,7 +566,7 @@ var DataTable = function DataTable(_ref) {
562
566
  }), placeholder && items && items.length > 0 && /*#__PURE__*/_react["default"].createElement(_StyledDataTable.StyledPlaceholder, {
563
567
  top: headerHeight,
564
568
  bottom: footerHeight
565
- }, placeholderContent))), paginate && adjustedData.length > step && items && items.length ? /*#__PURE__*/_react["default"].createElement(_Pagination.Pagination, _extends({
569
+ }, placeholderContent))), paginate && adjustedData.length > paginationStep && items && items.length ? /*#__PURE__*/_react["default"].createElement(_Pagination.Pagination, _extends({
566
570
  alignSelf: "end"
567
571
  }, paginationProps)) : null);
568
572
  };
@@ -110,8 +110,8 @@ var filterAndSortData = function filterAndSortData(data, filters, onSearch, sort
110
110
  var d1Val = datumValue(d1, property);
111
111
  var d2Val = datumValue(d2, property);
112
112
 
113
- if (typeof d1Val === 'string' && typeof d2Val === 'string') {
114
- var sortResult = d1Val.localeCompare(d2Val, undefined, {
113
+ if (typeof d1Val === 'string' && typeof d2Val === 'string' || typeof d1Val === 'string' && !d2Val || typeof d2Val === 'string' && !d1Val) {
114
+ var sortResult = (d1Val || '').localeCompare(d2Val || '', undefined, {
115
115
  sensitivity: 'base'
116
116
  });
117
117
  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<JSX.IntrinsicElements['table'], 'onSelect' | 'placeholder'> {}
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>
@@ -41,7 +41,9 @@ var columns = [{
41
41
  }
42
42
  }, (_datum$failures = datum.failures) == null ? void 0 : _datum$failures.map(function (_ref) {
43
43
  var reason = _ref.reason;
44
- return /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, reason);
44
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Text, {
45
+ key: reason
46
+ }, reason);
45
47
  }));
46
48
 
47
49
  return /*#__PURE__*/_react["default"].createElement(_grommet.Tip, {
@@ -28,7 +28,9 @@ var columns = [{
28
28
  header: 'Rocket',
29
29
  size: 'small',
30
30
  render: function render(datum) {
31
- return /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, datum.rocket.name);
31
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Text, {
32
+ key: datum.rocket.name
33
+ }, datum.rocket.name);
32
34
  }
33
35
  }, {
34
36
  property: 'success',
@@ -44,7 +46,9 @@ var columns = [{
44
46
  }
45
47
  }, (_datum$failures = datum.failures) == null ? void 0 : _datum$failures.map(function (_ref) {
46
48
  var reason = _ref.reason;
47
- return /*#__PURE__*/_react["default"].createElement(_grommet.Text, null, reason);
49
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Text, {
50
+ key: reason
51
+ }, reason);
48
52
  }));
49
53
 
50
54
  return /*#__PURE__*/_react["default"].createElement(_grommet.Tip, {
@@ -33,12 +33,12 @@ var _MaskedInput = require("../MaskedInput");
33
33
 
34
34
  var _utils = require("../../utils");
35
35
 
36
- var _utils2 = require("../Calendar/utils");
37
-
38
- var _utils3 = require("./utils");
36
+ var _utils2 = require("./utils");
39
37
 
40
38
  var _propTypes = require("./propTypes");
41
39
 
40
+ var _Calendar3 = require("../Calendar/Calendar");
41
+
42
42
  var _excluded = ["buttonProps", "calendarProps", "defaultValue", "disabled", "dropProps", "format", "id", "icon", "inline", "inputProps", "name", "onChange", "onFocus", "plain", "reverse", "value", "messages"],
43
43
  _excluded2 = ["icon"];
44
44
 
@@ -50,6 +50,30 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
50
50
 
51
51
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
52
52
 
53
+ var getReference = function getReference(value) {
54
+ var adjustedDate;
55
+ var res;
56
+ if (typeof value === 'string') res = value;else if (Array.isArray(value) && Array.isArray(value[0])) res = value[0].find(function (date) {
57
+ return date;
58
+ });else if (Array.isArray(value) && value.length) {
59
+ res = value[0];
60
+ }
61
+
62
+ if (res) {
63
+ var _res;
64
+
65
+ adjustedDate = new Date(res); // if time is not specified in ISOstring, normalize to midnight
66
+
67
+ if (((_res = res) == null ? void 0 : _res.indexOf('T')) === -1) {
68
+ var offset = adjustedDate.getTimezoneOffset();
69
+ var hour = adjustedDate.getHours();
70
+ adjustedDate.setHours(hour, offset);
71
+ }
72
+ }
73
+
74
+ return adjustedDate;
75
+ };
76
+
53
77
  var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
54
78
  var buttonProps = _ref.buttonProps,
55
79
  calendarProps = _ref.calendarProps,
@@ -95,39 +119,38 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
95
119
  value = _useFormInput[0],
96
120
  setValue = _useFormInput[1];
97
121
 
98
- var timestamp = (0, _react.useMemo)(function () {
99
- if (Array.isArray(defaultValue) && defaultValue.length) return (0, _utils2.getTimestamp)(defaultValue[0]);
100
- if (typeof defaultValue === 'string') return (0, _utils2.getTimestamp)(defaultValue);
101
- if (Array.isArray(value) && value.length) return (0, _utils2.getTimestamp)(value[0]); // check to see if value is not an empty string
102
- // empty string should behave like undefined
122
+ var _useState = (0, _react.useState)((0, _Calendar3.getOutputFormat)(value)),
123
+ outputFormat = _useState[0],
124
+ setOutputFormat = _useState[1];
103
125
 
104
- if (typeof value === 'string' && value.length) return (0, _utils2.getTimestamp)(value);
105
- return undefined;
106
- }, [defaultValue, value]); // whether or not we should normalize the date based on the timestamp.
107
- // will be set to false if the initial timestamp is undefined (meaning
108
- // a user did not provide a defaultValue or value). in this case, we
109
- // will just rely on the UTC timestamp and don't need to normalize.
126
+ (0, _react.useEffect)(function () {
127
+ setOutputFormat(function (previousFormat) {
128
+ var nextFormat = (0, _Calendar3.getOutputFormat)(value); // when user types, date could become something like 07//2020
129
+ // and value becomes undefined. don't lose the format from the
130
+ // previous valid date
110
131
 
111
- var _useState = (0, _react.useState)(true),
112
- normalize = _useState[0],
113
- setNormalize = _useState[1]; // normalize value based on timestamp vs user's local timezone
132
+ return previousFormat !== nextFormat ? previousFormat : nextFormat;
133
+ });
134
+ }, [value]); // keep track of timestamp from original date(s)
114
135
 
136
+ var _useState2 = (0, _react.useState)(getReference(value)),
137
+ reference = _useState2[0],
138
+ setReference = _useState2[1]; // do we expect multiple dates?
115
139
 
116
- var normalizedDate = (0, _utils2.normalizeForTimezone)(value, timestamp, normalize); // do we expect multiple dates?
117
140
 
118
141
  var range = Array.isArray(value) || format && format.includes('-'); // parse format and build a formal schema we can use elsewhere
119
142
 
120
143
  var schema = (0, _react.useMemo)(function () {
121
- return (0, _utils3.formatToSchema)(format);
144
+ return (0, _utils2.formatToSchema)(format);
122
145
  }, [format]); // mask is only used when a format is provided
123
146
 
124
147
  var mask = (0, _react.useMemo)(function () {
125
- return (0, _utils3.schemaToMask)(schema);
148
+ return (0, _utils2.schemaToMask)(schema);
126
149
  }, [schema]); // textValue is only used when a format is provided
127
150
 
128
- var _useState2 = (0, _react.useState)(schema ? (0, _utils3.valueToText)(normalizedDate, schema) : undefined),
129
- textValue = _useState2[0],
130
- setTextValue = _useState2[1]; // Setting the icon through `inputProps` is deprecated.
151
+ var _useState3 = (0, _react.useState)(schema ? (0, _utils2.valueToText)(value, schema) : undefined),
152
+ textValue = _useState3[0],
153
+ setTextValue = _useState3[1]; // Setting the icon through `inputProps` is deprecated.
131
154
  // The `icon` prop should be used instead.
132
155
 
133
156
 
@@ -152,17 +175,17 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
152
175
 
153
176
  (0, _react.useEffect)(function () {
154
177
  if (schema && value !== undefined) {
155
- var nextTextValue = (0, _utils3.valueToText)(normalizedDate, schema);
178
+ var nextTextValue = (0, _utils2.valueToText)(value, schema);
156
179
 
157
- if (!(0, _utils3.valuesAreEqual)((0, _utils3.textToValue)(textValue, schema, range, timestamp), (0, _utils3.textToValue)(nextTextValue, schema, range, timestamp)) || textValue === '' && nextTextValue !== '') {
180
+ if (!(0, _utils2.valuesAreEqual)((0, _utils2.textToValue)(textValue, schema, range, reference), (0, _utils2.textToValue)(nextTextValue, schema, range, reference)) || textValue === '' && nextTextValue !== '') {
158
181
  setTextValue(nextTextValue);
159
182
  }
160
183
  }
161
- }, [range, schema, textValue, value, normalizedDate, timestamp]); // when format and not inline, whether to show the Calendar in a Drop
184
+ }, [range, schema, textValue, reference, value]); // when format and not inline, whether to show the Calendar in a Drop
162
185
 
163
- var _useState3 = (0, _react.useState)(),
164
- open = _useState3[0],
165
- setOpen = _useState3[1];
186
+ var _useState4 = (0, _react.useState)(),
187
+ open = _useState4[0],
188
+ setOpen = _useState4[1];
166
189
 
167
190
  var openCalendar = (0, _react.useCallback)(function () {
168
191
  setOpen(true);
@@ -183,33 +206,23 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
183
206
  ref: inline ? ref : undefined,
184
207
  id: inline && !format ? id : undefined,
185
208
  range: range,
186
- date: range ? undefined : normalizedDate // when caller initializes with empty array, dates should be undefined
209
+ date: range ? undefined : value // when caller initializes with empty array, dates should be undefined
187
210
  // allowing the user to select both begin and end of the range
188
211
  ,
189
- dates: range && value.length ? [normalizedDate] : undefined // places focus on days grid when Calendar opens
212
+ dates: range && value.length ? [value] : undefined // places focus on days grid when Calendar opens
190
213
  ,
191
214
  initialFocus: open ? 'days' : undefined,
192
- normalize: normalize,
193
215
  onSelect: disabled ? undefined : function (nextValue) {
194
216
  var normalizedValue;
195
217
 
196
218
  if (range && Array.isArray(nextValue)) {
197
219
  normalizedValue = nextValue[0];
198
220
  } // clicking an edge date removes it
199
- else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue; // timestamp will be undefined if no defaultValue or value have
200
- // been passed in, indicating that we should stay local if the
201
- // user first picks a date via the Calendar.
202
-
221
+ else if (range) normalizedValue = [nextValue, nextValue];else normalizedValue = nextValue;
203
222
 
204
- var nextNormalize = normalize;
205
-
206
- if (timestamp === undefined) {
207
- nextNormalize = false;
208
- setNormalize(nextNormalize);
209
- }
210
-
211
- if (schema) setTextValue((0, _utils3.valueToText)((0, _utils2.normalizeForTimezone)(normalizedValue, undefined, nextNormalize), schema));
223
+ if (schema) setTextValue((0, _utils2.valueToText)(normalizedValue, schema));
212
224
  setValue(normalizedValue);
225
+ setReference(getReference(nextValue));
213
226
  if (_onChange) _onChange({
214
227
  value: normalizedValue
215
228
  });
@@ -221,9 +234,7 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
221
234
  }, 1);
222
235
  }
223
236
  }
224
- }, _extends({}, calendarProps, {
225
- timestamp: timestamp
226
- })));
237
+ }, calendarProps));
227
238
 
228
239
  var formContextValue = (0, _react.useMemo)(function () {
229
240
  return {
@@ -294,27 +305,8 @@ var DateInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
294
305
  onChange: function onChange(event) {
295
306
  var nextTextValue = event.target.value;
296
307
  setTextValue(nextTextValue);
297
- var localTimestamp; // get the UTC timestamp relative to the user's timezone
298
- // once a date is complete
299
-
300
- if (timestamp === undefined && Date.parse(nextTextValue)) {
301
- var _Date$toISOString$spl = new Date(nextTextValue).toISOString().split('T');
302
-
303
- localTimestamp = _Date$toISOString$spl[1];
304
- } // timestamp will be undefined if no defaultValue or value have
305
- // been passed in, indicating that we should stay local
306
-
307
-
308
- var nextNormalize = normalize;
309
-
310
- if (timestamp === undefined) {
311
- nextNormalize = false;
312
- setNormalize(nextNormalize);
313
- }
314
-
315
- var nextValue = (0, _utils3.textToValue)(nextTextValue, schema, range, timestamp || localTimestamp, nextNormalize); // reset to original state
316
-
317
- if (nextValue === undefined) setNormalize(true); // update value even when undefined
308
+ var nextValue = (0, _utils2.textToValue)(nextTextValue, schema, range, reference, outputFormat);
309
+ if (nextValue !== undefined) setReference(getReference(nextValue)); // update value even when undefined
318
310
 
319
311
  setValue(nextValue);
320
312
 
@@ -5,8 +5,17 @@ exports.valuesAreEqual = exports.valueToText = exports.textToValue = exports.sch
5
5
 
6
6
  var _utils = require("../Calendar/utils");
7
7
 
8
+ 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); }
9
+
10
+ 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; } }
11
+
12
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
13
+
8
14
  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); }
9
15
 
16
+ // Converting between Date and String types is handled via a "schema".
17
+ // The schema is an array of strings, split into strings with identical
18
+ // characters. So, 'mm/dd/yyyy' will be ['mm', '/', 'dd', '/', 'yyyyy'].
10
19
  var formatToSchema = function formatToSchema(format) {
11
20
  if (!format) return undefined;
12
21
  var result = [];
@@ -79,7 +88,16 @@ var valueToText = function valueToText(value, schema) {
79
88
 
80
89
  if (!value || Array.isArray(value) && !value.length) return text;
81
90
  var dates = (Array.isArray(value) ? value : [value]).map(function (v) {
82
- return new Date(v);
91
+ // TO DO should we extract this to a reusable function?
92
+ var adjustedDate = new Date(v); // if time is not specified in ISOstring, normalize to midnight
93
+
94
+ if (v.indexOf('T') === -1) {
95
+ var offset = adjustedDate.getTimezoneOffset();
96
+ var hour = adjustedDate.getHours();
97
+ adjustedDate.setHours(hour, offset);
98
+ }
99
+
100
+ return adjustedDate;
83
101
  });
84
102
  var dateIndex = 0;
85
103
  var parts = {};
@@ -137,7 +155,7 @@ var pullDigits = function pullDigits(text, index) {
137
155
  return text.slice(index, end);
138
156
  };
139
157
 
140
- var textToValue = function textToValue(text, schema, range, timestamp, normalize) {
158
+ var textToValue = function textToValue(text, schema, range, reference, outputFormat) {
141
159
  if (!text) return range ? [] : undefined;
142
160
  var result;
143
161
 
@@ -145,10 +163,17 @@ var textToValue = function textToValue(text, schema, range, timestamp, normalize
145
163
  var leapYear = parts.y % 4 === 0 && parts.y % 100 !== 0 || parts.y % 400 === 0; // Do a little sanity checking on the parts first.
146
164
  // If not valid, leave as is.
147
165
 
148
- 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;
149
- var date = new Date(parts.y, parts.m - 1, parts.d).toISOString(); // match time and timezone of any supplied valueProp
166
+ 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
167
+
168
+ var time = reference ? [reference.getHours(), reference.getMinutes(), reference.getSeconds(), reference.getMilliseconds()] : null;
169
+
170
+ var date = _construct(Date, [parts.y, parts.m - 1, parts.d].concat(time)).toISOString();
150
171
 
151
- if (timestamp) date = (0, _utils.formatToLocalYYYYMMDD)(date, normalize).split('T')[0] + "T" + timestamp;else date = "" + (0, _utils.formatToLocalYYYYMMDD)(date, normalize).split('T')[0];
172
+ if (date && outputFormat === 'no timezone') {
173
+ var _handleOffset$toISOSt = (0, _utils.handleOffset)(date).toISOString().split('T');
174
+
175
+ date = _handleOffset$toISOSt[0];
176
+ }
152
177
 
153
178
  if (!range) {
154
179
  if (!result) result = date;
@@ -64,7 +64,7 @@ var formatBytes = function formatBytes(size) {
64
64
  var ContentsBox = (0, _styledComponents["default"])(_Box.Box).withConfig({
65
65
  displayName: "FileInput__ContentsBox",
66
66
  componentId: "sc-1jzq7im-0"
67
- })(["position:relative;", " ", ";", ";", ";"], function (props) {
67
+ })(["cursor:pointer;position:relative;", " ", ";", ";", ";"], function (props) {
68
68
  return props.disabled && (0, _utils.disabledStyle)();
69
69
  }, function (props) {
70
70
  return props.theme.fileInput && props.theme.fileInput.extend;
@@ -314,6 +314,7 @@ var FileInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
314
314
  justify: "between"
315
315
  }, files.length <= aggregateThreshold && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Message, theme.fileInput.message, message), /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
316
316
  onSpace: function onSpace(event) {
317
+ event.preventDefault();
317
318
  if (controlRef.current === event.target) inputRef.current.click();
318
319
  },
319
320
  onEnter: function onEnter(event) {
@@ -14,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
14
14
  var StyledFileInput = _styledComponents["default"].input.withConfig({
15
15
  displayName: "StyledFileInput",
16
16
  componentId: "sc-rl7ywv-0"
17
- })(["position:absolute;height:100%;width:100%;", " opacity:0;border:none;", " ", " &::-moz-focus-inner{border:none;outline:none;}"], _utils.inputStyle, function (props) {
17
+ })(["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;}"], _utils.inputStyle, function (props) {
18
18
  return !props.disabled && 'cursor: pointer;';
19
19
  }, function (props) {
20
20
  return props.rightOffset && "\n width: calc(100% - " + props.rightOffset + "px);\n right: " + props.rightOffset + "px;\n ";