@flodesk/grain 11.22.5 → 11.23.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/arrange/index.js +34 -47
- package/es/components/autocomplete.js +94 -149
- package/es/components/autocomplete2.js +127 -166
- package/es/components/badge.js +12 -17
- package/es/components/box.js +115 -126
- package/es/components/breakpoints-provider.js +6 -4
- package/es/components/button.js +26 -39
- package/es/components/checkbox.js +31 -28
- package/es/components/dropdown.js +52 -50
- package/es/components/flex/index.js +31 -46
- package/es/components/icon-button.js +17 -25
- package/es/components/icon-toggle.js +28 -32
- package/es/components/icon.js +10 -20
- package/es/components/link.js +18 -18
- package/es/components/modal.js +75 -69
- package/es/components/nav/index.js +36 -43
- package/es/components/pagination.js +45 -63
- package/es/components/popover.js +47 -48
- package/es/components/progress.js +12 -15
- package/es/components/provider.js +7 -6
- package/es/components/radio.js +25 -24
- package/es/components/select.js +90 -98
- package/es/components/slider.js +25 -29
- package/es/components/spinner.js +11 -26
- package/es/components/stack.js +10 -19
- package/es/components/switch.js +21 -21
- package/es/components/tab.js +18 -25
- package/es/components/text/index.js +38 -48
- package/es/components/text-button.js +28 -41
- package/es/components/text-input.js +52 -74
- package/es/components/text-toggle.js +20 -31
- package/es/components/textarea.js +38 -33
- package/es/components/toast.js +29 -28
- package/es/components/tooltip.js +43 -77
- package/es/foundational/field.js +37 -32
- package/es/foundational/menu.js +110 -96
- package/es/foundational/styles.js +23 -23
- package/es/hooks/useKeyPress.js +10 -31
- package/es/hooks/useMedia.js +8 -45
- package/es/hooks/useOnClickOutside.js +4 -7
- package/es/hooks/usePrev.js +3 -3
- package/es/hooks/useWidth.js +3 -29
- package/es/hooks/useWindowSize.js +4 -32
- package/es/icons/icon-align-center.js +28 -32
- package/es/icons/icon-align-left.js +35 -39
- package/es/icons/icon-align-right.js +35 -39
- package/es/icons/icon-archive.js +21 -25
- package/es/icons/icon-arrow-down.js +21 -25
- package/es/icons/icon-arrow-left.js +21 -25
- package/es/icons/icon-arrow-right.js +21 -25
- package/es/icons/icon-arrow-up.js +21 -25
- package/es/icons/icon-at.js +21 -25
- package/es/icons/icon-bold.js +28 -32
- package/es/icons/icon-bolt-filled.js +21 -25
- package/es/icons/icon-bolt.js +21 -25
- package/es/icons/icon-browser.js +21 -25
- package/es/icons/icon-brush.js +20 -24
- package/es/icons/icon-bullet-list.js +21 -25
- package/es/icons/icon-chart.js +29 -33
- package/es/icons/icon-check.js +21 -25
- package/es/icons/icon-chevron-down.js +21 -25
- package/es/icons/icon-chevron-horizontal.js +21 -25
- package/es/icons/icon-chevron-left.js +21 -25
- package/es/icons/icon-chevron-right.js +21 -25
- package/es/icons/icon-chevron-up.js +28 -32
- package/es/icons/icon-chevron-vertical.js +28 -32
- package/es/icons/icon-clip.js +37 -41
- package/es/icons/icon-clock.js +21 -25
- package/es/icons/icon-column-and-rows.js +25 -29
- package/es/icons/icon-column-one.js +21 -25
- package/es/icons/icon-column-two.js +21 -25
- package/es/icons/icon-columns-and-row.js +25 -29
- package/es/icons/icon-columns.js +21 -25
- package/es/icons/icon-content-align-bottom.js +21 -25
- package/es/icons/icon-content-align-center.js +21 -25
- package/es/icons/icon-content-align-top.js +21 -25
- package/es/icons/icon-crop.js +21 -25
- package/es/icons/icon-cross.js +23 -27
- package/es/icons/icon-download.js +28 -32
- package/es/icons/icon-drag.js +21 -25
- package/es/icons/icon-duplicate.js +21 -25
- package/es/icons/icon-ellipsis.js +21 -25
- package/es/icons/icon-file.js +28 -32
- package/es/icons/icon-folder-add.js +21 -25
- package/es/icons/icon-folder-move.js +21 -25
- package/es/icons/icon-folder-remove.js +21 -25
- package/es/icons/icon-folder.js +21 -25
- package/es/icons/icon-gear.js +35 -39
- package/es/icons/icon-globe.js +28 -32
- package/es/icons/icon-heart.js +21 -25
- package/es/icons/icon-hide.js +21 -25
- package/es/icons/icon-image.js +21 -25
- package/es/icons/icon-info.js +21 -25
- package/es/icons/icon-italic.js +28 -32
- package/es/icons/icon-layout-text-bottom.js +28 -32
- package/es/icons/icon-layout-text-left.js +21 -25
- package/es/icons/icon-layout-text-right.js +28 -32
- package/es/icons/icon-layout-text-top.js +21 -25
- package/es/icons/icon-link.js +21 -25
- package/es/icons/icon-location.js +21 -25
- package/es/icons/icon-mail.js +21 -25
- package/es/icons/icon-minus.js +19 -23
- package/es/icons/icon-monitor.js +21 -25
- package/es/icons/icon-number-list.js +29 -33
- package/es/icons/icon-pencil.js +28 -32
- package/es/icons/icon-phone.js +21 -25
- package/es/icons/icon-play.js +21 -25
- package/es/icons/icon-plus.js +21 -25
- package/es/icons/icon-question.js +21 -25
- package/es/icons/icon-redo.js +21 -25
- package/es/icons/icon-reset.js +22 -26
- package/es/icons/icon-row-and-columns.js +25 -29
- package/es/icons/icon-rows-and-column.js +25 -29
- package/es/icons/icon-rows.js +21 -25
- package/es/icons/icon-search.js +21 -25
- package/es/icons/icon-send.js +21 -25
- package/es/icons/icon-share.js +21 -25
- package/es/icons/icon-show.js +21 -25
- package/es/icons/icon-smile.js +28 -32
- package/es/icons/icon-square.js +21 -25
- package/es/icons/icon-strike.js +28 -32
- package/es/icons/icon-switch.js +21 -25
- package/es/icons/icon-tablet.js +21 -25
- package/es/icons/icon-text-align-center.js +21 -25
- package/es/icons/icon-text-align-left.js +21 -25
- package/es/icons/icon-text-align-right.js +21 -25
- package/es/icons/icon-text-justify.js +21 -25
- package/es/icons/icon-trash.js +28 -32
- package/es/icons/icon-type.js +28 -32
- package/es/icons/icon-underline.js +28 -32
- package/es/icons/icon-undo.js +28 -32
- package/es/icons/icon-upload.js +28 -32
- package/es/styles/base.js +1 -1
- package/es/styles/card.js +4 -8
- package/es/styles/colors/core.js +1 -1
- package/es/styles/colors/theme.js +1 -1
- package/es/styles/foundational-variables.js +5 -0
- package/es/styles/index.js +2 -2
- package/es/styles/shadows.js +1 -1
- package/es/styles/utilities.js +65 -90
- package/es/styles/variables.js +1 -1
- package/es/types.js +28 -29
- package/es/utilities/attributes.js +46 -49
- package/es/utilities/helpers.js +13 -36
- package/es/utilities/responsive.js +16 -43
- package/es/utilities/style-config.js +32 -76
- package/es/utilities/styles.js +17 -29
- package/es/variables/breakpoints.js +1 -1
- package/es/variables/colors.js +1 -1
- package/es/variables/vars.js +3 -13
- package/package.json +6 -6
- package/es/styles/component-variables.js +0 -2
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import "core-js/modules/es.array.index-of.js";
|
|
3
|
-
import "core-js/modules/es.symbol.js";
|
|
4
|
-
import "core-js/modules/es.object.define-property.js";
|
|
5
|
-
import "core-js/modules/es.array.filter.js";
|
|
6
|
-
import "core-js/modules/es.object.to-string.js";
|
|
7
|
-
import "core-js/modules/es.object.get-own-property-descriptor.js";
|
|
8
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
9
|
-
import "core-js/modules/es.object.get-own-property-descriptors.js";
|
|
10
|
-
import "core-js/modules/es.object.define-properties.js";
|
|
11
|
-
import "core-js/modules/es.object.assign.js";
|
|
12
|
-
var _excluded = ["children", "gap", "columnGap", "rowGap", "alignItems", "justifyItems", "justifyContent", "alignContent", "columns", "rows", "autoFlow", "className", "style"];
|
|
1
|
+
const _excluded = ["children", "gap", "columnGap", "rowGap", "alignItems", "justifyItems", "justifyContent", "alignContent", "columns", "rows", "autoFlow", "className", "style"];
|
|
13
2
|
|
|
14
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); }
|
|
15
4
|
|
|
16
5
|
import "core-js/modules/es.regexp.exec.js";
|
|
17
6
|
import "core-js/modules/es.string.replace.js";
|
|
18
7
|
import "core-js/modules/es.string.trim.js";
|
|
19
|
-
import "core-js/modules/es.array.concat.js";
|
|
20
8
|
|
|
21
9
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
22
10
|
|
|
@@ -35,50 +23,49 @@ import { Box } from '../box';
|
|
|
35
23
|
import styles from './styles.module.css';
|
|
36
24
|
import { BreakpointsContext } from '../breakpoints-provider';
|
|
37
25
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
style = _ref.style,
|
|
26
|
+
export const Arrange = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
27
|
+
let {
|
|
28
|
+
children,
|
|
29
|
+
gap,
|
|
30
|
+
columnGap,
|
|
31
|
+
rowGap,
|
|
32
|
+
alignItems = 'center',
|
|
33
|
+
justifyItems,
|
|
34
|
+
justifyContent = 'start',
|
|
35
|
+
alignContent,
|
|
36
|
+
columns,
|
|
37
|
+
rows,
|
|
38
|
+
autoFlow = 'column',
|
|
39
|
+
className,
|
|
40
|
+
style
|
|
41
|
+
} = _ref,
|
|
55
42
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
56
43
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
gap
|
|
62
|
-
columnGap
|
|
63
|
-
rowGap
|
|
64
|
-
alignItems
|
|
65
|
-
justifyItems
|
|
66
|
-
justifyContent
|
|
67
|
-
alignContent
|
|
44
|
+
const propClassName = className ? className : '';
|
|
45
|
+
const propStyle = style ? style : {};
|
|
46
|
+
const breakpoints = useContext(BreakpointsContext);
|
|
47
|
+
const sharedProps = {
|
|
48
|
+
gap,
|
|
49
|
+
columnGap,
|
|
50
|
+
rowGap,
|
|
51
|
+
alignItems,
|
|
52
|
+
justifyItems,
|
|
53
|
+
justifyContent,
|
|
54
|
+
alignContent,
|
|
68
55
|
autoFlow: !columns ? autoFlow : undefined
|
|
69
56
|
};
|
|
70
|
-
|
|
57
|
+
const attributes = generateAttributes({
|
|
71
58
|
styleProps: _objectSpread({
|
|
72
|
-
columns
|
|
73
|
-
rows
|
|
59
|
+
columns,
|
|
60
|
+
rows
|
|
74
61
|
}, sharedProps),
|
|
75
62
|
classNameProps: _objectSpread({}, sharedProps),
|
|
76
|
-
breakpoints
|
|
63
|
+
breakpoints
|
|
77
64
|
});
|
|
78
65
|
|
|
79
|
-
|
|
66
|
+
const styleAttributes = _objectSpread(_objectSpread({}, attributes.styles), propStyle);
|
|
80
67
|
|
|
81
|
-
|
|
68
|
+
const classAttributes = "".concat(attributes.classNames, " ").concat(propClassName, " ").concat(styles.arrange).trim().replace(/\s+/g, ' ');
|
|
82
69
|
return ___EmotionJSX(Box, _extends({
|
|
83
70
|
ref: ref,
|
|
84
71
|
className: classAttributes,
|
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import "core-js/modules/es.array.index-of.js";
|
|
3
|
-
import "core-js/modules/es.symbol.js";
|
|
4
|
-
import "core-js/modules/es.symbol.description.js";
|
|
5
|
-
import "core-js/modules/es.symbol.iterator.js";
|
|
6
|
-
import "core-js/modules/es.array.iterator.js";
|
|
7
|
-
import "core-js/modules/es.string.iterator.js";
|
|
1
|
+
const _excluded = ["options", "value", "onChange", "isCreatable", "onCreate", "menuPlacement", "menuWidth", "menuMaxHeight", "menuZIndex", "placeholder", "label", "hint", "menuItemsHaveEllipsis", "hasPortal", "hasError", "errorMessage", "searchField"];
|
|
8
2
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
9
|
-
import "core-js/modules/es.array.slice.js";
|
|
10
|
-
import "core-js/modules/es.array.from.js";
|
|
11
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
12
|
-
var _excluded = ["options", "value", "onChange", "isCreatable", "onCreate", "menuPlacement", "menuWidth", "menuMaxHeight", "menuZIndex", "placeholder", "label", "hint", "menuItemsHaveEllipsis", "hasPortal", "hasError", "errorMessage", "searchField"];
|
|
13
|
-
|
|
14
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
|
-
|
|
16
|
-
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."); }
|
|
17
|
-
|
|
18
|
-
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); }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
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; }
|
|
23
|
-
|
|
24
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
3
|
|
|
26
4
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
27
5
|
|
|
@@ -29,13 +7,6 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
29
7
|
|
|
30
8
|
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); }
|
|
31
9
|
|
|
32
|
-
import "core-js/modules/es.object.assign.js";
|
|
33
|
-
import "core-js/modules/es.array.filter.js";
|
|
34
|
-
import "core-js/modules/es.object.to-string.js";
|
|
35
|
-
import "core-js/modules/es.array.includes.js";
|
|
36
|
-
import "core-js/modules/es.string.includes.js";
|
|
37
|
-
import "core-js/modules/es.array.find.js";
|
|
38
|
-
import "core-js/modules/es.array.map.js";
|
|
39
10
|
import PropTypes from 'prop-types';
|
|
40
11
|
import React, { forwardRef, Fragment, useMemo, useRef, useState } from 'react';
|
|
41
12
|
import { Icon, Box, Text } from '.';
|
|
@@ -48,8 +19,8 @@ import { FloatingPortal } from '@floating-ui/react-dom-interactions';
|
|
|
48
19
|
import { Global } from '@emotion/react';
|
|
49
20
|
import { getColor, getRadius } from '../utilities';
|
|
50
21
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
51
|
-
|
|
52
|
-
|
|
22
|
+
const Trigger = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
23
|
+
let props = Object.assign({}, _ref);
|
|
53
24
|
return ___EmotionJSX(Box, _extends({
|
|
54
25
|
ref: ref
|
|
55
26
|
}, props, {
|
|
@@ -57,77 +28,63 @@ var Trigger = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
57
28
|
}));
|
|
58
29
|
});
|
|
59
30
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}, "No results"));
|
|
67
|
-
};
|
|
31
|
+
const EmptyState = () => ___EmotionJSX(Box, {
|
|
32
|
+
paddingY: "s",
|
|
33
|
+
paddingX: "12px"
|
|
34
|
+
}, ___EmotionJSX(Text, {
|
|
35
|
+
color: "content2"
|
|
36
|
+
}, "No results"));
|
|
68
37
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}));
|
|
80
|
-
};
|
|
38
|
+
const ExpandIcon = () => ___EmotionJSX(Box, {
|
|
39
|
+
right: "fieldPaddingX",
|
|
40
|
+
position: "absolute",
|
|
41
|
+
top: "0px",
|
|
42
|
+
bottom: "0px",
|
|
43
|
+
margin: "auto",
|
|
44
|
+
height: "fit-content"
|
|
45
|
+
}, ___EmotionJSX(Icon, {
|
|
46
|
+
icon: ___EmotionJSX(IconChevronDown, null)
|
|
47
|
+
}));
|
|
81
48
|
|
|
82
|
-
|
|
49
|
+
const getFilteredOptions = (query, options, searchField) => {
|
|
83
50
|
if (query === '') return options;
|
|
84
|
-
return options.filter(
|
|
85
|
-
return option[searchField].toLowerCase().includes(query.toLowerCase());
|
|
86
|
-
});
|
|
51
|
+
return options.filter(option => option[searchField].toLowerCase().includes(query.toLowerCase()));
|
|
87
52
|
};
|
|
88
53
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
54
|
+
const getShowGroupTitle = (index, option, filteredOptions) => {
|
|
55
|
+
const firstOptionHasTitle = index === 0 && option.groupTitle;
|
|
56
|
+
const titleChanged = index > 0 && option.groupTitle !== filteredOptions[index - 1].groupTitle;
|
|
92
57
|
return firstOptionHasTitle || titleChanged;
|
|
93
58
|
};
|
|
94
59
|
|
|
95
|
-
|
|
96
|
-
export
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
errorMessage = _ref2.errorMessage,
|
|
117
|
-
_ref2$searchField = _ref2.searchField,
|
|
118
|
-
searchField = _ref2$searchField === void 0 ? 'content' : _ref2$searchField,
|
|
60
|
+
const menuItemStyles = "\n .autocompleteMenuItem {\n display: flex;\n gap: 8px;\n align-items: center;\n list-style: none;\n padding: 4px 12px;\n min-height: var(--grn-textBoxHeight);\n border-radius: ".concat(getRadius('s'), ";\n appearance: none;\n\n &.hasPreContent {\n padding-left: 0;\n }\n }\n\n .autocompleteMenuItemText {\n flex-grow: 1;\n\n &.hasEllipsis {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n }\n");
|
|
61
|
+
export const Autocomplete = _ref2 => {
|
|
62
|
+
let {
|
|
63
|
+
options,
|
|
64
|
+
value,
|
|
65
|
+
onChange,
|
|
66
|
+
isCreatable,
|
|
67
|
+
onCreate,
|
|
68
|
+
menuPlacement = defaultProps.menuPlacement,
|
|
69
|
+
menuWidth,
|
|
70
|
+
menuMaxHeight = defaultProps.menuMaxHeight,
|
|
71
|
+
menuZIndex,
|
|
72
|
+
placeholder,
|
|
73
|
+
label,
|
|
74
|
+
hint,
|
|
75
|
+
menuItemsHaveEllipsis = true,
|
|
76
|
+
hasPortal = true,
|
|
77
|
+
hasError,
|
|
78
|
+
errorMessage,
|
|
79
|
+
searchField = 'content'
|
|
80
|
+
} = _ref2,
|
|
119
81
|
props = _objectWithoutProperties(_ref2, _excluded);
|
|
120
82
|
|
|
121
|
-
|
|
122
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
123
|
-
query = _useState2[0],
|
|
124
|
-
setQuery = _useState2[1];
|
|
83
|
+
const [query, setQuery] = useState('');
|
|
125
84
|
|
|
126
|
-
|
|
85
|
+
const handleCreatableChange = option => {
|
|
127
86
|
if (onCreate) {
|
|
128
|
-
|
|
129
|
-
return item.value === option.value;
|
|
130
|
-
});
|
|
87
|
+
const isCreatableOption = !options.find(item => item.value === option.value);
|
|
131
88
|
|
|
132
89
|
if (isCreatableOption) {
|
|
133
90
|
onCreate(option);
|
|
@@ -138,7 +95,7 @@ export var Autocomplete = function Autocomplete(_ref2) {
|
|
|
138
95
|
onChange(option);
|
|
139
96
|
};
|
|
140
97
|
|
|
141
|
-
|
|
98
|
+
const handleChange = option => {
|
|
142
99
|
if (isCreatable) {
|
|
143
100
|
handleCreatableChange(option);
|
|
144
101
|
} else {
|
|
@@ -146,39 +103,27 @@ export var Autocomplete = function Autocomplete(_ref2) {
|
|
|
146
103
|
}
|
|
147
104
|
};
|
|
148
105
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}, [
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
floating = _useMenuPosition.floating,
|
|
171
|
-
floatingStyles = _useMenuPosition.floatingStyles;
|
|
172
|
-
|
|
173
|
-
var OptionsRoot = hasPortal ? FloatingPortal : Fragment;
|
|
174
|
-
var preContentRef = useRef(null);
|
|
175
|
-
|
|
176
|
-
var _useState3 = useState(0),
|
|
177
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
178
|
-
preContentWidth = _useState4[0],
|
|
179
|
-
setPreContentWidth = _useState4[1];
|
|
180
|
-
|
|
181
|
-
React.useEffect(function () {
|
|
106
|
+
const filteredOptions = getFilteredOptions(query, options, searchField);
|
|
107
|
+
const isShowCreateOption = isCreatable && query.length > 0;
|
|
108
|
+
const noResults = !Boolean(filteredOptions.length) && !isShowCreateOption;
|
|
109
|
+
const fieldMarginTop = label || hint ? 'betweenFormControlAndLabel' : undefined;
|
|
110
|
+
const selectedOption = useMemo(() => options.find(option => option.value === value), [options, value]);
|
|
111
|
+
const newOption = useMemo(() => ({
|
|
112
|
+
value: query,
|
|
113
|
+
content: query
|
|
114
|
+
}), [query]);
|
|
115
|
+
const {
|
|
116
|
+
reference,
|
|
117
|
+
floating,
|
|
118
|
+
floatingStyles
|
|
119
|
+
} = useMenuPosition({
|
|
120
|
+
menuWidth,
|
|
121
|
+
menuPlacement
|
|
122
|
+
});
|
|
123
|
+
const OptionsRoot = hasPortal ? FloatingPortal : Fragment;
|
|
124
|
+
const preContentRef = useRef(null);
|
|
125
|
+
const [preContentWidth, setPreContentWidth] = useState(0);
|
|
126
|
+
React.useEffect(() => {
|
|
182
127
|
if (preContentRef.current) {
|
|
183
128
|
setPreContentWidth(preContentRef.current.offsetWidth);
|
|
184
129
|
}
|
|
@@ -189,9 +134,11 @@ export var Autocomplete = function Autocomplete(_ref2) {
|
|
|
189
134
|
as: "div",
|
|
190
135
|
value: selectedOption || '',
|
|
191
136
|
onChange: handleChange
|
|
192
|
-
}, props),
|
|
193
|
-
|
|
194
|
-
|
|
137
|
+
}, props), _ref3 => {
|
|
138
|
+
let {
|
|
139
|
+
open
|
|
140
|
+
} = _ref3;
|
|
141
|
+
const hasPreContent = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.preContent;
|
|
195
142
|
return ___EmotionJSX(React.Fragment, null, label && ___EmotionJSX(Combobox.Label, {
|
|
196
143
|
as: FieldLabel
|
|
197
144
|
}, label), hint && ___EmotionJSX(FieldHint, null, hint), ___EmotionJSX(Box, {
|
|
@@ -212,20 +159,14 @@ export var Autocomplete = function Autocomplete(_ref2) {
|
|
|
212
159
|
}, selectedOption.preContent), ___EmotionJSX(Combobox.Input, {
|
|
213
160
|
as: InputField,
|
|
214
161
|
autoComplete: "off",
|
|
215
|
-
onChange:
|
|
216
|
-
return setQuery(event.target.value);
|
|
217
|
-
},
|
|
162
|
+
onChange: event => setQuery(event.target.value),
|
|
218
163
|
placeholder: placeholder,
|
|
219
|
-
displayValue:
|
|
220
|
-
return option && option.content;
|
|
221
|
-
},
|
|
164
|
+
displayValue: option => option && option.content,
|
|
222
165
|
paddingRight: "32px",
|
|
223
166
|
paddingLeft: !open && hasPreContent ? "".concat(preContentWidth + 8, "px") : undefined,
|
|
224
167
|
hasError: hasError
|
|
225
168
|
}), ___EmotionJSX(ExpandIcon, null)), ___EmotionJSX(OptionsRoot, null, ___EmotionJSX(MenuCardTransition, {
|
|
226
|
-
afterLeave:
|
|
227
|
-
return setQuery('');
|
|
228
|
-
}
|
|
169
|
+
afterLeave: () => setQuery('')
|
|
229
170
|
}, ___EmotionJSX(Combobox.Options, {
|
|
230
171
|
static: true,
|
|
231
172
|
className: "grn-context",
|
|
@@ -236,8 +177,8 @@ export var Autocomplete = function Autocomplete(_ref2) {
|
|
|
236
177
|
zIndex: menuZIndex,
|
|
237
178
|
style: floatingStyles,
|
|
238
179
|
isDisabled: !open
|
|
239
|
-
}, filteredOptions.map(
|
|
240
|
-
|
|
180
|
+
}, filteredOptions.map((option, index) => {
|
|
181
|
+
const showGroupTitle = getShowGroupTitle(index, option, filteredOptions);
|
|
241
182
|
return ___EmotionJSX(Fragment, {
|
|
242
183
|
key: index
|
|
243
184
|
}, showGroupTitle && ___EmotionJSX(MenuGroupTitle, {
|
|
@@ -246,13 +187,15 @@ export var Autocomplete = function Autocomplete(_ref2) {
|
|
|
246
187
|
value: option,
|
|
247
188
|
as: Fragment,
|
|
248
189
|
disabled: option.isDisabled
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
190
|
+
}, _ref4 => {
|
|
191
|
+
let {
|
|
192
|
+
active
|
|
193
|
+
} = _ref4;
|
|
194
|
+
const isDisabled = option.isDisabled;
|
|
195
|
+
const isSelected = option.value === value;
|
|
196
|
+
const isActive = !option.isDisabled && active;
|
|
197
|
+
const hasEllipsis = menuItemsHaveEllipsis;
|
|
198
|
+
const hasPreContent = option.preContent;
|
|
256
199
|
return ___EmotionJSX("li", {
|
|
257
200
|
className: hasPreContent ? 'autocompleteMenuItem hasPreContent' : 'autocompleteMenuItem',
|
|
258
201
|
style: {
|
|
@@ -272,9 +215,11 @@ export var Autocomplete = function Autocomplete(_ref2) {
|
|
|
272
215
|
}));
|
|
273
216
|
}), isShowCreateOption && ___EmotionJSX(React.Fragment, null, filteredOptions.length > 0 && ___EmotionJSX(MenuItemDivider, null), ___EmotionJSX(Combobox.Option, {
|
|
274
217
|
value: newOption
|
|
275
|
-
},
|
|
276
|
-
|
|
277
|
-
|
|
218
|
+
}, _ref5 => {
|
|
219
|
+
let {
|
|
220
|
+
active
|
|
221
|
+
} = _ref5;
|
|
222
|
+
const isActive = active;
|
|
278
223
|
return ___EmotionJSX("li", {
|
|
279
224
|
className: "autocompleteMenuItem",
|
|
280
225
|
style: {
|