@flodesk/grain 5.10.0 → 5.11.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/es/components/autocomplete.js +29 -19
- package/es/components/icon.js +1 -3
- package/es/components/select.js +21 -14
- package/es/components/text-button.js +15 -7
- package/es/foundational/index.js +17 -8
- package/package.json +1 -1
|
@@ -34,7 +34,7 @@ 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, { forwardRef, useState } from 'react';
|
|
37
|
+
import React, { forwardRef, Fragment, useState } from 'react';
|
|
38
38
|
import styled from '@emotion/styled';
|
|
39
39
|
import { Icon, Box, Text } from '.';
|
|
40
40
|
import { IconChevronDown } from '../icons';
|
|
@@ -69,6 +69,19 @@ var EmptyState = function EmptyState() {
|
|
|
69
69
|
}, "No results"));
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
+
var ExpandIcon = function ExpandIcon() {
|
|
73
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
74
|
+
right: fieldXPadding,
|
|
75
|
+
position: "absolute",
|
|
76
|
+
top: "0px",
|
|
77
|
+
bottom: "0px",
|
|
78
|
+
margin: "auto",
|
|
79
|
+
height: "fit-content"
|
|
80
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
81
|
+
icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
|
|
72
85
|
export var Autocomplete = function Autocomplete(_ref3) {
|
|
73
86
|
var options = _ref3.options,
|
|
74
87
|
defaultOption = _ref3.defaultOption,
|
|
@@ -79,7 +92,7 @@ export var Autocomplete = function Autocomplete(_ref3) {
|
|
|
79
92
|
menuWidth = _ref3$menuWidth === void 0 ? '100%' : _ref3$menuWidth,
|
|
80
93
|
placeholder = _ref3.placeholder;
|
|
81
94
|
|
|
82
|
-
var _useState = useState(defaultOption
|
|
95
|
+
var _useState = useState(defaultOption),
|
|
83
96
|
_useState2 = _slicedToArray(_useState, 2),
|
|
84
97
|
selectedOption = _useState2[0],
|
|
85
98
|
setSelectedOption = _useState2[1];
|
|
@@ -96,8 +109,9 @@ export var Autocomplete = function Autocomplete(_ref3) {
|
|
|
96
109
|
};
|
|
97
110
|
|
|
98
111
|
var filteredOptions = query === '' ? options : options.filter(function (option) {
|
|
99
|
-
return option.toLowerCase().includes(query.toLowerCase());
|
|
112
|
+
return option.value.toLowerCase().includes(query.toLowerCase());
|
|
100
113
|
});
|
|
114
|
+
var noResults = !Boolean(filteredOptions.length);
|
|
101
115
|
return /*#__PURE__*/React.createElement(Combobox, {
|
|
102
116
|
as: Root,
|
|
103
117
|
value: selectedOption,
|
|
@@ -109,17 +123,11 @@ export var Autocomplete = function Autocomplete(_ref3) {
|
|
|
109
123
|
onChange: function onChange(event) {
|
|
110
124
|
return setQuery(event.target.value);
|
|
111
125
|
},
|
|
112
|
-
placeholder: placeholder
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
bottom: "0px",
|
|
118
|
-
margin: "auto",
|
|
119
|
-
height: "fit-content"
|
|
120
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
121
|
-
icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
|
|
122
|
-
}))), /*#__PURE__*/React.createElement(Combobox.Options, {
|
|
126
|
+
placeholder: placeholder,
|
|
127
|
+
displayValue: function displayValue(option) {
|
|
128
|
+
return option && option.content;
|
|
129
|
+
}
|
|
130
|
+
}), /*#__PURE__*/React.createElement(ExpandIcon, null)), /*#__PURE__*/React.createElement(Combobox.Options, {
|
|
123
131
|
menuAlign: menuAlign,
|
|
124
132
|
menuWidth: menuWidth,
|
|
125
133
|
as: MenuCard
|
|
@@ -127,20 +135,22 @@ export var Autocomplete = function Autocomplete(_ref3) {
|
|
|
127
135
|
return /*#__PURE__*/React.createElement(Combobox.Option, {
|
|
128
136
|
key: index,
|
|
129
137
|
value: option,
|
|
130
|
-
as:
|
|
138
|
+
as: Fragment,
|
|
139
|
+
disabled: option.isDisabled
|
|
131
140
|
}, function (_ref4) {
|
|
132
141
|
var active = _ref4.active,
|
|
133
142
|
selected = _ref4.selected;
|
|
134
143
|
return /*#__PURE__*/React.createElement(MenuCardItem, {
|
|
135
144
|
isSelected: selected,
|
|
136
|
-
isActive: active
|
|
137
|
-
|
|
145
|
+
isActive: !option.isDisabled && active,
|
|
146
|
+
isDisabled: option.isDisabled
|
|
147
|
+
}, option.content);
|
|
138
148
|
});
|
|
139
|
-
}),
|
|
149
|
+
}), noResults && /*#__PURE__*/React.createElement(EmptyState, null)));
|
|
140
150
|
};
|
|
141
151
|
Autocomplete.propTypes = {
|
|
142
152
|
options: PropTypes.array,
|
|
143
|
-
defaultOption: PropTypes.
|
|
153
|
+
defaultOption: PropTypes.object,
|
|
144
154
|
onChange: PropTypes.func,
|
|
145
155
|
menuAlign: PropTypes.oneOf(['left', 'right']),
|
|
146
156
|
menuWidth: types.dimension
|
package/es/components/icon.js
CHANGED
|
@@ -21,9 +21,7 @@ import PropTypes from 'prop-types';
|
|
|
21
21
|
import React, { forwardRef } from 'react';
|
|
22
22
|
import styled from '@emotion/styled';
|
|
23
23
|
import { types } from '../types';
|
|
24
|
-
var Wrapper = styled.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n
|
|
25
|
-
return getColor(p.color);
|
|
26
|
-
}, function (p) {
|
|
24
|
+
var Wrapper = styled.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: block;\n color: ", ";\n\n svg {\n display: block;\n height: ", ";\n ", "\n"])), function (p) {
|
|
27
25
|
return getColor(p.color);
|
|
28
26
|
}, function (p) {
|
|
29
27
|
return getIconSize(p.size);
|
package/es/components/select.js
CHANGED
|
@@ -38,7 +38,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
38
38
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
39
39
|
|
|
40
40
|
import PropTypes from 'prop-types';
|
|
41
|
-
import React, { useState } from 'react';
|
|
41
|
+
import React, { useState, forwardRef, Fragment } from 'react';
|
|
42
42
|
import styled from '@emotion/styled';
|
|
43
43
|
import { Icon, Box, Text } from '.';
|
|
44
44
|
import { IconChevronDown } from '../icons';
|
|
@@ -46,13 +46,14 @@ import { Listbox } from '@headlessui/react';
|
|
|
46
46
|
import { getColor, getRadius } from '../utilities';
|
|
47
47
|
import { types } from '../types';
|
|
48
48
|
import { fieldXPadding, MenuCard, MenuCardItem, textBoxHeight, transitions } from '../foundational';
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
var SelectButton = function SelectButton(_ref) {
|
|
49
|
+
var DefaultTriggerButton = styled.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
|
+
var DefaultTrigger = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
52
51
|
var children = _ref.children,
|
|
53
52
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
54
53
|
|
|
55
|
-
return /*#__PURE__*/React.createElement(
|
|
54
|
+
return /*#__PURE__*/React.createElement(DefaultTriggerButton, Object.assign({
|
|
55
|
+
ref: ref
|
|
56
|
+
}, props), /*#__PURE__*/React.createElement(Text, {
|
|
56
57
|
hasEllipsis: true,
|
|
57
58
|
weight: "medium"
|
|
58
59
|
}, children), /*#__PURE__*/React.createElement(Box, {
|
|
@@ -60,7 +61,7 @@ var SelectButton = function SelectButton(_ref) {
|
|
|
60
61
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
61
62
|
icon: /*#__PURE__*/React.createElement(IconChevronDown, null)
|
|
62
63
|
})));
|
|
63
|
-
};
|
|
64
|
+
});
|
|
64
65
|
|
|
65
66
|
var SelectRoot = function SelectRoot(_ref2) {
|
|
66
67
|
var props = Object.assign({}, _ref2);
|
|
@@ -76,9 +77,10 @@ export var Select = function Select(_ref3) {
|
|
|
76
77
|
_ref3$menuAlign = _ref3.menuAlign,
|
|
77
78
|
menuAlign = _ref3$menuAlign === void 0 ? 'left' : _ref3$menuAlign,
|
|
78
79
|
_ref3$menuWidth = _ref3.menuWidth,
|
|
79
|
-
menuWidth = _ref3$menuWidth === void 0 ? '100%' : _ref3$menuWidth
|
|
80
|
+
menuWidth = _ref3$menuWidth === void 0 ? '100%' : _ref3$menuWidth,
|
|
81
|
+
trigger = _ref3.trigger;
|
|
80
82
|
|
|
81
|
-
var _useState = useState(defaultOption ||
|
|
83
|
+
var _useState = useState(defaultOption || {}),
|
|
82
84
|
_useState2 = _slicedToArray(_useState, 2),
|
|
83
85
|
selectedOption = _useState2[0],
|
|
84
86
|
setSelectedOption = _useState2[1];
|
|
@@ -92,7 +94,9 @@ export var Select = function Select(_ref3) {
|
|
|
92
94
|
as: SelectRoot,
|
|
93
95
|
value: selectedOption,
|
|
94
96
|
onChange: handleChange
|
|
95
|
-
}, /*#__PURE__*/React.createElement(
|
|
97
|
+
}, /*#__PURE__*/React.createElement(Listbox.Button, {
|
|
98
|
+
as: Fragment
|
|
99
|
+
}, trigger ? trigger(selectedOption) : /*#__PURE__*/React.createElement(DefaultTrigger, null, selectedOption.content)), /*#__PURE__*/React.createElement(Listbox.Options, {
|
|
96
100
|
menuAlign: menuAlign,
|
|
97
101
|
menuWidth: menuWidth,
|
|
98
102
|
as: MenuCard
|
|
@@ -100,21 +104,24 @@ export var Select = function Select(_ref3) {
|
|
|
100
104
|
return /*#__PURE__*/React.createElement(Listbox.Option, {
|
|
101
105
|
key: index,
|
|
102
106
|
value: option,
|
|
103
|
-
as:
|
|
107
|
+
as: Fragment,
|
|
108
|
+
disabled: option.isDisabled
|
|
104
109
|
}, function (_ref4) {
|
|
105
110
|
var active = _ref4.active,
|
|
106
111
|
selected = _ref4.selected;
|
|
107
112
|
return /*#__PURE__*/React.createElement(MenuCardItem, {
|
|
108
113
|
isSelected: selected,
|
|
109
|
-
isActive: active
|
|
110
|
-
|
|
114
|
+
isActive: active,
|
|
115
|
+
isDisabled: option.isDisabled
|
|
116
|
+
}, option.content);
|
|
111
117
|
});
|
|
112
118
|
})));
|
|
113
119
|
};
|
|
114
120
|
Select.propTypes = {
|
|
115
121
|
options: PropTypes.array,
|
|
116
|
-
defaultOption: PropTypes.
|
|
122
|
+
defaultOption: PropTypes.object,
|
|
117
123
|
onChange: PropTypes.func,
|
|
118
124
|
menuAlign: PropTypes.oneOf(['left', 'right']),
|
|
119
|
-
menuWidth: types.dimension
|
|
125
|
+
menuWidth: types.dimension,
|
|
126
|
+
trigger: PropTypes.func
|
|
120
127
|
};
|
|
@@ -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", "isDisabled", "icon"];
|
|
7
|
+
var _excluded = ["children", "isDisabled", "icon", "iconPosition"];
|
|
8
8
|
|
|
9
9
|
var _templateObject;
|
|
10
10
|
|
|
@@ -17,27 +17,35 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
17
17
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
18
18
|
|
|
19
19
|
import { Icon } from '../components';
|
|
20
|
-
import React from 'react';
|
|
20
|
+
import React, { forwardRef } from 'react';
|
|
21
21
|
import styled from '@emotion/styled';
|
|
22
22
|
import PropTypes from 'prop-types';
|
|
23
23
|
import { ClearButtonBox } from '../foundational';
|
|
24
|
-
var Wrapper = styled(ClearButtonBox)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding: 0 8px;\n gap: 8px;\n"])))
|
|
25
|
-
|
|
24
|
+
var Wrapper = styled(ClearButtonBox)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding: 0 8px;\n gap: 8px;\n\n .buttonIcon {\n ", ";\n }\n"])), function (p) {
|
|
25
|
+
return p.iconPosition === 'right' && "order: 1";
|
|
26
|
+
});
|
|
27
|
+
export var TextButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
26
28
|
var children = _ref.children,
|
|
27
29
|
isDisabled = _ref.isDisabled,
|
|
28
30
|
icon = _ref.icon,
|
|
31
|
+
_ref$iconPosition = _ref.iconPosition,
|
|
32
|
+
iconPosition = _ref$iconPosition === void 0 ? 'left' : _ref$iconPosition,
|
|
29
33
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
30
34
|
|
|
31
35
|
return /*#__PURE__*/React.createElement(Wrapper, Object.assign({
|
|
32
36
|
disabled: isDisabled,
|
|
33
|
-
icon: icon
|
|
37
|
+
icon: icon,
|
|
38
|
+
iconPosition: iconPosition,
|
|
39
|
+
ref: ref
|
|
34
40
|
}, props), icon && /*#__PURE__*/React.createElement(Icon, {
|
|
35
|
-
icon: icon
|
|
41
|
+
icon: icon,
|
|
42
|
+
className: "buttonIcon"
|
|
36
43
|
}), children && children);
|
|
37
|
-
};
|
|
44
|
+
});
|
|
38
45
|
TextButton.propTypes = {
|
|
39
46
|
children: PropTypes.node,
|
|
40
47
|
icon: PropTypes.node,
|
|
48
|
+
iconPosition: PropTypes.oneOf(['left', 'right']),
|
|
41
49
|
onClick: PropTypes.func,
|
|
42
50
|
isDisabled: PropTypes.bool
|
|
43
51
|
};
|
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", "icon"];
|
|
7
|
+
var _excluded = ["children", "isSelected", "isActive", "isDisabled", "icon"];
|
|
8
8
|
|
|
9
9
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
10
10
|
|
|
@@ -43,22 +43,30 @@ export var MenuCard = styled.ul(_templateObject5 || (_templateObject5 = _taggedT
|
|
|
43
43
|
var menuAlign = _ref3.menuAlign;
|
|
44
44
|
return "".concat(menuAlign, ": 0;");
|
|
45
45
|
});
|
|
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
|
|
46
|
+
var MenuItemWrapper = styled.li(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n display: grid;\n grid-auto-flow: column;\n grid-template-columns: ", ";\n ", ";\n ", ";\n ", ";\n align-items: center;\n justify-content: start;\n list-style: none;\n padding: 0 12px;\n min-height: ", ";\n border-radius: ", ";\n appearance: none;\n"])), function (p) {
|
|
47
47
|
return p.hasIcon ? 'auto 1fr' : '1fr auto';
|
|
48
48
|
}, function (p) {
|
|
49
49
|
return (p.hasIcon || p.isSelected) && 'gap: 8px';
|
|
50
|
+
}, function (_ref4) {
|
|
51
|
+
var isDisabled = _ref4.isDisabled;
|
|
52
|
+
return isDisabled && "color: ".concat(getColor('contentDisabled'));
|
|
53
|
+
}, function (_ref5) {
|
|
54
|
+
var isDisabled = _ref5.isDisabled;
|
|
55
|
+
return !isDisabled && "cursor: pointer;";
|
|
50
56
|
}, textBoxHeight, getRadius('s'));
|
|
51
|
-
export var MenuCardItem = /*#__PURE__*/forwardRef(function (
|
|
52
|
-
var children =
|
|
53
|
-
isSelected =
|
|
54
|
-
isActive =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
export var MenuCardItem = /*#__PURE__*/forwardRef(function (_ref6, ref) {
|
|
58
|
+
var children = _ref6.children,
|
|
59
|
+
isSelected = _ref6.isSelected,
|
|
60
|
+
isActive = _ref6.isActive,
|
|
61
|
+
isDisabled = _ref6.isDisabled,
|
|
62
|
+
icon = _ref6.icon,
|
|
63
|
+
props = _objectWithoutProperties(_ref6, _excluded);
|
|
57
64
|
|
|
58
65
|
return /*#__PURE__*/React.createElement(MenuItemWrapper, Object.assign({
|
|
59
66
|
ref: ref,
|
|
60
67
|
isActive: isActive,
|
|
61
68
|
isSelected: isSelected,
|
|
69
|
+
isDisabled: isDisabled,
|
|
62
70
|
style: {
|
|
63
71
|
background: isActive ? getColor('overlay') : undefined
|
|
64
72
|
},
|
|
@@ -68,6 +76,7 @@ export var MenuCardItem = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
|
68
76
|
hasEvenBoundary: true
|
|
69
77
|
}), /*#__PURE__*/React.createElement(Box, {
|
|
70
78
|
width: "100%",
|
|
79
|
+
minWidth: "0px",
|
|
71
80
|
tag: "span"
|
|
72
81
|
}, /*#__PURE__*/React.createElement(Text, {
|
|
73
82
|
hasEllipsis: true
|