grommet 2.25.1 → 2.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Anchor/Anchor.js +14 -1
- package/components/Button/Button.js +82 -9
- package/components/Button/StyledButtonKind.js +9 -3
- package/components/Button/index.d.ts +1 -1
- package/components/Button/propTypes.js +1 -1
- package/components/DataChart/DataChart.js +11 -13
- package/components/DataChart/XAxis.js +29 -18
- package/components/DataTable/DataTable.js +13 -9
- package/components/DataTable/buildState.js +2 -2
- package/components/DataTable/index.d.ts +4 -1
- package/components/DataTable/stories/SpaceX.js +3 -1
- package/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/components/Form/Form.js +72 -4
- package/components/FormField/FormField.js +4 -1
- package/components/Grommet/Grommet.js +7 -2
- package/components/Grommet/index.d.ts +1 -0
- package/components/Grommet/propTypes.js +2 -1
- package/components/Heading/Heading.js +4 -2
- package/components/Heading/StyledHeading.js +1 -1
- package/components/Heading/index.d.ts +1 -0
- package/components/Heading/propTypes.js +2 -1
- package/components/Layer/LayerContainer.js +18 -0
- package/components/Menu/Menu.js +7 -4
- package/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/components/Meter/Circle.js +5 -1
- package/components/PageHeader/PageHeader.js +22 -13
- package/components/PageHeader/index.d.ts +10 -1
- package/components/PageHeader/propTypes.js +1 -0
- package/components/PageHeader/stories/Size.js +55 -0
- package/components/Select/SelectContainer.js +77 -44
- package/components/Select/stories/Clear.js +7 -1
- package/components/Select/utils.js +1 -0
- package/components/Spinner/Spinner.js +1 -0
- package/components/Tab/Tab.js +1 -1
- package/components/Tabs/Tabs.js +9 -1
- package/contexts/AnalyticsContext/AnalyticsContext.js +65 -0
- package/contexts/AnalyticsContext/index.d.ts +7 -0
- package/contexts/AnalyticsContext/index.js +11 -0
- package/contexts/index.js +8 -0
- package/es6/components/Anchor/Anchor.js +14 -2
- package/es6/components/Button/Button.js +83 -11
- package/es6/components/Button/StyledButtonKind.js +9 -3
- package/es6/components/Button/index.d.ts +1 -1
- package/es6/components/Button/propTypes.js +1 -1
- package/es6/components/DataChart/DataChart.js +11 -13
- package/es6/components/DataChart/XAxis.js +29 -19
- package/es6/components/DataTable/DataTable.js +13 -9
- package/es6/components/DataTable/buildState.js +2 -2
- package/es6/components/DataTable/index.d.ts +4 -1
- package/es6/components/DataTable/stories/SpaceX.js +3 -1
- package/es6/components/DataTable/stories/SpaceXUngrouped.js +6 -2
- package/es6/components/Form/Form.js +70 -4
- package/es6/components/FormField/FormField.js +4 -1
- package/es6/components/Grommet/Grommet.js +6 -2
- package/es6/components/Grommet/index.d.ts +1 -0
- package/es6/components/Grommet/propTypes.js +2 -1
- package/es6/components/Heading/Heading.js +4 -2
- package/es6/components/Heading/StyledHeading.js +1 -1
- package/es6/components/Heading/index.d.ts +1 -0
- package/es6/components/Heading/propTypes.js +2 -1
- package/es6/components/Layer/LayerContainer.js +17 -0
- package/es6/components/Menu/Menu.js +7 -4
- package/es6/components/Menu/stories/CustomThemed/Themed.tsx +6 -0
- package/es6/components/Meter/Circle.js +5 -1
- package/es6/components/PageHeader/PageHeader.js +24 -14
- package/es6/components/PageHeader/index.d.ts +10 -1
- package/es6/components/PageHeader/propTypes.js +1 -0
- package/es6/components/PageHeader/stories/Size.js +43 -0
- package/es6/components/Select/SelectContainer.js +76 -45
- package/es6/components/Select/stories/Clear.js +7 -1
- package/es6/components/Select/utils.js +1 -0
- package/es6/components/Spinner/Spinner.js +1 -0
- package/es6/components/Tab/Tab.js +1 -1
- package/es6/components/Tabs/Tabs.js +8 -1
- package/es6/contexts/AnalyticsContext/AnalyticsContext.js +47 -0
- package/es6/contexts/AnalyticsContext/index.d.ts +7 -0
- package/es6/contexts/AnalyticsContext/index.js +1 -0
- package/es6/contexts/index.js +1 -0
- package/es6/themes/base.d.ts +40 -8
- package/es6/themes/base.js +43 -0
- package/es6/utils/mixins.js +3 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +36 -30
- package/themes/base.d.ts +40 -8
- package/themes/base.js +43 -0
- package/tools/pack.js +20 -13
- package/tools/release-stable.js +2 -4
- package/utils/mixins.js +7 -1
|
@@ -4,7 +4,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
|
-
import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState } from 'react';
|
|
7
|
+
import React, { cloneElement, Children, forwardRef, useContext, useMemo, useState, useCallback } from 'react';
|
|
8
8
|
import { ThemeContext } from 'styled-components';
|
|
9
9
|
import { backgroundAndTextColors, colorIsDark, normalizeBackground, normalizeColor } from '../../utils';
|
|
10
10
|
import { defaultProps } from '../../default-props';
|
|
@@ -13,7 +13,8 @@ import { Box } from '../Box';
|
|
|
13
13
|
import { Tip } from '../Tip';
|
|
14
14
|
import { Badge } from './Badge';
|
|
15
15
|
import { StyledButton } from './StyledButton';
|
|
16
|
-
import { StyledButtonKind } from './StyledButtonKind';
|
|
16
|
+
import { StyledButtonKind } from './StyledButtonKind';
|
|
17
|
+
import { useAnalytics } from '../../contexts/AnalyticsContext'; // We have two Styled* components to separate
|
|
17
18
|
// the newer default|primary|secondary approach,
|
|
18
19
|
// which we use the term "kind" to refer to,
|
|
19
20
|
// from the previous approach. Hopefully, when we get to grommet v3,
|
|
@@ -48,7 +49,8 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
|
|
|
48
49
|
if (typeof kind === 'object') index = 0; // stop when we have a color or no more paths
|
|
49
50
|
|
|
50
51
|
while (index >= 0 && !result[1]) {
|
|
51
|
-
var
|
|
52
|
+
var baseObj = typeof kind === 'object' && kind || theme.button;
|
|
53
|
+
var obj = baseObj; // find sub-object under the button theme that corresponds with this path
|
|
52
54
|
// for example: 'active.primary'
|
|
53
55
|
|
|
54
56
|
if (paths[index]) {
|
|
@@ -60,14 +62,30 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
if (obj) {
|
|
65
|
+
var _obj, _obj$icon, _obj$icon$props;
|
|
66
|
+
|
|
63
67
|
// use passed in color for background if the theme has a background color
|
|
64
68
|
var background = colorProp && obj.background && obj.background.color ? colorProp : obj.background; // if theme object explicitly sets the color to undefined, pass false
|
|
65
69
|
// to indicate that the theme doesn't want any text color
|
|
66
70
|
|
|
67
|
-
var objColor = obj.color || (Object.prototype.hasOwnProperty.call(obj, 'color') && obj.color === undefined ? false : undefined);
|
|
71
|
+
var objColor = obj.color || (Object.prototype.hasOwnProperty.call(obj, 'color') && obj.color === undefined ? false : undefined);
|
|
72
|
+
var color = void 0;
|
|
73
|
+
if ((_obj = obj) != null && (_obj$icon = _obj.icon) != null && (_obj$icon$props = _obj$icon.props) != null && _obj$icon$props.color) color = obj.icon.props.color; // if no icon defined for this state, see if there is an icon
|
|
74
|
+
// with color defined at one higher level
|
|
75
|
+
else if (paths[index + 1]) {
|
|
76
|
+
var _obj2, _obj2$icon, _obj2$icon$props;
|
|
77
|
+
|
|
78
|
+
var _parts = paths[index + 1].split('.');
|
|
79
|
+
|
|
80
|
+
while (baseObj && _parts.length) {
|
|
81
|
+
obj = baseObj[_parts.shift()];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if ((_obj2 = obj) != null && (_obj2$icon = _obj2.icon) != null && (_obj2$icon$props = _obj2$icon.props) != null && _obj2$icon$props.color) color = obj.icon.props.color;
|
|
85
|
+
} // use passed in color for text if the theme doesn't have
|
|
68
86
|
// background or border color
|
|
69
87
|
|
|
70
|
-
|
|
88
|
+
if (!color) color = colorProp && (!obj.background || !obj.background.color) && (!obj.border || !obj.border.color) ? colorProp : objColor;
|
|
71
89
|
result = backgroundAndTextColors(background, color, theme);
|
|
72
90
|
}
|
|
73
91
|
|
|
@@ -75,6 +93,39 @@ var getIconColor = function getIconColor(paths, theme, colorProp, kind) {
|
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
return result[1] || undefined;
|
|
96
|
+
}; // get the icon for the current button state
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
var getKindIcon = function getKindIcon(paths, theme, kind) {
|
|
100
|
+
if (paths === void 0) {
|
|
101
|
+
paths = [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var result;
|
|
105
|
+
var index = paths.length - 1; // caller has specified a themeObj to use for styling
|
|
106
|
+
// relevant for cases like pagination which looks to theme.pagination.button
|
|
107
|
+
|
|
108
|
+
if (typeof kind === 'object') index = 0; // stop when we have a color or no more paths
|
|
109
|
+
|
|
110
|
+
while (index >= 0 && !result) {
|
|
111
|
+
var _obj3;
|
|
112
|
+
|
|
113
|
+
var obj = typeof kind === 'object' && kind || theme.button; // find sub-object under the button theme that corresponds with this path
|
|
114
|
+
// for example: 'active.primary'
|
|
115
|
+
|
|
116
|
+
if (paths[index]) {
|
|
117
|
+
var parts = paths[index].split('.');
|
|
118
|
+
|
|
119
|
+
while (obj && parts.length) {
|
|
120
|
+
obj = obj[parts.shift()];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if ((_obj3 = obj) != null && _obj3.icon) result = obj.icon;
|
|
125
|
+
index -= 1;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return result || undefined;
|
|
78
129
|
};
|
|
79
130
|
|
|
80
131
|
var getPropertyColor = function getPropertyColor(property, paths, theme, kind, primary) {
|
|
@@ -108,6 +159,8 @@ var getPropertyColor = function getPropertyColor(property, paths, theme, kind, p
|
|
|
108
159
|
};
|
|
109
160
|
|
|
110
161
|
var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
162
|
+
var _theme$button$kind;
|
|
163
|
+
|
|
111
164
|
var active = _ref.active,
|
|
112
165
|
_ref$align = _ref.align,
|
|
113
166
|
align = _ref$align === void 0 ? 'center' : _ref$align,
|
|
@@ -126,13 +179,13 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
126
179
|
kindArg = _ref.kind,
|
|
127
180
|
label = _ref.label,
|
|
128
181
|
_onBlur = _ref.onBlur,
|
|
129
|
-
|
|
182
|
+
onClickProp = _ref.onClick,
|
|
130
183
|
_onFocus = _ref.onFocus,
|
|
131
184
|
onMouseOut = _ref.onMouseOut,
|
|
132
185
|
onMouseOver = _ref.onMouseOver,
|
|
133
186
|
plain = _ref.plain,
|
|
134
187
|
primary = _ref.primary,
|
|
135
|
-
|
|
188
|
+
reverseProp = _ref.reverse,
|
|
136
189
|
secondary = _ref.secondary,
|
|
137
190
|
selected = _ref.selected,
|
|
138
191
|
size = _ref.size,
|
|
@@ -156,9 +209,20 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
156
209
|
|
|
157
210
|
if ((icon || label) && children) {
|
|
158
211
|
console.warn('Button should not have children if icon or label is provided');
|
|
159
|
-
}
|
|
160
|
-
// outside of theme.button
|
|
212
|
+
}
|
|
161
213
|
|
|
214
|
+
var sendAnalytics = useAnalytics();
|
|
215
|
+
var onClick = useCallback(function (event) {
|
|
216
|
+
sendAnalytics({
|
|
217
|
+
type: 'buttonClick',
|
|
218
|
+
element: event.target,
|
|
219
|
+
event: event,
|
|
220
|
+
href: href,
|
|
221
|
+
label: typeof label === 'string' ? label : undefined
|
|
222
|
+
});
|
|
223
|
+
if (onClickProp) onClickProp(event);
|
|
224
|
+
}, [onClickProp, sendAnalytics, href, label]); // kindArg is object if we are referencing a theme object
|
|
225
|
+
// outside of theme.button
|
|
162
226
|
|
|
163
227
|
var kindObj = useMemo(function () {
|
|
164
228
|
return typeof kindArg === 'object';
|
|
@@ -236,7 +300,8 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
236
300
|
}
|
|
237
301
|
};
|
|
238
302
|
|
|
239
|
-
var
|
|
303
|
+
var kindIcon = hover && getKindIcon(themePaths == null ? void 0 : themePaths.hover, theme, kind) || getKindIcon(themePaths == null ? void 0 : themePaths.base, theme, kind);
|
|
304
|
+
var buttonIcon = icon || kindIcon; // only change color if user did not specify the color themselves...
|
|
240
305
|
|
|
241
306
|
if (icon && !icon.props.color) {
|
|
242
307
|
if (kind) {
|
|
@@ -252,8 +317,15 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
252
317
|
color: theme.global.colors.text[isDarkBackground() ? 'dark' : 'light']
|
|
253
318
|
});
|
|
254
319
|
}
|
|
320
|
+
} else if (kindIcon && !plain) {
|
|
321
|
+
var _iconColor = hover && getIconColor(themePaths.hover, theme) || getIconColor(themePaths.base, theme, color, kind);
|
|
322
|
+
|
|
323
|
+
if (_iconColor) buttonIcon = /*#__PURE__*/cloneElement(kindIcon, {
|
|
324
|
+
color: _iconColor
|
|
325
|
+
});
|
|
255
326
|
}
|
|
256
327
|
|
|
328
|
+
var reverse = reverseProp != null ? reverseProp : (_theme$button$kind = theme.button[kind]) == null ? void 0 : _theme$button$kind.reverse;
|
|
257
329
|
var domTag = !as && href ? 'a' : as;
|
|
258
330
|
var first = reverse ? label : buttonIcon;
|
|
259
331
|
var second = reverse ? buttonIcon : label;
|
|
@@ -348,7 +420,7 @@ var Button = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
348
420
|
href: href,
|
|
349
421
|
kind: kind,
|
|
350
422
|
themePaths: themePaths,
|
|
351
|
-
onClick: onClick,
|
|
423
|
+
onClick: onClickProp ? onClick : undefined,
|
|
352
424
|
onFocus: function onFocus(event) {
|
|
353
425
|
setFocus(true);
|
|
354
426
|
if (_onFocus) _onFocus(event);
|
|
@@ -18,11 +18,17 @@ var fontStyle = function fontStyle(props) {
|
|
|
18
18
|
return css(["font-size:", ";line-height:", ";"], data.size, data.height);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
var padFromTheme = function padFromTheme(size, theme, themeObj) {
|
|
21
|
+
var padFromTheme = function padFromTheme(size, theme, themeObj, kind) {
|
|
22
|
+
var _themeObj$size, _themeObj$size$size, _themeObj$size$size$k;
|
|
23
|
+
|
|
22
24
|
if (size === void 0) {
|
|
23
25
|
size = 'medium';
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
if (size && themeObj != null && (_themeObj$size = themeObj.size) != null && (_themeObj$size$size = _themeObj$size[size]) != null && (_themeObj$size$size$k = _themeObj$size$size[kind]) != null && _themeObj$size$size$k.pad) {
|
|
29
|
+
return themeObj.size[size][kind].pad;
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
if (size && themeObj.size && themeObj.size[size] && themeObj.size[size].pad) {
|
|
27
33
|
return {
|
|
28
34
|
vertical: themeObj.size[size].pad.vertical,
|
|
@@ -47,7 +53,7 @@ var padStyle = function padStyle(_ref) {
|
|
|
47
53
|
// caller has specified a themeObj to use for styling
|
|
48
54
|
// relevant for cases like pagination which looks to theme.pagination.button
|
|
49
55
|
var themeObj = typeof kind === 'object' ? kind : theme.button;
|
|
50
|
-
var pad = padFromTheme(size, theme, themeObj);
|
|
56
|
+
var pad = padFromTheme(size, theme, themeObj, kind);
|
|
51
57
|
return pad ? css(["padding:", " ", ";"], pad.vertical, pad.horizontal) : '';
|
|
52
58
|
};
|
|
53
59
|
|
|
@@ -86,7 +92,7 @@ var kindStyle = function kindStyle(_ref2) {
|
|
|
86
92
|
// relevant for cases like pagination which looks to theme.pagination.button
|
|
87
93
|
|
|
88
94
|
var themeObj = typeof kind === 'object' ? kind : theme.button;
|
|
89
|
-
var pad = padFromTheme(size, theme, themeObj);
|
|
95
|
+
var pad = padFromTheme(size, theme, themeObj, kind);
|
|
90
96
|
themePaths.base.forEach(function (themePath) {
|
|
91
97
|
var obj = getPath(themeObj, themePath);
|
|
92
98
|
|
|
@@ -64,7 +64,7 @@ export interface ButtonProps {
|
|
|
64
64
|
primary?: boolean;
|
|
65
65
|
reverse?: boolean;
|
|
66
66
|
secondary?: boolean;
|
|
67
|
-
size?: 'small' | 'medium' | 'large';
|
|
67
|
+
size?: 'small' | 'medium' | 'large' | string;
|
|
68
68
|
tip?: TipProps | string;
|
|
69
69
|
type?: 'button' | 'reset' | 'submit';
|
|
70
70
|
as?: PolymorphicType;
|
|
@@ -29,7 +29,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
29
29
|
primary: PropTypes.bool,
|
|
30
30
|
reverse: PropTypes.bool,
|
|
31
31
|
secondary: PropTypes.bool,
|
|
32
|
-
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
32
|
+
size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large']), PropTypes.string]),
|
|
33
33
|
target: PropTypes.oneOfType([PropTypes.oneOf(['_self', '_blank', '_parent', '_top']), PropTypes.string]),
|
|
34
34
|
tip: PropTypes.oneOfType([PropTypes.shape({
|
|
35
35
|
content: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
|
|
@@ -489,22 +489,18 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
489
489
|
|
|
490
490
|
var offsetPad = useMemo(function () {
|
|
491
491
|
return offsets ? offsets[offsets.length - 1] + thicknesses[thicknesses.length - 1] + "px" : undefined;
|
|
492
|
-
}, [offsets, thicknesses]); // The thickness of the
|
|
492
|
+
}, [offsets, thicknesses]); // The thickness of the segments. We need to convert to numbers
|
|
493
493
|
// to be able to compare across charts where some might be using T-shirt
|
|
494
494
|
// labels and others might be pixel values.
|
|
495
495
|
|
|
496
|
-
var
|
|
496
|
+
var segmentThickness = useMemo(function () {
|
|
497
497
|
var result = 0;
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
result = Math.max(result, parseMetricToNum(theme.global.edgeSize[thickness] || thickness));
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
|
|
498
|
+
charts.forEach(function (_, index) {
|
|
499
|
+
var thickness = chartProps[index].thickness;
|
|
500
|
+
result = Math.max(result, parseMetricToNum(theme.global.edgeSize[thickness] || thickness));
|
|
501
|
+
});
|
|
506
502
|
return result + "px";
|
|
507
|
-
}, [charts, chartProps,
|
|
503
|
+
}, [charts, chartProps, theme]);
|
|
508
504
|
var dateFormats = useMemo(function () {
|
|
509
505
|
var result = {};
|
|
510
506
|
var full = axis && axis.x && axis.x.granularity === 'coarse';
|
|
@@ -549,10 +545,12 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
549
545
|
end: offsetPad
|
|
550
546
|
}) : pad,
|
|
551
547
|
renderValue: renderValue,
|
|
548
|
+
thickness: segmentThickness,
|
|
552
549
|
serie: axis.x.property && getPropertySeries(axis.x.property),
|
|
553
550
|
style: offsetPad ? {
|
|
554
551
|
transform: "translate(" + offsets[Math.floor(offsets.length / 2)] + "px, 0px)"
|
|
555
|
-
} : {}
|
|
552
|
+
} : {},
|
|
553
|
+
theme: theme
|
|
556
554
|
}) : null;
|
|
557
555
|
var yAxisElement = axis && axis.y && (chartProps.length || boundsProp != null && boundsProp.y) ? /*#__PURE__*/React.createElement(YAxis, {
|
|
558
556
|
axis: axis,
|
|
@@ -656,7 +654,7 @@ var DataChart = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
656
654
|
series: series,
|
|
657
655
|
seriesStyles: seriesStyles,
|
|
658
656
|
renderValue: renderValue,
|
|
659
|
-
thickness:
|
|
657
|
+
thickness: segmentThickness
|
|
660
658
|
}));
|
|
661
659
|
var legendElement = legend ? /*#__PURE__*/React.createElement(Legend, {
|
|
662
660
|
series: series,
|
|
@@ -1,47 +1,57 @@
|
|
|
1
|
-
var _excluded = ["values", "pad", "renderValue", "serie"];
|
|
1
|
+
var _excluded = ["values", "pad", "renderValue", "serie", "theme", "thickness"];
|
|
2
2
|
|
|
3
3
|
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); }
|
|
4
4
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
|
-
import React, { forwardRef } from 'react';
|
|
7
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
8
|
+
import { edgeToNum } from '../../utils';
|
|
8
9
|
import { Box } from '../Box';
|
|
9
10
|
var XAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
10
11
|
var values = _ref.values,
|
|
11
|
-
|
|
12
|
+
padProp = _ref.pad,
|
|
12
13
|
renderValue = _ref.renderValue,
|
|
13
14
|
serie = _ref.serie,
|
|
15
|
+
theme = _ref.theme,
|
|
16
|
+
thickness = _ref.thickness,
|
|
14
17
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
15
18
|
|
|
16
|
-
//
|
|
17
|
-
//
|
|
19
|
+
// pad to the edge of the thickness, for when padding is more than half
|
|
20
|
+
// the thickness
|
|
21
|
+
var pad = useMemo(function () {
|
|
22
|
+
return {
|
|
23
|
+
start: edgeToNum(padProp.start || padProp.horizontal, theme) - edgeToNum(thickness, theme) / 2 + "px",
|
|
24
|
+
end: edgeToNum(padProp.end || padProp.horizontal, theme) - edgeToNum(thickness, theme) / 2 + "px"
|
|
25
|
+
};
|
|
26
|
+
}, [padProp, theme, thickness]); // When there are only labels at the end of the axis and there isn't
|
|
27
|
+
// much space for them, let them take as much space as they like
|
|
28
|
+
// flowing in from the edges.
|
|
29
|
+
// Otherwise, align their container to the
|
|
18
30
|
// data/guide lines and then let their content overflow that.
|
|
19
|
-
var itemProps = values.length === 2 ? {} : {
|
|
20
|
-
width: '1px',
|
|
21
|
-
overflow: 'visible',
|
|
22
|
-
align: 'center'
|
|
23
|
-
};
|
|
24
|
-
var horizontal = pad.horizontal,
|
|
25
|
-
start = pad.start,
|
|
26
|
-
end = pad.end; // ignore vertical parts
|
|
27
31
|
|
|
32
|
+
var labelContainerProps = useMemo(function () {
|
|
33
|
+
// 24px was chosen empirically as 48px is enough to show some simple text
|
|
34
|
+
var centered = values.length !== 2 || edgeToNum(padProp.start || padProp.horizontal, theme) >= 24;
|
|
35
|
+
if (centered) return {
|
|
36
|
+
width: thickness,
|
|
37
|
+
overflow: 'visible',
|
|
38
|
+
align: 'center'
|
|
39
|
+
};
|
|
40
|
+
return {};
|
|
41
|
+
}, [padProp, theme, thickness, values]);
|
|
28
42
|
return /*#__PURE__*/React.createElement(Box, _extends({
|
|
29
43
|
ref: ref,
|
|
30
44
|
gridArea: "xAxis",
|
|
31
45
|
direction: "row",
|
|
32
46
|
justify: "between",
|
|
33
|
-
pad:
|
|
34
|
-
horizontal: horizontal,
|
|
35
|
-
start: start,
|
|
36
|
-
end: end
|
|
37
|
-
}
|
|
47
|
+
pad: pad
|
|
38
48
|
}, rest), values.map(function (dataIndex, i) {
|
|
39
49
|
return (
|
|
40
50
|
/*#__PURE__*/
|
|
41
51
|
// eslint-disable-next-line react/no-array-index-key
|
|
42
52
|
React.createElement(Box, _extends({
|
|
43
53
|
key: i
|
|
44
|
-
},
|
|
54
|
+
}, labelContainerProps), serie ? renderValue(serie, dataIndex) : dataIndex)
|
|
45
55
|
);
|
|
46
56
|
}));
|
|
47
57
|
});
|
|
@@ -110,11 +110,14 @@ var DataTable = function DataTable(_ref) {
|
|
|
110
110
|
|
|
111
111
|
var _useState5 = useState(sortProp || {}),
|
|
112
112
|
sort = _useState5[0],
|
|
113
|
-
setSort = _useState5[1];
|
|
113
|
+
setSort = _useState5[1];
|
|
114
|
+
|
|
115
|
+
useEffect(function () {
|
|
116
|
+
if (sortProp) setSort(sortProp);
|
|
117
|
+
}, [sortProp]); // the data filtered and sorted, if needed
|
|
114
118
|
// Note: onUpdate mode expects the data to be passed
|
|
115
119
|
// in completely filtered and sorted already.
|
|
116
120
|
|
|
117
|
-
|
|
118
121
|
var adjustedData = useMemo(function () {
|
|
119
122
|
return onUpdate ? data : filterAndSortData(data, filters, onSearch, sort);
|
|
120
123
|
}, [data, filters, onSearch, onUpdate, sort]); // the values to put in the footer cells
|
|
@@ -368,6 +371,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
368
371
|
items = _usePagination[0],
|
|
369
372
|
paginationProps = _usePagination[1];
|
|
370
373
|
|
|
374
|
+
var paginationStep = paginationProps.step;
|
|
371
375
|
var Container = paginate ? StyledContainer : Fragment;
|
|
372
376
|
var containterProps = paginate ? _extends({}, theme.dataTable.container, {
|
|
373
377
|
fill: fill
|
|
@@ -421,13 +425,13 @@ var DataTable = function DataTable(_ref) {
|
|
|
421
425
|
expanded: Object.keys(groupState).filter(function (k) {
|
|
422
426
|
return groupState[k].expanded;
|
|
423
427
|
}),
|
|
424
|
-
count: limit +
|
|
428
|
+
count: limit + paginationStep
|
|
425
429
|
};
|
|
426
430
|
if (sort != null && sort.property) opts.sort = sort;
|
|
427
431
|
if (showProp) opts.show = showProp;
|
|
428
432
|
onUpdate(opts);
|
|
429
433
|
setLimit(function (prev) {
|
|
430
|
-
return prev +
|
|
434
|
+
return prev + paginationStep;
|
|
431
435
|
});
|
|
432
436
|
}
|
|
433
437
|
} : onMore,
|
|
@@ -441,7 +445,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
441
445
|
rowProps: rowProps,
|
|
442
446
|
selected: selected,
|
|
443
447
|
size: size,
|
|
444
|
-
step:
|
|
448
|
+
step: paginationStep,
|
|
445
449
|
verticalAlign: typeof verticalAlign === 'string' ? verticalAlign : verticalAlign == null ? void 0 : verticalAlign.body
|
|
446
450
|
}) : /*#__PURE__*/React.createElement(Body, {
|
|
447
451
|
ref: bodyRef,
|
|
@@ -452,13 +456,13 @@ var DataTable = function DataTable(_ref) {
|
|
|
452
456
|
onMore: onUpdate ? function () {
|
|
453
457
|
if (adjustedData.length === limit) {
|
|
454
458
|
var opts = {
|
|
455
|
-
count: limit +
|
|
459
|
+
count: limit + paginationStep
|
|
456
460
|
};
|
|
457
461
|
if (sort != null && sort.property) opts.sort = sort;
|
|
458
462
|
if (showProp) opts.show = showProp;
|
|
459
463
|
onUpdate(opts);
|
|
460
464
|
setLimit(function (prev) {
|
|
461
|
-
return prev +
|
|
465
|
+
return prev + paginationStep;
|
|
462
466
|
});
|
|
463
467
|
}
|
|
464
468
|
} : onMore,
|
|
@@ -475,7 +479,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
475
479
|
selected: selected,
|
|
476
480
|
show: !paginate ? showProp : undefined,
|
|
477
481
|
size: size,
|
|
478
|
-
step:
|
|
482
|
+
step: paginationStep,
|
|
479
483
|
rowDetails: rowDetails,
|
|
480
484
|
rowExpand: rowExpand,
|
|
481
485
|
setRowExpand: setRowExpand,
|
|
@@ -537,7 +541,7 @@ var DataTable = function DataTable(_ref) {
|
|
|
537
541
|
}), placeholder && items && items.length > 0 && /*#__PURE__*/React.createElement(StyledPlaceholder, {
|
|
538
542
|
top: headerHeight,
|
|
539
543
|
bottom: footerHeight
|
|
540
|
-
}, placeholderContent))), paginate && adjustedData.length >
|
|
544
|
+
}, placeholderContent))), paginate && adjustedData.length > paginationStep && items && items.length ? /*#__PURE__*/React.createElement(Pagination, _extends({
|
|
541
545
|
alignSelf: "end"
|
|
542
546
|
}, paginationProps)) : null);
|
|
543
547
|
};
|
|
@@ -93,8 +93,8 @@ export var filterAndSortData = function filterAndSortData(data, filters, onSearc
|
|
|
93
93
|
var d1Val = datumValue(d1, property);
|
|
94
94
|
var d2Val = datumValue(d2, property);
|
|
95
95
|
|
|
96
|
-
if (typeof d1Val === 'string' && typeof d2Val === 'string') {
|
|
97
|
-
var sortResult = d1Val.localeCompare(d2Val, undefined, {
|
|
96
|
+
if (typeof d1Val === 'string' && typeof d2Val === 'string' || typeof d1Val === 'string' && !d2Val || typeof d2Val === 'string' && !d1Val) {
|
|
97
|
+
var sortResult = (d1Val || '').localeCompare(d2Val || '', undefined, {
|
|
98
98
|
sensitivity: 'base'
|
|
99
99
|
});
|
|
100
100
|
return sortAsc ? sortResult : -sortResult;
|
|
@@ -129,7 +129,10 @@ export interface DataTableProps<TRowType = any> {
|
|
|
129
129
|
|
|
130
130
|
export interface DataTableExtendedProps<TRowType = any>
|
|
131
131
|
extends DataTableProps<TRowType>,
|
|
132
|
-
Omit<
|
|
132
|
+
Omit<
|
|
133
|
+
JSX.IntrinsicElements['table'],
|
|
134
|
+
'onSelect' | 'placeholder' | 'border'
|
|
135
|
+
> {}
|
|
133
136
|
|
|
134
137
|
declare class DataTable<TRowType = any> extends React.Component<
|
|
135
138
|
DataTableExtendedProps<TRowType>
|
|
@@ -29,7 +29,9 @@ var columns = [{
|
|
|
29
29
|
}
|
|
30
30
|
}, (_datum$failures = datum.failures) == null ? void 0 : _datum$failures.map(function (_ref) {
|
|
31
31
|
var reason = _ref.reason;
|
|
32
|
-
return /*#__PURE__*/React.createElement(Text,
|
|
32
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
33
|
+
key: reason
|
|
34
|
+
}, reason);
|
|
33
35
|
}));
|
|
34
36
|
return /*#__PURE__*/React.createElement(Tip, {
|
|
35
37
|
plain: true,
|
|
@@ -16,7 +16,9 @@ var columns = [{
|
|
|
16
16
|
header: 'Rocket',
|
|
17
17
|
size: 'small',
|
|
18
18
|
render: function render(datum) {
|
|
19
|
-
return /*#__PURE__*/React.createElement(Text,
|
|
19
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
20
|
+
key: datum.rocket.name
|
|
21
|
+
}, datum.rocket.name);
|
|
20
22
|
}
|
|
21
23
|
}, {
|
|
22
24
|
property: 'success',
|
|
@@ -32,7 +34,9 @@ var columns = [{
|
|
|
32
34
|
}
|
|
33
35
|
}, (_datum$failures = datum.failures) == null ? void 0 : _datum$failures.map(function (_ref) {
|
|
34
36
|
var reason = _ref.reason;
|
|
35
|
-
return /*#__PURE__*/React.createElement(Text,
|
|
37
|
+
return /*#__PURE__*/React.createElement(Text, {
|
|
38
|
+
key: reason
|
|
39
|
+
}, reason);
|
|
36
40
|
}));
|
|
37
41
|
return /*#__PURE__*/React.createElement(Tip, {
|
|
38
42
|
plain: true,
|
|
@@ -5,7 +5,9 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
5
5
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
6
6
|
|
|
7
7
|
import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import { useAnalytics } from '../../contexts';
|
|
8
9
|
import { MessageContext } from '../../contexts/MessageContext';
|
|
10
|
+
import { useForwardedRef } from '../../utils';
|
|
9
11
|
import { FormContext } from './FormContext';
|
|
10
12
|
import { FormPropTypes } from './propTypes';
|
|
11
13
|
var defaultValue = {};
|
|
@@ -182,6 +184,8 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
182
184
|
valueProp = _ref2.value,
|
|
183
185
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
184
186
|
|
|
187
|
+
var formRef = useForwardedRef(ref);
|
|
188
|
+
|
|
185
189
|
var _useContext = useContext(MessageContext),
|
|
186
190
|
format = _useContext.format;
|
|
187
191
|
|
|
@@ -225,6 +229,11 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
225
229
|
|
|
226
230
|
var validationRulesRef = useRef({});
|
|
227
231
|
var requiredFields = useRef([]);
|
|
232
|
+
var analyticsRef = useRef({
|
|
233
|
+
start: new Date(),
|
|
234
|
+
errors: {}
|
|
235
|
+
});
|
|
236
|
+
var sendAnalytics = useAnalytics();
|
|
228
237
|
var buildValid = useCallback(function (nextErrors) {
|
|
229
238
|
var valid = false;
|
|
230
239
|
valid = requiredFields.current.filter(function (n) {
|
|
@@ -247,6 +256,19 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
247
256
|
});
|
|
248
257
|
};
|
|
249
258
|
|
|
259
|
+
var updateAnalytics = function updateAnalytics() {
|
|
260
|
+
var _validationResultsRef;
|
|
261
|
+
|
|
262
|
+
var errorFields = Object.keys((_validationResultsRef = validationResultsRef.current) == null ? void 0 : _validationResultsRef.errors);
|
|
263
|
+
var errorCounts = analyticsRef.current.errors;
|
|
264
|
+
|
|
265
|
+
if (errorFields.length > 0) {
|
|
266
|
+
errorFields.forEach(function (key) {
|
|
267
|
+
errorCounts[key] = (errorCounts[key] || 0) + 1;
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
250
272
|
var applyValidationRules = useCallback(function (validationRules) {
|
|
251
273
|
var _validateForm = validateForm(validationRules, value, format, messages),
|
|
252
274
|
validatedErrors = _validateForm[0],
|
|
@@ -271,6 +293,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
271
293
|
valid: buildValid(nextErrors)
|
|
272
294
|
}));
|
|
273
295
|
validationResultsRef.current = nextValidationResults;
|
|
296
|
+
updateAnalytics();
|
|
274
297
|
return nextValidationResults;
|
|
275
298
|
});
|
|
276
299
|
}, [buildValid, format, messages, onValidate, value]); // Validate all fields holding values onMount if set to
|
|
@@ -318,17 +341,38 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
318
341
|
// as the user fixes them (basically act like validate=change for that)
|
|
319
342
|
|
|
320
343
|
useEffect(function () {
|
|
321
|
-
var
|
|
344
|
+
var _validationResultsRef2;
|
|
322
345
|
|
|
323
346
|
var validationRules = Object.entries(validationRulesRef.current);
|
|
324
347
|
|
|
325
|
-
if ((
|
|
348
|
+
if ((_validationResultsRef2 = validationResultsRef.current) != null && _validationResultsRef2.errors && Object.keys(validationResultsRef.current.errors).length > 0) {
|
|
326
349
|
applyValidationRules(validationRules.filter(function (_ref6) {
|
|
327
350
|
var n = _ref6[0];
|
|
328
351
|
return touched[n] && validationResultsRef.current.errors[n];
|
|
329
352
|
}));
|
|
330
353
|
}
|
|
331
|
-
}, [applyValidationRules, touched]);
|
|
354
|
+
}, [applyValidationRules, touched]);
|
|
355
|
+
useEffect(function () {
|
|
356
|
+
var element = formRef.current;
|
|
357
|
+
analyticsRef.current = {
|
|
358
|
+
start: new Date(),
|
|
359
|
+
errors: {}
|
|
360
|
+
};
|
|
361
|
+
sendAnalytics({
|
|
362
|
+
type: 'formOpen',
|
|
363
|
+
element: element
|
|
364
|
+
});
|
|
365
|
+
return function () {
|
|
366
|
+
if (!analyticsRef.current.submitted) {
|
|
367
|
+
sendAnalytics({
|
|
368
|
+
type: 'formClose',
|
|
369
|
+
element: element,
|
|
370
|
+
errors: analyticsRef.current.errors,
|
|
371
|
+
elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}, [sendAnalytics, formRef]); // There are three basic patterns of handling form input value state:
|
|
332
376
|
//
|
|
333
377
|
// 1 - form controlled
|
|
334
378
|
//
|
|
@@ -516,9 +560,16 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
516
560
|
};
|
|
517
561
|
}, [onChange, pendingValidation, touched, validateOn, validationResults.errors, validationResults.infos, value, valueProp]);
|
|
518
562
|
return /*#__PURE__*/React.createElement("form", _extends({
|
|
519
|
-
ref:
|
|
563
|
+
ref: formRef
|
|
520
564
|
}, rest, {
|
|
521
565
|
onReset: function onReset(event) {
|
|
566
|
+
sendAnalytics({
|
|
567
|
+
type: 'formReset',
|
|
568
|
+
element: formRef.current,
|
|
569
|
+
data: event,
|
|
570
|
+
errors: analyticsRef.current.errors,
|
|
571
|
+
elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
|
|
572
|
+
});
|
|
522
573
|
setPendingValidation(undefined);
|
|
523
574
|
|
|
524
575
|
if (!valueProp) {
|
|
@@ -530,6 +581,10 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
530
581
|
|
|
531
582
|
setTouched(defaultTouched);
|
|
532
583
|
setValidationResults(defaultValidationResults);
|
|
584
|
+
analyticsRef.current = {
|
|
585
|
+
start: new Date(),
|
|
586
|
+
errors: {}
|
|
587
|
+
};
|
|
533
588
|
|
|
534
589
|
if (_onReset) {
|
|
535
590
|
event.persist(); // extract from React's synthetic event pool
|
|
@@ -560,6 +615,7 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
560
615
|
};
|
|
561
616
|
if (onValidate) onValidate(nextValidationResults);
|
|
562
617
|
validationResultsRef.current = nextValidationResults;
|
|
618
|
+
updateAnalytics();
|
|
563
619
|
return nextValidationResults;
|
|
564
620
|
});
|
|
565
621
|
|
|
@@ -571,6 +627,16 @@ var Form = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
571
627
|
adjustedEvent.touched = touched;
|
|
572
628
|
|
|
573
629
|
_onSubmit(adjustedEvent);
|
|
630
|
+
|
|
631
|
+
sendAnalytics({
|
|
632
|
+
type: 'formSubmit',
|
|
633
|
+
element: formRef.current,
|
|
634
|
+
data: adjustedEvent,
|
|
635
|
+
errors: analyticsRef.current.errors,
|
|
636
|
+
elapsed: new Date().getTime() - analyticsRef.current.start.getTime()
|
|
637
|
+
});
|
|
638
|
+
analyticsRef.current.errors = {};
|
|
639
|
+
analyticsRef.current.submitted = true;
|
|
574
640
|
}
|
|
575
641
|
}
|
|
576
642
|
}), /*#__PURE__*/React.createElement(FormContext.Provider, {
|