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
@@ -55,11 +55,6 @@ export var sameDayOrBefore = function sameDayOrBefore(date1, date2) {
55
55
  };
56
56
  export var daysApart = function daysApart(date1, date2) {
57
57
  return Math.floor((date1.getTime() - date2.getTime()) / DAY_MILLISECONDS);
58
- };
59
- export var formatToLocalYYYYMMDD = function formatToLocalYYYYMMDD(date, normalize) {
60
- var adjustedDate = new Date(date);
61
- var nextDate = normalize ? new Date(adjustedDate.getTime() - adjustedDate.getTimezoneOffset() * 60000) : new Date(adjustedDate.getTime());
62
- return nextDate.toISOString().split('T')[0];
63
58
  }; // betweenDates takes an array of two elements and checks if the
64
59
  // supplied date lies between them, inclusive.
65
60
  // returns 2 if exact match to one end, 1 if between, undefined otherwise
@@ -68,11 +63,11 @@ export var betweenDates = function betweenDates(date, dates) {
68
63
  var result;
69
64
 
70
65
  if (dates) {
71
- var _dates$map = dates.map(function (d) {
66
+ var _ref = Array.isArray(dates) ? dates.map(function (d) {
72
67
  return d ? new Date(d) : undefined;
73
- }),
74
- from = _dates$map[0],
75
- to = _dates$map[1];
68
+ }) : [dates, undefined],
69
+ from = _ref[0],
70
+ to = _ref[1];
76
71
 
77
72
  if (from && sameDay(date, from) || to && sameDay(date, to)) {
78
73
  result = 2;
@@ -95,8 +90,8 @@ export var withinDates = function withinDates(date, dates) {
95
90
  if (dates) {
96
91
  if (Array.isArray(dates)) {
97
92
  dates.some(function (d) {
98
- if (typeof d === 'string') {
99
- if (sameDay(date, new Date(d))) {
93
+ if (d instanceof Date) {
94
+ if (sameDay(date, d)) {
100
95
  result = 2;
101
96
  }
102
97
  } else {
@@ -105,114 +100,18 @@ export var withinDates = function withinDates(date, dates) {
105
100
 
106
101
  return result;
107
102
  });
108
- } else if (sameDay(date, new Date(dates))) {
103
+ } else if (sameDay(date, dates)) {
109
104
  result = 2;
110
105
  }
111
106
  }
112
107
 
113
108
  return result;
114
109
  };
115
- export var getTimestamp = function getTimestamp(date) {
116
- return /T.*/.test(date) ? new Date(date).toISOString().split('T')[1] : // for Calendar, explicitly mark that caller has provided
117
- // value with no timestamp
118
- false;
119
- }; // Checks if daylight savings is in effect for a timezone and date
120
- // Reference: https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset
121
-
122
- var inDaylightSavings = function inDaylightSavings(day) {
123
- var jan = new Date(day.getFullYear(), 0, 1).getTimezoneOffset();
124
- var july = new Date(day.getFullYear(), 6, 1).getTimezoneOffset();
125
- return Math.max(jan, july) !== day.getTimezoneOffset();
126
- }; // Adjust for differences between timestamp on value and
127
- // local timezone of user. Internal Calendar logic relies
128
- // on Javascript date contructor which translates the provided
129
- // date into the equivalent moment for the user's timezone, which
130
- // can create undesired results. The standardizes the input value
131
- // for internal calculations
132
- // Reference: https://www.ursahealth.com/new-insights/dates-and-timezones-in-javascript
133
- // If normalize is false just convert the value toISOString(),
134
- // valueOffset/localOffset will be 0.
135
-
136
-
137
- export var normalizeForTimezone = function normalizeForTimezone(value, timestamp, normalize) {
138
- if (normalize === void 0) {
139
- normalize = true;
140
- }
141
-
142
- var adjustedDate;
143
- var hourDelta = 0;
144
- var valueOffset = 0;
145
- var localOffset = 0;
146
-
147
- if (normalize) {
148
- if (timestamp && typeof timestamp === 'string') {
149
- hourDelta = parseInt(timestamp == null ? void 0 : timestamp.split(':')[0], 10);
150
- }
151
-
152
- var today = new Date();
153
- adjustedDate = value && (Array.isArray(value) ? value : [value]).map(function (v) {
154
- var day = new Date(v); // If one of the days either day or today is in daylight savings and the
155
- // other is not the timezoneOffset will be different. If they are both
156
- // in or out of daylight savings the timezoneOffset will be the same.
157
-
158
- if (day && !inDaylightSavings(day) && day.getTimezoneOffset() > today.getTimezoneOffset()) {
159
- // today is in daylight savings but the selected day is not
160
- hourDelta -= 1;
161
- } else if (day && inDaylightSavings(day) && day.getTimezoneOffset() < today.getTimezoneOffset()) {
162
- // the selected day is in daylight savings but today is not
163
- hourDelta += 1;
164
- }
165
-
166
- valueOffset = hourDelta === 0 ? 0 : hourDelta * 60 * 60 * 1000;
167
- localOffset = new Date().getTimezoneOffset() * 60 * 1000;
168
- return new Date(new Date(v).getTime() - valueOffset + localOffset).toISOString();
169
- });
170
- } else {
171
- adjustedDate = value && (Array.isArray(value) ? value : [value]).map(function (v) {
172
- return new Date(new Date(v).getTime()).toISOString();
173
- });
174
- }
175
-
176
- if (typeof value === 'string') {
177
- var _adjustedDate = adjustedDate;
178
- adjustedDate = _adjustedDate[0];
179
- }
180
-
181
- return adjustedDate;
182
- }; // format the date to align with date format caller passed in
183
-
184
- export var formatDateToPropStructure = function formatDateToPropStructure(date, timestamp, normalize) {
185
- var adjustedDate;
186
-
187
- if (date) {
188
- if (timestamp) {
189
- adjustedDate = formatToLocalYYYYMMDD(date, normalize).split('T')[0] + "T" + timestamp;
190
- } else if (timestamp === false) {
191
- var _formatToLocalYYYYMMD = formatToLocalYYYYMMDD(date, normalize).split('T');
192
-
193
- adjustedDate = _formatToLocalYYYYMMD[0];
194
- } else adjustedDate = date;
195
- }
196
-
197
- return adjustedDate;
198
- };
199
- export var getFormattedDate = function getFormattedDate(nextDate, nextDates, normalize, range, timestamp) {
200
- var adjustedDate;
201
- var adjustedDates;
202
-
203
- if (nextDates && Array.isArray(nextDates[0]) && (!nextDates[0][0] || !nextDates[0][1]) && range === true) {
204
- // return string for backwards compatibility
205
- var _nextDates$0$filter = nextDates[0].filter(function (d) {
206
- return d;
207
- });
208
-
209
- adjustedDates = _nextDates$0$filter[0];
210
- adjustedDates = formatDateToPropStructure(adjustedDates, timestamp, normalize);
211
- } else if (nextDates) {
212
- adjustedDates = [[formatDateToPropStructure(nextDates[0][0], timestamp, normalize), formatDateToPropStructure(nextDates[0][1], timestamp, normalize)]];
213
- } else {
214
- adjustedDate = formatDateToPropStructure(nextDate, timestamp, normalize);
215
- }
110
+ export var handleOffset = function handleOffset(date) {
111
+ var normalizedDate = new Date(date);
112
+ var offset = normalizedDate.getTimezoneOffset();
113
+ var hour = normalizedDate.getHours(); // add back offset
216
114
 
217
- return adjustedDates || adjustedDate;
115
+ normalizedDate.setHours(hour, offset < 0 ? -offset : offset);
116
+ return normalizedDate;
218
117
  };
@@ -30,9 +30,12 @@ export var calcBounds = function calcBounds(values, options) {
30
30
  // coarseness influences the rounding of the bounds, the smaller the
31
31
  // number, the more the bounds will be rounded. e.g. 111 -> 110 -> 100
32
32
  // Normalize to an array. Backwards compatible has no coarseness for x-axis
33
- 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
33
+ var coarseness = Array.isArray(options.coarseness) && options.coarseness || options.coarseness && [undefined, options.coarseness] || [undefined, 5];
34
+ var coarseX = coarseness[0],
35
+ coarseY = coarseness[1]; // the number of steps is one less than the number of labels
34
36
 
35
37
  var steps = options.steps || [1, 1];
38
+ var stepsY = steps[1];
36
39
  var calcValues = normalizeValues(values || []); // min and max values
37
40
 
38
41
  var minX;
@@ -79,19 +82,16 @@ export var calcBounds = function calcBounds(values, options) {
79
82
  // graph axis labels.
80
83
 
81
84
 
82
- var cX = coarseness[0],
83
- cY = coarseness[1];
84
-
85
- if (cX) {
85
+ if (coarseX) {
86
86
  var deltaX = maxX - minX;
87
- var intervalX = Number.parseFloat((deltaX / cX).toPrecision(1));
87
+ var intervalX = Number.parseFloat((deltaX / coarseX).toPrecision(1));
88
88
  minX = alignMin(minX, intervalX);
89
89
  maxX = alignMax(maxX, intervalX);
90
90
  }
91
91
 
92
- if (cY) {
92
+ if (coarseY) {
93
93
  var deltaY = maxY - minY;
94
- var intervalY = Number.parseFloat((deltaY / cY).toPrecision(1));
94
+ var intervalY = Number.parseFloat((deltaY / coarseY).toPrecision(1));
95
95
  minY = alignMin(minY, intervalY);
96
96
  maxY = alignMax(maxY, intervalY);
97
97
  }
@@ -99,19 +99,26 @@ export var calcBounds = function calcBounds(values, options) {
99
99
  if (minY < 0 && maxY > 0 && Math.abs(minY) !== Math.abs(maxY)) {
100
100
  // Adjust min and max when crossing 0 to ensure 0 will be shown on
101
101
  // the Y axis based on the number of steps.
102
- // const ratio = Math.abs(max) / Math.abs(min);
103
- var stepInterval = (maxY - minY) / steps[1];
104
- var minSteps = minY / stepInterval;
105
- var maxSteps = maxY / stepInterval;
106
-
107
- if (Math.abs(minSteps) < Math.abs(maxSteps)) {
108
- stepInterval = maxY / Math.floor(maxSteps);
109
- maxY = stepInterval * Math.floor(maxSteps);
110
- minY = stepInterval * Math.floor(minSteps);
102
+ if (stepsY === 1) {
103
+ var largest = Math.max(Math.abs(minY), Math.abs(maxY));
104
+ minY = -largest;
105
+ maxY = largest;
111
106
  } else {
112
- stepInterval = Math.abs(minY / Math.ceil(minSteps));
113
- minY = stepInterval * Math.ceil(minSteps);
114
- maxY = stepInterval * Math.ceil(maxSteps);
107
+ var stepInterval = (maxY - minY) / stepsY;
108
+ var minSteps = minY / stepInterval;
109
+ var maxSteps = maxY / stepInterval;
110
+
111
+ if (Math.abs(minSteps) < Math.abs(maxSteps)) {
112
+ // more above than below
113
+ stepInterval = maxY / Math.floor(maxSteps);
114
+ maxY = stepInterval * Math.floor(maxSteps);
115
+ minY = stepInterval * Math.floor(minSteps);
116
+ } else {
117
+ // more below than above
118
+ stepInterval = Math.abs(minY / Math.ceil(minSteps));
119
+ minY = stepInterval * Math.ceil(minSteps);
120
+ maxY = stepInterval * Math.ceil(maxSteps);
121
+ }
115
122
  }
116
123
  }
117
124
  }
@@ -131,27 +138,37 @@ export var calcs = function calcs(values, options) {
131
138
 
132
139
  // the number of steps is one less than the number of labels
133
140
  var steps = options.steps || [1, 1];
141
+ var stepsX = steps[0],
142
+ stepsY = steps[1];
134
143
  var bounds = options.bounds || calcBounds(values, options);
135
144
  if (options.min !== undefined) bounds[1][0] = options.min;
136
145
  if (options.max !== undefined) bounds[1][1] = options.max;
137
- 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.
146
+ var boundsX = bounds[0],
147
+ boundsY = bounds[1];
148
+ var boundsXmin = boundsX[0],
149
+ boundsXmax = boundsX[1];
150
+ var boundsYmin = boundsY[0],
151
+ boundsYmax = boundsY[1];
152
+ var dimensions = [round(boundsXmax - boundsXmin, 2), round(boundsYmax - boundsYmin, 2)];
153
+ var dimensionsX = dimensions[0],
154
+ dimensionsY = dimensions[1]; // Calculate x and y axis values across the specfied number of steps.
138
155
 
139
156
  var yAxis = [];
140
- var y = bounds[1][1]; // To deal with javascript math limitations, round the step with 4 decimal
157
+ var y = boundsYmax; // To deal with javascript math limitations, round the step with 4 decimal
141
158
  // places and then push the values with 2 decimal places
142
159
 
143
- var yStepInterval = round(dimensions[1] / steps[1], 4);
160
+ var yStepInterval = round(dimensionsY / stepsY, 4);
144
161
 
145
- while (round(y, 2) >= bounds[1][0]) {
162
+ while (round(y, 2) >= boundsYmin) {
146
163
  yAxis.push(round(y, 2));
147
164
  y -= yStepInterval;
148
165
  }
149
166
 
150
167
  var xAxis = [];
151
- var x = bounds[0][0];
152
- var xStepInterval = round(dimensions[0] / steps[0], 4);
168
+ var x = boundsXmin;
169
+ var xStepInterval = round(dimensionsX / stepsX, 4);
153
170
 
154
- while (round(x, 2) <= bounds[0][1]) {
171
+ while (round(x, 2) <= boundsXmax) {
155
172
  xAxis.push(round(x, 2));
156
173
  x += xStepInterval;
157
174
  }
@@ -2,24 +2,28 @@ import React, { useMemo, useState } from 'react';
2
2
  import { Box, Chart, Keyboard, Stack, Text } from 'grommet';
3
3
  import { calcs } from '../calcs';
4
4
  import { generateData } from './data';
5
+ var count = 30,
6
+ max = 100,
7
+ min = 0;
5
8
 
6
- var ScanChart = function ScanChart(props) {
9
+ var ScanChart = function ScanChart() {
7
10
  var _useState = useState(undefined),
8
11
  active = _useState[0],
9
12
  setActive = _useState[1];
10
13
 
11
- var data = props.data,
12
- max = props.max;
14
+ var data = useMemo(function () {
15
+ return generateData(count, max, min);
16
+ }, []);
13
17
  var values = data.map(function (d) {
14
18
  return [d.time, d.value];
15
19
  });
16
20
 
17
21
  var _useMemo = useMemo(function () {
18
22
  return calcs(values, {
19
- min: 0,
23
+ min: min,
20
24
  max: max
21
25
  });
22
- }, [values, max]),
26
+ }, [values]),
23
27
  axis = _useMemo.axis,
24
28
  bounds = _useMemo.bounds,
25
29
  pad = _useMemo.pad,
@@ -145,10 +149,7 @@ var ScanChart = function ScanChart(props) {
145
149
  };
146
150
 
147
151
  export var Scan = function Scan() {
148
- return /*#__PURE__*/React.createElement(ScanChart, {
149
- data: generateData(30, 100),
150
- max: 100
151
- });
152
+ return /*#__PURE__*/React.createElement(ScanChart, null);
152
153
  };
153
154
  Scan.parameters = {
154
155
  chromatic: {
@@ -1,26 +1,25 @@
1
1
  // generate a data set
2
2
  var dataSet = {
3
- generateData: function generateData(count, max) {
4
- var data = [];
5
- var value = max / 2;
6
- var increase = true;
7
- var date = new Date();
3
+ generateData: function generateData(count, max, min) {
4
+ if (count === void 0) {
5
+ count = 5;
6
+ }
8
7
 
9
- while (data.length < count) {
10
- if (increase) {
11
- value += (max - value) % Math.ceil((data.length % (max / 4) + 1) / 2);
8
+ if (max === void 0) {
9
+ max = 100;
10
+ }
12
11
 
13
- if (value >= max) {
14
- increase = false;
15
- }
16
- } else {
17
- value -= value % Math.ceil((data.length % (max / 4) + 1) / 2);
12
+ if (min === void 0) {
13
+ min = 0;
14
+ }
18
15
 
19
- if (value <= 0) {
20
- increase = true;
21
- }
22
- }
16
+ var data = [];
17
+ var date = new Date();
18
+ var span = max - min;
23
19
 
20
+ while (data.length < count) {
21
+ var s = Math.sin(data.length / 2.0);
22
+ var value = s * (span / 2) + (span / 2 + min);
24
23
  var nextDay = date.getDate() - 1;
25
24
  date = new Date(date);
26
25
  date.setDate(nextDay);
@@ -151,7 +151,9 @@ var CheckBox = /*#__PURE__*/forwardRef(function (_ref, ref) {
151
151
  align: "center",
152
152
  justify: "center",
153
153
  margin: label && (_ref2 = {}, _ref2[side] = theme.checkBox.gap || 'small', _ref2)
154
- }, themeableProps), /*#__PURE__*/React.createElement(StyledCheckBoxInput, _extends({}, rest, {
154
+ }, themeableProps), /*#__PURE__*/React.createElement(StyledCheckBoxInput, _extends({
155
+ "aria-label": ariaLabel || a11yTitle
156
+ }, rest, {
155
157
  ref: ref,
156
158
  type: "checkbox"
157
159
  }, removeUndefined({
@@ -180,7 +182,6 @@ var CheckBox = /*#__PURE__*/forwardRef(function (_ref, ref) {
180
182
  var first = reverse ? normalizedLabel : checkBoxNode;
181
183
  var second = reverse ? checkBoxNode : normalizedLabel;
182
184
  return /*#__PURE__*/React.createElement(StyledCheckBoxContainer, _extends({
183
- "aria-label": ariaLabel || a11yTitle,
184
185
  fillProp: fill,
185
186
  reverse: reverse
186
187
  }, removeUndefined({
@@ -6,9 +6,8 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
6
6
 
7
7
  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; }
8
8
 
9
- import React, { forwardRef, useContext, useMemo, useRef, useState } from 'react';
9
+ import React, { forwardRef, useContext, useMemo, useState } from 'react';
10
10
  import { ThemeContext } from 'styled-components';
11
- import { useLayoutEffect } from '../../utils/use-isomorphic-layout-effect';
12
11
  import { Box } from '../Box';
13
12
  import { Chart, calcs, calcBounds } from '../Chart';
14
13
  import { Grid } from '../Grid';
@@ -60,12 +59,9 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
60
59
 
61
60
  var _useState = useState(),
62
61
  activeProperty = _useState[0],
63
- setActiveProperty = _useState[1]; // refs used for ie11 not having Grid
62
+ setActiveProperty = _useState[1]; // normalize seriesProp to an array of objects, one per property
64
63
 
65
64
 
66
- var xRef = useRef();
67
- var spacerRef = useRef(); // normalize seriesProp to an array of objects, one per property
68
-
69
65
  var series = useMemo(function () {
70
66
  if (Array.isArray(seriesProp)) return seriesProp.filter(function (s) {
71
67
  return s.property || typeof s === 'string';
@@ -521,14 +517,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
521
517
  }
522
518
  });
523
519
  return result;
524
- }, [axis, data, series]); // for ie11, align the spacer Box height to the x-axis height
525
-
526
- useLayoutEffect(function () {
527
- if (xRef.current && spacerRef.current) {
528
- var rect = xRef.current.getBoundingClientRect();
529
- spacerRef.current.style.height = rect.height + "px";
530
- }
531
- }, []);
520
+ }, [axis, data, series]);
532
521
 
533
522
  var renderValue = function renderValue(serie, dataIndex, valueArg) {
534
523
  var value;
@@ -554,7 +543,6 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
554
543
 
555
544
 
556
545
  var xAxisElement = axis && axis.x && chartProps.length ? /*#__PURE__*/React.createElement(XAxis, {
557
- ref: xRef,
558
546
  axis: axis,
559
547
  values: (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis[0],
560
548
  pad: offsetPad ? _extends({}, pad, {
@@ -664,6 +652,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
664
652
  activeProperty: activeProperty,
665
653
  axis: axis,
666
654
  data: data,
655
+ pad: pad,
667
656
  series: series,
668
657
  seriesStyles: seriesStyles,
669
658
  renderValue: renderValue,
@@ -1,12 +1,11 @@
1
- import React, { Fragment, useCallback, useMemo, useRef, useState } from 'react';
2
- import styled from 'styled-components';
1
+ import React, { Fragment, useCallback, useContext, useMemo, useRef, useState } from 'react';
2
+ import styled, { ThemeContext } from 'styled-components';
3
3
  import { Box } from '../Box';
4
4
  import { Drop } from '../Drop';
5
5
  import { Grid } from '../Grid';
6
6
  import { Keyboard } from '../Keyboard';
7
7
  import { Text } from '../Text';
8
- import { focusStyle, unfocusStyle } from '../../utils';
9
- import { halfPad } from './utils';
8
+ import { focusStyle, parseMetricToNum, unfocusStyle } from '../../utils';
10
9
  import { Swatch } from './Swatch';
11
10
  var DetailControl = styled(Box).withConfig({
12
11
  displayName: "Detail__DetailControl",
@@ -17,11 +16,12 @@ var Detail = function Detail(_ref) {
17
16
  var activeProperty = _ref.activeProperty,
18
17
  axis = _ref.axis,
19
18
  data = _ref.data,
20
- pad = _ref.pad,
19
+ padProp = _ref.pad,
21
20
  series = _ref.series,
22
21
  seriesStyles = _ref.seriesStyles,
23
22
  renderValue = _ref.renderValue,
24
23
  thickness = _ref.thickness;
24
+ var theme = useContext(ThemeContext) || defaultProps.theme;
25
25
 
26
26
  var _useState = useState(),
27
27
  detailIndex = _useState[0],
@@ -31,6 +31,20 @@ var Detail = function Detail(_ref) {
31
31
  var detailRefs = useMemo(function () {
32
32
  return [];
33
33
  }, []);
34
+ var pad = useMemo(function () {
35
+ // ensure the hit targets and center lines align with
36
+ // the data/guide lines
37
+ var horizontal = (padProp == null ? void 0 : padProp.horizontal) || typeof padProp === 'string' && padProp || 0;
38
+ horizontal = theme.global.edgeSize[horizontal] || horizontal;
39
+ horizontal = parseMetricToNum(horizontal);
40
+ var vertical = (padProp == null ? void 0 : padProp.vertical) || typeof padProp === 'string' && padProp || 0;
41
+ vertical = theme.global.edgeSize[vertical] || vertical;
42
+ vertical = parseMetricToNum(vertical);
43
+ return {
44
+ horizontal: horizontal - parseMetricToNum(thickness) / 2 + "px",
45
+ vertical: vertical + "px"
46
+ };
47
+ }, [padProp, theme.global.edgeSize, thickness]);
34
48
  var onMouseLeave = useCallback(function (event) {
35
49
  // Only remove detail if the mouse isn't over the active index.
36
50
  // This helps distinguish leaving the drop on the edge where it is
@@ -54,11 +68,7 @@ var Detail = function Detail(_ref) {
54
68
  tabIndex: 0,
55
69
  direction: "row",
56
70
  fill: true,
57
- pad: // ensure the hit targets and center lines align with
58
- // the data/guide lines
59
- (pad == null ? void 0 : pad.horizontal) && halfPad[pad.horizontal] && {
60
- horizontal: halfPad[pad.horizontal]
61
- } || pad,
71
+ pad: pad,
62
72
  justify: "between",
63
73
  responsive: false,
64
74
  onFocus: function onFocus() {},
@@ -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
+ };