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
|
@@ -204,9 +204,12 @@ var FormField = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
if (child && child.type && grommetInputNames.indexOf(child.type.displayName) !== -1 && child.props.plain === undefined && child.props.focusIndicator === undefined) {
|
|
207
|
+
var _formFieldTheme$check;
|
|
208
|
+
|
|
207
209
|
return /*#__PURE__*/cloneElement(child, {
|
|
208
210
|
plain: true,
|
|
209
|
-
focusIndicator: false
|
|
211
|
+
focusIndicator: false,
|
|
212
|
+
pad: 'CheckBox'.indexOf(child.type.displayName) !== -1 ? formFieldTheme == null ? void 0 : (_formFieldTheme$check = formFieldTheme.checkBox) == null ? void 0 : _formFieldTheme$check.pad : undefined
|
|
210
213
|
});
|
|
211
214
|
}
|
|
212
215
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["children", "full", "containerTarget", "theme", "options", "messages"];
|
|
1
|
+
var _excluded = ["children", "full", "containerTarget", "theme", "options", "messages", "onAnalytics"];
|
|
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
|
|
|
@@ -15,6 +15,7 @@ import { OptionsContext } from '../../contexts/OptionsContext';
|
|
|
15
15
|
import { format as _format, MessageContext } from '../../contexts/MessageContext';
|
|
16
16
|
import defaultMessages from '../../languages/default.json';
|
|
17
17
|
import { GrommetPropTypes } from './propTypes';
|
|
18
|
+
import { AnalyticsProvider } from '../../contexts/AnalyticsContext';
|
|
18
19
|
var FullGlobalStyle = createGlobalStyle(["body{margin:0;}"]);
|
|
19
20
|
|
|
20
21
|
var deviceResponsive = function deviceResponsive(userAgent, theme) {
|
|
@@ -52,6 +53,7 @@ var Grommet = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
52
53
|
_props$options = props.options,
|
|
53
54
|
options = _props$options === void 0 ? defaultOptions : _props$options,
|
|
54
55
|
messagesProp = props.messages,
|
|
56
|
+
onAnalytics = props.onAnalytics,
|
|
55
57
|
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
56
58
|
|
|
57
59
|
var background = props.background,
|
|
@@ -132,11 +134,13 @@ var Grommet = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
132
134
|
value: options
|
|
133
135
|
}, /*#__PURE__*/React.createElement(MessageContext.Provider, {
|
|
134
136
|
value: messages
|
|
137
|
+
}, /*#__PURE__*/React.createElement(AnalyticsProvider, {
|
|
138
|
+
onAnalytics: onAnalytics
|
|
135
139
|
}, /*#__PURE__*/React.createElement(StyledGrommet, _extends({
|
|
136
140
|
full: full
|
|
137
141
|
}, rest, {
|
|
138
142
|
ref: grommetRef
|
|
139
|
-
}), children), full && /*#__PURE__*/React.createElement(FullGlobalStyle, null)))))));
|
|
143
|
+
}), children), full && /*#__PURE__*/React.createElement(FullGlobalStyle, null))))))));
|
|
140
144
|
});
|
|
141
145
|
Grommet.displayName = 'Grommet';
|
|
142
146
|
Grommet.propTypes = GrommetPropTypes;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["color", "fill", "level"];
|
|
1
|
+
var _excluded = ["color", "fill", "level", "weight"];
|
|
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
|
|
|
@@ -12,6 +12,7 @@ var Heading = /*#__PURE__*/forwardRef(function (_ref, ref // munged to avoid sty
|
|
|
12
12
|
var color = _ref.color,
|
|
13
13
|
fill = _ref.fill,
|
|
14
14
|
level = _ref.level,
|
|
15
|
+
weight = _ref.weight,
|
|
15
16
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
17
|
|
|
17
18
|
return (
|
|
@@ -21,7 +22,8 @@ var Heading = /*#__PURE__*/forwardRef(function (_ref, ref // munged to avoid sty
|
|
|
21
22
|
as: "h" + level,
|
|
22
23
|
colorProp: color,
|
|
23
24
|
fillProp: fill,
|
|
24
|
-
level: +level
|
|
25
|
+
level: +level,
|
|
26
|
+
weight: weight
|
|
25
27
|
}, rest, {
|
|
26
28
|
ref: ref
|
|
27
29
|
}))
|
|
@@ -10,7 +10,7 @@ var sizeStyle = function sizeStyle(props) {
|
|
|
10
10
|
|
|
11
11
|
if (levelStyle) {
|
|
12
12
|
var data = levelStyle[size];
|
|
13
|
-
var styles = [css(["font-size:", ";line-height:", ";max-width:", ";font-weight:", ";"], data ? data.size : size, data ? data.height : 'normal', props.fillProp && 'none' || data && data.maxWidth || levelStyle.medium.maxWidth, levelStyle.font.weight || headingTheme.weight)];
|
|
13
|
+
var styles = [css(["font-size:", ";line-height:", ";max-width:", ";font-weight:", ";"], data ? data.size : size, data ? data.height : 'normal', props.fillProp && 'none' || data && data.maxWidth || levelStyle.medium.maxWidth, props.weight || levelStyle.font.weight || headingTheme.weight)];
|
|
14
14
|
|
|
15
15
|
if (props.responsive && headingTheme.responsiveBreakpoint) {
|
|
16
16
|
var breakpoint = props.theme.global.breakpoints[headingTheme.responsiveBreakpoint];
|
|
@@ -12,7 +12,8 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
12
12
|
responsive: PropTypes.bool,
|
|
13
13
|
size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large', 'xlarge']), PropTypes.string]),
|
|
14
14
|
textAlign: PropTypes.oneOf(['start', 'center', 'end', 'justify']),
|
|
15
|
-
truncate: PropTypes.bool
|
|
15
|
+
truncate: PropTypes.bool,
|
|
16
|
+
weight: PropTypes.oneOfType([PropTypes.oneOf(['normal', 'bold', 'lighter', 'bolder']), PropTypes.number, PropTypes.string])
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -12,6 +12,7 @@ import { Keyboard } from '../Keyboard';
|
|
|
12
12
|
import { ResponsiveContext } from '../../contexts/ResponsiveContext';
|
|
13
13
|
import { OptionsContext } from '../../contexts/OptionsContext';
|
|
14
14
|
import { ContainerTargetContext } from '../../contexts/ContainerTargetContext';
|
|
15
|
+
import { useAnalytics } from '../../contexts/AnalyticsContext';
|
|
15
16
|
import { backgroundIsDark, findVisibleParent, PortalContext } from '../../utils';
|
|
16
17
|
import { StyledLayer, StyledContainer, StyledOverlay } from './StyledLayer';
|
|
17
18
|
var HiddenAnchor = styled.a.withConfig({
|
|
@@ -57,6 +58,22 @@ var LayerContainer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
57
58
|
var nextPortalContext = useMemo(function () {
|
|
58
59
|
return [].concat(portalContext, [portalId]);
|
|
59
60
|
}, [portalContext, portalId]);
|
|
61
|
+
var sendAnalytics = useAnalytics();
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
var start = new Date();
|
|
64
|
+
var element = layerRef.current;
|
|
65
|
+
sendAnalytics({
|
|
66
|
+
type: 'layerOpen',
|
|
67
|
+
element: element
|
|
68
|
+
});
|
|
69
|
+
return function () {
|
|
70
|
+
sendAnalytics({
|
|
71
|
+
type: 'layerClose',
|
|
72
|
+
element: element,
|
|
73
|
+
elapsed: new Date().getTime() - start.getTime()
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
}, [sendAnalytics, layerRef]);
|
|
60
77
|
useEffect(function () {
|
|
61
78
|
if (position !== 'hidden') {
|
|
62
79
|
var node = layerRef.current || containerRef.current || ref.current;
|
|
@@ -284,21 +284,23 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
284
284
|
// go to the first menu item instead.
|
|
285
285
|
,
|
|
286
286
|
tabIndex: activeItemIndex === constants.none ? '-1' : undefined
|
|
287
|
-
}, buttonProps), typeof content === 'function' ? function () {
|
|
287
|
+
}, theme.menu.item, buttonProps), typeof content === 'function' ? function () {
|
|
288
288
|
return content(_extends({}, props, {
|
|
289
289
|
drop: true
|
|
290
290
|
}));
|
|
291
291
|
} : content));
|
|
292
292
|
|
|
293
293
|
var menuItem = function menuItem(item, index) {
|
|
294
|
+
var _theme$menu$item, _theme$menu$item2, _theme$menu$item3;
|
|
295
|
+
|
|
294
296
|
// Determine whether the label is done as a child or
|
|
295
297
|
// as an option Button kind property.
|
|
296
298
|
var child = !theme.button.option ? /*#__PURE__*/React.createElement(Box, {
|
|
297
299
|
align: "start",
|
|
298
300
|
pad: "small",
|
|
299
301
|
direction: "row",
|
|
300
|
-
gap: item.gap,
|
|
301
|
-
justify: item.justify
|
|
302
|
+
gap: item.gap || ((_theme$menu$item = theme.menu.item) == null ? void 0 : _theme$menu$item.gap),
|
|
303
|
+
justify: item.justify || ((_theme$menu$item2 = theme.menu.item) == null ? void 0 : _theme$menu$item2.justify)
|
|
302
304
|
}, item.reverse && item.label, item.icon, !item.reverse && item.label) : undefined; // if we have a child, turn on plain, and hoverIndicator
|
|
303
305
|
|
|
304
306
|
return (
|
|
@@ -320,9 +322,10 @@ var Menu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
320
322
|
focusIndicator: false,
|
|
321
323
|
plain: !child ? undefined : true,
|
|
322
324
|
align: "start",
|
|
323
|
-
justify: item.justify,
|
|
324
325
|
kind: !child ? 'option' : undefined,
|
|
325
326
|
hoverIndicator: !child ? undefined : 'background'
|
|
327
|
+
}, theme.menu.item, {
|
|
328
|
+
justify: item.justify || ((_theme$menu$item3 = theme.menu.item) == null ? void 0 : _theme$menu$item3.justify)
|
|
326
329
|
}, !child ? item : _extends({}, item, {
|
|
327
330
|
gap: undefined,
|
|
328
331
|
icon: undefined,
|
|
@@ -60,10 +60,16 @@ const customBreakpoints: ThemeType = {
|
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
menu: {
|
|
63
|
+
background: 'light-3',
|
|
63
64
|
icons: {
|
|
64
65
|
down: FormDown,
|
|
65
66
|
up: FormUp,
|
|
66
67
|
},
|
|
68
|
+
item: {
|
|
69
|
+
color: 'brand',
|
|
70
|
+
style: { fontFamily: 'Arial', fontWeight: 'bold' },
|
|
71
|
+
},
|
|
72
|
+
extend: `border: 3px solid gray`,
|
|
67
73
|
},
|
|
68
74
|
};
|
|
69
75
|
|
|
@@ -28,8 +28,12 @@ var Circle = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
28
28
|
var centerY = width / 2;
|
|
29
29
|
var radius = width / 2 - strokeWidth / 2; // truncate to avoid floating point arithmetic errors
|
|
30
30
|
// see: https://github.com/grommet/grommet/issues/6190
|
|
31
|
+
// Choose a scale factor at least 3 orders of magnitude above max
|
|
32
|
+
|
|
33
|
+
var scalePower = Math.max(5, Math.ceil(Math.log10(max)) + 3);
|
|
34
|
+
var scale = Math.pow(10, scalePower);
|
|
35
|
+
var anglePer = Math.floor((type === 'semicircle' ? 180 : 360) / max * scale) / scale; // (type === 'semicircle' ? 180 : 360) / max;
|
|
31
36
|
|
|
32
|
-
var anglePer = Math.floor((type === 'semicircle' ? 180 : 360) / max * 10000) / 10000;
|
|
33
37
|
var someHighlight = (values || []).some(function (v) {
|
|
34
38
|
return v.highlight;
|
|
35
39
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var _excluded = ["actions", "gridProps", "parent", "responsive", "subtitle", "title"];
|
|
2
|
-
|
|
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); }
|
|
1
|
+
var _excluded = ["actions", "gridProps", "parent", "responsive", "size", "subtitle", "title"];
|
|
4
2
|
|
|
5
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; }
|
|
6
4
|
|
|
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
|
+
|
|
7
7
|
import React, { forwardRef, useContext } from 'react';
|
|
8
8
|
import { ThemeContext } from 'styled-components';
|
|
9
9
|
import { Box } from '../Box';
|
|
@@ -12,14 +12,24 @@ import { Heading } from '../Heading';
|
|
|
12
12
|
import { Grid } from '../Grid';
|
|
13
13
|
import { Paragraph } from '../Paragraph';
|
|
14
14
|
import { ResponsiveContext } from '../../contexts/ResponsiveContext';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
|
|
16
|
+
var sizeStyle = function sizeStyle(size, feature, theme) {
|
|
17
|
+
var _ref, _theme$pageHeader$siz;
|
|
18
|
+
|
|
19
|
+
var style = _extends({}, theme.pageHeader[feature], (_ref = size && ((_theme$pageHeader$siz = theme.pageHeader.size[size]) == null ? void 0 : _theme$pageHeader$siz[feature])) != null ? _ref : theme.pageHeader[feature]);
|
|
20
|
+
|
|
21
|
+
return style;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var PageHeader = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
25
|
+
var actions = _ref2.actions,
|
|
26
|
+
gridPropsProp = _ref2.gridProps,
|
|
27
|
+
parent = _ref2.parent,
|
|
28
|
+
responsive = _ref2.responsive,
|
|
29
|
+
size = _ref2.size,
|
|
30
|
+
subtitle = _ref2.subtitle,
|
|
31
|
+
title = _ref2.title,
|
|
32
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
23
33
|
|
|
24
34
|
var theme = useContext(ThemeContext);
|
|
25
35
|
var breakpoint = useContext(ResponsiveContext);
|
|
@@ -42,7 +52,7 @@ var PageHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
42
52
|
ref: ref,
|
|
43
53
|
direction: "column",
|
|
44
54
|
gap: "none",
|
|
45
|
-
pad: theme
|
|
55
|
+
pad: sizeStyle(size, 'pad', theme)
|
|
46
56
|
}, rest), /*#__PURE__*/React.createElement(Grid, _extends({
|
|
47
57
|
columns: columns,
|
|
48
58
|
rows: rows,
|
|
@@ -53,9 +63,9 @@ var PageHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
53
63
|
gridArea: "parent"
|
|
54
64
|
}, theme.pageHeader.parent), parent), /*#__PURE__*/React.createElement(Box, {
|
|
55
65
|
gridArea: "title"
|
|
56
|
-
}, typeof title === 'string' ? /*#__PURE__*/React.createElement(Heading,
|
|
66
|
+
}, typeof title === 'string' ? /*#__PURE__*/React.createElement(Heading, sizeStyle(size, 'title', theme), title) : title), /*#__PURE__*/React.createElement(Box, {
|
|
57
67
|
gridArea: "subtitle"
|
|
58
|
-
}, typeof subtitle === 'string' ? /*#__PURE__*/React.createElement(Paragraph,
|
|
68
|
+
}, typeof subtitle === 'string' ? /*#__PURE__*/React.createElement(Paragraph, sizeStyle(size, 'subtitle', theme), subtitle) : subtitle), /*#__PURE__*/React.createElement(Box, _extends({
|
|
59
69
|
gridArea: "actions"
|
|
60
70
|
}, actionsProps), actions)));
|
|
61
71
|
});
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
GridAreaType,
|
|
6
6
|
MarginType,
|
|
7
7
|
} from '../../utils';
|
|
8
|
+
import { BoxProps } from '../Box/index';
|
|
8
9
|
|
|
9
10
|
import { GridProps } from '../Grid';
|
|
10
11
|
export interface PageHeaderProps {
|
|
@@ -16,11 +17,19 @@ export interface PageHeaderProps {
|
|
|
16
17
|
gridProps?: GridProps;
|
|
17
18
|
parent?: JSX.Element;
|
|
18
19
|
responsive?: boolean;
|
|
20
|
+
size?: 'small' | 'medium' | 'large';
|
|
19
21
|
subtitle?: string | JSX.Element;
|
|
20
22
|
title?: string | JSX.Element;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
type divProps = Omit<JSX.IntrinsicElements['div'], 'onClick' | 'title'>;
|
|
26
|
+
|
|
27
|
+
export interface PageHeaderExtendedProps
|
|
28
|
+
extends BoxProps,
|
|
29
|
+
PageHeaderProps,
|
|
30
|
+
divProps {}
|
|
31
|
+
|
|
32
|
+
declare const PageHeader: React.FC<PageHeaderExtendedProps>;
|
|
24
33
|
export type PageHeaderType = PageHeaderProps;
|
|
25
34
|
|
|
26
35
|
export { PageHeader };
|
|
@@ -11,6 +11,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
11
11
|
gridProps: GridPropTypes,
|
|
12
12
|
parent: PropTypes.element,
|
|
13
13
|
responsive: PropTypes.bool,
|
|
14
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
14
15
|
subtitle: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
|
|
15
16
|
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
|
|
16
17
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Anchor, Button, PageHeader, Page, PageContent } from 'grommet';
|
|
3
|
+
export var Size = function Size() {
|
|
4
|
+
return (
|
|
5
|
+
/*#__PURE__*/
|
|
6
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
7
|
+
// <Grommet theme={...}>
|
|
8
|
+
React.createElement(Page, null, /*#__PURE__*/React.createElement(PageContent, null, /*#__PURE__*/React.createElement(PageHeader, {
|
|
9
|
+
title: "Small PageHeader",
|
|
10
|
+
subtitle: "Grommet helps you build responsive and accessible \n mobile-first projects for the web with an easy to use component \n library.",
|
|
11
|
+
actions: /*#__PURE__*/React.createElement(Button, {
|
|
12
|
+
label: "Page-level action"
|
|
13
|
+
}),
|
|
14
|
+
parent: /*#__PURE__*/React.createElement(Anchor, {
|
|
15
|
+
label: "Parent Page"
|
|
16
|
+
}),
|
|
17
|
+
size: "small"
|
|
18
|
+
}), /*#__PURE__*/React.createElement(PageHeader, {
|
|
19
|
+
title: "Medium PageHeader (default)",
|
|
20
|
+
subtitle: "Grommet helps you build responsive and accessible \n mobile-first projects for the web with an easy to use component \n library.",
|
|
21
|
+
actions: /*#__PURE__*/React.createElement(Button, {
|
|
22
|
+
label: "Page-level action"
|
|
23
|
+
}),
|
|
24
|
+
parent: /*#__PURE__*/React.createElement(Anchor, {
|
|
25
|
+
label: "Parent Page"
|
|
26
|
+
})
|
|
27
|
+
}), /*#__PURE__*/React.createElement(PageHeader, {
|
|
28
|
+
title: "Large PageHeader",
|
|
29
|
+
subtitle: "Grommet helps you build responsive and accessible \n mobile-first projects for the web with an easy to use component \n library.",
|
|
30
|
+
actions: /*#__PURE__*/React.createElement(Button, {
|
|
31
|
+
label: "Page-level action"
|
|
32
|
+
}),
|
|
33
|
+
parent: /*#__PURE__*/React.createElement(Anchor, {
|
|
34
|
+
label: "Parent Page"
|
|
35
|
+
}),
|
|
36
|
+
size: "large"
|
|
37
|
+
}))) // </Grommet>
|
|
38
|
+
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
export default {
|
|
42
|
+
title: 'Layout/PageHeader/Size'
|
|
43
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
var _excluded = ["clear", "onClear", "name", "theme"];
|
|
2
|
+
|
|
1
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); }
|
|
2
4
|
|
|
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
|
+
|
|
3
7
|
import React, { forwardRef, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
4
8
|
import styled, { ThemeContext } from 'styled-components';
|
|
5
9
|
import { getHoverIndicatorStyle, selectedStyle, setFocusWithoutScroll } from '../../utils';
|
|
@@ -11,7 +15,8 @@ import { Keyboard } from '../Keyboard';
|
|
|
11
15
|
import { Text } from '../Text';
|
|
12
16
|
import { TextInput } from '../TextInput';
|
|
13
17
|
import { StyledContainer } from './StyledSelect';
|
|
14
|
-
import { applyKey } from './utils';
|
|
18
|
+
import { applyKey } from './utils';
|
|
19
|
+
import { containsFocus } from '../../utils/DOM'; // position relative is so scroll can be managed correctly
|
|
15
20
|
|
|
16
21
|
var OptionsBox = styled.div.withConfig({
|
|
17
22
|
displayName: "SelectContainer__OptionsBox",
|
|
@@ -20,26 +25,38 @@ var OptionsBox = styled.div.withConfig({
|
|
|
20
25
|
var SelectOption = styled(Button).withConfig({
|
|
21
26
|
displayName: "SelectContainer__SelectOption",
|
|
22
27
|
componentId: "sc-1wi0ul8-1"
|
|
23
|
-
})(["", " ", " display:block;width:100%;"], function (props) {
|
|
28
|
+
})(["", " ", " &:focus{", "}display:block;width:100%;"], function (props) {
|
|
24
29
|
return props.selected && props.textComponent && selectedStyle;
|
|
25
30
|
}, function (props) {
|
|
26
31
|
return props.active && getHoverIndicatorStyle(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
32
|
+
}, function (props) {
|
|
33
|
+
return props.active && getHoverIndicatorStyle(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
34
|
+
}); // ensure ClearButton receives visual indication of keyboard
|
|
35
|
+
|
|
36
|
+
var StyledButton = styled(Button).withConfig({
|
|
37
|
+
displayName: "SelectContainer__StyledButton",
|
|
38
|
+
componentId: "sc-1wi0ul8-2"
|
|
39
|
+
})(["&:focus{", "}"], function (props) {
|
|
40
|
+
return getHoverIndicatorStyle('background', props.theme);
|
|
27
41
|
});
|
|
28
42
|
var ClearButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
29
43
|
var clear = _ref.clear,
|
|
30
44
|
onClear = _ref.onClear,
|
|
31
45
|
name = _ref.name,
|
|
32
|
-
theme = _ref.theme
|
|
46
|
+
theme = _ref.theme,
|
|
47
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
48
|
+
|
|
33
49
|
var label = clear.label,
|
|
34
50
|
position = clear.position;
|
|
35
51
|
var align = position !== 'bottom' ? 'start' : 'center';
|
|
36
52
|
var buttonLabel = label || "Clear " + (name || 'selection');
|
|
37
|
-
return /*#__PURE__*/React.createElement(
|
|
53
|
+
return /*#__PURE__*/React.createElement(StyledButton, _extends({
|
|
54
|
+
a11yTitle: buttonLabel + ". Or, press " + (position === 'bottom' ? 'shift tab' : 'down arrow') + " to move to select options",
|
|
38
55
|
fill: "horizontal",
|
|
39
56
|
ref: ref,
|
|
40
57
|
onClick: onClear,
|
|
41
58
|
focusIndicator: false
|
|
42
|
-
}, /*#__PURE__*/React.createElement(Box, _extends({}, theme.select.clear.container, {
|
|
59
|
+
}, rest), /*#__PURE__*/React.createElement(Box, _extends({}, theme.select.clear.container, {
|
|
43
60
|
align: align
|
|
44
61
|
}), /*#__PURE__*/React.createElement(Text, theme.select.clear.text, buttonLabel)));
|
|
45
62
|
});
|
|
@@ -74,8 +91,13 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
74
91
|
_ref2$replace = _ref2.replace,
|
|
75
92
|
replace = _ref2$replace === void 0 ? true : _ref2$replace;
|
|
76
93
|
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
94
|
+
var shouldShowClearButton = useCallback(function (position) {
|
|
95
|
+
var hasValue = Boolean(multiple ? value.length : value);
|
|
96
|
+
var showAtPosition = position === 'bottom' ? (clear == null ? void 0 : clear.position) === 'bottom' : (clear == null ? void 0 : clear.position) !== 'bottom';
|
|
97
|
+
return clear && hasValue && showAtPosition;
|
|
98
|
+
}, [clear, multiple, value]);
|
|
77
99
|
|
|
78
|
-
var _useState = useState(usingKeyboard ? 0 : -1),
|
|
100
|
+
var _useState = useState(usingKeyboard && !shouldShowClearButton('top') ? 0 : -1),
|
|
79
101
|
activeIndex = _useState[0],
|
|
80
102
|
setActiveIndex = _useState[1];
|
|
81
103
|
|
|
@@ -91,7 +113,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
91
113
|
useEffect(function () {
|
|
92
114
|
var _activeRef$current;
|
|
93
115
|
|
|
94
|
-
if (activeIndex) (_activeRef$current = activeRef.current) == null ? void 0 : _activeRef$current.focus();
|
|
116
|
+
if (activeIndex >= 0) (_activeRef$current = activeRef.current) == null ? void 0 : _activeRef$current.focus();
|
|
95
117
|
}, [activeIndex]); // set initial focus
|
|
96
118
|
|
|
97
119
|
useEffect(function () {
|
|
@@ -119,11 +141,11 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
119
141
|
};
|
|
120
142
|
}, [onSearch, usingKeyboard, clear]);
|
|
121
143
|
var optionLabel = useCallback(function (index) {
|
|
122
|
-
return applyKey(options[index], labelKey);
|
|
123
|
-
}, [labelKey, options]);
|
|
144
|
+
return applyKey(options[index], labelKey || valueKey);
|
|
145
|
+
}, [labelKey, options, valueKey]);
|
|
124
146
|
var optionValue = useCallback(function (index) {
|
|
125
|
-
return applyKey(options[index], valueKey);
|
|
126
|
-
}, [options, valueKey]);
|
|
147
|
+
return applyKey(options[index], valueKey || labelKey);
|
|
148
|
+
}, [options, valueKey, labelKey]);
|
|
127
149
|
var isDisabled = useCallback(function (index) {
|
|
128
150
|
var option = options[index];
|
|
129
151
|
var result;
|
|
@@ -215,7 +237,6 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
215
237
|
var onNextOption = useCallback(function (event) {
|
|
216
238
|
event.preventDefault();
|
|
217
239
|
var nextActiveIndex = activeIndex + 1;
|
|
218
|
-
var clearButton = clearRef.current;
|
|
219
240
|
|
|
220
241
|
while (nextActiveIndex < options.length && isDisabled(nextActiveIndex)) {
|
|
221
242
|
nextActiveIndex += 1;
|
|
@@ -225,21 +246,19 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
225
246
|
setActiveIndex(nextActiveIndex);
|
|
226
247
|
setKeyboardNavigation(true);
|
|
227
248
|
}
|
|
228
|
-
|
|
229
|
-
if (clear && clear.position === 'bottom' && clearButton && nextActiveIndex >= options.length) {
|
|
230
|
-
setActiveIndex(options.length);
|
|
231
|
-
setFocusWithoutScroll(clearButton);
|
|
232
|
-
}
|
|
233
|
-
}, [activeIndex, isDisabled, options, clear]);
|
|
249
|
+
}, [activeIndex, isDisabled, options]);
|
|
234
250
|
var onPreviousOption = useCallback(function (event) {
|
|
235
251
|
event.preventDefault();
|
|
236
252
|
var nextActiveIndex = activeIndex - 1;
|
|
237
|
-
var clearButton = clearRef.current;
|
|
238
253
|
|
|
239
254
|
if (nextActiveIndex === -1) {
|
|
240
255
|
var searchInput = searchRef.current;
|
|
256
|
+
var clearButton = clearRef.current;
|
|
241
257
|
|
|
242
|
-
if (
|
|
258
|
+
if (clearButton && clearButton.focus && shouldShowClearButton('top')) {
|
|
259
|
+
setActiveIndex(nextActiveIndex);
|
|
260
|
+
setFocusWithoutScroll(clearButton);
|
|
261
|
+
} else if (searchInput && searchInput.focus) {
|
|
243
262
|
setActiveIndex(nextActiveIndex);
|
|
244
263
|
setFocusWithoutScroll(searchInput);
|
|
245
264
|
}
|
|
@@ -253,11 +272,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
253
272
|
setActiveIndex(nextActiveIndex);
|
|
254
273
|
setKeyboardNavigation(true);
|
|
255
274
|
}
|
|
256
|
-
|
|
257
|
-
if (clear && clear.position !== 'bottom' && clearButton && activeIndex === 0) {
|
|
258
|
-
setActiveIndex(-1);
|
|
259
|
-
}
|
|
260
|
-
}, [activeIndex, isDisabled, clear]);
|
|
275
|
+
}, [activeIndex, isDisabled, shouldShowClearButton]);
|
|
261
276
|
var onKeyDownOption = useCallback(function (event) {
|
|
262
277
|
if (!onSearch) {
|
|
263
278
|
var nextActiveIndex = options.findIndex(function (e, index) {
|
|
@@ -289,19 +304,18 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
289
304
|
};
|
|
290
305
|
}, [keyboardNavigation]);
|
|
291
306
|
var onSelectOption = useCallback(function (event) {
|
|
292
|
-
if (
|
|
307
|
+
if ((shouldShowClearButton('bottom') || shouldShowClearButton('top')) && containsFocus(clearRef.current)) {
|
|
308
|
+
onChange(event, {
|
|
309
|
+
option: undefined,
|
|
310
|
+
value: '',
|
|
311
|
+
selected: ''
|
|
312
|
+
});
|
|
313
|
+
} else if (activeIndex >= 0 && activeIndex < options.length) {
|
|
293
314
|
event.preventDefault(); // prevent submitting forms
|
|
294
315
|
|
|
295
316
|
selectOption(activeIndex)(event);
|
|
296
317
|
}
|
|
297
|
-
}, [activeIndex, selectOption, options]);
|
|
298
|
-
|
|
299
|
-
var shouldShowClearButton = function shouldShowClearButton(position) {
|
|
300
|
-
var hasValue = Boolean(multiple ? value.length : value);
|
|
301
|
-
var showAtPosition = position === 'bottom' ? (clear == null ? void 0 : clear.position) === 'bottom' : (clear == null ? void 0 : clear.position) !== 'bottom';
|
|
302
|
-
return clear && hasValue && showAtPosition;
|
|
303
|
-
};
|
|
304
|
-
|
|
318
|
+
}, [activeIndex, selectOption, options, onChange, shouldShowClearButton]);
|
|
305
319
|
var customSearchInput = theme.select.searchInput;
|
|
306
320
|
var SelectTextInput = customSearchInput || TextInput;
|
|
307
321
|
var selectOptionsStyle = theme.select.options ? _extends({}, theme.select.options.box, theme.select.options.container) : {};
|
|
@@ -332,7 +346,19 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
332
346
|
setActiveIndex(-1);
|
|
333
347
|
onSearch(nextSearch);
|
|
334
348
|
}
|
|
335
|
-
})), /*#__PURE__*/React.createElement(
|
|
349
|
+
})), shouldShowClearButton('top') && /*#__PURE__*/React.createElement(ClearButton, {
|
|
350
|
+
ref: clearRef,
|
|
351
|
+
clear: clear,
|
|
352
|
+
name: name,
|
|
353
|
+
onClear: onClear,
|
|
354
|
+
onFocus: function onFocus() {
|
|
355
|
+
return setActiveIndex(-1);
|
|
356
|
+
},
|
|
357
|
+
onMouseOver: function onMouseOver() {
|
|
358
|
+
return setActiveIndex(-1);
|
|
359
|
+
},
|
|
360
|
+
theme: theme
|
|
361
|
+
}), /*#__PURE__*/React.createElement(OptionsBox, {
|
|
336
362
|
role: "listbox",
|
|
337
363
|
tabIndex: "-1",
|
|
338
364
|
ref: optionsRef,
|
|
@@ -340,13 +366,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
340
366
|
onMouseMove: function onMouseMove() {
|
|
341
367
|
return setKeyboardNavigation(false);
|
|
342
368
|
}
|
|
343
|
-
},
|
|
344
|
-
ref: clearRef,
|
|
345
|
-
clear: clear,
|
|
346
|
-
name: name,
|
|
347
|
-
onClear: onClear,
|
|
348
|
-
theme: theme
|
|
349
|
-
}), options.length > 0 ? /*#__PURE__*/React.createElement(InfiniteScroll, {
|
|
369
|
+
}, options.length > 0 ? /*#__PURE__*/React.createElement(InfiniteScroll, {
|
|
350
370
|
items: options,
|
|
351
371
|
step: theme.select.step,
|
|
352
372
|
onMore: onMore,
|
|
@@ -396,7 +416,12 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
396
416
|
label: !child ? optionLabel(index) : undefined,
|
|
397
417
|
disabled: optionDisabled || undefined,
|
|
398
418
|
active: optionActive,
|
|
399
|
-
selected: optionSelected
|
|
419
|
+
selected: optionSelected // allow keyboard navigation to start from
|
|
420
|
+
// selected option after tabbing to it
|
|
421
|
+
,
|
|
422
|
+
onFocus: function onFocus() {
|
|
423
|
+
return setActiveIndex(index);
|
|
424
|
+
},
|
|
400
425
|
onMouseOver: !optionDisabled ? onActiveOption(index) : undefined,
|
|
401
426
|
onClick: !optionDisabled ? selectOption(index) : undefined,
|
|
402
427
|
textComponent: textComponent
|
|
@@ -407,12 +432,18 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
407
432
|
role: "menuitem",
|
|
408
433
|
hoverIndicator: "background",
|
|
409
434
|
disabled: true
|
|
410
|
-
}, /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, theme.select.container.text, emptySearchMessage))), shouldShowClearButton('bottom') && /*#__PURE__*/React.createElement(ClearButton, {
|
|
435
|
+
}, /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, theme.select.container.text, emptySearchMessage)))), shouldShowClearButton('bottom') && /*#__PURE__*/React.createElement(ClearButton, {
|
|
411
436
|
ref: clearRef,
|
|
412
437
|
clear: clear,
|
|
413
438
|
name: name,
|
|
414
439
|
onClear: onClear,
|
|
440
|
+
onFocus: function onFocus() {
|
|
441
|
+
return setActiveIndex(-1);
|
|
442
|
+
},
|
|
443
|
+
onMouseOver: function onMouseOver() {
|
|
444
|
+
return setActiveIndex(-1);
|
|
445
|
+
},
|
|
415
446
|
theme: theme
|
|
416
|
-
})))
|
|
447
|
+
})));
|
|
417
448
|
});
|
|
418
449
|
export { SelectContainer };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { Box, Select } from 'grommet';
|
|
3
|
-
var options = [
|
|
3
|
+
var options = [];
|
|
4
|
+
|
|
5
|
+
for (var i = 0; i < 500; i += 1) {
|
|
6
|
+
options.push("Number " + i);
|
|
7
|
+
}
|
|
4
8
|
|
|
5
9
|
var ClearTop = function ClearTop() {
|
|
6
10
|
var _useState = useState(),
|
|
@@ -21,6 +25,7 @@ var ClearTop = function ClearTop() {
|
|
|
21
25
|
var nextValue = _ref.value;
|
|
22
26
|
return setValue(nextValue);
|
|
23
27
|
},
|
|
28
|
+
dropHeight: "large",
|
|
24
29
|
clear: true
|
|
25
30
|
}));
|
|
26
31
|
};
|
|
@@ -44,6 +49,7 @@ var ClearBottom = function ClearBottom() {
|
|
|
44
49
|
var nextValue = _ref2.value;
|
|
45
50
|
return setValue(nextValue);
|
|
46
51
|
},
|
|
52
|
+
dropHeight: "large",
|
|
47
53
|
clear: {
|
|
48
54
|
position: 'bottom'
|
|
49
55
|
}
|