@flodesk/grain 5.11.1 → 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.
@@ -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 ? 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
- }), /*#__PURE__*/React.createElement(Box, {
114
- right: fieldXPadding,
115
- position: "absolute",
116
- top: "0px",
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: React.Fragment
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
- }, option);
145
+ isActive: !option.isDisabled && active,
146
+ isDisabled: option.isDisabled
147
+ }, option.content);
138
148
  });
139
- }), !Boolean(filteredOptions.length) && /*#__PURE__*/React.createElement(EmptyState, null)));
149
+ }), noResults && /*#__PURE__*/React.createElement(EmptyState, null)));
140
150
  };
141
151
  Autocomplete.propTypes = {
142
152
  options: PropTypes.array,
143
- defaultOption: PropTypes.string,
153
+ defaultOption: PropTypes.object,
144
154
  onChange: PropTypes.func,
145
155
  menuAlign: PropTypes.oneOf(['left', 'right']),
146
156
  menuWidth: types.dimension
@@ -80,7 +80,7 @@ export var Select = function Select(_ref3) {
80
80
  menuWidth = _ref3$menuWidth === void 0 ? '100%' : _ref3$menuWidth,
81
81
  trigger = _ref3.trigger;
82
82
 
83
- var _useState = useState(defaultOption || ''),
83
+ var _useState = useState(defaultOption || {}),
84
84
  _useState2 = _slicedToArray(_useState, 2),
85
85
  selectedOption = _useState2[0],
86
86
  setSelectedOption = _useState2[1];
@@ -43,21 +43,24 @@ 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 ", ";\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) {
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
50
  }, function (_ref4) {
51
51
  var isDisabled = _ref4.isDisabled;
52
52
  return isDisabled && "color: ".concat(getColor('contentDisabled'));
53
+ }, function (_ref5) {
54
+ var isDisabled = _ref5.isDisabled;
55
+ return !isDisabled && "cursor: pointer;";
53
56
  }, textBoxHeight, getRadius('s'));
54
- export var MenuCardItem = /*#__PURE__*/forwardRef(function (_ref5, ref) {
55
- var children = _ref5.children,
56
- isSelected = _ref5.isSelected,
57
- isActive = _ref5.isActive,
58
- isDisabled = _ref5.isDisabled,
59
- icon = _ref5.icon,
60
- props = _objectWithoutProperties(_ref5, _excluded);
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);
61
64
 
62
65
  return /*#__PURE__*/React.createElement(MenuItemWrapper, Object.assign({
63
66
  ref: ref,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flodesk/grain",
3
- "version": "5.11.1",
3
+ "version": "5.11.2",
4
4
  "description": "Flodesk design system",
5
5
  "module": "es/index.js",
6
6
  "author": "Flodesk",