grommet 2.25.0 → 2.25.1

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 (47) hide show
  1. package/components/Calendar/Calendar.js +232 -292
  2. package/components/Calendar/utils.js +16 -129
  3. package/components/Chart/calcs.js +44 -27
  4. package/components/Chart/stories/Scan.js +11 -9
  5. package/components/Chart/stories/data.js +16 -17
  6. package/components/CheckBox/CheckBox.js +3 -2
  7. package/components/DataChart/DataChart.js +3 -15
  8. package/components/DataChart/Detail.js +18 -11
  9. package/components/DataChart/stories/Pad.js +54 -0
  10. package/components/DateInput/DateInput.js +60 -68
  11. package/components/DateInput/utils.js +30 -5
  12. package/components/FileInput/FileInput.js +2 -1
  13. package/components/FileInput/StyledFileInput.js +1 -1
  14. package/components/Form/Form.js +6 -1
  15. package/components/FormField/FormField.js +25 -28
  16. package/components/Image/Image.js +4 -2
  17. package/components/Menu/index.d.ts +2 -2
  18. package/components/Select/SelectContainer.js +24 -36
  19. package/components/Tabs/Tabs.js +2 -1
  20. package/components/Video/StyledVideo.js +2 -2
  21. package/es6/components/Calendar/Calendar.js +230 -292
  22. package/es6/components/Calendar/utils.js +13 -114
  23. package/es6/components/Chart/calcs.js +44 -27
  24. package/es6/components/Chart/stories/Scan.js +10 -9
  25. package/es6/components/Chart/stories/data.js +16 -17
  26. package/es6/components/CheckBox/CheckBox.js +3 -2
  27. package/es6/components/DataChart/DataChart.js +4 -15
  28. package/es6/components/DataChart/Detail.js +20 -10
  29. package/es6/components/DataChart/stories/Pad.js +42 -0
  30. package/es6/components/DateInput/DateInput.js +57 -64
  31. package/es6/components/DateInput/utils.js +29 -7
  32. package/es6/components/FileInput/FileInput.js +2 -1
  33. package/es6/components/FileInput/StyledFileInput.js +1 -1
  34. package/es6/components/Form/Form.js +6 -1
  35. package/es6/components/FormField/FormField.js +25 -29
  36. package/es6/components/Image/Image.js +4 -2
  37. package/es6/components/Menu/index.d.ts +2 -2
  38. package/es6/components/Select/SelectContainer.js +25 -37
  39. package/es6/components/Tabs/Tabs.js +2 -1
  40. package/es6/components/Video/StyledVideo.js +2 -2
  41. package/es6/themes/base.d.ts +13 -27
  42. package/es6/themes/base.js +6 -1
  43. package/grommet.min.js +1 -1
  44. package/grommet.min.js.map +1 -1
  45. package/package.json +44 -42
  46. package/themes/base.d.ts +13 -27
  47. package/themes/base.js +6 -1
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.withinDates = exports.subtractMonths = exports.subtractDays = exports.startOfMonth = exports.sameDayOrBefore = exports.sameDayOrAfter = exports.sameDay = exports.normalizeForTimezone = exports.getTimestamp = exports.getFormattedDate = exports.formatToLocalYYYYMMDD = exports.formatDateToPropStructure = exports.endOfMonth = exports.daysApart = exports.betweenDates = exports.addMonths = exports.addDays = void 0;
4
+ exports.withinDates = exports.subtractMonths = exports.subtractDays = exports.startOfMonth = exports.sameDayOrBefore = exports.sameDayOrAfter = exports.sameDay = exports.handleOffset = exports.endOfMonth = exports.daysApart = exports.betweenDates = exports.addMonths = exports.addDays = void 0;
5
5
  // Utility functions for the Calendar.
6
6
  // Just what's needed to avoid having to include a dependency like momentjs.
7
7
  var DAY_MILLISECONDS = 24 * 60 * 60 * 1000;
@@ -87,30 +87,22 @@ exports.sameDayOrBefore = sameDayOrBefore;
87
87
 
88
88
  var daysApart = function daysApart(date1, date2) {
89
89
  return Math.floor((date1.getTime() - date2.getTime()) / DAY_MILLISECONDS);
90
- };
91
-
92
- exports.daysApart = daysApart;
93
-
94
- var formatToLocalYYYYMMDD = function formatToLocalYYYYMMDD(date, normalize) {
95
- var adjustedDate = new Date(date);
96
- var nextDate = normalize ? new Date(adjustedDate.getTime() - adjustedDate.getTimezoneOffset() * 60000) : new Date(adjustedDate.getTime());
97
- return nextDate.toISOString().split('T')[0];
98
90
  }; // betweenDates takes an array of two elements and checks if the
99
91
  // supplied date lies between them, inclusive.
100
92
  // returns 2 if exact match to one end, 1 if between, undefined otherwise
101
93
 
102
94
 
103
- exports.formatToLocalYYYYMMDD = formatToLocalYYYYMMDD;
95
+ exports.daysApart = daysApart;
104
96
 
105
97
  var betweenDates = function betweenDates(date, dates) {
106
98
  var result;
107
99
 
108
100
  if (dates) {
109
- var _dates$map = dates.map(function (d) {
101
+ var _ref = Array.isArray(dates) ? dates.map(function (d) {
110
102
  return d ? new Date(d) : undefined;
111
- }),
112
- from = _dates$map[0],
113
- to = _dates$map[1];
103
+ }) : [dates, undefined],
104
+ from = _ref[0],
105
+ to = _ref[1];
114
106
 
115
107
  if (from && sameDay(date, from) || to && sameDay(date, to)) {
116
108
  result = 2;
@@ -136,8 +128,8 @@ var withinDates = function withinDates(date, dates) {
136
128
  if (dates) {
137
129
  if (Array.isArray(dates)) {
138
130
  dates.some(function (d) {
139
- if (typeof d === 'string') {
140
- if (sameDay(date, new Date(d))) {
131
+ if (d instanceof Date) {
132
+ if (sameDay(date, d)) {
141
133
  result = 2;
142
134
  }
143
135
  } else {
@@ -146,7 +138,7 @@ var withinDates = function withinDates(date, dates) {
146
138
 
147
139
  return result;
148
140
  });
149
- } else if (sameDay(date, new Date(dates))) {
141
+ } else if (sameDay(date, dates)) {
150
142
  result = 2;
151
143
  }
152
144
  }
@@ -156,118 +148,13 @@ var withinDates = function withinDates(date, dates) {
156
148
 
157
149
  exports.withinDates = withinDates;
158
150
 
159
- var getTimestamp = function getTimestamp(date) {
160
- return /T.*/.test(date) ? new Date(date).toISOString().split('T')[1] : // for Calendar, explicitly mark that caller has provided
161
- // value with no timestamp
162
- false;
163
- }; // Checks if daylight savings is in effect for a timezone and date
164
- // Reference: https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset
165
-
166
-
167
- exports.getTimestamp = getTimestamp;
168
-
169
- var inDaylightSavings = function inDaylightSavings(day) {
170
- var jan = new Date(day.getFullYear(), 0, 1).getTimezoneOffset();
171
- var july = new Date(day.getFullYear(), 6, 1).getTimezoneOffset();
172
- return Math.max(jan, july) !== day.getTimezoneOffset();
173
- }; // Adjust for differences between timestamp on value and
174
- // local timezone of user. Internal Calendar logic relies
175
- // on Javascript date contructor which translates the provided
176
- // date into the equivalent moment for the user's timezone, which
177
- // can create undesired results. The standardizes the input value
178
- // for internal calculations
179
- // Reference: https://www.ursahealth.com/new-insights/dates-and-timezones-in-javascript
180
- // If normalize is false just convert the value toISOString(),
181
- // valueOffset/localOffset will be 0.
182
-
183
-
184
- var normalizeForTimezone = function normalizeForTimezone(value, timestamp, normalize) {
185
- if (normalize === void 0) {
186
- normalize = true;
187
- }
188
-
189
- var adjustedDate;
190
- var hourDelta = 0;
191
- var valueOffset = 0;
192
- var localOffset = 0;
193
-
194
- if (normalize) {
195
- if (timestamp && typeof timestamp === 'string') {
196
- hourDelta = parseInt(timestamp == null ? void 0 : timestamp.split(':')[0], 10);
197
- }
198
-
199
- var today = new Date();
200
- adjustedDate = value && (Array.isArray(value) ? value : [value]).map(function (v) {
201
- var day = new Date(v); // If one of the days either day or today is in daylight savings and the
202
- // other is not the timezoneOffset will be different. If they are both
203
- // in or out of daylight savings the timezoneOffset will be the same.
204
-
205
- if (day && !inDaylightSavings(day) && day.getTimezoneOffset() > today.getTimezoneOffset()) {
206
- // today is in daylight savings but the selected day is not
207
- hourDelta -= 1;
208
- } else if (day && inDaylightSavings(day) && day.getTimezoneOffset() < today.getTimezoneOffset()) {
209
- // the selected day is in daylight savings but today is not
210
- hourDelta += 1;
211
- }
212
-
213
- valueOffset = hourDelta === 0 ? 0 : hourDelta * 60 * 60 * 1000;
214
- localOffset = new Date().getTimezoneOffset() * 60 * 1000;
215
- return new Date(new Date(v).getTime() - valueOffset + localOffset).toISOString();
216
- });
217
- } else {
218
- adjustedDate = value && (Array.isArray(value) ? value : [value]).map(function (v) {
219
- return new Date(new Date(v).getTime()).toISOString();
220
- });
221
- }
222
-
223
- if (typeof value === 'string') {
224
- var _adjustedDate = adjustedDate;
225
- adjustedDate = _adjustedDate[0];
226
- }
227
-
228
- return adjustedDate;
229
- }; // format the date to align with date format caller passed in
230
-
231
-
232
- exports.normalizeForTimezone = normalizeForTimezone;
233
-
234
- var formatDateToPropStructure = function formatDateToPropStructure(date, timestamp, normalize) {
235
- var adjustedDate;
236
-
237
- if (date) {
238
- if (timestamp) {
239
- adjustedDate = formatToLocalYYYYMMDD(date, normalize).split('T')[0] + "T" + timestamp;
240
- } else if (timestamp === false) {
241
- var _formatToLocalYYYYMMD = formatToLocalYYYYMMDD(date, normalize).split('T');
242
-
243
- adjustedDate = _formatToLocalYYYYMMD[0];
244
- } else adjustedDate = date;
245
- }
246
-
247
- return adjustedDate;
248
- };
249
-
250
- exports.formatDateToPropStructure = formatDateToPropStructure;
251
-
252
- var getFormattedDate = function getFormattedDate(nextDate, nextDates, normalize, range, timestamp) {
253
- var adjustedDate;
254
- var adjustedDates;
255
-
256
- if (nextDates && Array.isArray(nextDates[0]) && (!nextDates[0][0] || !nextDates[0][1]) && range === true) {
257
- // return string for backwards compatibility
258
- var _nextDates$0$filter = nextDates[0].filter(function (d) {
259
- return d;
260
- });
261
-
262
- adjustedDates = _nextDates$0$filter[0];
263
- adjustedDates = formatDateToPropStructure(adjustedDates, timestamp, normalize);
264
- } else if (nextDates) {
265
- adjustedDates = [[formatDateToPropStructure(nextDates[0][0], timestamp, normalize), formatDateToPropStructure(nextDates[0][1], timestamp, normalize)]];
266
- } else {
267
- adjustedDate = formatDateToPropStructure(nextDate, timestamp, normalize);
268
- }
151
+ var handleOffset = function handleOffset(date) {
152
+ var normalizedDate = new Date(date);
153
+ var offset = normalizedDate.getTimezoneOffset();
154
+ var hour = normalizedDate.getHours(); // add back offset
269
155
 
270
- return adjustedDates || adjustedDate;
156
+ normalizedDate.setHours(hour, offset < 0 ? -offset : offset);
157
+ return normalizedDate;
271
158
  };
272
159
 
273
- exports.getFormattedDate = getFormattedDate;
160
+ exports.handleOffset = handleOffset;
@@ -39,9 +39,12 @@ var calcBounds = function calcBounds(values, options) {
39
39
  // coarseness influences the rounding of the bounds, the smaller the
40
40
  // number, the more the bounds will be rounded. e.g. 111 -> 110 -> 100
41
41
  // Normalize to an array. Backwards compatible has no coarseness for x-axis
42
- var coarseness = Array.isArray(options.coarseness) && options.coarseness || options.coarseness && [undefined, options.coarseness] || [undefined, 5]; // the number of steps is one less than the number of labels
42
+ var coarseness = Array.isArray(options.coarseness) && options.coarseness || options.coarseness && [undefined, options.coarseness] || [undefined, 5];
43
+ var coarseX = coarseness[0],
44
+ coarseY = coarseness[1]; // the number of steps is one less than the number of labels
43
45
 
44
46
  var steps = options.steps || [1, 1];
47
+ var stepsY = steps[1];
45
48
  var calcValues = (0, _utils.normalizeValues)(values || []); // min and max values
46
49
 
47
50
  var minX;
@@ -88,19 +91,16 @@ var calcBounds = function calcBounds(values, options) {
88
91
  // graph axis labels.
89
92
 
90
93
 
91
- var cX = coarseness[0],
92
- cY = coarseness[1];
93
-
94
- if (cX) {
94
+ if (coarseX) {
95
95
  var deltaX = maxX - minX;
96
- var intervalX = Number.parseFloat((deltaX / cX).toPrecision(1));
96
+ var intervalX = Number.parseFloat((deltaX / coarseX).toPrecision(1));
97
97
  minX = alignMin(minX, intervalX);
98
98
  maxX = alignMax(maxX, intervalX);
99
99
  }
100
100
 
101
- if (cY) {
101
+ if (coarseY) {
102
102
  var deltaY = maxY - minY;
103
- var intervalY = Number.parseFloat((deltaY / cY).toPrecision(1));
103
+ var intervalY = Number.parseFloat((deltaY / coarseY).toPrecision(1));
104
104
  minY = alignMin(minY, intervalY);
105
105
  maxY = alignMax(maxY, intervalY);
106
106
  }
@@ -108,19 +108,26 @@ var calcBounds = function calcBounds(values, options) {
108
108
  if (minY < 0 && maxY > 0 && Math.abs(minY) !== Math.abs(maxY)) {
109
109
  // Adjust min and max when crossing 0 to ensure 0 will be shown on
110
110
  // the Y axis based on the number of steps.
111
- // const ratio = Math.abs(max) / Math.abs(min);
112
- var stepInterval = (maxY - minY) / steps[1];
113
- var minSteps = minY / stepInterval;
114
- var maxSteps = maxY / stepInterval;
115
-
116
- if (Math.abs(minSteps) < Math.abs(maxSteps)) {
117
- stepInterval = maxY / Math.floor(maxSteps);
118
- maxY = stepInterval * Math.floor(maxSteps);
119
- minY = stepInterval * Math.floor(minSteps);
111
+ if (stepsY === 1) {
112
+ var largest = Math.max(Math.abs(minY), Math.abs(maxY));
113
+ minY = -largest;
114
+ maxY = largest;
120
115
  } else {
121
- stepInterval = Math.abs(minY / Math.ceil(minSteps));
122
- minY = stepInterval * Math.ceil(minSteps);
123
- maxY = stepInterval * Math.ceil(maxSteps);
116
+ var stepInterval = (maxY - minY) / stepsY;
117
+ var minSteps = minY / stepInterval;
118
+ var maxSteps = maxY / stepInterval;
119
+
120
+ if (Math.abs(minSteps) < Math.abs(maxSteps)) {
121
+ // more above than below
122
+ stepInterval = maxY / Math.floor(maxSteps);
123
+ maxY = stepInterval * Math.floor(maxSteps);
124
+ minY = stepInterval * Math.floor(minSteps);
125
+ } else {
126
+ // more below than above
127
+ stepInterval = Math.abs(minY / Math.ceil(minSteps));
128
+ minY = stepInterval * Math.ceil(minSteps);
129
+ maxY = stepInterval * Math.ceil(maxSteps);
130
+ }
124
131
  }
125
132
  }
126
133
  }
@@ -143,27 +150,37 @@ var calcs = function calcs(values, options) {
143
150
 
144
151
  // the number of steps is one less than the number of labels
145
152
  var steps = options.steps || [1, 1];
153
+ var stepsX = steps[0],
154
+ stepsY = steps[1];
146
155
  var bounds = options.bounds || calcBounds(values, options);
147
156
  if (options.min !== undefined) bounds[1][0] = options.min;
148
157
  if (options.max !== undefined) bounds[1][1] = options.max;
149
- var dimensions = [round(bounds[0][1] - bounds[0][0], 2), round(bounds[1][1] - bounds[1][0], 2)]; // Calculate x and y axis values across the specfied number of steps.
158
+ var boundsX = bounds[0],
159
+ boundsY = bounds[1];
160
+ var boundsXmin = boundsX[0],
161
+ boundsXmax = boundsX[1];
162
+ var boundsYmin = boundsY[0],
163
+ boundsYmax = boundsY[1];
164
+ var dimensions = [round(boundsXmax - boundsXmin, 2), round(boundsYmax - boundsYmin, 2)];
165
+ var dimensionsX = dimensions[0],
166
+ dimensionsY = dimensions[1]; // Calculate x and y axis values across the specfied number of steps.
150
167
 
151
168
  var yAxis = [];
152
- var y = bounds[1][1]; // To deal with javascript math limitations, round the step with 4 decimal
169
+ var y = boundsYmax; // To deal with javascript math limitations, round the step with 4 decimal
153
170
  // places and then push the values with 2 decimal places
154
171
 
155
- var yStepInterval = round(dimensions[1] / steps[1], 4);
172
+ var yStepInterval = round(dimensionsY / stepsY, 4);
156
173
 
157
- while (round(y, 2) >= bounds[1][0]) {
174
+ while (round(y, 2) >= boundsYmin) {
158
175
  yAxis.push(round(y, 2));
159
176
  y -= yStepInterval;
160
177
  }
161
178
 
162
179
  var xAxis = [];
163
- var x = bounds[0][0];
164
- var xStepInterval = round(dimensions[0] / steps[0], 4);
180
+ var x = boundsXmin;
181
+ var xStepInterval = round(dimensionsX / stepsX, 4);
165
182
 
166
- while (round(x, 2) <= bounds[0][1]) {
183
+ while (round(x, 2) <= boundsXmax) {
167
184
  xAxis.push(round(x, 2));
168
185
  x += xStepInterval;
169
186
  }
@@ -15,23 +15,28 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
15
15
 
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
 
18
- var ScanChart = function ScanChart(props) {
18
+ var count = 30,
19
+ max = 100,
20
+ min = 0;
21
+
22
+ var ScanChart = function ScanChart() {
19
23
  var _useState = (0, _react.useState)(undefined),
20
24
  active = _useState[0],
21
25
  setActive = _useState[1];
22
26
 
23
- var data = props.data,
24
- max = props.max;
27
+ var data = (0, _react.useMemo)(function () {
28
+ return (0, _data.generateData)(count, max, min);
29
+ }, []);
25
30
  var values = data.map(function (d) {
26
31
  return [d.time, d.value];
27
32
  });
28
33
 
29
34
  var _useMemo = (0, _react.useMemo)(function () {
30
35
  return (0, _calcs.calcs)(values, {
31
- min: 0,
36
+ min: min,
32
37
  max: max
33
38
  });
34
- }, [values, max]),
39
+ }, [values]),
35
40
  axis = _useMemo.axis,
36
41
  bounds = _useMemo.bounds,
37
42
  pad = _useMemo.pad,
@@ -157,10 +162,7 @@ var ScanChart = function ScanChart(props) {
157
162
  };
158
163
 
159
164
  var Scan = function Scan() {
160
- return /*#__PURE__*/_react["default"].createElement(ScanChart, {
161
- data: (0, _data.generateData)(30, 100),
162
- max: 100
163
- });
165
+ return /*#__PURE__*/_react["default"].createElement(ScanChart, null);
164
166
  };
165
167
 
166
168
  exports.Scan = Scan;
@@ -4,27 +4,26 @@ exports.__esModule = true;
4
4
  exports.generateData = void 0;
5
5
  // generate a data set
6
6
  var dataSet = {
7
- generateData: function generateData(count, max) {
8
- var data = [];
9
- var value = max / 2;
10
- var increase = true;
11
- var date = new Date();
7
+ generateData: function generateData(count, max, min) {
8
+ if (count === void 0) {
9
+ count = 5;
10
+ }
12
11
 
13
- while (data.length < count) {
14
- if (increase) {
15
- value += (max - value) % Math.ceil((data.length % (max / 4) + 1) / 2);
12
+ if (max === void 0) {
13
+ max = 100;
14
+ }
16
15
 
17
- if (value >= max) {
18
- increase = false;
19
- }
20
- } else {
21
- value -= value % Math.ceil((data.length % (max / 4) + 1) / 2);
16
+ if (min === void 0) {
17
+ min = 0;
18
+ }
22
19
 
23
- if (value <= 0) {
24
- increase = true;
25
- }
26
- }
20
+ var data = [];
21
+ var date = new Date();
22
+ var span = max - min;
27
23
 
24
+ while (data.length < count) {
25
+ var s = Math.sin(data.length / 2.0);
26
+ var value = s * (span / 2) + (span / 2 + min);
28
27
  var nextDay = date.getDate() - 1;
29
28
  date = new Date(date);
30
29
  date.setDate(nextDay);
@@ -170,7 +170,9 @@ var CheckBox = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
170
170
  align: "center",
171
171
  justify: "center",
172
172
  margin: label && (_ref2 = {}, _ref2[side] = theme.checkBox.gap || 'small', _ref2)
173
- }, themeableProps), /*#__PURE__*/_react["default"].createElement(_StyledCheckBox.StyledCheckBoxInput, _extends({}, rest, {
173
+ }, themeableProps), /*#__PURE__*/_react["default"].createElement(_StyledCheckBox.StyledCheckBoxInput, _extends({
174
+ "aria-label": ariaLabel || a11yTitle
175
+ }, rest, {
174
176
  ref: ref,
175
177
  type: "checkbox"
176
178
  }, (0, _object.removeUndefined)({
@@ -200,7 +202,6 @@ var CheckBox = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
200
202
  var first = reverse ? normalizedLabel : checkBoxNode;
201
203
  var second = reverse ? checkBoxNode : normalizedLabel;
202
204
  return /*#__PURE__*/_react["default"].createElement(_StyledCheckBox.StyledCheckBoxContainer, _extends({
203
- "aria-label": ariaLabel || a11yTitle,
204
205
  fillProp: fill,
205
206
  reverse: reverse
206
207
  }, (0, _object.removeUndefined)({
@@ -7,8 +7,6 @@ var _react = _interopRequireWildcard(require("react"));
7
7
 
8
8
  var _styledComponents = require("styled-components");
9
9
 
10
- var _useIsomorphicLayoutEffect = require("../../utils/use-isomorphic-layout-effect");
11
-
12
10
  var _Box = require("../Box");
13
11
 
14
12
  var _Chart = require("../Chart");
@@ -86,11 +84,8 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
86
84
 
87
85
  var _useState = (0, _react.useState)(),
88
86
  activeProperty = _useState[0],
89
- setActiveProperty = _useState[1]; // refs used for ie11 not having Grid
90
-
87
+ setActiveProperty = _useState[1]; // normalize seriesProp to an array of objects, one per property
91
88
 
92
- var xRef = (0, _react.useRef)();
93
- var spacerRef = (0, _react.useRef)(); // normalize seriesProp to an array of objects, one per property
94
89
 
95
90
  var series = (0, _react.useMemo)(function () {
96
91
  if (Array.isArray(seriesProp)) return seriesProp.filter(function (s) {
@@ -547,14 +542,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
547
542
  }
548
543
  });
549
544
  return result;
550
- }, [axis, data, series]); // for ie11, align the spacer Box height to the x-axis height
551
-
552
- (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
553
- if (xRef.current && spacerRef.current) {
554
- var rect = xRef.current.getBoundingClientRect();
555
- spacerRef.current.style.height = rect.height + "px";
556
- }
557
- }, []);
545
+ }, [axis, data, series]);
558
546
 
559
547
  var renderValue = function renderValue(serie, dataIndex, valueArg) {
560
548
  var value;
@@ -580,7 +568,6 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
580
568
 
581
569
 
582
570
  var xAxisElement = axis && axis.x && chartProps.length ? /*#__PURE__*/_react["default"].createElement(_XAxis.XAxis, {
583
- ref: xRef,
584
571
  axis: axis,
585
572
  values: (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis[0],
586
573
  pad: offsetPad ? _extends({}, pad, {
@@ -691,6 +678,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
691
678
  activeProperty: activeProperty,
692
679
  axis: axis,
693
680
  data: data,
681
+ pad: pad,
694
682
  series: series,
695
683
  seriesStyles: seriesStyles,
696
684
  renderValue: renderValue,
@@ -5,7 +5,7 @@ exports.Detail = void 0;
5
5
 
6
6
  var _react = _interopRequireWildcard(require("react"));
7
7
 
8
- var _styledComponents = _interopRequireDefault(require("styled-components"));
8
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
9
 
10
10
  var _Box = require("../Box");
11
11
 
@@ -19,12 +19,8 @@ var _Text = require("../Text");
19
19
 
20
20
  var _utils = require("../../utils");
21
21
 
22
- var _utils2 = require("./utils");
23
-
24
22
  var _Swatch = require("./Swatch");
25
23
 
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
27
-
28
24
  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); }
29
25
 
30
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -38,11 +34,12 @@ var Detail = function Detail(_ref) {
38
34
  var activeProperty = _ref.activeProperty,
39
35
  axis = _ref.axis,
40
36
  data = _ref.data,
41
- pad = _ref.pad,
37
+ padProp = _ref.pad,
42
38
  series = _ref.series,
43
39
  seriesStyles = _ref.seriesStyles,
44
40
  renderValue = _ref.renderValue,
45
41
  thickness = _ref.thickness;
42
+ var theme = (0, _react.useContext)(_styledComponents.ThemeContext) || defaultProps.theme;
46
43
 
47
44
  var _useState = (0, _react.useState)(),
48
45
  detailIndex = _useState[0],
@@ -52,6 +49,20 @@ var Detail = function Detail(_ref) {
52
49
  var detailRefs = (0, _react.useMemo)(function () {
53
50
  return [];
54
51
  }, []);
52
+ var pad = (0, _react.useMemo)(function () {
53
+ // ensure the hit targets and center lines align with
54
+ // the data/guide lines
55
+ var horizontal = (padProp == null ? void 0 : padProp.horizontal) || typeof padProp === 'string' && padProp || 0;
56
+ horizontal = theme.global.edgeSize[horizontal] || horizontal;
57
+ horizontal = (0, _utils.parseMetricToNum)(horizontal);
58
+ var vertical = (padProp == null ? void 0 : padProp.vertical) || typeof padProp === 'string' && padProp || 0;
59
+ vertical = theme.global.edgeSize[vertical] || vertical;
60
+ vertical = (0, _utils.parseMetricToNum)(vertical);
61
+ return {
62
+ horizontal: horizontal - (0, _utils.parseMetricToNum)(thickness) / 2 + "px",
63
+ vertical: vertical + "px"
64
+ };
65
+ }, [padProp, theme.global.edgeSize, thickness]);
55
66
  var onMouseLeave = (0, _react.useCallback)(function (event) {
56
67
  // Only remove detail if the mouse isn't over the active index.
57
68
  // This helps distinguish leaving the drop on the edge where it is
@@ -75,11 +86,7 @@ var Detail = function Detail(_ref) {
75
86
  tabIndex: 0,
76
87
  direction: "row",
77
88
  fill: true,
78
- pad: // ensure the hit targets and center lines align with
79
- // the data/guide lines
80
- (pad == null ? void 0 : pad.horizontal) && _utils2.halfPad[pad.horizontal] && {
81
- horizontal: _utils2.halfPad[pad.horizontal]
82
- } || pad,
89
+ pad: pad,
83
90
  justify: "between",
84
91
  responsive: false,
85
92
  onFocus: function onFocus() {},
@@ -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;