grommet 2.20.1 → 2.21.0

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 (167) hide show
  1. package/components/Button/Button.js +2 -3
  2. package/components/Chart/Chart.js +14 -6
  3. package/components/DataChart/DataChart.js +84 -21
  4. package/components/DataChart/Detail.js +8 -0
  5. package/components/DataChart/XAxis.js +19 -10
  6. package/components/DataChart/index.d.ts +10 -2
  7. package/components/DataChart/propTypes.js +2 -1
  8. package/components/DataChart/stories/Offset.js +82 -0
  9. package/components/DataChart/stories/StackedAreas.js +77 -0
  10. package/components/DataChart/stories/StackedLines.js +73 -0
  11. package/components/DateInput/DateInput.js +21 -9
  12. package/components/DateInput/index.d.ts +1 -0
  13. package/components/DateInput/propTypes.js +1 -0
  14. package/components/List/List.js +11 -2
  15. package/components/List/index.d.ts +1 -0
  16. package/components/List/propTypes.js +1 -0
  17. package/components/Markdown/Markdown.js +4 -2
  18. package/components/Menu/Menu.js +39 -12
  19. package/components/Notification/Notification.js +17 -6
  20. package/components/Notification/index.d.ts +7 -1
  21. package/components/Notification/propTypes.js +4 -1
  22. package/components/RangeInput/StyledRangeInput.js +1 -1
  23. package/components/RangeInput/stories/SimpleRange.js +2 -6
  24. package/components/Select/Select.js +44 -12
  25. package/components/Select/SelectContainer.js +22 -6
  26. package/components/Select/stories/ChildrenRender.js +37 -33
  27. package/components/Select/stories/Clear.js +7 -3
  28. package/components/Select/stories/Controlled.js +32 -28
  29. package/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
  30. package/components/Select/stories/Disabled.js +29 -25
  31. package/components/Select/stories/InsideFormField.js +29 -27
  32. package/components/Select/stories/LazyLoadingOptions.js +27 -25
  33. package/components/Select/stories/ManyOptions.js +47 -43
  34. package/components/Select/stories/Multiple.js +25 -21
  35. package/components/Select/stories/ObjectOptions.js +27 -25
  36. package/components/Select/stories/Search.js +62 -58
  37. package/components/Select/stories/Simple.js +26 -22
  38. package/components/Select/stories/Uncontrolled.js +24 -20
  39. package/components/Select/stories/ValueLabel.js +40 -36
  40. package/components/Select/stories/typescript/CreateOption.tsx +34 -30
  41. package/components/Sidebar/stories/Labels.js +25 -19
  42. package/components/Sidebar/stories/typescript/Simple.tsx +17 -12
  43. package/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  44. package/components/SkipLinks/stories/Simple.js +82 -78
  45. package/components/Tab/Tab.js +6 -1
  46. package/components/Table/stories/Default.js +30 -28
  47. package/components/Table/stories/InfiniteScrollInTable.js +39 -35
  48. package/components/Table/stories/MeterInTable.js +26 -24
  49. package/components/Tag/Tag.js +17 -6
  50. package/components/Tag/index.d.ts +8 -0
  51. package/components/Tag/propTypes.js +2 -1
  52. package/components/Tag/stories/Size.js +45 -0
  53. package/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  54. package/components/TextArea/stories/Fill.js +18 -16
  55. package/components/TextArea/stories/InsideFormField.js +43 -41
  56. package/components/TextArea/stories/NonResizable.js +13 -11
  57. package/components/TextArea/stories/Simple.js +13 -11
  58. package/components/TextInput/TextInput.js +5 -8
  59. package/{es6/components/TextInput/stories/typescript → components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
  60. package/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  61. package/components/TextInput/stories/DefaultSuggestion.js +20 -19
  62. package/components/TextInput/stories/Icon.js +22 -21
  63. package/components/TextInput/stories/InsideFormField.js +32 -30
  64. package/components/TextInput/stories/OnSelect.js +20 -19
  65. package/components/TextInput/stories/Password.js +30 -29
  66. package/components/TextInput/stories/Simple.js +17 -16
  67. package/components/TextInput/stories/StyledPlaceholder.js +10 -9
  68. package/components/TextInput/stories/Suggestions.js +19 -18
  69. package/components/TextInput/stories/Uncontrolled.js +18 -17
  70. package/components/TextInput/stories/WithTags.js +19 -18
  71. package/components/Tip/stories/Caret.js +37 -31
  72. package/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
  73. package/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
  74. package/components/Tip/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
  75. package/components/Tip/stories/HeaderActions.js +66 -60
  76. package/components/Tip/stories/InfoTip.js +59 -56
  77. package/components/Tip/stories/typescript/Animated.tsx +26 -21
  78. package/components/Tip/stories/typescript/Children.tsx +52 -51
  79. package/components/Tip/stories/typescript/Simple.tsx +12 -7
  80. package/es6/components/Button/Button.js +2 -3
  81. package/es6/components/Chart/Chart.js +14 -6
  82. package/es6/components/DataChart/DataChart.js +84 -21
  83. package/es6/components/DataChart/Detail.js +7 -0
  84. package/es6/components/DataChart/XAxis.js +19 -10
  85. package/es6/components/DataChart/index.d.ts +10 -2
  86. package/es6/components/DataChart/propTypes.js +2 -1
  87. package/es6/components/DataChart/stories/Offset.js +70 -0
  88. package/es6/components/DataChart/stories/StackedAreas.js +65 -0
  89. package/es6/components/DataChart/stories/StackedLines.js +61 -0
  90. package/es6/components/DateInput/DateInput.js +21 -9
  91. package/es6/components/DateInput/index.d.ts +1 -0
  92. package/es6/components/DateInput/propTypes.js +1 -0
  93. package/es6/components/List/List.js +11 -2
  94. package/es6/components/List/index.d.ts +1 -0
  95. package/es6/components/List/propTypes.js +1 -0
  96. package/es6/components/Markdown/Markdown.js +4 -2
  97. package/es6/components/Menu/Menu.js +40 -13
  98. package/es6/components/Notification/Notification.js +18 -7
  99. package/es6/components/Notification/index.d.ts +7 -1
  100. package/es6/components/Notification/propTypes.js +4 -1
  101. package/es6/components/RangeInput/StyledRangeInput.js +1 -1
  102. package/es6/components/RangeInput/stories/SimpleRange.js +3 -6
  103. package/es6/components/Select/Select.js +44 -12
  104. package/es6/components/Select/SelectContainer.js +22 -6
  105. package/es6/components/Select/stories/ChildrenRender.js +38 -33
  106. package/es6/components/Select/stories/Clear.js +8 -4
  107. package/es6/components/Select/stories/Controlled.js +33 -28
  108. package/es6/components/Select/stories/{CustomSearch.js → CustomThemed/CustomSearch.js} +2 -2
  109. package/es6/components/Select/stories/Disabled.js +30 -25
  110. package/es6/components/Select/stories/InsideFormField.js +30 -27
  111. package/es6/components/Select/stories/LazyLoadingOptions.js +28 -25
  112. package/es6/components/Select/stories/ManyOptions.js +48 -43
  113. package/es6/components/Select/stories/Multiple.js +26 -21
  114. package/es6/components/Select/stories/ObjectOptions.js +28 -25
  115. package/es6/components/Select/stories/Search.js +63 -58
  116. package/es6/components/Select/stories/Simple.js +27 -22
  117. package/es6/components/Select/stories/Uncontrolled.js +25 -20
  118. package/es6/components/Select/stories/ValueLabel.js +41 -36
  119. package/es6/components/Select/stories/typescript/CreateOption.tsx +34 -30
  120. package/es6/components/Sidebar/stories/Labels.js +26 -20
  121. package/es6/components/Sidebar/stories/typescript/Simple.tsx +17 -12
  122. package/es6/components/SkipLinks/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  123. package/es6/components/SkipLinks/stories/Simple.js +83 -79
  124. package/es6/components/Tab/Tab.js +6 -1
  125. package/es6/components/Table/stories/Default.js +31 -28
  126. package/es6/components/Table/stories/InfiniteScrollInTable.js +40 -36
  127. package/es6/components/Table/stories/MeterInTable.js +27 -24
  128. package/es6/components/Tag/Tag.js +17 -6
  129. package/es6/components/Tag/index.d.ts +8 -0
  130. package/es6/components/Tag/propTypes.js +2 -1
  131. package/es6/components/Tag/stories/Size.js +33 -0
  132. package/es6/components/TextArea/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  133. package/es6/components/TextArea/stories/Fill.js +19 -16
  134. package/es6/components/TextArea/stories/InsideFormField.js +44 -41
  135. package/es6/components/TextArea/stories/NonResizable.js +14 -11
  136. package/es6/components/TextArea/stories/Simple.js +14 -11
  137. package/es6/components/TextInput/TextInput.js +5 -8
  138. package/{components/TextInput/stories/typescript → es6/components/TextInput/stories/CustomThemed}/CustomSuggestions.tsx +1 -1
  139. package/es6/components/TextInput/stories/{Themed.js → CustomThemed/Themed.js} +1 -1
  140. package/es6/components/TextInput/stories/DefaultSuggestion.js +21 -19
  141. package/es6/components/TextInput/stories/Icon.js +23 -21
  142. package/es6/components/TextInput/stories/InsideFormField.js +33 -30
  143. package/es6/components/TextInput/stories/OnSelect.js +21 -19
  144. package/es6/components/TextInput/stories/Password.js +31 -29
  145. package/es6/components/TextInput/stories/Simple.js +18 -16
  146. package/es6/components/TextInput/stories/StyledPlaceholder.js +11 -9
  147. package/es6/components/TextInput/stories/Suggestions.js +20 -18
  148. package/es6/components/TextInput/stories/Uncontrolled.js +19 -17
  149. package/es6/components/TextInput/stories/WithTags.js +20 -18
  150. package/es6/components/Tip/stories/Caret.js +38 -32
  151. package/es6/components/Tip/stories/{ResponsiveTip.js → CustomThemed/ResponsiveTip.js} +1 -1
  152. package/es6/components/Tip/stories/{SidebarTip.js → CustomThemed/SidebarTip.js} +1 -1
  153. package/es6/components/Tip/stories/{typescript → CustomThemed}/Themed.tsx +1 -1
  154. package/es6/components/Tip/stories/HeaderActions.js +67 -61
  155. package/es6/components/Tip/stories/InfoTip.js +60 -57
  156. package/es6/components/Tip/stories/typescript/Animated.tsx +26 -21
  157. package/es6/components/Tip/stories/typescript/Children.tsx +52 -51
  158. package/es6/components/Tip/stories/typescript/Simple.tsx +12 -7
  159. package/es6/languages/default.json +2 -1
  160. package/es6/themes/base.d.ts +34 -1
  161. package/es6/themes/base.js +39 -0
  162. package/grommet.min.js +1 -1
  163. package/grommet.min.js.map +1 -1
  164. package/languages/default.json +2 -1
  165. package/package.json +4 -4
  166. package/themes/base.d.ts +34 -1
  167. package/themes/base.js +39 -0
@@ -138,8 +138,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
138
138
  icon = _ref.icon,
139
139
  _ref$focusIndicator = _ref.focusIndicator,
140
140
  focusIndicator = _ref$focusIndicator === void 0 ? true : _ref$focusIndicator,
141
- _ref$gap = _ref.gap,
142
- gap = _ref$gap === void 0 ? 'small' : _ref$gap,
141
+ gap = _ref.gap,
143
142
  fill = _ref.fill,
144
143
  href = _ref.href,
145
144
  justify = _ref.justify,
@@ -284,7 +283,7 @@ var Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
284
283
  direction: "row",
285
284
  align: "center",
286
285
  justify: justify || (align === 'center' ? 'center' : 'between'),
287
- gap: gap,
286
+ gap: gap || theme.button.gap,
288
287
  responsive: false
289
288
  }, first, second);
290
289
  } else if (typeof children === 'function') {
@@ -84,16 +84,24 @@ var Chart = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
84
84
 
85
85
  if (pad) {
86
86
  if (pad.horizontal) {
87
- var padSize = (0, _utils.parseMetricToNum)(theme.global.edgeSize[pad.horizontal]);
88
- result[0] += padSize;
89
- result[2] += padSize;
87
+ var padSize = (0, _utils.parseMetricToNum)(theme.global.edgeSize[pad.horizontal] || pad.horizontal);
88
+ result[0] = padSize;
89
+ result[2] = padSize;
90
90
  }
91
91
 
92
92
  if (pad.vertical) {
93
- var _padSize = (0, _utils.parseMetricToNum)(theme.global.edgeSize[pad.vertical]);
93
+ var _padSize = (0, _utils.parseMetricToNum)(theme.global.edgeSize[pad.vertical] || pad.vertical);
94
94
 
95
- result[1] += _padSize;
96
- result[3] += _padSize;
95
+ result[1] = _padSize;
96
+ result[3] = _padSize;
97
+ }
98
+
99
+ if (pad.start) {
100
+ result[0] = (0, _utils.parseMetricToNum)(theme.global.edgeSize[pad.start] || pad.start);
101
+ }
102
+
103
+ if (pad.end) {
104
+ result[2] = (0, _utils.parseMetricToNum)(theme.global.edgeSize[pad.end] || pad.end);
97
105
  }
98
106
 
99
107
  if (typeof pad === 'string') {
@@ -35,8 +35,9 @@ var _utils2 = require("./utils");
35
35
 
36
36
  var _propTypes = require("./propTypes");
37
37
 
38
- var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "gap", "guide", "legend", "pad", "series", "size"],
39
- _excluded2 = ["property", "type", "x", "y"];
38
+ var _excluded = ["a11yTitle", "axis", "bounds", "chart", "data", "detail", "gap", "guide", "legend", "offset", "pad", "series", "size"],
39
+ _excluded2 = ["property", "type", "x", "y"],
40
+ _excluded3 = ["property"];
40
41
 
41
42
  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); }
42
43
 
@@ -46,11 +47,16 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
46
47
 
47
48
  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; }
48
49
 
49
- // DataChart takes a generic data array of objects plus as few properties
50
+ var stackedChartType = {
51
+ areas: 'area',
52
+ bars: 'bar',
53
+ lines: 'line'
54
+ }; // DataChart takes a generic data array of objects plus as few properties
50
55
  // as possible, and creates a Stack of Charts with x and y axes, a legend,
51
56
  // and interactive detail.
52
57
  // Much of the code here-in involves the "few properties" aspect where we
53
58
  // normalize and automatically handle whatever the caller didn't specify.
59
+
54
60
  var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
55
61
  var a11yTitle = _ref.a11yTitle,
56
62
  _ref$axis = _ref.axis,
@@ -65,6 +71,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
65
71
  gap = _ref$gap === void 0 ? 'small' : _ref$gap,
66
72
  guideProp = _ref.guide,
67
73
  legend = _ref.legend,
74
+ offset = _ref.offset,
68
75
  padProp = _ref.pad,
69
76
  seriesProp = _ref.series,
70
77
  size = _ref.size,
@@ -102,7 +109,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
102
109
  });
103
110
  }; // Normalize chart to an array of objects.
104
111
  // Each chart has one or more properties associated with it.
105
- // A stacked bar chart has an array of properties.
112
+ // A stacked bar or area chart has an array of properties.
106
113
  // A point chart can have x, y, thickness, and color each driven
107
114
  // by a separate property.
108
115
 
@@ -160,10 +167,11 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
160
167
 
161
168
  if (property) {
162
169
  if (Array.isArray(property)) {
163
- // A range chart or a stacked bar chart have multiple properties.
170
+ // A range chart or a stacked bar or area chart has multiple
171
+ // properties.
164
172
  // In this case, this returns an array of values,
165
173
  // one per property.
166
- if (type === 'bars') {
174
+ if (stackedChartType[type]) {
167
175
  // Further down, where we render, each property is rendered
168
176
  // using a separate Chart component and the values are stacked
169
177
  // such that they line up appropriately.
@@ -177,6 +185,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
177
185
  return values.map(function (v, i) {
178
186
  var base = totals[i] || 0;
179
187
  totals[i] = base + v;
188
+ if (type === 'lines') return [i, base + v];
180
189
  return [i, base, base + v];
181
190
  });
182
191
  });
@@ -312,15 +321,20 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
312
321
  } else steps[1] = 1;
313
322
 
314
323
  var chartBounds = chartValues.map(function (_, index) {
315
- if (charts[index].type === 'bars') {
316
- // merge values for bars case
317
- var mergedValues = chartValues[index][0].slice(0);
318
- chartValues[index].slice(1).filter(function (values) {
324
+ var type = charts[index].type;
325
+
326
+ if (stackedChartType[type]) {
327
+ var _chartValues$index, _chartValues$index$;
328
+
329
+ // merge values for bars, areas, and lines cases
330
+ var mergedValues = ((_chartValues$index = chartValues[index]) == null ? void 0 : (_chartValues$index$ = _chartValues$index[0]) == null ? void 0 : _chartValues$index$.slice(0)) || [];
331
+ chartValues[index].slice(1) // skip first index as that is the x value
332
+ .filter(function (values) {
319
333
  return values;
320
334
  }) // property name isn't valid
321
335
  .forEach(function (values) {
322
336
  mergedValues = mergedValues.map(function (__, i) {
323
- return [i, Math.min(mergedValues[i][1], values[i][1]), Math.max(mergedValues[i][2], values[i][2])];
337
+ return type === 'lines' ? [i, Math.min(mergedValues[i][1], values[i][1]), Math.max(mergedValues[i][1], values[i][1])] : [i, Math.min(mergedValues[i][1], values[i][1]), Math.max(mergedValues[i][2], values[i][2])];
324
338
  });
325
339
  });
326
340
  return (0, _Chart.calcBounds)(mergedValues, {
@@ -350,10 +364,14 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
350
364
  }
351
365
 
352
366
  return chartValues.map(function (values, index) {
353
- var calcValues = charts[index].type === 'bars' ? values[0] : values;
367
+ var _charts$index = charts[index],
368
+ thickness = _charts$index.thickness,
369
+ type = _charts$index.type;
370
+ var calcValues = stackedChartType[type] ? values[0] : values;
354
371
  return (0, _Chart.calcs)(calcValues, {
355
372
  bounds: chartBounds[index],
356
- steps: steps
373
+ steps: steps,
374
+ thickness: thickness
357
375
  });
358
376
  });
359
377
  }, [axis, boundsProp, charts, chartValues, data, granularities]); // normalize how we style data properties for use by Legend and Detail
@@ -443,6 +461,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
443
461
 
444
462
  return result;
445
463
  }, [axis, granularities, guideProp]); // set the pad to half the thickness, based on the chart types
464
+ // except when using offset, then add even more horizontal pad
446
465
 
447
466
  var pad = (0, _react.useMemo)(function () {
448
467
  if (padProp !== undefined) return padProp;
@@ -454,7 +473,31 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
454
473
  if (type && type !== 'bar') result.vertical = _utils2.halfPad[thickness];
455
474
  });
456
475
  return result;
457
- }, [chartProps, charts, padProp]); // The thickness of the Detail segments. We need to convert to numbers
476
+ }, [chartProps, charts, padProp]); // calculate the thickness in pixels of each chart
477
+
478
+ var thicknesses = (0, _react.useMemo)(function () {
479
+ return offset ? charts.map(function (_, index) {
480
+ var thickness = chartProps[index].thickness;
481
+ return (0, _utils.parseMetricToNum)(theme.global.edgeSize[thickness] || thickness);
482
+ }) : undefined;
483
+ }, [charts, chartProps, offset, theme]); // calculate the offset for each chart, which is a sum of the thicknesses
484
+ // that preceded it
485
+
486
+ var offsets = (0, _react.useMemo)(function () {
487
+ return offset ? thicknesses.map(function (t, i) {
488
+ return thicknesses.slice(0, i).reduce(function (a, b) {
489
+ return a + b;
490
+ }, 0);
491
+ }) : undefined;
492
+ }, [offset, thicknesses]); // Calculate the total pad we should add to the end of each chart.
493
+ // We do this to shrink the width of each chart so we can shift them
494
+ // via `translate` and have them take up the right amount of width.
495
+
496
+ var offsetPad = (0, _react.useMemo)(function () {
497
+ return offset ? thicknesses.reduce(function (a, b) {
498
+ return a + b;
499
+ }, 0) + "px" : undefined;
500
+ }, [offset, thicknesses]); // The thickness of the Detail segments. We need to convert to numbers
458
501
  // to be able to compare across charts where some might be using T-shirt
459
502
  // labels and others might be pixel values.
460
503
 
@@ -518,7 +561,7 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
518
561
  ref: xRef,
519
562
  axis: axis,
520
563
  chartProps: chartProps,
521
- data: data,
564
+ pad: pad,
522
565
  renderValue: renderValue,
523
566
  serie: axis.x.property && getPropertySeries(axis.x.property)
524
567
  }) : null;
@@ -559,20 +602,39 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
559
602
  y = _ref9.y,
560
603
  chartRest = _objectWithoutPropertiesLoose(_ref9, _excluded2);
561
604
 
562
- if (type === 'bars') {
605
+ // When we offset, we increase the padding on the end for all charts
606
+ // by the same amount and we shift each successive chart to the
607
+ // right by an offset for that chart. The last chart's right side
608
+ // will end up aligning with where the charts would have been
609
+ // had we not padded their ends.
610
+ var chartPad = offsetPad ? _extends({}, pad, {
611
+ end: offsetPad
612
+ }) : pad;
613
+ var offsetProps = offsetPad ? {
614
+ style: {
615
+ transform: "translate(" + offsets[i] + "px, 0px)"
616
+ }
617
+ } : {};
618
+
619
+ if (stackedChartType[type]) {
563
620
  // reverse to ensure area Charts are stacked in the right order
564
621
  return prop.map(function (cProp, j) {
565
622
  var pProp = cProp.property || cProp;
623
+
624
+ var _ref10 = typeof cProp === 'object' ? cProp : {},
625
+ property = _ref10.property,
626
+ propRest = _objectWithoutPropertiesLoose(_ref10, _excluded3);
627
+
566
628
  return /*#__PURE__*/_react["default"].createElement(_Chart.Chart // eslint-disable-next-line react/no-array-index-key
567
629
  , _extends({
568
630
  key: j // when property name isn't valid, send empty array
569
631
  ,
570
632
  values: chartValues[i][j] || [],
571
633
  overflow: true
572
- }, seriesStyles[pProp], chartProps[i], chartRest, {
573
- type: "bar",
634
+ }, seriesStyles[pProp], chartProps[i], chartRest, propRest, offsetProps, {
635
+ type: stackedChartType[type] || type,
574
636
  size: size,
575
- pad: pad
637
+ pad: chartPad
576
638
  }));
577
639
  }).reverse();
578
640
  }
@@ -582,15 +644,16 @@ var DataChart = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
582
644
  key: i,
583
645
  values: chartValues[i],
584
646
  overflow: true
585
- }, seriesStyles[prop], chartProps[i], chartRest, {
647
+ }, seriesStyles[prop], chartProps[i], chartRest, offsetProps, {
586
648
  type: type,
587
649
  size: size,
588
- pad: pad
650
+ pad: chartPad
589
651
  }));
590
652
  }), detail && /*#__PURE__*/_react["default"].createElement(_Detail.Detail, {
591
653
  activeProperty: activeProperty,
592
654
  axis: axis,
593
655
  data: data,
656
+ pad: pad,
594
657
  series: series,
595
658
  seriesStyles: seriesStyles,
596
659
  renderValue: renderValue,
@@ -19,6 +19,8 @@ var _Text = require("../Text");
19
19
 
20
20
  var _utils = require("../../utils");
21
21
 
22
+ var _utils2 = require("./utils");
23
+
22
24
  var _Swatch = require("./Swatch");
23
25
 
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -36,6 +38,7 @@ var Detail = function Detail(_ref) {
36
38
  var activeProperty = _ref.activeProperty,
37
39
  axis = _ref.axis,
38
40
  data = _ref.data,
41
+ pad = _ref.pad,
39
42
  series = _ref.series,
40
43
  seriesStyles = _ref.seriesStyles,
41
44
  renderValue = _ref.renderValue,
@@ -72,6 +75,11 @@ var Detail = function Detail(_ref) {
72
75
  tabIndex: 0,
73
76
  direction: "row",
74
77
  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,
75
83
  justify: "between",
76
84
  responsive: false,
77
85
  onFocus: function onFocus() {},
@@ -11,30 +11,39 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
11
11
 
12
12
  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; }
13
13
 
14
+ function _extends() { _extends = Object.assign || 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); }
15
+
14
16
  var XAxis = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
15
17
  var chartProps = _ref.chartProps,
16
- data = _ref.data,
18
+ pad = _ref.pad,
17
19
  renderValue = _ref.renderValue,
18
20
  serie = _ref.serie;
19
21
  // pull the x-axis values from the first chart, all should have the same
20
22
  var _axis = (Array.isArray(chartProps[0]) ? chartProps[0][0] : chartProps[0]).axis,
21
- axisValues = _axis[0];
23
+ axisValues = _axis[0]; // When there are only labels at the end of the axis, let them take as much
24
+ // space as they like. If there are more, align their container to the
25
+ // data/guide lines and then let their content overflow that.
26
+
27
+ var itemProps = axisValues.length === 2 ? {} : {
28
+ width: '1px',
29
+ overflow: 'visible',
30
+ align: 'center'
31
+ };
22
32
  return /*#__PURE__*/_react["default"].createElement(_Box.Box, {
23
33
  ref: ref,
24
34
  gridArea: "xAxis",
25
35
  direction: "row",
26
- justify: "between"
36
+ justify: "between",
37
+ pad: pad != null && pad.horizontal ? {
38
+ horizontal: pad.horizontal
39
+ } : undefined
27
40
  }, axisValues.map(function (dataIndex, i) {
28
- var align;
29
- if (axisValues.length === data.length) align = 'center';else if (i === 0) align = 'start';else if (i === axisValues.length - 1) align = 'end';else align = 'center';
30
41
  return (
31
42
  /*#__PURE__*/
32
43
  // eslint-disable-next-line react/no-array-index-key
33
- _react["default"].createElement(_Box.Box, {
34
- key: i,
35
- flex: true,
36
- align: align
37
- }, serie ? renderValue(serie, dataIndex) : dataIndex)
44
+ _react["default"].createElement(_Box.Box, _extends({
45
+ key: i
46
+ }, itemProps), serie ? renderValue(serie, dataIndex) : dataIndex)
38
47
  );
39
48
  }));
40
49
  });
@@ -14,7 +14,12 @@ type ChartType =
14
14
  property:
15
15
  | string
16
16
  | string[]
17
- | { property?: string; color: string }[]
17
+ | {
18
+ property: string;
19
+ color?: string;
20
+ opacity?: string;
21
+ thickness?: string;
22
+ }[]
18
23
  | {
19
24
  color?:
20
25
  | string
@@ -33,7 +38,7 @@ type ChartType =
33
38
  };
34
39
  round?: ChartProps['round']; // defaults to undefined
35
40
  thickness?: ChartProps['thickness']; // defaults to auto assigned based on available space and amount of data
36
- type?: ChartProps['type'] | 'bars'; // defaults to 'bar',
41
+ type?: ChartProps['type'] | 'bars' | 'areas' | 'lines'; // defaults to 'bar',
37
42
  };
38
43
 
39
44
  type SeriesType =
@@ -87,6 +92,9 @@ export interface DataChartProps {
87
92
  };
88
93
  // legend - when true, { side: 'bottom' }
89
94
  legend?: boolean | { side: 'left' | 'right' | 'bottom' };
95
+ // offset - whether to shift the charts to reveal them all, mostly useful
96
+ // for bar charts
97
+ offset?: boolean;
90
98
  // pad - padding around the guides/visuals
91
99
  // defaults to what's needed based on axis and chart types
92
100
  pad?: GridProps['pad'];
@@ -40,7 +40,7 @@ var chartType = _propTypes["default"].oneOfType([_propTypes["default"].string, _
40
40
  point: _generalPropTypes.pointPropType,
41
41
  round: _propTypes["default"].bool,
42
42
  thickness: thicknessType,
43
- type: _propTypes["default"].oneOf(['bar', 'bars', 'line', 'area', 'point'])
43
+ type: _propTypes["default"].oneOf(['bar', 'bars', 'line', 'area', 'areas', 'lines', 'point'])
44
44
  })]);
45
45
 
46
46
  var seriesType = _propTypes["default"].oneOfType([_propTypes["default"].string, // property
@@ -82,6 +82,7 @@ if (process.env.NODE_ENV !== 'production') {
82
82
  })])
83
83
  })]),
84
84
  legend: _propTypes["default"].bool,
85
+ offset: _propTypes["default"].bool,
85
86
  pad: _generalPropTypes.padPropType,
86
87
  series: _propTypes["default"].oneOfType([seriesType, _propTypes["default"].arrayOf(seriesType)]),
87
88
  size: _propTypes["default"].oneOfType([_propTypes["default"].oneOf(['fill']), _propTypes["default"].shape({
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports["default"] = exports.Offset = 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 = 0; i < 7; i += 1) {
15
+ data.push({
16
+ date: "2020-07-" + (i % 31 + 1).toString().padStart(2, 0),
17
+ usage: Math.floor(Math.abs(Math.sin(i / 2.0) * 100)),
18
+ bonus: Math.floor(Math.abs(Math.cos(i / 2.0) * 100)),
19
+ over: Math.floor(Math.abs(Math.sin(i / 2.0) * 50))
20
+ });
21
+ }
22
+
23
+ var Offset = function Offset() {
24
+ return (
25
+ /*#__PURE__*/
26
+ // Uncomment <Grommet> lines when using outside of storybook
27
+ // <Grommet theme={grommet}>
28
+ _react["default"].createElement(_grommet.Box, {
29
+ align: "center",
30
+ justify: "start",
31
+ pad: "large"
32
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.DataChart, {
33
+ data: data,
34
+ series: [{
35
+ property: 'date',
36
+ render: function render(date) {
37
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Text, {
38
+ margin: {
39
+ horizontal: 'xsmall'
40
+ }
41
+ }, new Date(date).toLocaleDateString('en-US', {
42
+ month: 'numeric',
43
+ day: 'numeric'
44
+ }));
45
+ }
46
+ }, 'usage', 'bonus', 'over'],
47
+ chart: [{
48
+ property: 'usage',
49
+ type: 'bar',
50
+ thickness: 'small'
51
+ }, {
52
+ property: 'bonus',
53
+ type: 'bar',
54
+ thickness: 'small'
55
+ }, {
56
+ property: 'over',
57
+ type: 'bar',
58
+ thickness: 'small'
59
+ }],
60
+ offset: true,
61
+ axis: {
62
+ x: {
63
+ property: 'date',
64
+ granularity: 'fine'
65
+ },
66
+ y: true
67
+ },
68
+ guide: {
69
+ y: true
70
+ },
71
+ legend: true
72
+ })) // </Grommet>
73
+
74
+ );
75
+ };
76
+
77
+ exports.Offset = Offset;
78
+ Offset.storyName = 'Offset';
79
+ var _default = {
80
+ title: 'Visualizations/DataChart/Offset'
81
+ };
82
+ exports["default"] = _default;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports["default"] = exports.StackedAreas = 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 = 0; i < 7; i += 1) {
15
+ data.push({
16
+ date: "2020-07-" + (i % 31 + 1).toString().padStart(2, 0),
17
+ usage: Math.floor(Math.abs(Math.sin(i / 2.0) * 100)),
18
+ bonus: Math.floor(Math.abs(Math.cos(i / 2.0) * 100))
19
+ });
20
+ }
21
+
22
+ var StackedAreas = function StackedAreas() {
23
+ return (
24
+ /*#__PURE__*/
25
+ // Uncomment <Grommet> lines when using outside of storybook
26
+ // <Grommet theme={grommet}>
27
+ _react["default"].createElement(_grommet.Box, {
28
+ align: "center",
29
+ justify: "start",
30
+ pad: "large"
31
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.DataChart, {
32
+ data: data,
33
+ series: [{
34
+ property: 'date',
35
+ render: function render(date) {
36
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Text, {
37
+ margin: {
38
+ horizontal: 'xsmall'
39
+ }
40
+ }, new Date(date).toLocaleDateString('en-US', {
41
+ month: 'numeric',
42
+ day: 'numeric'
43
+ }));
44
+ }
45
+ }, 'usage', 'bonus'],
46
+ chart: [{
47
+ property: [{
48
+ property: 'usage',
49
+ opacity: 'strong'
50
+ }, 'bonus'],
51
+ type: 'areas',
52
+ thickness: 'hair'
53
+ }],
54
+ axis: {
55
+ x: {
56
+ property: 'date',
57
+ granularity: 'fine'
58
+ },
59
+ y: true
60
+ },
61
+ guide: {
62
+ y: {
63
+ granularity: 'medium'
64
+ }
65
+ },
66
+ legend: true
67
+ })) // </Grommet>
68
+
69
+ );
70
+ };
71
+
72
+ exports.StackedAreas = StackedAreas;
73
+ StackedAreas.storyName = 'Stacked areas';
74
+ var _default = {
75
+ title: 'Visualizations/DataChart/Stacked areas'
76
+ };
77
+ exports["default"] = _default;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports["default"] = exports.StackedLines = 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 = 0; i < 7; i += 1) {
15
+ data.push({
16
+ date: "2020-07-" + (i % 31 + 1).toString().padStart(2, 0),
17
+ usage: Math.floor(Math.abs(Math.sin(i / 2.0) * 100)),
18
+ bonus: Math.floor(Math.abs(Math.cos(i / 2.0) * 100))
19
+ });
20
+ }
21
+
22
+ var StackedLines = function StackedLines() {
23
+ return (
24
+ /*#__PURE__*/
25
+ // Uncomment <Grommet> lines when using outside of storybook
26
+ // <Grommet theme={grommet}>
27
+ _react["default"].createElement(_grommet.Box, {
28
+ align: "center",
29
+ justify: "start",
30
+ pad: "large"
31
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.DataChart, {
32
+ data: data,
33
+ series: [{
34
+ property: 'date',
35
+ render: function render(date) {
36
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Text, {
37
+ margin: {
38
+ horizontal: 'xsmall'
39
+ }
40
+ }, new Date(date).toLocaleDateString('en-US', {
41
+ month: 'numeric',
42
+ day: 'numeric'
43
+ }));
44
+ }
45
+ }, 'usage', 'bonus'],
46
+ chart: [{
47
+ property: ['usage', 'bonus'],
48
+ type: 'lines',
49
+ thickness: 'xsmall',
50
+ round: true
51
+ }],
52
+ axis: {
53
+ x: {
54
+ property: 'date',
55
+ granularity: 'fine'
56
+ },
57
+ y: true
58
+ },
59
+ guide: {
60
+ y: true
61
+ },
62
+ legend: true
63
+ })) // </Grommet>
64
+
65
+ );
66
+ };
67
+
68
+ exports.StackedLines = StackedLines;
69
+ StackedLines.storyName = 'Stacked lines';
70
+ var _default = {
71
+ title: 'Visualizations/DataChart/Stacked lines'
72
+ };
73
+ exports["default"] = _default;