grommet 2.25.2 → 2.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Anchor/Anchor.js +1 -1
- package/components/Box/stories/BackgroundThemed.js +54 -0
- package/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/components/Button/Button.js +2 -2
- package/components/Calendar/Calendar.js +2 -1
- package/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
- package/components/CheckBoxGroup/index.d.ts +2 -1
- package/components/CheckBoxGroup/propTypes.js +1 -0
- package/components/FormField/FormField.js +1 -1
- package/components/Heading/Heading.js +31 -2
- package/components/Heading/StyledHeading.js +1 -1
- package/components/Heading/index.d.ts +1 -0
- package/components/Heading/propTypes.js +1 -0
- package/components/Heading/stories/All.js +4 -1
- package/components/Layer/LayerContainer.js +16 -9
- package/components/List/List.js +131 -33
- package/components/List/index.d.ts +1 -0
- package/components/List/propTypes.js +1 -0
- package/components/List/stories/Pinned.js +36 -0
- package/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/components/Select/DefaultSelectTextInput.js +43 -0
- package/components/Select/EmptySearchOption.js +34 -0
- package/components/Select/Select.js +30 -95
- package/components/Select/SelectContainer.js +19 -59
- package/components/Select/StyledSelect.js +58 -2
- package/components/Select/index.d.ts +11 -9
- package/components/Select/propTypes.js +44 -40
- package/components/Select/utils.js +103 -3
- package/components/SelectMultiple/README.md +2 -0
- package/components/SelectMultiple/SelectMultiple.js +476 -0
- package/components/SelectMultiple/SelectMultipleContainer.js +481 -0
- package/components/SelectMultiple/SelectMultipleValue.js +166 -0
- package/components/SelectMultiple/SelectionSummary.js +104 -0
- package/components/SelectMultiple/index.d.ts +21 -0
- package/components/SelectMultiple/index.js +8 -0
- package/components/SelectMultiple/propTypes.js +28 -0
- package/components/SelectMultiple/stories/Default.js +76 -0
- package/components/SelectMultiple/stories/Disabled.js +84 -0
- package/components/SelectMultiple/stories/FormField.js +66 -0
- package/components/SelectMultiple/stories/Limited.js +68 -0
- package/components/SelectMultiple/stories/LongList.js +76 -0
- package/components/SelectMultiple/stories/ObjectOptions.js +80 -0
- package/components/SelectMultiple/stories/ShowSelectedInline.js +76 -0
- package/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +8 -0
- package/es6/components/Anchor/Anchor.js +2 -2
- package/es6/components/Box/stories/BackgroundThemed.js +39 -0
- package/es6/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/es6/components/Button/Button.js +3 -3
- package/es6/components/Calendar/Calendar.js +2 -1
- package/es6/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
- package/es6/components/CheckBoxGroup/index.d.ts +2 -1
- package/es6/components/CheckBoxGroup/propTypes.js +1 -0
- package/es6/components/FormField/FormField.js +1 -1
- package/es6/components/Heading/Heading.js +30 -3
- package/es6/components/Heading/StyledHeading.js +1 -1
- package/es6/components/Heading/index.d.ts +1 -0
- package/es6/components/Heading/propTypes.js +1 -0
- package/es6/components/Heading/stories/All.js +4 -1
- package/es6/components/Layer/LayerContainer.js +16 -9
- package/es6/components/List/List.js +131 -34
- package/es6/components/List/index.d.ts +1 -0
- package/es6/components/List/propTypes.js +1 -0
- package/es6/components/List/stories/Pinned.js +21 -0
- package/es6/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/es6/components/Select/DefaultSelectTextInput.js +31 -0
- package/es6/components/Select/EmptySearchOption.js +21 -0
- package/es6/components/Select/Select.js +26 -89
- package/es6/components/Select/SelectContainer.js +19 -58
- package/es6/components/Select/StyledSelect.js +45 -1
- package/es6/components/Select/index.d.ts +11 -9
- package/es6/components/Select/propTypes.js +41 -39
- package/es6/components/Select/utils.js +75 -1
- package/es6/components/SelectMultiple/README.md +2 -0
- package/es6/components/SelectMultiple/SelectMultiple.js +447 -0
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +453 -0
- package/es6/components/SelectMultiple/SelectMultipleValue.js +152 -0
- package/es6/components/SelectMultiple/SelectionSummary.js +91 -0
- package/es6/components/SelectMultiple/index.d.ts +21 -0
- package/es6/components/SelectMultiple/index.js +1 -0
- package/es6/components/SelectMultiple/propTypes.js +18 -0
- package/es6/components/SelectMultiple/stories/Default.js +60 -0
- package/es6/components/SelectMultiple/stories/Disabled.js +68 -0
- package/es6/components/SelectMultiple/stories/FormField.js +50 -0
- package/es6/components/SelectMultiple/stories/Limited.js +53 -0
- package/es6/components/SelectMultiple/stories/LongList.js +63 -0
- package/es6/components/SelectMultiple/stories/ObjectOptions.js +64 -0
- package/es6/components/SelectMultiple/stories/ShowSelectedInline.js +61 -0
- package/es6/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/es6/components/index.d.ts +1 -0
- package/es6/components/index.js +1 -0
- package/es6/index.d.ts +1 -0
- package/es6/themes/base.d.ts +8 -2
- package/es6/themes/base.js +54 -38
- package/es6/themes/grommet.js +15 -0
- package/es6/utils/DOM.js +4 -0
- package/es6/utils/background.js +65 -12
- package/es6/utils/general-prop-types.js +2 -0
- package/es6/utils/index.d.ts +2 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +7 -6
- package/themes/base.d.ts +8 -2
- package/themes/base.js +55 -38
- package/themes/grommet.js +15 -0
- package/utils/DOM.js +9 -2
- package/utils/background.js +64 -12
- package/utils/general-prop-types.js +2 -0
- package/utils/index.d.ts +2 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { BasicSelectProps } from '../Select';
|
|
3
|
+
|
|
4
|
+
export interface SelectMultipleProps extends BasicSelectProps {
|
|
5
|
+
defaultValue?: (string | number | object)[];
|
|
6
|
+
help?: string | React.ReactNode;
|
|
7
|
+
limit?: number;
|
|
8
|
+
value?: (string | number | object)[];
|
|
9
|
+
showSelectedInline?: boolean;
|
|
10
|
+
sortSelectedOnClose?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Try without Omit<> to see where we define our own attributes for overrides
|
|
14
|
+
// value, name, id, onChange, placeholder
|
|
15
|
+
export interface SelectMultipleExtendedProps
|
|
16
|
+
extends SelectMultipleProps,
|
|
17
|
+
Omit<JSX.IntrinsicElements['input'], keyof SelectMultipleProps> {}
|
|
18
|
+
|
|
19
|
+
declare const SelectMultiple: React.FC<SelectMultipleExtendedProps>;
|
|
20
|
+
|
|
21
|
+
export { SelectMultiple };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SelectMultiple } from './SelectMultiple';
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { genericSelectProps } from '../Select/propTypes';
|
|
5
|
+
var PropType = {};
|
|
6
|
+
|
|
7
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
8
|
+
PropType = _extends({}, genericSelectProps, {
|
|
9
|
+
defaultValue: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number])),
|
|
10
|
+
help: PropTypes.node,
|
|
11
|
+
limit: PropTypes.number,
|
|
12
|
+
value: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number])),
|
|
13
|
+
showSelectedInline: PropTypes.bool,
|
|
14
|
+
sortSelectedOnClose: PropTypes.bool
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export var SelectMultiplePropTypes = PropType;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Box, Text } from 'grommet';
|
|
3
|
+
import { SelectMultiple } from '../SelectMultiple';
|
|
4
|
+
var defaultOptions = ['Apple', 'Orange', 'Banana', 'Grape', 'Melon', 'Strawberry', 'Kiwi', 'Mango', 'Raspberry', 'Rhubarb'];
|
|
5
|
+
export var Default = function Default() {
|
|
6
|
+
var _useState = useState(defaultOptions),
|
|
7
|
+
options = _useState[0],
|
|
8
|
+
setOptions = _useState[1];
|
|
9
|
+
|
|
10
|
+
var _useState2 = useState([]),
|
|
11
|
+
valueMultiple = _useState2[0],
|
|
12
|
+
setValueMultiple = _useState2[1];
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
17
|
+
// <Grommet theme={...}>
|
|
18
|
+
React.createElement(Box, {
|
|
19
|
+
fill: true,
|
|
20
|
+
align: "center",
|
|
21
|
+
pad: "large",
|
|
22
|
+
gap: "large"
|
|
23
|
+
}, /*#__PURE__*/React.createElement(Text, null, "SelectMultiple Default"), /*#__PURE__*/React.createElement(SelectMultiple, {
|
|
24
|
+
value: valueMultiple,
|
|
25
|
+
placeholder: "Select",
|
|
26
|
+
options: options,
|
|
27
|
+
onSearch: function onSearch(text) {
|
|
28
|
+
// The line below escapes regular expression special characters:
|
|
29
|
+
// [ \ ^ $ . | ? * + ( )
|
|
30
|
+
var escapedText = text.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); // Create the regular expression with modified value which
|
|
31
|
+
// handles escaping special characters. Without escaping special
|
|
32
|
+
// characters, errors will appear in the console
|
|
33
|
+
|
|
34
|
+
var exp = new RegExp(escapedText, 'i');
|
|
35
|
+
setOptions(defaultOptions.filter(function (o) {
|
|
36
|
+
return exp.test(o);
|
|
37
|
+
}));
|
|
38
|
+
},
|
|
39
|
+
onClose: function onClose() {
|
|
40
|
+
return setOptions(defaultOptions);
|
|
41
|
+
},
|
|
42
|
+
onChange: function onChange(_ref) {
|
|
43
|
+
var value = _ref.value;
|
|
44
|
+
setValueMultiple(value);
|
|
45
|
+
}
|
|
46
|
+
})) // </Grommet>
|
|
47
|
+
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
Default.parameters = {
|
|
51
|
+
chromatic: {
|
|
52
|
+
disable: true
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
Default.args = {
|
|
56
|
+
full: true
|
|
57
|
+
};
|
|
58
|
+
export default {
|
|
59
|
+
title: 'Input/SelectMultiple/Default'
|
|
60
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Box, Text } from 'grommet';
|
|
3
|
+
import { SelectMultiple } from '../SelectMultiple';
|
|
4
|
+
var defaultOptions = ['French Vanilla Cake with Buttercream', 'Sweet Grilled Peaches', 'Chocolate Chip Cookies', 'Pineapple Upside-Down Cake', 'Peanut Butter Chocolate Fondue', 'Strawberry Shortcake', 'Peach Cobbler', 'German Chocolate Cake', 'Carrot Cake with Cream Cheese Frosting', 'Cinnamon Coffee Cake'];
|
|
5
|
+
export var Disabled = function Disabled() {
|
|
6
|
+
var _useState = useState(defaultOptions),
|
|
7
|
+
options = _useState[0],
|
|
8
|
+
setOptions = _useState[1];
|
|
9
|
+
|
|
10
|
+
var _useState2 = useState(['Chocolate Chip Cookies', 'Strawberry Shortcake']),
|
|
11
|
+
valueMultiple = _useState2[0],
|
|
12
|
+
setValueMultiple = _useState2[1];
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
17
|
+
// <Grommet theme={...}>
|
|
18
|
+
React.createElement(Box, {
|
|
19
|
+
fill: true,
|
|
20
|
+
align: "center",
|
|
21
|
+
pad: "large",
|
|
22
|
+
gap: "large"
|
|
23
|
+
}, /*#__PURE__*/React.createElement(Text, null, "SelectMultiple Disabled"), /*#__PURE__*/React.createElement(SelectMultiple, {
|
|
24
|
+
width: "medium",
|
|
25
|
+
showSelectedInline: true,
|
|
26
|
+
dropProps: {
|
|
27
|
+
width: 'medium'
|
|
28
|
+
} // icon={<CaretDown />}
|
|
29
|
+
// icon={false}
|
|
30
|
+
,
|
|
31
|
+
disabled: ['Chocolate Chip Cookies', 'Pineapple Upside-Down Cake'],
|
|
32
|
+
value: valueMultiple,
|
|
33
|
+
placeholder: "Select",
|
|
34
|
+
options: options,
|
|
35
|
+
onSearch: function onSearch(text) {
|
|
36
|
+
// The line below escapes regular expression special characters:
|
|
37
|
+
// [ \ ^ $ . | ? * + ( )
|
|
38
|
+
var escapedText = text.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); // Create the regular expression with modified value which
|
|
39
|
+
// handles escaping special characters. Without escaping special
|
|
40
|
+
// characters, errors will appear in the console
|
|
41
|
+
|
|
42
|
+
var exp = new RegExp(escapedText, 'i');
|
|
43
|
+
setOptions(defaultOptions.filter(function (o) {
|
|
44
|
+
return exp.test(o);
|
|
45
|
+
}));
|
|
46
|
+
},
|
|
47
|
+
onClose: function onClose() {
|
|
48
|
+
return setOptions(defaultOptions);
|
|
49
|
+
},
|
|
50
|
+
onChange: function onChange(_ref) {
|
|
51
|
+
var value = _ref.value;
|
|
52
|
+
setValueMultiple(value);
|
|
53
|
+
}
|
|
54
|
+
})) // </Grommet>
|
|
55
|
+
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
Disabled.parameters = {
|
|
59
|
+
chromatic: {
|
|
60
|
+
disable: true
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
Disabled.args = {
|
|
64
|
+
full: true
|
|
65
|
+
};
|
|
66
|
+
export default {
|
|
67
|
+
title: 'Input/SelectMultiple/Disabled'
|
|
68
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useCallback, useState } from 'react';
|
|
2
|
+
import { Box, Button, Form, FormField } from 'grommet';
|
|
3
|
+
import { SelectMultiple } from '../SelectMultiple';
|
|
4
|
+
var options = ['Apple', 'Orange', 'Banana', 'Grape', 'Melon', 'Strawberry', 'Kiwi', 'Mango', 'Raspberry', 'Rhubarb'];
|
|
5
|
+
export var InsideFormField = function InsideFormField() {
|
|
6
|
+
var _useState = useState({}),
|
|
7
|
+
value = _useState[0],
|
|
8
|
+
setValue = _useState[1];
|
|
9
|
+
|
|
10
|
+
var onChange = useCallback(function (nextValue) {
|
|
11
|
+
return setValue(nextValue);
|
|
12
|
+
}, []);
|
|
13
|
+
return (
|
|
14
|
+
/*#__PURE__*/
|
|
15
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
16
|
+
// <Grommet theme={...}>
|
|
17
|
+
React.createElement(Box, {
|
|
18
|
+
align: "center",
|
|
19
|
+
pad: "large"
|
|
20
|
+
}, /*#__PURE__*/React.createElement(Form, {
|
|
21
|
+
value: value,
|
|
22
|
+
onChange: onChange,
|
|
23
|
+
onSubmit: function onSubmit() {
|
|
24
|
+
return console.log('Submit', value);
|
|
25
|
+
}
|
|
26
|
+
}, /*#__PURE__*/React.createElement(FormField, {
|
|
27
|
+
label: "Label",
|
|
28
|
+
name: "select"
|
|
29
|
+
}, /*#__PURE__*/React.createElement(SelectMultiple, {
|
|
30
|
+
showSelectedInline: true,
|
|
31
|
+
name: "select",
|
|
32
|
+
placeholder: "placeholder",
|
|
33
|
+
options: options
|
|
34
|
+
})), /*#__PURE__*/React.createElement(Button, {
|
|
35
|
+
type: "submit",
|
|
36
|
+
label: "Update",
|
|
37
|
+
primary: true
|
|
38
|
+
}))) // </Grommet>
|
|
39
|
+
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
InsideFormField.parameters = {
|
|
43
|
+
chromatic: {
|
|
44
|
+
disable: true
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
InsideFormField.storyName = 'Inside a FormField';
|
|
48
|
+
export default {
|
|
49
|
+
title: 'Input/SelectMultiple/Inside a FormField'
|
|
50
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Box, SelectMultiple, Text } from 'grommet';
|
|
3
|
+
var defaultOptions = ['Apple', 'Orange', 'Banana', 'Grape', 'Melon', 'Strawberry', 'Kiwi', 'Mango', 'Raspberry', 'Rhubarb'];
|
|
4
|
+
export var SelectMultipleLimited = function SelectMultipleLimited() {
|
|
5
|
+
var _useState = useState([]),
|
|
6
|
+
valueMultiple = _useState[0],
|
|
7
|
+
setValueMultiple = _useState[1];
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
/*#__PURE__*/
|
|
11
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
12
|
+
// <Grommet theme={...}>
|
|
13
|
+
React.createElement(Box, {
|
|
14
|
+
fill: true,
|
|
15
|
+
align: "center",
|
|
16
|
+
pad: "large",
|
|
17
|
+
gap: "large"
|
|
18
|
+
}, /*#__PURE__*/React.createElement(Text, null, "SelectMultiple Limited"), /*#__PURE__*/React.createElement(SelectMultiple, {
|
|
19
|
+
limit: 5,
|
|
20
|
+
help: /*#__PURE__*/React.createElement(Box, {
|
|
21
|
+
direction: "row",
|
|
22
|
+
justify: "between",
|
|
23
|
+
flex: false,
|
|
24
|
+
pad: {
|
|
25
|
+
horizontal: 'xsmall',
|
|
26
|
+
bottom: 'xsmall'
|
|
27
|
+
}
|
|
28
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
29
|
+
size: "small"
|
|
30
|
+
}, "Select up to 5")),
|
|
31
|
+
value: valueMultiple,
|
|
32
|
+
placeholder: "Select",
|
|
33
|
+
options: defaultOptions,
|
|
34
|
+
onChange: function onChange(_ref) {
|
|
35
|
+
var value = _ref.value;
|
|
36
|
+
setValueMultiple(value);
|
|
37
|
+
}
|
|
38
|
+
})) // </Grommet>
|
|
39
|
+
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
SelectMultipleLimited.parameters = {
|
|
43
|
+
chromatic: {
|
|
44
|
+
disable: true
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
SelectMultipleLimited.args = {
|
|
48
|
+
full: true
|
|
49
|
+
};
|
|
50
|
+
SelectMultipleLimited.storyName = 'Limited';
|
|
51
|
+
export default {
|
|
52
|
+
title: 'Input/SelectMultiple/Limited'
|
|
53
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, SelectMultiple } from 'grommet';
|
|
3
|
+
var dummyOptions = Array(2000).fill().map(function (_, i) {
|
|
4
|
+
return "option " + i;
|
|
5
|
+
}).sort(function (a, b) {
|
|
6
|
+
return a.localeCompare(b, undefined, {
|
|
7
|
+
numeric: true,
|
|
8
|
+
sensitivity: 'base'
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
export var LongList = function LongList() {
|
|
12
|
+
var _React$useState = React.useState([]),
|
|
13
|
+
selected = _React$useState[0],
|
|
14
|
+
setSelected = _React$useState[1];
|
|
15
|
+
|
|
16
|
+
var _React$useState2 = React.useState(dummyOptions.slice(0, 200)),
|
|
17
|
+
options = _React$useState2[0],
|
|
18
|
+
setOptions = _React$useState2[1];
|
|
19
|
+
|
|
20
|
+
var onMore = function onMore() {
|
|
21
|
+
setTimeout(function () {
|
|
22
|
+
setOptions(dummyOptions.slice(0, options.length + 200));
|
|
23
|
+
}, 1000);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
var onChange = function onChange(_ref) {
|
|
27
|
+
var nextSelected = _ref.value;
|
|
28
|
+
return setSelected(nextSelected);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
/*#__PURE__*/
|
|
33
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
34
|
+
// <Grommet theme={...}>
|
|
35
|
+
React.createElement(Box, {
|
|
36
|
+
fill: true,
|
|
37
|
+
align: "center",
|
|
38
|
+
justify: "start",
|
|
39
|
+
pad: "large"
|
|
40
|
+
}, /*#__PURE__*/React.createElement(SelectMultiple, {
|
|
41
|
+
showSelectedInline: true,
|
|
42
|
+
placeholder: "select an option...",
|
|
43
|
+
value: selected,
|
|
44
|
+
options: options,
|
|
45
|
+
dropHeight: "medium",
|
|
46
|
+
onMore: onMore,
|
|
47
|
+
onChange: onChange
|
|
48
|
+
})) // </Grommet>
|
|
49
|
+
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
LongList.storyName = 'Long list';
|
|
53
|
+
LongList.parameters = {
|
|
54
|
+
chromatic: {
|
|
55
|
+
disable: true
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
LongList.args = {
|
|
59
|
+
full: true
|
|
60
|
+
};
|
|
61
|
+
export default {
|
|
62
|
+
title: 'Input/SelectMultiple/Long list'
|
|
63
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Box, Text } from 'grommet';
|
|
3
|
+
import { SelectMultiple } from '../SelectMultiple';
|
|
4
|
+
var objectOptions = [{
|
|
5
|
+
label: 'Red',
|
|
6
|
+
value: 1
|
|
7
|
+
}, {
|
|
8
|
+
label: 'Blue',
|
|
9
|
+
value: 2
|
|
10
|
+
}, {
|
|
11
|
+
label: 'Green',
|
|
12
|
+
value: 3
|
|
13
|
+
}, {
|
|
14
|
+
label: 'Purple',
|
|
15
|
+
value: 4
|
|
16
|
+
}];
|
|
17
|
+
export var ObjectOptions = function ObjectOptions() {
|
|
18
|
+
var _useState = useState(objectOptions),
|
|
19
|
+
options = _useState[0],
|
|
20
|
+
setOptions = _useState[1];
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
/*#__PURE__*/
|
|
24
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
25
|
+
// <Grommet theme={...}>
|
|
26
|
+
React.createElement(Box, {
|
|
27
|
+
fill: true,
|
|
28
|
+
gap: "large",
|
|
29
|
+
align: "center",
|
|
30
|
+
justify: "start",
|
|
31
|
+
pad: "large"
|
|
32
|
+
}, /*#__PURE__*/React.createElement(Text, null, "SelectMultiple with Object Options"), /*#__PURE__*/React.createElement(SelectMultiple, {
|
|
33
|
+
onSearch: function onSearch(text) {
|
|
34
|
+
var escapedText = text.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); // Create the regular expression with modified value which
|
|
35
|
+
// handles escaping special characters. Without escaping special
|
|
36
|
+
// characters, errors will appear in the console
|
|
37
|
+
|
|
38
|
+
var exp = new RegExp(escapedText, 'i');
|
|
39
|
+
setOptions(objectOptions.filter(function (o) {
|
|
40
|
+
return exp.test(o.label);
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
showSelectedInline: true,
|
|
44
|
+
id: "select",
|
|
45
|
+
name: "select",
|
|
46
|
+
placeholder: "Select",
|
|
47
|
+
labelKey: "label",
|
|
48
|
+
valueKey: {
|
|
49
|
+
key: 'value'
|
|
50
|
+
},
|
|
51
|
+
options: options
|
|
52
|
+
})) // </Grommet>
|
|
53
|
+
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
ObjectOptions.storyName = 'Object options';
|
|
57
|
+
ObjectOptions.parameters = {
|
|
58
|
+
chromatic: {
|
|
59
|
+
disable: true
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export default {
|
|
63
|
+
title: 'Input/SelectMultiple/Object options'
|
|
64
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Box, SelectMultiple, Text } from 'grommet';
|
|
3
|
+
var defaultOptions = ['Apple', 'Orange', 'Banana', 'Grape', 'Melon', 'Strawberry', 'Kiwi', 'Mango', 'Raspberry', 'Rhubarb'];
|
|
4
|
+
export var ShowSelectedInline = function ShowSelectedInline() {
|
|
5
|
+
var _useState = useState(defaultOptions),
|
|
6
|
+
options = _useState[0],
|
|
7
|
+
setOptions = _useState[1];
|
|
8
|
+
|
|
9
|
+
var _useState2 = useState([]),
|
|
10
|
+
valueMultiple = _useState2[0],
|
|
11
|
+
setValueMultiple = _useState2[1];
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
/*#__PURE__*/
|
|
15
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
16
|
+
// <Grommet theme={...}>
|
|
17
|
+
React.createElement(Box, {
|
|
18
|
+
fill: true,
|
|
19
|
+
align: "center",
|
|
20
|
+
pad: "large",
|
|
21
|
+
gap: "large"
|
|
22
|
+
}, /*#__PURE__*/React.createElement(Text, null, "SelectMultiple showSelectedInline"), /*#__PURE__*/React.createElement(SelectMultiple, {
|
|
23
|
+
showSelectedInline: true,
|
|
24
|
+
placeholder: "Select",
|
|
25
|
+
options: options,
|
|
26
|
+
onSearch: function onSearch(text) {
|
|
27
|
+
// The line below escapes regular expression special characters:
|
|
28
|
+
// [ \ ^ $ . | ? * + ( )
|
|
29
|
+
var escapedText = text.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); // Create the regular expression with modified value which
|
|
30
|
+
// handles escaping special characters. Without escaping special
|
|
31
|
+
// characters, errors will appear in the console
|
|
32
|
+
|
|
33
|
+
var exp = new RegExp(escapedText, 'i');
|
|
34
|
+
setOptions(defaultOptions.filter(function (o) {
|
|
35
|
+
return exp.test(o);
|
|
36
|
+
}));
|
|
37
|
+
},
|
|
38
|
+
onClose: function onClose() {
|
|
39
|
+
return setOptions(defaultOptions);
|
|
40
|
+
},
|
|
41
|
+
value: valueMultiple,
|
|
42
|
+
onChange: function onChange(_ref) {
|
|
43
|
+
var value = _ref.value;
|
|
44
|
+
setValueMultiple(value);
|
|
45
|
+
}
|
|
46
|
+
})) // </Grommet>
|
|
47
|
+
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
ShowSelectedInline.storyName = 'showSelectedInline';
|
|
51
|
+
ShowSelectedInline.parameters = {
|
|
52
|
+
chromatic: {
|
|
53
|
+
disable: true
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
ShowSelectedInline.args = {
|
|
57
|
+
full: true
|
|
58
|
+
};
|
|
59
|
+
export default {
|
|
60
|
+
title: 'Input/SelectMultiple/showSelectedInline'
|
|
61
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FormClose } from 'grommet-icons';
|
|
4
|
+
import { Box, Button, Text } from 'grommet';
|
|
5
|
+
import { SelectMultiple } from '../../SelectMultiple.js';
|
|
6
|
+
|
|
7
|
+
const allSeasons = [
|
|
8
|
+
'S01',
|
|
9
|
+
'S02',
|
|
10
|
+
'S03',
|
|
11
|
+
'S04',
|
|
12
|
+
'S05',
|
|
13
|
+
'S06',
|
|
14
|
+
'S07',
|
|
15
|
+
'S08',
|
|
16
|
+
'S09',
|
|
17
|
+
'S10',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const Children = () => {
|
|
21
|
+
const [selected, setSelected] = useState([]);
|
|
22
|
+
|
|
23
|
+
const onRemoveSeason = (season) => {
|
|
24
|
+
setSelected(selected.filter((selectedSeason) => selectedSeason !== season));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const renderSeason = (season) => (
|
|
28
|
+
<Button
|
|
29
|
+
key={`season_tag_${season}`}
|
|
30
|
+
onClick={(event) => {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
event.stopPropagation();
|
|
33
|
+
onRemoveSeason(season);
|
|
34
|
+
}}
|
|
35
|
+
onFocus={(event) => event.stopPropagation()}
|
|
36
|
+
a11yTitle={season}
|
|
37
|
+
>
|
|
38
|
+
<Box
|
|
39
|
+
align="center"
|
|
40
|
+
direction="row"
|
|
41
|
+
gap="xsmall"
|
|
42
|
+
pad={{ vertical: 'xsmall', horizontal: 'small' }}
|
|
43
|
+
margin="xsmall"
|
|
44
|
+
background="light-3"
|
|
45
|
+
round="large"
|
|
46
|
+
>
|
|
47
|
+
<Text size="small">{season}</Text>
|
|
48
|
+
<Box round="full" margin={{ left: 'xsmall' }}>
|
|
49
|
+
<FormClose size="small" style={{ width: '12px', height: '12px' }} />
|
|
50
|
+
</Box>
|
|
51
|
+
</Box>
|
|
52
|
+
</Button>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const renderOption = (option, state) => (
|
|
56
|
+
<Box pad="small" background={state.active ? 'active' : undefined}>
|
|
57
|
+
{option}
|
|
58
|
+
</Box>
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
// Uncomment <Grommet> lines when using outside of storybook
|
|
63
|
+
// <Grommet theme={...}>
|
|
64
|
+
<Box fill align="center" pad="large" gap="large">
|
|
65
|
+
<Text>SelectMultiple with custom children</Text>
|
|
66
|
+
<SelectMultiple
|
|
67
|
+
sortSelectedOnClose={false}
|
|
68
|
+
showSelectedInline
|
|
69
|
+
valueLabel={(option) => (
|
|
70
|
+
<Box wrap direction="row" width="small">
|
|
71
|
+
{option && option.length ? (
|
|
72
|
+
<>
|
|
73
|
+
{option.map((i) => {
|
|
74
|
+
console.log(option);
|
|
75
|
+
return renderSeason(i);
|
|
76
|
+
})}
|
|
77
|
+
</>
|
|
78
|
+
) : (
|
|
79
|
+
<Text color="text-weak">Select Season</Text>
|
|
80
|
+
)}
|
|
81
|
+
</Box>
|
|
82
|
+
)}
|
|
83
|
+
options={allSeasons}
|
|
84
|
+
value={selected}
|
|
85
|
+
onChange={({ value }) => {
|
|
86
|
+
setSelected([...value]);
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{renderOption}
|
|
90
|
+
</SelectMultiple>
|
|
91
|
+
</Box>
|
|
92
|
+
// </Grommet>
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
Children.parameters = {
|
|
97
|
+
chromatic: { disable: true },
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Children.args = {
|
|
101
|
+
full: true,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export default {
|
|
105
|
+
title: 'Input/SelectMultiple/Children',
|
|
106
|
+
};
|
package/es6/components/index.js
CHANGED
package/es6/index.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export * from './components/RangeSelector';
|
|
|
56
56
|
export * from './components/RoutedAnchor';
|
|
57
57
|
export * from './components/RoutedButton';
|
|
58
58
|
export * from './components/Select';
|
|
59
|
+
export * from './components/SelectMultiple';
|
|
59
60
|
export * from './components/Sidebar';
|
|
60
61
|
export * from './components/SkipLink';
|
|
61
62
|
export * from './components/SkipLinks';
|
package/es6/themes/base.d.ts
CHANGED
|
@@ -278,6 +278,9 @@ export interface ThemeType {
|
|
|
278
278
|
duration?: string;
|
|
279
279
|
};
|
|
280
280
|
};
|
|
281
|
+
backgrounds?: {
|
|
282
|
+
[x: string]: BackgroundType | { dark?: string; light?: string };
|
|
283
|
+
};
|
|
281
284
|
borderSize?: {
|
|
282
285
|
xsmall?: string;
|
|
283
286
|
small?: string;
|
|
@@ -782,8 +785,8 @@ export interface ThemeType {
|
|
|
782
785
|
margin?: MarginType;
|
|
783
786
|
pad?: PadType;
|
|
784
787
|
};
|
|
785
|
-
checkBox
|
|
786
|
-
pad
|
|
788
|
+
checkBox?: {
|
|
789
|
+
pad?: PadType;
|
|
787
790
|
};
|
|
788
791
|
disabled?: {
|
|
789
792
|
background?: BackgroundType;
|
|
@@ -1395,6 +1398,9 @@ export interface ThemeType {
|
|
|
1395
1398
|
searchInput?: ReactComponentElement<any>;
|
|
1396
1399
|
step?: number;
|
|
1397
1400
|
};
|
|
1401
|
+
selectMultiple?: {
|
|
1402
|
+
maxInline?: number;
|
|
1403
|
+
};
|
|
1398
1404
|
skipLinks?: {
|
|
1399
1405
|
position?: LayerPositionType;
|
|
1400
1406
|
container?: BoxProps;
|