@flodesk/grain 5.9.0 → 5.10.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/es/components/autocomplete.js +25 -16
- package/es/components/box.js +6 -3
- package/es/components/dropdown.js +49 -0
- package/es/components/index.js +3 -1
- package/es/components/multi-autocomplete.js +189 -0
- package/es/components/select.js +11 -11
- package/es/foundational/index.js +22 -10
- package/package.json +1 -1
|
@@ -34,13 +34,13 @@ import "core-js/modules/es.array.map.js";
|
|
|
34
34
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
35
35
|
|
|
36
36
|
import PropTypes from 'prop-types';
|
|
37
|
-
import React, { useState } from 'react';
|
|
37
|
+
import React, { forwardRef, useState } from 'react';
|
|
38
38
|
import styled from '@emotion/styled';
|
|
39
39
|
import { Icon, Box, Text } from '.';
|
|
40
40
|
import { IconChevronDown } from '../icons';
|
|
41
41
|
import { Combobox } from '@headlessui/react';
|
|
42
42
|
import { types } from '../types';
|
|
43
|
-
import { fieldStyles, fieldXPadding, focusFieldStyles,
|
|
43
|
+
import { fieldStyles, fieldXPadding, focusFieldStyles, MenuCard, MenuCardItem } from '../foundational';
|
|
44
44
|
var Input = styled(Combobox.Input)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n ", ";\n"])), fieldStyles({
|
|
45
45
|
paddingRight: '32px'
|
|
46
46
|
}), focusFieldStyles);
|
|
@@ -52,12 +52,14 @@ var Root = function Root(_ref) {
|
|
|
52
52
|
}));
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
var Trigger = function
|
|
55
|
+
var Trigger = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
56
56
|
var props = Object.assign({}, _ref2);
|
|
57
|
-
return /*#__PURE__*/React.createElement(Box, Object.assign({
|
|
57
|
+
return /*#__PURE__*/React.createElement(Box, Object.assign({
|
|
58
|
+
ref: ref
|
|
59
|
+
}, props, {
|
|
58
60
|
position: "relative"
|
|
59
61
|
}));
|
|
60
|
-
};
|
|
62
|
+
});
|
|
61
63
|
|
|
62
64
|
var EmptyState = function EmptyState() {
|
|
63
65
|
return /*#__PURE__*/React.createElement(Box, {
|
|
@@ -70,9 +72,14 @@ var EmptyState = function EmptyState() {
|
|
|
70
72
|
export var Autocomplete = function Autocomplete(_ref3) {
|
|
71
73
|
var options = _ref3.options,
|
|
72
74
|
defaultOption = _ref3.defaultOption,
|
|
73
|
-
onChange = _ref3.onChange
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
onChange = _ref3.onChange,
|
|
76
|
+
_ref3$menuAlign = _ref3.menuAlign,
|
|
77
|
+
menuAlign = _ref3$menuAlign === void 0 ? 'left' : _ref3$menuAlign,
|
|
78
|
+
_ref3$menuWidth = _ref3.menuWidth,
|
|
79
|
+
menuWidth = _ref3$menuWidth === void 0 ? '100%' : _ref3$menuWidth,
|
|
80
|
+
placeholder = _ref3.placeholder;
|
|
81
|
+
|
|
82
|
+
var _useState = useState(defaultOption ? defaultOption : ''),
|
|
76
83
|
_useState2 = _slicedToArray(_useState, 2),
|
|
77
84
|
selectedOption = _useState2[0],
|
|
78
85
|
setSelectedOption = _useState2[1];
|
|
@@ -89,7 +96,7 @@ export var Autocomplete = function Autocomplete(_ref3) {
|
|
|
89
96
|
};
|
|
90
97
|
|
|
91
98
|
var filteredOptions = query === '' ? options : options.filter(function (option) {
|
|
92
|
-
return option.
|
|
99
|
+
return option.toLowerCase().includes(query.toLowerCase());
|
|
93
100
|
});
|
|
94
101
|
return /*#__PURE__*/React.createElement(Combobox, {
|
|
95
102
|
as: Root,
|
|
@@ -98,11 +105,11 @@ export var Autocomplete = function Autocomplete(_ref3) {
|
|
|
98
105
|
}, /*#__PURE__*/React.createElement(Combobox.Button, {
|
|
99
106
|
as: Trigger
|
|
100
107
|
}, /*#__PURE__*/React.createElement(Input, {
|
|
101
|
-
|
|
108
|
+
autoComplete: "off",
|
|
102
109
|
onChange: function onChange(event) {
|
|
103
110
|
return setQuery(event.target.value);
|
|
104
111
|
},
|
|
105
|
-
placeholder:
|
|
112
|
+
placeholder: placeholder
|
|
106
113
|
}), /*#__PURE__*/React.createElement(Box, {
|
|
107
114
|
right: fieldXPadding,
|
|
108
115
|
position: "absolute",
|
|
@@ -113,25 +120,27 @@ export var Autocomplete = function Autocomplete(_ref3) {
|
|
|
113
120
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
114
121
|
icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
|
|
115
122
|
}))), /*#__PURE__*/React.createElement(Combobox.Options, {
|
|
116
|
-
|
|
123
|
+
menuAlign: menuAlign,
|
|
124
|
+
menuWidth: menuWidth,
|
|
125
|
+
as: MenuCard
|
|
117
126
|
}, filteredOptions.map(function (option, index) {
|
|
118
127
|
return /*#__PURE__*/React.createElement(Combobox.Option, {
|
|
119
128
|
key: index,
|
|
120
|
-
value: option
|
|
129
|
+
value: option,
|
|
121
130
|
as: React.Fragment
|
|
122
131
|
}, function (_ref4) {
|
|
123
132
|
var active = _ref4.active,
|
|
124
133
|
selected = _ref4.selected;
|
|
125
|
-
return /*#__PURE__*/React.createElement(
|
|
134
|
+
return /*#__PURE__*/React.createElement(MenuCardItem, {
|
|
126
135
|
isSelected: selected,
|
|
127
136
|
isActive: active
|
|
128
|
-
}, option
|
|
137
|
+
}, option);
|
|
129
138
|
});
|
|
130
139
|
}), !Boolean(filteredOptions.length) && /*#__PURE__*/React.createElement(EmptyState, null)));
|
|
131
140
|
};
|
|
132
141
|
Autocomplete.propTypes = {
|
|
133
142
|
options: PropTypes.array,
|
|
134
|
-
defaultOption: PropTypes.
|
|
143
|
+
defaultOption: PropTypes.string,
|
|
135
144
|
onChange: PropTypes.func,
|
|
136
145
|
menuAlign: PropTypes.oneOf(['left', 'right']),
|
|
137
146
|
menuWidth: types.dimension
|
package/es/components/box.js
CHANGED
|
@@ -7,7 +7,7 @@ import "core-js/modules/es.object.define-properties.js";
|
|
|
7
7
|
|
|
8
8
|
var _templateObject;
|
|
9
9
|
|
|
10
|
-
var _excluded = ["children", "color", "backgroundColor", "borderColor", "borderWidth", "borderSide", "width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight", "radius", "padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "paddingX", "paddingY", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight", "marginX", "marginY", "position", "top", "bottom", "left", "right", "shadow", "overflow", "aspectRatio", "zIndex"];
|
|
10
|
+
var _excluded = ["children", "color", "backgroundColor", "borderColor", "borderWidth", "borderSide", "width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight", "radius", "padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight", "paddingX", "paddingY", "margin", "marginTop", "marginBottom", "marginLeft", "marginRight", "marginX", "marginY", "position", "top", "bottom", "left", "right", "shadow", "overflow", "aspectRatio", "zIndex", "tag"];
|
|
11
11
|
import "core-js/modules/es.object.assign.js";
|
|
12
12
|
|
|
13
13
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
@@ -60,11 +60,14 @@ export var Box = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
60
60
|
overflow = _ref.overflow,
|
|
61
61
|
aspectRatio = _ref.aspectRatio,
|
|
62
62
|
zIndex = _ref.zIndex,
|
|
63
|
+
_ref$tag = _ref.tag,
|
|
64
|
+
tag = _ref$tag === void 0 ? 'div' : _ref$tag,
|
|
63
65
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
var Tag = tag;
|
|
68
|
+
return /*#__PURE__*/React.createElement(Tag, Object.assign({
|
|
66
69
|
ref: ref,
|
|
67
|
-
css: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n
|
|
70
|
+
css: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n ", ";\n\n color: ", ";\n background-color: ", ";\n position: ", ";\n border-radius: ", ";\n box-shadow: ", ";\n overflow: ", ";\n aspect-ratio: ", ";\n z-index: ", ";\n "])), getBorder(borderSide, borderWidth, borderColor), getResponsiveSpace('padding', padding), getResponsiveSpace('padding-top', paddingTop || paddingY), getResponsiveSpace('padding-bottom', paddingBottom || paddingY), getResponsiveSpace('padding-left', paddingLeft || paddingX), getResponsiveSpace('padding-right', paddingRight || paddingX), getResponsiveSpace('margin', margin), getResponsiveSpace('margin-top', marginTop || marginY), getResponsiveSpace('margin-bottom', marginBottom || marginY), getResponsiveSpace('margin-left', marginLeft || marginX), getResponsiveSpace('margin-right', marginRight || marginX), getResponsiveSpace('top', top), getResponsiveSpace('bottom', bottom), getResponsiveSpace('left', left), getResponsiveSpace('right', right), getResponsiveDimension('width', width), getResponsiveDimension('min-width', minWidth), getResponsiveDimension('max-width', maxWidth), getResponsiveDimension('height', height), getResponsiveDimension('min-height', minHeight), getResponsiveDimension('max-height', maxHeight), getColor(color), getColor(backgroundColor), position, getRadius(radius), getShadow(shadow), overflow, aspectRatio, zIndex)
|
|
68
71
|
}, props), children);
|
|
69
72
|
});
|
|
70
73
|
Box.propTypes = {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "core-js/modules/es.object.assign.js";
|
|
2
|
+
import "core-js/modules/es.array.map.js";
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Box } from '.';
|
|
6
|
+
import { Menu } from '@headlessui/react';
|
|
7
|
+
import { types } from '../types';
|
|
8
|
+
import { MenuCard, MenuCardItem } from '../foundational';
|
|
9
|
+
|
|
10
|
+
var Root = function Root(_ref) {
|
|
11
|
+
var props = Object.assign({}, _ref);
|
|
12
|
+
return /*#__PURE__*/React.createElement(Box, Object.assign({
|
|
13
|
+
position: "relative"
|
|
14
|
+
}, props));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export var Dropdown = function Dropdown(_ref2) {
|
|
18
|
+
var options = _ref2.options,
|
|
19
|
+
_ref2$menuAlign = _ref2.menuAlign,
|
|
20
|
+
menuAlign = _ref2$menuAlign === void 0 ? 'left' : _ref2$menuAlign,
|
|
21
|
+
_ref2$menuWidth = _ref2.menuWidth,
|
|
22
|
+
menuWidth = _ref2$menuWidth === void 0 ? 'auto' : _ref2$menuWidth,
|
|
23
|
+
trigger = _ref2.trigger;
|
|
24
|
+
return /*#__PURE__*/React.createElement(Menu, {
|
|
25
|
+
as: Root
|
|
26
|
+
}, /*#__PURE__*/React.createElement(Menu.Button, {
|
|
27
|
+
as: "div"
|
|
28
|
+
}, trigger), /*#__PURE__*/React.createElement(Menu.Items, {
|
|
29
|
+
as: MenuCard,
|
|
30
|
+
menuAlign: menuAlign,
|
|
31
|
+
menuWidth: menuWidth
|
|
32
|
+
}, options.map(function (option, index) {
|
|
33
|
+
return /*#__PURE__*/React.createElement(Menu.Item, {
|
|
34
|
+
key: index
|
|
35
|
+
}, function (_ref3) {
|
|
36
|
+
var active = _ref3.active;
|
|
37
|
+
return /*#__PURE__*/React.createElement(MenuCardItem, {
|
|
38
|
+
icon: option.icon,
|
|
39
|
+
isActive: active,
|
|
40
|
+
onClick: option.onClick
|
|
41
|
+
}, option.content);
|
|
42
|
+
});
|
|
43
|
+
})));
|
|
44
|
+
};
|
|
45
|
+
Dropdown.propTypes = {
|
|
46
|
+
options: PropTypes.array,
|
|
47
|
+
menuAlign: PropTypes.oneOf(['left', 'right']),
|
|
48
|
+
menuWidth: types.dimension
|
|
49
|
+
};
|
package/es/components/index.js
CHANGED
|
@@ -14,4 +14,6 @@ export { Stack } from './stack';
|
|
|
14
14
|
export { Slider } from './slider';
|
|
15
15
|
export { Spinner } from './spinner';
|
|
16
16
|
export { Switch } from './switch';
|
|
17
|
-
export { Autocomplete } from './autocomplete';
|
|
17
|
+
export { Autocomplete } from './autocomplete';
|
|
18
|
+
export { MultiAutocomplete } from './multi-autocomplete';
|
|
19
|
+
export { Dropdown } from './dropdown';
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import "core-js/modules/es.array.slice.js";
|
|
2
|
+
import "core-js/modules/es.object.freeze.js";
|
|
3
|
+
import "core-js/modules/es.object.define-properties.js";
|
|
4
|
+
import "core-js/modules/es.symbol.js";
|
|
5
|
+
import "core-js/modules/es.symbol.description.js";
|
|
6
|
+
import "core-js/modules/es.symbol.iterator.js";
|
|
7
|
+
import "core-js/modules/es.array.iterator.js";
|
|
8
|
+
import "core-js/modules/es.string.iterator.js";
|
|
9
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
10
|
+
import "core-js/modules/es.array.from.js";
|
|
11
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
12
|
+
|
|
13
|
+
var _templateObject, _templateObject2, _templateObject3;
|
|
14
|
+
|
|
15
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
+
|
|
17
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
|
|
19
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
+
|
|
21
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
22
|
+
|
|
23
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
24
|
+
|
|
25
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
+
|
|
27
|
+
import "core-js/modules/es.object.assign.js";
|
|
28
|
+
import "core-js/modules/es.array.filter.js";
|
|
29
|
+
import "core-js/modules/es.object.to-string.js";
|
|
30
|
+
import "core-js/modules/es.array.includes.js";
|
|
31
|
+
import "core-js/modules/es.string.includes.js";
|
|
32
|
+
import "core-js/modules/es.array.map.js";
|
|
33
|
+
|
|
34
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
35
|
+
|
|
36
|
+
import PropTypes from 'prop-types';
|
|
37
|
+
import React, { forwardRef, useState } from 'react';
|
|
38
|
+
import styled from '@emotion/styled';
|
|
39
|
+
import { Icon, Box, Text, Arrange } from '.';
|
|
40
|
+
import { IconChevronDown, IconCross } from '../icons';
|
|
41
|
+
import { Combobox } from '@headlessui/react';
|
|
42
|
+
import { types } from '../types';
|
|
43
|
+
import { ClearButtonBox, fieldStyles, fieldXPadding, focusFieldStyles, MenuCard, MenuCardItem } from '../foundational';
|
|
44
|
+
var Input = styled(Combobox.Input)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n ", ";\n"])), fieldStyles({
|
|
45
|
+
paddingRight: '32px'
|
|
46
|
+
}), focusFieldStyles);
|
|
47
|
+
|
|
48
|
+
var Root = function Root(_ref) {
|
|
49
|
+
var props = Object.assign({}, _ref);
|
|
50
|
+
return /*#__PURE__*/React.createElement(Box, Object.assign({}, props, {
|
|
51
|
+
position: "relative"
|
|
52
|
+
}));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var Trigger = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
56
|
+
var props = Object.assign({}, _ref2);
|
|
57
|
+
return /*#__PURE__*/React.createElement(Box, Object.assign({
|
|
58
|
+
ref: ref
|
|
59
|
+
}, props, {
|
|
60
|
+
position: "relative"
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
var EmptyState = function EmptyState() {
|
|
65
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
66
|
+
padding: "s"
|
|
67
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
68
|
+
color: "content2"
|
|
69
|
+
}, "No results"));
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
var Tags = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n align-items: start;\n gap: 4px;\n margin-bottom: 8px;\n flex-wrap: wrap;\n"])));
|
|
73
|
+
var RemoveButton = styled(ClearButtonBox)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n width: 24px;\n height: 24px;\n"])));
|
|
74
|
+
|
|
75
|
+
var Tag = function Tag(_ref3) {
|
|
76
|
+
var children = _ref3.children,
|
|
77
|
+
onRemoveClick = _ref3.onRemoveClick;
|
|
78
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
79
|
+
backgroundColor: "fade1",
|
|
80
|
+
radius: "s",
|
|
81
|
+
height: "32px",
|
|
82
|
+
paddingLeft: "12px",
|
|
83
|
+
paddingRight: "8px"
|
|
84
|
+
}, /*#__PURE__*/React.createElement(Arrange, {
|
|
85
|
+
gap: "4px",
|
|
86
|
+
height: "100%"
|
|
87
|
+
}, children, /*#__PURE__*/React.createElement(RemoveButton, {
|
|
88
|
+
onClick: function onClick() {
|
|
89
|
+
return onRemoveClick();
|
|
90
|
+
}
|
|
91
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
92
|
+
icon: /*#__PURE__*/React.createElement(IconCross, null),
|
|
93
|
+
size: "s"
|
|
94
|
+
}))));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export var MultiAutocomplete = function MultiAutocomplete(_ref4) {
|
|
98
|
+
var options = _ref4.options,
|
|
99
|
+
_ref4$defaultOptions = _ref4.defaultOptions,
|
|
100
|
+
defaultOptions = _ref4$defaultOptions === void 0 ? [] : _ref4$defaultOptions,
|
|
101
|
+
onChange = _ref4.onChange,
|
|
102
|
+
_ref4$menuAlign = _ref4.menuAlign,
|
|
103
|
+
menuAlign = _ref4$menuAlign === void 0 ? 'left' : _ref4$menuAlign,
|
|
104
|
+
_ref4$menuWidth = _ref4.menuWidth,
|
|
105
|
+
menuWidth = _ref4$menuWidth === void 0 ? '100%' : _ref4$menuWidth,
|
|
106
|
+
placeholder = _ref4.placeholder;
|
|
107
|
+
|
|
108
|
+
var _useState = useState(defaultOptions),
|
|
109
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
110
|
+
selectedOptions = _useState2[0],
|
|
111
|
+
setSelectedOptions = _useState2[1];
|
|
112
|
+
|
|
113
|
+
var _useState3 = useState(''),
|
|
114
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
115
|
+
query = _useState4[0],
|
|
116
|
+
setQuery = _useState4[1];
|
|
117
|
+
|
|
118
|
+
var handleChange = function handleChange(option) {
|
|
119
|
+
setSelectedOptions(option);
|
|
120
|
+
onChange && onChange(option);
|
|
121
|
+
setQuery('');
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
var filteredOptions = query === '' ? options : options.filter(function (option) {
|
|
125
|
+
return option.content.toLowerCase().includes(query.toLowerCase());
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
var deselectOption = function deselectOption(option) {
|
|
129
|
+
var remaining = selectedOptions.filter(function (item) {
|
|
130
|
+
return item !== option;
|
|
131
|
+
});
|
|
132
|
+
setSelectedOptions(remaining);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return /*#__PURE__*/React.createElement(Combobox, {
|
|
136
|
+
as: Root,
|
|
137
|
+
value: selectedOptions,
|
|
138
|
+
onChange: handleChange,
|
|
139
|
+
multiple: true
|
|
140
|
+
}, selectedOptions.length > 0 && /*#__PURE__*/React.createElement(Tags, null, selectedOptions.map(function (option) {
|
|
141
|
+
return /*#__PURE__*/React.createElement(Tag, {
|
|
142
|
+
onRemoveClick: function onRemoveClick() {
|
|
143
|
+
return deselectOption(option);
|
|
144
|
+
},
|
|
145
|
+
key: option.id
|
|
146
|
+
}, option.content);
|
|
147
|
+
})), /*#__PURE__*/React.createElement(Combobox.Button, {
|
|
148
|
+
as: Trigger
|
|
149
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
150
|
+
autoComplete: "off",
|
|
151
|
+
onChange: function onChange(event) {
|
|
152
|
+
return setQuery(event.target.value);
|
|
153
|
+
},
|
|
154
|
+
placeholder: placeholder
|
|
155
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
156
|
+
right: fieldXPadding,
|
|
157
|
+
position: "absolute",
|
|
158
|
+
top: "0px",
|
|
159
|
+
bottom: "0px",
|
|
160
|
+
margin: "auto",
|
|
161
|
+
height: "fit-content"
|
|
162
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
163
|
+
icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
|
|
164
|
+
}))), /*#__PURE__*/React.createElement(Combobox.Options, {
|
|
165
|
+
menuAlign: menuAlign,
|
|
166
|
+
menuWidth: menuWidth,
|
|
167
|
+
as: MenuCard
|
|
168
|
+
}, filteredOptions.map(function (option, index) {
|
|
169
|
+
return /*#__PURE__*/React.createElement(Combobox.Option, {
|
|
170
|
+
key: index,
|
|
171
|
+
value: option,
|
|
172
|
+
as: React.Fragment
|
|
173
|
+
}, function (_ref5) {
|
|
174
|
+
var active = _ref5.active,
|
|
175
|
+
selected = _ref5.selected;
|
|
176
|
+
return /*#__PURE__*/React.createElement(MenuCardItem, {
|
|
177
|
+
isSelected: selected,
|
|
178
|
+
isActive: active
|
|
179
|
+
}, option.content);
|
|
180
|
+
});
|
|
181
|
+
}), !Boolean(filteredOptions.length) && /*#__PURE__*/React.createElement(EmptyState, null)));
|
|
182
|
+
};
|
|
183
|
+
MultiAutocomplete.propTypes = {
|
|
184
|
+
options: PropTypes.array,
|
|
185
|
+
defaultOption: PropTypes.object,
|
|
186
|
+
onChange: PropTypes.func,
|
|
187
|
+
menuAlign: PropTypes.oneOf(['left', 'right']),
|
|
188
|
+
menuWidth: types.dimension
|
|
189
|
+
};
|
package/es/components/select.js
CHANGED
|
@@ -45,8 +45,8 @@ import { IconChevronDown } from '../icons';
|
|
|
45
45
|
import { Listbox } from '@headlessui/react';
|
|
46
46
|
import { getColor, getRadius } from '../utilities';
|
|
47
47
|
import { types } from '../types';
|
|
48
|
-
import {
|
|
49
|
-
var SelectButtonWrapper = styled(Listbox.Button)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n gap: 8px;\n appearance: none;\n border: none;\n background: ", ";\n padding: 0
|
|
48
|
+
import { fieldXPadding, MenuCard, MenuCardItem, textBoxHeight, transitions } from '../foundational';
|
|
49
|
+
var SelectButtonWrapper = styled(Listbox.Button)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ";\n display: flex;\n align-items: center;\n gap: 8px;\n appearance: none;\n border: none;\n background: ", ";\n padding: 0 ", ";\n min-height: ", ";\n border-radius: ", ";\n font: inherit;\n color: inherit;\n cursor: pointer;\n width: 100%;\n text-align: left;\n\n &:hover {\n background: ", ";\n }\n"])), transitions, getColor('fade1'), fieldXPadding, textBoxHeight, getRadius('s'), getColor('fade2'));
|
|
50
50
|
|
|
51
51
|
var SelectButton = function SelectButton(_ref) {
|
|
52
52
|
var children = _ref.children,
|
|
@@ -76,9 +76,9 @@ export var Select = function Select(_ref3) {
|
|
|
76
76
|
_ref3$menuAlign = _ref3.menuAlign,
|
|
77
77
|
menuAlign = _ref3$menuAlign === void 0 ? 'left' : _ref3$menuAlign,
|
|
78
78
|
_ref3$menuWidth = _ref3.menuWidth,
|
|
79
|
-
menuWidth = _ref3$menuWidth === void 0 ? '
|
|
79
|
+
menuWidth = _ref3$menuWidth === void 0 ? '100%' : _ref3$menuWidth;
|
|
80
80
|
|
|
81
|
-
var _useState = useState(defaultOption ||
|
|
81
|
+
var _useState = useState(defaultOption || ''),
|
|
82
82
|
_useState2 = _slicedToArray(_useState, 2),
|
|
83
83
|
selectedOption = _useState2[0],
|
|
84
84
|
setSelectedOption = _useState2[1];
|
|
@@ -92,28 +92,28 @@ export var Select = function Select(_ref3) {
|
|
|
92
92
|
as: SelectRoot,
|
|
93
93
|
value: selectedOption,
|
|
94
94
|
onChange: handleChange
|
|
95
|
-
}, /*#__PURE__*/React.createElement(SelectButton, null, selectedOption
|
|
95
|
+
}, /*#__PURE__*/React.createElement(SelectButton, null, selectedOption), /*#__PURE__*/React.createElement(Listbox.Options, {
|
|
96
96
|
menuAlign: menuAlign,
|
|
97
97
|
menuWidth: menuWidth,
|
|
98
|
-
as:
|
|
99
|
-
}, options.map(function (option) {
|
|
98
|
+
as: MenuCard
|
|
99
|
+
}, options.map(function (option, index) {
|
|
100
100
|
return /*#__PURE__*/React.createElement(Listbox.Option, {
|
|
101
|
-
key:
|
|
101
|
+
key: index,
|
|
102
102
|
value: option,
|
|
103
103
|
as: React.Fragment
|
|
104
104
|
}, function (_ref4) {
|
|
105
105
|
var active = _ref4.active,
|
|
106
106
|
selected = _ref4.selected;
|
|
107
|
-
return /*#__PURE__*/React.createElement(
|
|
107
|
+
return /*#__PURE__*/React.createElement(MenuCardItem, {
|
|
108
108
|
isSelected: selected,
|
|
109
109
|
isActive: active
|
|
110
|
-
}, option
|
|
110
|
+
}, option);
|
|
111
111
|
});
|
|
112
112
|
})));
|
|
113
113
|
};
|
|
114
114
|
Select.propTypes = {
|
|
115
115
|
options: PropTypes.array,
|
|
116
|
-
defaultOption: PropTypes.
|
|
116
|
+
defaultOption: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
117
117
|
onChange: PropTypes.func,
|
|
118
118
|
menuAlign: PropTypes.oneOf(['left', 'right']),
|
|
119
119
|
menuWidth: types.dimension
|
package/es/foundational/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import "core-js/modules/es.object.define-properties.js";
|
|
|
4
4
|
import "core-js/modules/es.object.keys.js";
|
|
5
5
|
import "core-js/modules/es.array.index-of.js";
|
|
6
6
|
import "core-js/modules/es.symbol.js";
|
|
7
|
-
var _excluded = ["children", "isSelected", "isActive"];
|
|
7
|
+
var _excluded = ["children", "isSelected", "isActive", "icon"];
|
|
8
8
|
|
|
9
9
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
10
10
|
|
|
@@ -23,6 +23,7 @@ import { Box, Icon, Text } from '../components';
|
|
|
23
23
|
import { IconCheck } from '../icons';
|
|
24
24
|
import { forwardRef } from 'react';
|
|
25
25
|
export var fieldXPadding = '12px';
|
|
26
|
+
export var textBoxHeight = '40px';
|
|
26
27
|
export var transitions = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n transition: ", ";\n\n &:hover {\n transition: ", ";\n }\n\n &:active {\n transition: 0s;\n }\n"])), getTransition('slow'), getTransition('fast'));
|
|
27
28
|
export var ClearButtonBox = styled.button(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", ";\n --grn-borderColor-active: var(--grn-color-fade5);\n\n appearance: none;\n border: 1px solid transparent;\n padding: 0;\n font-family: inherit;\n font-size: inherit;\n cursor: pointer;\n font-weight: ", ";\n border-radius: ", ";\n height: var(--grn-clearButtonHeight-m);\n background-color: transparent;\n display: flex;\n align-items: center;\n justify-content: center;\n\n &:hover {\n background-color: var(--grn-color-backgroundOverlay);\n }\n\n &:active {\n border-color: var(--grn-borderColor-active);\n outline-color: var(--grn-borderColor-active);\n background-color: transparent;\n }\n\n &:disabled {\n color: ", ";\n cursor: default;\n border-color: transparent;\n\n &:hover {\n background-color: transparent;\n }\n }\n"])), transitions, getWeight('medium'), getRadius('s'), getColor('contentDisabled'));
|
|
28
29
|
export var fieldStyles = function fieldStyles(_ref) {
|
|
@@ -35,31 +36,42 @@ export var fieldStyles = function fieldStyles(_ref) {
|
|
|
35
36
|
return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n --grn-fieldBorderColor-hover: var(--grn-color-fade6);\n --grn-fieldBorderColor-focus: var(--grn-color-grey6);\n\n ", ";\n appearance: none;\n border: none;\n font: inherit;\n color: inherit;\n background-color: transparent;\n transition-property: border-color;\n width: 100%;\n border-radius: ", ";\n height: var(--grn-textBoxHeight-m);\n padding: 0 ", " 0 ", ";\n outline: none;\n border: 1px solid ", ";\n\n &::placeholder {\n color: ", ";\n }\n"])), transitions, getRadius('s'), paddingRight, paddingLeft, borderColor, getColor('grey5'));
|
|
36
37
|
};
|
|
37
38
|
export var focusFieldStyles = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n &:hover {\n border-color: var(--grn-fieldBorderColor-hover);\n }\n\n &:focus {\n transition: 0s;\n border-color: var(--grn-fieldBorderColor-focus);\n }\n"])));
|
|
38
|
-
export var
|
|
39
|
+
export var MenuCard = styled.ul(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n padding: 8px;\n margin: 0;\n position: absolute;\n background: white;\n box-shadow: ", ";\n border-radius: ", ";\n max-height: 468px;\n overflow: auto;\n width: ", ";\n ", "\n\n &:focus {\n outline: none;\n }\n"])), getShadow('m'), getRadius('s'), function (_ref2) {
|
|
39
40
|
var menuWidth = _ref2.menuWidth;
|
|
40
41
|
return getDimension(menuWidth);
|
|
41
42
|
}, function (_ref3) {
|
|
42
43
|
var menuAlign = _ref3.menuAlign;
|
|
43
44
|
return "".concat(menuAlign, ": 0;");
|
|
44
45
|
});
|
|
45
|
-
var MenuItemWrapper = styled.li(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n display: grid;\n grid-auto-flow: column;\n
|
|
46
|
-
|
|
46
|
+
var MenuItemWrapper = styled.li(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n display: grid;\n grid-auto-flow: column;\n grid-template-columns: ", ";\n ", ";\n align-items: center;\n justify-content: start;\n list-style: none;\n padding: 0 12px;\n min-height: ", ";\n cursor: pointer;\n border-radius: ", ";\n appearance: none;\n"])), function (p) {
|
|
47
|
+
return p.hasIcon ? 'auto 1fr' : '1fr auto';
|
|
48
|
+
}, function (p) {
|
|
49
|
+
return (p.hasIcon || p.isSelected) && 'gap: 8px';
|
|
50
|
+
}, textBoxHeight, getRadius('s'));
|
|
51
|
+
export var MenuCardItem = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
47
52
|
var children = _ref4.children,
|
|
48
53
|
isSelected = _ref4.isSelected,
|
|
49
54
|
isActive = _ref4.isActive,
|
|
55
|
+
icon = _ref4.icon,
|
|
50
56
|
props = _objectWithoutProperties(_ref4, _excluded);
|
|
51
57
|
|
|
52
58
|
return /*#__PURE__*/React.createElement(MenuItemWrapper, Object.assign({
|
|
53
59
|
ref: ref,
|
|
54
60
|
isActive: isActive,
|
|
61
|
+
isSelected: isSelected,
|
|
55
62
|
style: {
|
|
56
63
|
background: isActive ? getColor('overlay') : undefined
|
|
57
|
-
}
|
|
58
|
-
|
|
64
|
+
},
|
|
65
|
+
hasIcon: Boolean(icon)
|
|
66
|
+
}, props), icon && /*#__PURE__*/React.createElement(Icon, {
|
|
67
|
+
icon: icon,
|
|
68
|
+
hasEvenBoundary: true
|
|
69
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
70
|
+
width: "100%",
|
|
71
|
+
tag: "span"
|
|
72
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
59
73
|
hasEllipsis: true
|
|
60
|
-
}, children), isSelected && /*#__PURE__*/React.createElement(
|
|
61
|
-
marginLeft: "auto"
|
|
62
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
74
|
+
}, children)), isSelected && /*#__PURE__*/React.createElement(Icon, {
|
|
63
75
|
icon: /*#__PURE__*/React.createElement(IconCheck, null)
|
|
64
|
-
}))
|
|
76
|
+
}));
|
|
65
77
|
});
|