grommet 2.32.2 → 2.33.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.
- package/all/stories/CustomThemed/ExtendTheme.tsx +2 -4
- package/components/Chart/Chart.js +20 -20
- package/components/Chart/calcs.js +163 -92
- package/components/Chart/index.d.ts +10 -4
- package/components/Chart/propTypes.js +10 -1
- package/components/Chart/stories/{Vertical.js → Horizontal.js} +34 -6
- package/components/Chart/utils.js +68 -64
- package/components/DataChart/DataChart.js +114 -68
- package/components/DataChart/Detail.js +55 -21
- package/components/DataChart/XAxis.js +33 -6
- package/components/DataChart/XGuide.js +14 -1
- package/components/DataChart/YAxis.js +58 -39
- package/components/DataChart/YGuide.js +13 -10
- package/components/DataChart/index.d.ts +2 -0
- package/components/DataChart/propTypes.js +3 -1
- package/components/DataChart/stories/Horizontal.js +63 -0
- package/components/DataChart/utils.js +27 -2
- package/components/DataFilter/DataFilter.js +25 -2
- package/components/DataSort/DataSort.js +1 -1
- package/components/DataTable/buildState.js +6 -1
- package/components/DataTableColumns/DataTableColumns.js +2 -2
- package/components/DateInput/DateInput.js +22 -2
- package/components/Footer/stories/DoubleFooter.js +6 -2
- package/components/Footer/stories/Sitemap.js +0 -2
- package/components/Footer/stories/Social.js +2 -2
- package/components/Menu/Menu.js +9 -6
- package/components/Select/Select.js +1 -1
- package/components/SelectMultiple/SelectMultipleContainer.js +5 -5
- package/components/Tabs/Tabs.js +2 -1
- package/es6/all/stories/CustomThemed/ExtendTheme.tsx +2 -4
- package/es6/components/Chart/Chart.js +20 -20
- package/es6/components/Chart/calcs.js +164 -93
- package/es6/components/Chart/index.d.ts +10 -4
- package/es6/components/Chart/propTypes.js +10 -1
- package/es6/components/Chart/stories/{Vertical.js → Horizontal.js} +32 -4
- package/es6/components/Chart/utils.js +66 -63
- package/es6/components/DataChart/DataChart.js +115 -69
- package/es6/components/DataChart/Detail.js +55 -21
- package/es6/components/DataChart/XAxis.js +33 -6
- package/es6/components/DataChart/XGuide.js +14 -1
- package/es6/components/DataChart/YAxis.js +59 -40
- package/es6/components/DataChart/YGuide.js +13 -10
- package/es6/components/DataChart/index.d.ts +2 -0
- package/es6/components/DataChart/propTypes.js +3 -1
- package/es6/components/DataChart/stories/Horizontal.js +57 -0
- package/es6/components/DataChart/utils.js +22 -0
- package/es6/components/DataFilter/DataFilter.js +27 -3
- package/es6/components/DataSort/DataSort.js +1 -1
- package/es6/components/DataTable/buildState.js +6 -1
- package/es6/components/DataTableColumns/DataTableColumns.js +2 -2
- package/es6/components/DateInput/DateInput.js +22 -2
- package/es6/components/Footer/stories/DoubleFooter.js +6 -2
- package/es6/components/Footer/stories/Sitemap.js +0 -2
- package/es6/components/Footer/stories/Social.js +2 -2
- package/es6/components/Menu/Menu.js +9 -6
- package/es6/components/Select/Select.js +1 -1
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +5 -5
- package/es6/components/Tabs/Tabs.js +2 -1
- package/es6/themes/base.d.ts +5 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/package.json +37 -40
- package/themes/base.d.ts +5 -1
|
@@ -4,6 +4,22 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
4
4
|
import React, { forwardRef, useMemo } from 'react';
|
|
5
5
|
import { edgeToNum } from '../../utils';
|
|
6
6
|
import { Box } from '../Box';
|
|
7
|
+
import { showInUnits } from './utils';
|
|
8
|
+
var onlyHorizontalPad = function onlyHorizontalPad(pad) {
|
|
9
|
+
var result;
|
|
10
|
+
if (pad) {
|
|
11
|
+
if (typeof pad === 'string') result = {
|
|
12
|
+
horizontal: pad
|
|
13
|
+
};else result = {
|
|
14
|
+
horizontal: pad.horizontal,
|
|
15
|
+
start: pad.start,
|
|
16
|
+
end: pad.end,
|
|
17
|
+
left: pad.left,
|
|
18
|
+
right: pad.right
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
7
23
|
var XAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
8
24
|
var values = _ref.values,
|
|
9
25
|
padProp = _ref.pad,
|
|
@@ -12,13 +28,17 @@ var XAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
12
28
|
theme = _ref.theme,
|
|
13
29
|
thickness = _ref.thickness,
|
|
14
30
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
31
|
+
var _ref2 = serie || {},
|
|
32
|
+
render = _ref2.render,
|
|
33
|
+
suffix = _ref2.suffix;
|
|
34
|
+
|
|
15
35
|
// pad to the edge of the thickness, for when padding is more than half
|
|
16
36
|
// the thickness
|
|
17
37
|
var pad = useMemo(function () {
|
|
18
|
-
return {
|
|
38
|
+
return thickness && padProp && {
|
|
19
39
|
start: edgeToNum(padProp.start || padProp.horizontal, theme) - edgeToNum(thickness, theme) / 2 + "px",
|
|
20
40
|
end: edgeToNum(padProp.end || padProp.horizontal, theme) - edgeToNum(thickness, theme) / 2 + "px"
|
|
21
|
-
};
|
|
41
|
+
} || onlyHorizontalPad(padProp);
|
|
22
42
|
}, [padProp, theme, thickness]);
|
|
23
43
|
|
|
24
44
|
// When there are only labels at the end of the axis and there isn't
|
|
@@ -28,9 +48,9 @@ var XAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
28
48
|
// data/guide lines and then let their content overflow that.
|
|
29
49
|
var labelContainerProps = useMemo(function () {
|
|
30
50
|
// 24px was chosen empirically as 48px is enough to show some simple text
|
|
31
|
-
var centered = values.length !== 2 || edgeToNum(padProp.start || padProp.horizontal, theme) >= 24;
|
|
51
|
+
var centered = values.length !== 2 || edgeToNum((padProp == null ? void 0 : padProp.start) || (padProp == null ? void 0 : padProp.horizontal), theme) >= 24;
|
|
32
52
|
if (centered) return {
|
|
33
|
-
|
|
53
|
+
basis: thickness || '1px',
|
|
34
54
|
overflow: 'visible',
|
|
35
55
|
align: 'center'
|
|
36
56
|
};
|
|
@@ -42,13 +62,20 @@ var XAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
42
62
|
direction: "row",
|
|
43
63
|
justify: "between",
|
|
44
64
|
pad: pad
|
|
45
|
-
}, rest), values.map(function (
|
|
65
|
+
}, rest), values.map(function (axisValue, i) {
|
|
66
|
+
var content = serie ? renderValue(serie, axisValue) : axisValue;
|
|
67
|
+
if (content === axisValue && !render && !suffix) {
|
|
68
|
+
var maxValue = Math.max.apply(Math, values.map(function (v) {
|
|
69
|
+
return Math.abs(v);
|
|
70
|
+
}));
|
|
71
|
+
content = showInUnits(content, maxValue);
|
|
72
|
+
}
|
|
46
73
|
return (
|
|
47
74
|
/*#__PURE__*/
|
|
48
75
|
// eslint-disable-next-line react/no-array-index-key
|
|
49
76
|
React.createElement(Box, _extends({
|
|
50
77
|
key: i
|
|
51
|
-
}, labelContainerProps),
|
|
78
|
+
}, labelContainerProps), content)
|
|
52
79
|
);
|
|
53
80
|
}));
|
|
54
81
|
});
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
+
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); }
|
|
1
2
|
import React, { forwardRef } from 'react';
|
|
2
3
|
import { Box } from '../Box';
|
|
3
4
|
var XGuide = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
4
5
|
var guide = _ref.guide,
|
|
5
|
-
|
|
6
|
+
padArg = _ref.pad,
|
|
7
|
+
thickness = _ref.thickness;
|
|
8
|
+
var pad = padArg;
|
|
9
|
+
if (thickness) {
|
|
10
|
+
// omit any horizontal pad so the guides cover the thickness that
|
|
11
|
+
// is within the pad
|
|
12
|
+
if (typeof padArg === 'object') pad = _extends({}, padArg, {
|
|
13
|
+
top: 'none',
|
|
14
|
+
bottom: 'none'
|
|
15
|
+
});else if (typeof padArg === 'string') pad = {
|
|
16
|
+
horizontal: padArg
|
|
17
|
+
};
|
|
18
|
+
}
|
|
6
19
|
return /*#__PURE__*/React.createElement(Box, {
|
|
7
20
|
ref: ref,
|
|
8
21
|
fill: true,
|
|
@@ -1,57 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
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); }
|
|
2
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
3
|
+
import { edgeToNum } from '../../utils';
|
|
3
4
|
import { Box } from '../Box';
|
|
4
|
-
import {
|
|
5
|
-
|
|
5
|
+
import { showInUnits } from './utils';
|
|
6
|
+
var onlyVerticalPad = function onlyVerticalPad(pad) {
|
|
7
|
+
var result;
|
|
8
|
+
if (pad) {
|
|
9
|
+
if (typeof pad === 'string') result = {
|
|
10
|
+
vertical: pad
|
|
11
|
+
};else result = {
|
|
12
|
+
vertical: pad.vertical,
|
|
13
|
+
top: pad.top,
|
|
14
|
+
bottom: pad.bottom
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
6
19
|
var YAxis = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
7
20
|
var values = _ref.values,
|
|
8
|
-
|
|
21
|
+
padProp = _ref.pad,
|
|
9
22
|
renderValue = _ref.renderValue,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} else if (maxValue > 10000) {
|
|
26
|
-
divideBy = 1000;
|
|
27
|
-
unit = 'K';
|
|
28
|
-
}
|
|
29
|
-
}
|
|
23
|
+
serie = _ref.serie,
|
|
24
|
+
theme = _ref.theme,
|
|
25
|
+
thickness = _ref.thickness;
|
|
26
|
+
var _ref2 = serie || {},
|
|
27
|
+
render = _ref2.render,
|
|
28
|
+
suffix = _ref2.suffix;
|
|
29
|
+
|
|
30
|
+
// pad to the edge of the thickness, for when padding is more than half
|
|
31
|
+
// the thickness
|
|
32
|
+
var pad = useMemo(function () {
|
|
33
|
+
return padProp && thickness && {
|
|
34
|
+
top: edgeToNum(padProp.top || padProp.vertical, theme) - edgeToNum(thickness, theme) / 2 + "px",
|
|
35
|
+
bottom: edgeToNum(padProp.bottom || padProp.vertical, theme) - edgeToNum(thickness, theme) / 2 + "px"
|
|
36
|
+
} || onlyVerticalPad(padProp);
|
|
37
|
+
}, [padProp, theme, thickness]);
|
|
30
38
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
// When there are only labels at the end of the axis and there isn't
|
|
40
|
+
// much space for them, let them take as much space as they like
|
|
41
|
+
// flowing in from the edges.
|
|
42
|
+
// Otherwise, align their container to the
|
|
43
|
+
// data/guide lines and then let their content overflow that.
|
|
44
|
+
var labelContainerProps = useMemo(function () {
|
|
45
|
+
// 24px was chosen empirically as 48px is enough to show some simple text
|
|
46
|
+
var centered = values.length !== 2 || edgeToNum((padProp == null ? void 0 : padProp.start) || (padProp == null ? void 0 : padProp.horizontal), theme) >= 24;
|
|
47
|
+
if (centered) return {
|
|
48
|
+
basis: thickness || '1px',
|
|
49
|
+
overflow: 'visible',
|
|
50
|
+
justify: 'center'
|
|
51
|
+
};
|
|
52
|
+
return {};
|
|
53
|
+
}, [padProp, theme, thickness, values]);
|
|
35
54
|
return /*#__PURE__*/React.createElement(Box, {
|
|
36
55
|
ref: ref,
|
|
37
56
|
gridArea: "yAxis",
|
|
38
57
|
justify: "between",
|
|
39
|
-
flex: true
|
|
58
|
+
flex: true,
|
|
59
|
+
pad: pad
|
|
40
60
|
}, values.map(function (axisValue, i) {
|
|
41
|
-
var content = renderValue(serie,
|
|
42
|
-
if (content === axisValue) {
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
var content = serie ? renderValue(serie, axisValue, true) : axisValue;
|
|
62
|
+
if (content === axisValue && !render && !suffix) {
|
|
63
|
+
var maxValue = Math.max.apply(Math, values.map(function (v) {
|
|
64
|
+
return Math.abs(v);
|
|
65
|
+
}));
|
|
66
|
+
content = showInUnits(content, maxValue);
|
|
45
67
|
}
|
|
46
68
|
return /*#__PURE__*/React.createElement(Box
|
|
47
69
|
// eslint-disable-next-line react/no-array-index-key
|
|
48
|
-
, {
|
|
70
|
+
, _extends({
|
|
49
71
|
key: i,
|
|
50
|
-
align: "end"
|
|
51
|
-
|
|
52
|
-
flex: "shrink",
|
|
53
|
-
justify: basis ? 'center' : undefined
|
|
54
|
-
}, content);
|
|
72
|
+
align: "end"
|
|
73
|
+
}, labelContainerProps), content);
|
|
55
74
|
}));
|
|
56
75
|
});
|
|
57
76
|
export { YAxis };
|
|
@@ -3,16 +3,19 @@ import React, { forwardRef } from 'react';
|
|
|
3
3
|
import { Box } from '../Box';
|
|
4
4
|
var YGuide = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
5
5
|
var guide = _ref.guide,
|
|
6
|
-
padArg = _ref.pad
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
padArg = _ref.pad,
|
|
7
|
+
thickness = _ref.thickness;
|
|
8
|
+
var pad = padArg;
|
|
9
|
+
if (thickness) {
|
|
10
|
+
// omit any horizontal pad so the guides cover the thickness that
|
|
11
|
+
// is within the pad
|
|
12
|
+
if (typeof padArg === 'object') pad = _extends({}, padArg, {
|
|
13
|
+
start: 'none',
|
|
14
|
+
end: 'none'
|
|
15
|
+
});else if (typeof padArg === 'string') pad = {
|
|
16
|
+
vertical: padArg
|
|
17
|
+
};
|
|
18
|
+
}
|
|
16
19
|
return /*#__PURE__*/React.createElement(Box, {
|
|
17
20
|
ref: ref,
|
|
18
21
|
fill: true,
|
|
@@ -76,6 +76,7 @@ export interface DataChartProps {
|
|
|
76
76
|
bounds?:
|
|
77
77
|
| 'align'
|
|
78
78
|
| {
|
|
79
|
+
x?: number[];
|
|
79
80
|
y?: number[];
|
|
80
81
|
};
|
|
81
82
|
// chart - if undefined, { type: 'bar', property: <first series property> }
|
|
@@ -84,6 +85,7 @@ export interface DataChartProps {
|
|
|
84
85
|
data: {}[];
|
|
85
86
|
// detail - whether to show details via hover/touch interaction
|
|
86
87
|
detail?: boolean | ((datum: {}, index: number) => React.ReactNode);
|
|
88
|
+
direction?: 'horizontal' | 'vertical';
|
|
87
89
|
gap?: GridProps['gap']; // between axes and guides/visuals
|
|
88
90
|
gridArea?: GridAreaType; // generic
|
|
89
91
|
// guide - when true, {
|
|
@@ -54,11 +54,13 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
54
54
|
})])
|
|
55
55
|
})]),
|
|
56
56
|
bounds: PropTypes.oneOfType([PropTypes.oneOf(['align']), PropTypes.shape({
|
|
57
|
+
x: PropTypes.arrayOf(PropTypes.number),
|
|
57
58
|
y: PropTypes.arrayOf(PropTypes.number)
|
|
58
59
|
})]),
|
|
59
60
|
chart: PropTypes.oneOfType([chartType, PropTypes.arrayOf(chartType)]),
|
|
60
61
|
data: PropTypes.arrayOf(PropTypes.shape({})),
|
|
61
62
|
detail: PropTypes.bool,
|
|
63
|
+
direction: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
62
64
|
gap: PropTypes.oneOfType([PropTypes.oneOf(['none', 'xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge']), PropTypes.string]),
|
|
63
65
|
guide: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
|
64
66
|
x: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
|
@@ -75,7 +77,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
75
77
|
pad: padPropType,
|
|
76
78
|
placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
77
79
|
series: PropTypes.oneOfType([seriesType, PropTypes.arrayOf(seriesType)]),
|
|
78
|
-
size: PropTypes.oneOfType([PropTypes.oneOf(['fill']), PropTypes.shape({
|
|
80
|
+
size: PropTypes.oneOfType([PropTypes.oneOf(['xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'fill', 'full']), PropTypes.shape({
|
|
79
81
|
height: PropTypes.oneOfType([PropTypes.oneOf(['xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'fill']), PropTypes.string]),
|
|
80
82
|
width: PropTypes.oneOfType([PropTypes.oneOf(['xxsmall', 'xsmall', 'small', 'medium', 'large', 'xlarge', 'fill', 'auto']), PropTypes.string])
|
|
81
83
|
})])
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, DataChart } from 'grommet';
|
|
3
|
+
var data = [];
|
|
4
|
+
for (var i = 1; i < 8; i += 1) {
|
|
5
|
+
var v = Math.sin(i / 2.0);
|
|
6
|
+
data.push({
|
|
7
|
+
percent: Math.abs(v * 100),
|
|
8
|
+
label: "Label " + i
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export var Horizontal = function Horizontal() {
|
|
12
|
+
return (
|
|
13
|
+
/*#__PURE__*/
|
|
14
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
15
|
+
// <Grommet theme={grommet}>
|
|
16
|
+
React.createElement(Box, {
|
|
17
|
+
align: "center",
|
|
18
|
+
justify: "start",
|
|
19
|
+
pad: "large"
|
|
20
|
+
}, /*#__PURE__*/React.createElement(DataChart, {
|
|
21
|
+
data: data,
|
|
22
|
+
series: [{
|
|
23
|
+
property: 'label',
|
|
24
|
+
render: function render(label) {
|
|
25
|
+
return label;
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
property: 'percent',
|
|
29
|
+
suffix: '%'
|
|
30
|
+
}],
|
|
31
|
+
direction: "horizontal",
|
|
32
|
+
size: "medium",
|
|
33
|
+
axis: {
|
|
34
|
+
x: {
|
|
35
|
+
granularity: 'fine'
|
|
36
|
+
},
|
|
37
|
+
y: {
|
|
38
|
+
property: 'label',
|
|
39
|
+
granularity: 'fine'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
guide: {
|
|
43
|
+
x: {
|
|
44
|
+
granularity: 'fine'
|
|
45
|
+
},
|
|
46
|
+
y: {
|
|
47
|
+
granularity: 'fine'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}))
|
|
51
|
+
// </Grommet>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default {
|
|
56
|
+
title: 'Visualizations/DataChart/Horizontal'
|
|
57
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { round } from '../Chart';
|
|
1
2
|
export var points = ['circle', 'diamond', 'square', 'star', 'triangle', 'triangleDown'];
|
|
2
3
|
export var heightYGranularity = {
|
|
3
4
|
xxsmall: {
|
|
@@ -40,6 +41,21 @@ export var doublePad = {
|
|
|
40
41
|
xxsmall: 'xsmall'
|
|
41
42
|
};
|
|
42
43
|
var orderedSizes = ['xlarge', 'large', 'medium', 'small', 'xsmall', 'xxsmall', 'hair'];
|
|
44
|
+
export var showInUnits = function showInUnits(content, maxValue) {
|
|
45
|
+
var divideBy;
|
|
46
|
+
var unit;
|
|
47
|
+
var newContent = content;
|
|
48
|
+
if (maxValue > 10000000) {
|
|
49
|
+
divideBy = 1000000;
|
|
50
|
+
unit = 'M';
|
|
51
|
+
} else if (maxValue > 10000) {
|
|
52
|
+
divideBy = 1000;
|
|
53
|
+
unit = 'K';
|
|
54
|
+
}
|
|
55
|
+
if (divideBy) newContent = round(newContent / divideBy, 0);
|
|
56
|
+
if (unit) newContent = "" + newContent + unit;
|
|
57
|
+
return newContent;
|
|
58
|
+
};
|
|
43
59
|
export var largestSize = function largestSize(size1, size2) {
|
|
44
60
|
if (size1 && !size2) return size1;
|
|
45
61
|
if (size2 && !size1) return size2;
|
|
@@ -95,4 +111,10 @@ export var createDateFormat = function createDateFormat(firstValue, lastValue, f
|
|
|
95
111
|
if (options) dateFormat = new Intl.DateTimeFormat(undefined, options).format;
|
|
96
112
|
}
|
|
97
113
|
return dateFormat;
|
|
114
|
+
};
|
|
115
|
+
export var minimum = function minimum(value1, value2) {
|
|
116
|
+
return value1 !== undefined ? Math.min(value1, value2) : value2;
|
|
117
|
+
};
|
|
118
|
+
export var maximum = function maximum(value1, value2) {
|
|
119
|
+
return value1 !== undefined ? Math.max(value1, value2) : value2;
|
|
98
120
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _excluded = ["children", "options", "property", "range"];
|
|
2
2
|
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); }
|
|
3
3
|
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; }
|
|
4
|
-
import React, { useContext, useMemo } from 'react';
|
|
4
|
+
import React, { useContext, useMemo, useState } from 'react';
|
|
5
5
|
import { DataContext } from '../../contexts/DataContext';
|
|
6
6
|
import { DataForm } from '../Data/DataForm';
|
|
7
7
|
import { FormContext } from '../Form/FormContext';
|
|
@@ -10,6 +10,10 @@ import { CheckBoxGroup } from '../CheckBoxGroup';
|
|
|
10
10
|
import { RangeSelector } from '../RangeSelector';
|
|
11
11
|
import { SelectMultiple } from '../SelectMultiple';
|
|
12
12
|
import { DataFilterPropTypes } from './propTypes';
|
|
13
|
+
|
|
14
|
+
// empirical constants for when we change inputs
|
|
15
|
+
var maxCheckBoxGroupOptions = 4;
|
|
16
|
+
var minSelectSearchOptions = 10;
|
|
13
17
|
var getValueAt = function getValueAt(valueObject, pathArg) {
|
|
14
18
|
if (valueObject === undefined) return undefined;
|
|
15
19
|
var path = Array.isArray(pathArg) ? pathArg : pathArg.split('.');
|
|
@@ -54,6 +58,9 @@ export var DataFilter = function DataFilter(_ref) {
|
|
|
54
58
|
unfilteredData = _useContext.unfilteredData;
|
|
55
59
|
var _useContext2 = useContext(FormContext),
|
|
56
60
|
noForm = _useContext2.noForm;
|
|
61
|
+
var _useState = useState(''),
|
|
62
|
+
searchText = _useState[0],
|
|
63
|
+
setSearchText = _useState[1];
|
|
57
64
|
var _useMemo = useMemo(function () {
|
|
58
65
|
var _properties$property, _properties$property2;
|
|
59
66
|
if (children) return [undefined, undefined]; // caller driving
|
|
@@ -81,6 +88,19 @@ export var DataFilter = function DataFilter(_ref) {
|
|
|
81
88
|
}, [children, data, optionsProp, properties, property, rangeProp, unfilteredData]),
|
|
82
89
|
options = _useMemo[0],
|
|
83
90
|
range = _useMemo[1];
|
|
91
|
+
var searchedOptions = useMemo(function () {
|
|
92
|
+
if (!searchText) return options;
|
|
93
|
+
// The line below escapes regular expression special characters:
|
|
94
|
+
// [ \ ^ $ . | ? * + ( )
|
|
95
|
+
var escapedText = searchText.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
96
|
+
// Create the regular expression with modified value which
|
|
97
|
+
// handles escaping special characters. Without escaping special
|
|
98
|
+
// characters, errors will appear in the console
|
|
99
|
+
var exp = new RegExp(escapedText, 'i');
|
|
100
|
+
return options.filter(function (o) {
|
|
101
|
+
return typeof o === 'string' ? exp.test(o) : exp.test(o.label);
|
|
102
|
+
});
|
|
103
|
+
}, [options, searchText]);
|
|
84
104
|
var id = dataId + "-" + property;
|
|
85
105
|
var content = children;
|
|
86
106
|
if (!content) {
|
|
@@ -104,7 +124,7 @@ export var DataFilter = function DataFilter(_ref) {
|
|
|
104
124
|
name: property,
|
|
105
125
|
options: booleanOptions
|
|
106
126
|
});
|
|
107
|
-
} else if (options.length
|
|
127
|
+
} else if (options.length <= maxCheckBoxGroupOptions) {
|
|
108
128
|
content = /*#__PURE__*/React.createElement(CheckBoxGroup, {
|
|
109
129
|
id: id,
|
|
110
130
|
name: property,
|
|
@@ -115,7 +135,11 @@ export var DataFilter = function DataFilter(_ref) {
|
|
|
115
135
|
id: id,
|
|
116
136
|
name: property,
|
|
117
137
|
showSelectedInline: true,
|
|
118
|
-
options:
|
|
138
|
+
options: searchedOptions,
|
|
139
|
+
onSearch: options.length >= minSelectSearchOptions ? setSearchText : undefined,
|
|
140
|
+
onClose: function onClose() {
|
|
141
|
+
return setSearchText('');
|
|
142
|
+
}
|
|
119
143
|
});
|
|
120
144
|
}
|
|
121
145
|
}
|
|
@@ -29,7 +29,7 @@ var Content = function Content(_ref) {
|
|
|
29
29
|
var _useContext2 = useContext(MessageContext),
|
|
30
30
|
format = _useContext2.format;
|
|
31
31
|
var options = useMemo(function () {
|
|
32
|
-
return optionsArg || properties && Object.keys(properties).sort() || Object.keys(data[0]).sort();
|
|
32
|
+
return optionsArg || properties && Object.keys(properties).sort() || data.length > 0 && Object.keys(data[0]).sort() || data;
|
|
33
33
|
}, [data, optionsArg, properties]);
|
|
34
34
|
var directionOptions = [{
|
|
35
35
|
label: format({
|
|
@@ -26,7 +26,12 @@ export var datumValue = function datumValue(datum, property) {
|
|
|
26
26
|
|
|
27
27
|
// get the primary property name
|
|
28
28
|
export var normalizePrimaryProperty = function normalizePrimaryProperty(columns, primaryKey) {
|
|
29
|
-
var result
|
|
29
|
+
var result;
|
|
30
|
+
if (typeof primaryKey === 'string' || typeof primaryKey === 'boolean') {
|
|
31
|
+
result = primaryKey;
|
|
32
|
+
} else if (primaryKey === null) {
|
|
33
|
+
console.warn('null is not a supported value for primaryKey. See supported values: https://v2.grommet.io/datatable#primaryKey');
|
|
34
|
+
}
|
|
30
35
|
if (result === undefined) {
|
|
31
36
|
columns.forEach(function (column) {
|
|
32
37
|
// remember the first key property
|
|
@@ -108,8 +108,8 @@ var Content = function Content(_ref) {
|
|
|
108
108
|
if (nextSearch) {
|
|
109
109
|
var lowerSearch = nextSearch.toLowerCase();
|
|
110
110
|
nextFilteredOptions = options.filter(function (o) {
|
|
111
|
-
var _ref2, _ref3, _o$
|
|
112
|
-
return (_ref2 = (_ref3 = (_o$
|
|
111
|
+
var _ref2, _ref3, _o$label;
|
|
112
|
+
return (_ref2 = (_ref3 = (_o$label = o.label) != null ? _o$label : o.property) != null ? _ref3 : o) == null ? void 0 : _ref2.toLowerCase().includes(lowerSearch);
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
setSearch(nextSearch);
|
|
@@ -136,6 +136,26 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
136
136
|
}
|
|
137
137
|
}, [range, schema, textValue, reference, value]);
|
|
138
138
|
|
|
139
|
+
// textValue of MaskedInput is controlled.
|
|
140
|
+
// for uncontrolled forms, ensure the reset event
|
|
141
|
+
// resets the textValue
|
|
142
|
+
useEffect(function () {
|
|
143
|
+
var _ref$current;
|
|
144
|
+
var form = ref == null ? void 0 : (_ref$current = ref.current) == null ? void 0 : _ref$current.form;
|
|
145
|
+
var handleFormReset = function handleFormReset(e) {
|
|
146
|
+
if (schema && ref.current && e.target.contains(ref.current)) {
|
|
147
|
+
setTextValue('');
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
// place the listener on the form directly. if listener is on window,
|
|
151
|
+
// the event could get blocked if caller has e.stopPropagation(), etc. in
|
|
152
|
+
// their form onReset
|
|
153
|
+
form == null ? void 0 : form.addEventListener('reset', handleFormReset);
|
|
154
|
+
return function () {
|
|
155
|
+
return form == null ? void 0 : form.removeEventListener('reset', handleFormReset);
|
|
156
|
+
};
|
|
157
|
+
}, [schema, ref]);
|
|
158
|
+
|
|
139
159
|
// when format and not inline, whether to show the Calendar in a Drop
|
|
140
160
|
var _useState4 = useState(),
|
|
141
161
|
open = _useState4[0],
|
|
@@ -184,8 +204,8 @@ var DateInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
|
184
204
|
if (open && !range) {
|
|
185
205
|
closeCalendar();
|
|
186
206
|
setTimeout(function () {
|
|
187
|
-
var _ref$
|
|
188
|
-
return (_ref$
|
|
207
|
+
var _ref$current2;
|
|
208
|
+
return (_ref$current2 = ref.current) == null ? void 0 : _ref$current2.focus();
|
|
189
209
|
}, 1);
|
|
190
210
|
}
|
|
191
211
|
}
|
|
@@ -49,13 +49,17 @@ export var DoubleFooter = function DoubleFooter() {
|
|
|
49
49
|
flex: true
|
|
50
50
|
})), /*#__PURE__*/React.createElement(Footer, {
|
|
51
51
|
background: "dark-1",
|
|
52
|
-
pad: "large"
|
|
52
|
+
pad: "large",
|
|
53
|
+
title: "Links",
|
|
54
|
+
role: "contentinfo"
|
|
53
55
|
}, /*#__PURE__*/React.createElement(FooterContent, null)), /*#__PURE__*/React.createElement(Footer, {
|
|
54
56
|
background: "dark-2",
|
|
55
57
|
pad: {
|
|
56
58
|
horizontal: 'large',
|
|
57
59
|
vertical: 'small'
|
|
58
|
-
}
|
|
60
|
+
},
|
|
61
|
+
title: "Copyright",
|
|
62
|
+
role: "none"
|
|
59
63
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
60
64
|
direction: "row",
|
|
61
65
|
gap: "small"
|
|
@@ -56,11 +56,9 @@ export var Sitemap = function Sitemap() {
|
|
|
56
56
|
align: "center",
|
|
57
57
|
gap: "small"
|
|
58
58
|
}, /*#__PURE__*/React.createElement(GrommetIcon, {
|
|
59
|
-
color: "brand",
|
|
60
59
|
size: "large"
|
|
61
60
|
}), /*#__PURE__*/React.createElement(Text, {
|
|
62
61
|
alignSelf: "center",
|
|
63
|
-
color: "brand",
|
|
64
62
|
weight: "bold"
|
|
65
63
|
}, "grommet.io"))), /*#__PURE__*/React.createElement(FooterContent, null)))
|
|
66
64
|
// </Grommet>
|
|
@@ -35,7 +35,7 @@ export var Social = function Social() {
|
|
|
35
35
|
// Uncomment <Grommet> lines when using outside of storybook
|
|
36
36
|
// <Grommet theme={...}>
|
|
37
37
|
React.createElement(Box, null, /*#__PURE__*/React.createElement(Main, {
|
|
38
|
-
background: "light-
|
|
38
|
+
background: "light-1",
|
|
39
39
|
elevation: "large",
|
|
40
40
|
pad: "medium",
|
|
41
41
|
gap: "large"
|
|
@@ -45,7 +45,7 @@ export var Social = function Social() {
|
|
|
45
45
|
}, "Main Content"), /*#__PURE__*/React.createElement(Box, {
|
|
46
46
|
flex: true
|
|
47
47
|
})), /*#__PURE__*/React.createElement(Footer, {
|
|
48
|
-
background: "light-
|
|
48
|
+
background: "light-3",
|
|
49
49
|
pad: "small"
|
|
50
50
|
}, /*#__PURE__*/React.createElement(Box, {
|
|
51
51
|
align: "center",
|
|
@@ -266,15 +266,15 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
266
266
|
}));
|
|
267
267
|
} : content));
|
|
268
268
|
var menuItem = function menuItem(item, index) {
|
|
269
|
-
var _theme$menu$item, _theme$menu$item2, _theme$menu$item3;
|
|
269
|
+
var _theme$menu$item, _theme$menu$item2, _theme$menu$item3, _theme$menu$item4;
|
|
270
270
|
// Determine whether the label is done as a child or
|
|
271
271
|
// as an option Button kind property.
|
|
272
272
|
var child = !theme.button.option ? /*#__PURE__*/React.createElement(Box, {
|
|
273
|
-
align:
|
|
273
|
+
align: ((_theme$menu$item = theme.menu.item) == null ? void 0 : _theme$menu$item.align) || 'start',
|
|
274
274
|
pad: "small",
|
|
275
275
|
direction: "row",
|
|
276
|
-
gap: item.gap || ((_theme$menu$
|
|
277
|
-
justify: item.justify || ((_theme$menu$
|
|
276
|
+
gap: item.gap || ((_theme$menu$item2 = theme.menu.item) == null ? void 0 : _theme$menu$item2.gap),
|
|
277
|
+
justify: item.justify || ((_theme$menu$item3 = theme.menu.item) == null ? void 0 : _theme$menu$item3.justify)
|
|
278
278
|
}, item.reverse && item.label, item.icon, !item.reverse && item.label) : undefined;
|
|
279
279
|
|
|
280
280
|
// if we have a child, turn on plain, and hoverIndicator
|
|
@@ -300,7 +300,7 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
300
300
|
kind: !child ? 'option' : undefined,
|
|
301
301
|
hoverIndicator: !child ? undefined : 'background'
|
|
302
302
|
}, theme.menu.item, {
|
|
303
|
-
justify: item.justify || ((_theme$menu$
|
|
303
|
+
justify: item.justify || ((_theme$menu$item4 = theme.menu.item) == null ? void 0 : _theme$menu$item4.justify)
|
|
304
304
|
}, !child ? item : _extends({}, item, {
|
|
305
305
|
gap: undefined,
|
|
306
306
|
icon: undefined,
|
|
@@ -385,7 +385,10 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
385
385
|
overflow: "auto",
|
|
386
386
|
role: "menu",
|
|
387
387
|
a11yTitle: a11y
|
|
388
|
-
}, menuContent), !initialAlignTop && (
|
|
388
|
+
}, menuContent), !initialAlignTop && (
|
|
389
|
+
// don't show controlMirror if caller is using
|
|
390
|
+
// align.bottom === 'top'
|
|
391
|
+
alignControlMirror === 'bottom' && !align.bottom === 'top' || align.bottom === 'bottom') ? controlMirror : undefined))
|
|
389
392
|
}), content));
|
|
390
393
|
});
|
|
391
394
|
Menu.defaultProps = {
|
|
@@ -217,7 +217,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
217
217
|
// element to show, trumps inputValue
|
|
218
218
|
var selectValue = useMemo(function () {
|
|
219
219
|
if (valueLabel instanceof Function) {
|
|
220
|
-
if (value) return valueLabel(value);
|
|
220
|
+
if (value || value === 0 || value === false) return valueLabel(value);
|
|
221
221
|
} else if (valueLabel) return valueLabel;else if ( /*#__PURE__*/React.isValidElement(value)) return value; // deprecated
|
|
222
222
|
return undefined;
|
|
223
223
|
}, [value, valueLabel]);
|