@automattic/vip-design-system 0.26.5 → 0.26.7

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.
@@ -26,9 +26,10 @@ var _Heading = require("../Heading");
26
26
  var _jsxRuntime = require("theme-ui/jsx-runtime");
27
27
 
28
28
  var _excluded = ["children"],
29
- _excluded2 = ["children", "headingVariant"],
29
+ _excluded2 = ["children", "headingVariant", "sx"],
30
30
  _excluded3 = ["children", "icon"],
31
- _excluded4 = ["children", "sx"];
31
+ _excluded4 = ["children", "sx"],
32
+ _excluded5 = ["sx", "children", "className"];
32
33
 
33
34
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
34
35
 
@@ -87,6 +88,8 @@ var Trigger = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forward
87
88
  var children = _ref2.children,
88
89
  _ref2$headingVariant = _ref2.headingVariant,
89
90
  headingVariant = _ref2$headingVariant === void 0 ? 'h3' : _ref2$headingVariant,
91
+ _ref2$sx = _ref2.sx,
92
+ sx = _ref2$sx === void 0 ? {} : _ref2$sx,
90
93
  props = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, _excluded2);
91
94
  return (0, _jsxRuntime.jsx)(_Heading.Heading, {
92
95
  sx: {
@@ -95,7 +98,7 @@ var Trigger = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forward
95
98
  },
96
99
  variant: headingVariant,
97
100
  children: (0, _jsxRuntime.jsxs)(AccordionPrimitive.Trigger, (0, _extends2["default"])({
98
- sx: {
101
+ sx: (0, _extends2["default"])({
99
102
  color: 'heading',
100
103
  cursor: 'pointer',
101
104
  all: 'unset',
@@ -134,7 +137,7 @@ var Trigger = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forward
134
137
  return accordion.background.hover;
135
138
  }
136
139
  }
137
- }
140
+ }, sx)
138
141
  }, props, {
139
142
  ref: forwardedRef,
140
143
  children: [children, (0, _jsxRuntime.jsx)(_md.MdChevronRight, {
@@ -155,7 +158,8 @@ exports.Trigger = Trigger;
155
158
  Trigger.displayName = 'Accordion.Trigger';
156
159
  Trigger.propTypes = {
157
160
  children: _propTypes["default"].node.isRequired,
158
- headingVariant: _propTypes["default"].string
161
+ headingVariant: _propTypes["default"].string,
162
+ sx: _propTypes["default"].object
159
163
  };
160
164
 
161
165
  var TriggerWithIcon = /*#__PURE__*/_react["default"].forwardRef(function (_ref7, forwardedRef) {
@@ -200,6 +204,8 @@ var Content = /*#__PURE__*/_react["default"].forwardRef(function (_ref8, forward
200
204
  color: 'text',
201
205
  fontSize: 2,
202
206
  overflow: 'hidden',
207
+ px: 3,
208
+ py: 2,
203
209
  '&[data-state="open"]': {
204
210
  animation: slideDown + " 300ms cubic-bezier(0.87, 0, 0.13, 1)"
205
211
  },
@@ -209,13 +215,7 @@ var Content = /*#__PURE__*/_react["default"].forwardRef(function (_ref8, forward
209
215
  }, sx)
210
216
  }, props, {
211
217
  ref: forwardedRef,
212
- children: (0, _jsxRuntime.jsx)("div", {
213
- sx: {
214
- px: 3,
215
- py: 2
216
- },
217
- children: children
218
- })
218
+ children: children
219
219
  }));
220
220
  });
221
221
 
@@ -229,21 +229,19 @@ Content.propTypes = {
229
229
  var Root = /*#__PURE__*/_react["default"].forwardRef(function (_ref9, forwardRef) {
230
230
  var _ref9$sx = _ref9.sx,
231
231
  sx = _ref9$sx === void 0 ? {} : _ref9$sx,
232
- defaultValue = _ref9.defaultValue,
233
- type = _ref9.type,
234
232
  children = _ref9.children,
235
- className = _ref9.className;
236
- return (0, _jsxRuntime.jsx)(AccordionPrimitive.Root, {
233
+ className = _ref9.className,
234
+ props = (0, _objectWithoutPropertiesLoose2["default"])(_ref9, _excluded5);
235
+ return (0, _jsxRuntime.jsx)(AccordionPrimitive.Root, (0, _extends2["default"])({
237
236
  className: (0, _classnames["default"])('vip-accordion-component', className),
238
237
  collapsible: true,
239
- defaultValue: defaultValue,
240
238
  ref: forwardRef,
241
239
  sx: (0, _extends2["default"])({
242
240
  borderRadius: 6
243
- }, sx),
244
- type: type,
241
+ }, sx)
242
+ }, props, {
245
243
  children: children
246
- });
244
+ }));
247
245
  });
248
246
 
249
247
  exports.Root = Root;
@@ -27,7 +27,6 @@ var Validation = function Validation(_ref) {
27
27
  describedId = _ref$describedId === void 0 ? null : _ref$describedId,
28
28
  props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
29
29
  var Icon = isValid ? _md.MdCheckCircle : _md.MdErrorOutline;
30
- var IconLabel = isValid ? 'Valid' : 'Invalid';
31
30
  return (0, _jsxRuntime.jsxs)("p", (0, _extends2["default"])({
32
31
  sx: {
33
32
  color: isValid ? 'success' : 'error',
@@ -42,8 +41,7 @@ var Validation = function Validation(_ref) {
42
41
  sx: {
43
42
  mr: 1
44
43
  },
45
- role: "img",
46
- "aria-label": IconLabel
44
+ "aria-hidden": "true"
47
45
  }), children]
48
46
  }));
49
47
  };
@@ -27,9 +27,11 @@ var _FormSelectArrow = require("./FormSelectArrow");
27
27
 
28
28
  var _Label = require("../Form/Label");
29
29
 
30
+ var _FormSelectSearch = require("./FormSelectSearch");
31
+
30
32
  var _jsxRuntime = require("theme-ui/jsx-runtime");
31
33
 
32
- var _excluded = ["isInline", "forLabel", "options", "label", "getOptionLabel", "getOptionValue", "onChange", "value", "showAllValues", "displayMenu", "id", "className"];
34
+ var _excluded = ["isInline", "forLabel", "options", "label", "getOptionLabel", "getOptionValue", "onChange", "onInputChange", "value", "showAllValues", "searchIcon", "displayMenu", "noOptionsMessage", "id", "className"];
33
35
 
34
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
37
 
@@ -100,13 +102,34 @@ var defaultStyles = {
100
102
  '& .autocomplete__wrapper': {
101
103
  width: '100%'
102
104
  },
105
+ '& .autocomplete__option': {
106
+ borderColor: 'borders.2'
107
+ },
108
+ '& .autocomplete__option--odd': {
109
+ bg: 'backgroundSecondary'
110
+ },
111
+ '& .autocomplete__option:hover, & .autocomplete__option--focused': {
112
+ bg: 'midnight',
113
+ borderColor: 'midnight'
114
+ },
103
115
  '& .autocomplete__input--show-all-values': {
104
116
  paddingRight: 0
117
+ },
118
+ '& .autocomplete__hint': {
119
+ border: 'none',
120
+ paddingLeft: 3,
121
+ minHeight: '27px',
122
+ lineHeight: '27px'
105
123
  }
106
124
  };
107
125
  var inlineStyles = {
108
126
  borderWidth: 0
109
127
  };
128
+ var searchIconStyles = {
129
+ '& .autocomplete__input.autocomplete__input--show-all-values': {
130
+ paddingLeft: '30px'
131
+ }
132
+ };
110
133
 
111
134
  var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref, forwardRef) {
112
135
  var isInline = _ref.isInline,
@@ -117,11 +140,18 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
117
140
  getOptionValue = _ref.getOptionValue,
118
141
  _ref$onChange = _ref.onChange,
119
142
  onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
143
+ onInputChange = _ref.onInputChange,
120
144
  value = _ref.value,
121
145
  _ref$showAllValues = _ref.showAllValues,
122
146
  showAllValues = _ref$showAllValues === void 0 ? true : _ref$showAllValues,
147
+ _ref$searchIcon = _ref.searchIcon,
148
+ searchIcon = _ref$searchIcon === void 0 ? false : _ref$searchIcon,
123
149
  _ref$displayMenu = _ref.displayMenu,
124
150
  displayMenu = _ref$displayMenu === void 0 ? 'overlay' : _ref$displayMenu,
151
+ _ref$noOptionsMessage = _ref.noOptionsMessage,
152
+ noOptionsMessage = _ref$noOptionsMessage === void 0 ? function () {
153
+ return 'No results found.';
154
+ } : _ref$noOptionsMessage,
125
155
  _ref$id = _ref.id,
126
156
  id = _ref$id === void 0 ? 'vip-autocomplete' : _ref$id,
127
157
  className = _ref.className,
@@ -163,13 +193,16 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
163
193
  onChange(getOptionByLabel(inputValue), inputValue);
164
194
  }
165
195
  }, [onChange, getOptionByLabel]);
196
+ var handleTypeChange = (0, _react.useCallback)(function (query) {
197
+ return options.filter(function (option) {
198
+ return optionLabel(option).toLowerCase().indexOf(query.toLowerCase()) >= 0;
199
+ });
200
+ }, [options]);
166
201
  var suggest = (0, _react.useCallback)(function (query, populateResults) {
167
202
  var data = options;
168
203
 
169
204
  if (isDirty) {
170
- data = options.filter(function (option) {
171
- return optionLabel(option).toLowerCase().indexOf(query.toLowerCase()) >= 0;
172
- });
205
+ data = onInputChange ? onInputChange(query) : handleTypeChange(query);
173
206
  }
174
207
 
175
208
  populateResults(data.map(function (option) {
@@ -190,18 +223,19 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
190
223
  return (0, _jsxRuntime.jsxs)("div", {
191
224
  className: (0, _classnames["default"])('vip-form-autocomplete-component', className),
192
225
  children: [label && !isInline && (0, _jsxRuntime.jsx)(SelectLabel, {}), (0, _jsxRuntime.jsx)("div", {
193
- sx: (0, _extends2["default"])({}, defaultStyles, isInline && inlineStyles),
226
+ sx: (0, _extends2["default"])({}, defaultStyles, isInline && inlineStyles, searchIcon && searchIconStyles),
194
227
  children: (0, _jsxRuntime.jsxs)(_FormSelectContent.FormSelectContent, {
195
228
  isInline: inlineLabel,
196
229
  label: inlineLabel ? (0, _jsxRuntime.jsx)(SelectLabel, {}) : null,
197
- children: [(0, _jsxRuntime.jsx)(_react2["default"], (0, _extends2["default"])({
230
+ children: [searchIcon && (0, _jsxRuntime.jsx)(_FormSelectSearch.FormSelectSearch, {}), (0, _jsxRuntime.jsx)(_react2["default"], (0, _extends2["default"])({
198
231
  id: id,
199
232
  showAllValues: showAllValues,
200
233
  ref: forwardRef,
201
234
  source: suggest,
202
235
  defaultValue: value,
203
236
  displayMenu: displayMenu,
204
- onConfirm: onValueChange
237
+ onConfirm: onValueChange,
238
+ tNoResults: noOptionsMessage
205
239
  }, props)), (0, _jsxRuntime.jsx)(_FormSelectArrow.FormSelectArrow, {})]
206
240
  })
207
241
  })]
@@ -212,6 +246,7 @@ exports.FormAutocomplete = FormAutocomplete;
212
246
  FormAutocomplete.propTypes = {
213
247
  id: _propTypes["default"].string,
214
248
  showAllValues: _propTypes["default"].bool,
249
+ searchIcon: _propTypes["default"].bool,
215
250
  isInline: _propTypes["default"].bool,
216
251
  forLabel: _propTypes["default"].string,
217
252
  value: _propTypes["default"].string,
@@ -220,6 +255,8 @@ FormAutocomplete.propTypes = {
220
255
  options: _propTypes["default"].array,
221
256
  getOptionLabel: _propTypes["default"].func,
222
257
  getOptionValue: _propTypes["default"].func,
258
+ onInputChange: _propTypes["default"].func,
259
+ noOptionsMessage: _propTypes["default"].func,
223
260
  onChange: _propTypes["default"].func,
224
261
  className: _propTypes["default"].any
225
262
  };
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports["default"] = exports.WithDefaultValue = exports.Inline = exports.Default = void 0;
6
+ exports["default"] = exports.WithSearchIcon = exports.WithDefaultValue = exports.WithCustomMessages = exports.Inline = exports.Default = void 0;
7
7
 
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
 
@@ -107,4 +107,29 @@ var WithDefaultValue = function WithDefaultValue() {
107
107
  });
108
108
  };
109
109
 
110
- exports.WithDefaultValue = WithDefaultValue;
110
+ exports.WithDefaultValue = WithDefaultValue;
111
+
112
+ var WithSearchIcon = function WithSearchIcon() {
113
+ var customArgs = (0, _extends2["default"])({}, args, {
114
+ searchIcon: true
115
+ });
116
+ return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
117
+ children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
118
+ });
119
+ };
120
+
121
+ exports.WithSearchIcon = WithSearchIcon;
122
+
123
+ var WithCustomMessages = function WithCustomMessages() {
124
+ var customArgs = (0, _extends2["default"])({}, args, {
125
+ noOptionsMessage: function noOptionsMessage() {
126
+ return 'No data';
127
+ },
128
+ placeholder: 'Type to search'
129
+ });
130
+ return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
131
+ children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
132
+ });
133
+ };
134
+
135
+ exports.WithCustomMessages = WithCustomMessages;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ exports.__esModule = true;
6
+ exports.FormSelectSearch = void 0;
7
+
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _md = require("react-icons/md");
13
+
14
+ var _jsxRuntime = require("theme-ui/jsx-runtime");
15
+
16
+ /** @jsxImportSource theme-ui */
17
+
18
+ /**
19
+ * External dependencies
20
+ */
21
+ var FormSelectSearch = /*#__PURE__*/_react["default"].forwardRef(function (props, forwardRef) {
22
+ return (0, _jsxRuntime.jsx)(_md.MdSearch, (0, _extends2["default"])({
23
+ ref: forwardRef,
24
+ "aria-hidden": "true",
25
+ size: 24,
26
+ sx: {
27
+ position: 'absolute',
28
+ paddingRight: 2,
29
+ left: 2,
30
+ pointerEvents: 'none'
31
+ }
32
+ }, props));
33
+ });
34
+
35
+ exports.FormSelectSearch = FormSelectSearch;
36
+ FormSelectSearch.displayName = 'FormSelectSearch';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "0.26.5",
3
+ "version": "0.26.7",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "build-storybook",
@@ -57,7 +57,7 @@ Item.propTypes = {
57
57
  };
58
58
 
59
59
  export const Trigger = React.forwardRef(
60
- ( { children, headingVariant = 'h3', ...props }, forwardedRef ) => (
60
+ ( { children, headingVariant = 'h3', sx = {}, ...props }, forwardedRef ) => (
61
61
  <Heading
62
62
  sx={ {
63
63
  all: 'unset',
@@ -90,6 +90,7 @@ export const Trigger = React.forwardRef(
90
90
  '.vip-accordion-trigger-indicator': { transform: 'rotate(270deg)' },
91
91
  },
92
92
  '&:hover': { backgroundColor: ( { accordion } ) => accordion.background.hover },
93
+ ...sx,
93
94
  } }
94
95
  { ...props }
95
96
  ref={ forwardedRef }
@@ -115,6 +116,7 @@ Trigger.displayName = 'Accordion.Trigger';
115
116
  Trigger.propTypes = {
116
117
  children: PropTypes.node.isRequired,
117
118
  headingVariant: PropTypes.string,
119
+ sx: PropTypes.object,
118
120
  };
119
121
 
120
122
  export const TriggerWithIcon = React.forwardRef( ( { children, icon, ...props }, forwardedRef ) => (
@@ -139,6 +141,8 @@ export const Content = React.forwardRef( ( { children, sx = {}, ...props }, forw
139
141
  color: 'text',
140
142
  fontSize: 2,
141
143
  overflow: 'hidden',
144
+ px: 3,
145
+ py: 2,
142
146
 
143
147
  '&[data-state="open"]': {
144
148
  animation: `${ slideDown } 300ms cubic-bezier(0.87, 0, 0.13, 1)`,
@@ -151,14 +155,7 @@ export const Content = React.forwardRef( ( { children, sx = {}, ...props }, forw
151
155
  { ...props }
152
156
  ref={ forwardedRef }
153
157
  >
154
- <div
155
- sx={ {
156
- px: 3,
157
- py: 2,
158
- } }
159
- >
160
- { children }
161
- </div>
158
+ { children }
162
159
  </AccordionPrimitive.Content>
163
160
  );
164
161
  } );
@@ -170,23 +167,20 @@ Content.propTypes = {
170
167
  sx: PropTypes.object,
171
168
  };
172
169
 
173
- const Root = React.forwardRef(
174
- ( { sx = {}, defaultValue, type, children, className }, forwardRef ) => (
175
- <AccordionPrimitive.Root
176
- className={ classNames( 'vip-accordion-component', className ) }
177
- collapsible
178
- defaultValue={ defaultValue }
179
- ref={ forwardRef }
180
- sx={ {
181
- borderRadius: 6,
182
- ...sx,
183
- } }
184
- type={ type }
185
- >
186
- { children }
187
- </AccordionPrimitive.Root>
188
- )
189
- );
170
+ const Root = React.forwardRef( ( { sx = {}, children, className, ...props }, forwardRef ) => (
171
+ <AccordionPrimitive.Root
172
+ className={ classNames( 'vip-accordion-component', className ) }
173
+ collapsible
174
+ ref={ forwardRef }
175
+ sx={ {
176
+ borderRadius: 6,
177
+ ...sx,
178
+ } }
179
+ { ...props }
180
+ >
181
+ { children }
182
+ </AccordionPrimitive.Root>
183
+ ) );
190
184
 
191
185
  Root.displayName = 'Accordion';
192
186
 
@@ -12,7 +12,6 @@ import { MdErrorOutline, MdCheckCircle } from 'react-icons/md';
12
12
 
13
13
  const Validation = ( { children, isValid, describedId = null, ...props } ) => {
14
14
  const Icon = isValid ? MdCheckCircle : MdErrorOutline;
15
- const IconLabel = isValid ? 'Valid' : 'Invalid';
16
15
 
17
16
  return (
18
17
  <p
@@ -26,7 +25,7 @@ const Validation = ( { children, isValid, describedId = null, ...props } ) => {
26
25
  id={ describedId ? `describe-${ describedId }-validation` : undefined }
27
26
  { ...props }
28
27
  >
29
- <Icon sx={ { mr: 1 } } role="img" aria-label={ IconLabel } />
28
+ <Icon sx={ { mr: 1 } } aria-hidden="true" />
30
29
  { children }
31
30
  </p>
32
31
  );
@@ -15,6 +15,7 @@ import css from './FormAutocomplete.css';
15
15
  import { FormSelectContent } from './FormSelectContent';
16
16
  import { FormSelectArrow } from './FormSelectArrow';
17
17
  import { Label } from '../Form/Label';
18
+ import { FormSelectSearch } from './FormSelectSearch';
18
19
 
19
20
  const defaultStyles = {
20
21
  width: '100%',
@@ -59,15 +60,37 @@ const defaultStyles = {
59
60
  '& .autocomplete__wrapper': {
60
61
  width: '100%',
61
62
  },
63
+ '& .autocomplete__option': {
64
+ borderColor: 'borders.2',
65
+ },
66
+ '& .autocomplete__option--odd': {
67
+ bg: 'backgroundSecondary',
68
+ },
69
+ '& .autocomplete__option:hover, & .autocomplete__option--focused': {
70
+ bg: 'midnight',
71
+ borderColor: 'midnight',
72
+ },
62
73
  '& .autocomplete__input--show-all-values': {
63
74
  paddingRight: 0,
64
75
  },
76
+ '& .autocomplete__hint': {
77
+ border: 'none',
78
+ paddingLeft: 3,
79
+ minHeight: '27px',
80
+ lineHeight: '27px',
81
+ },
65
82
  };
66
83
 
67
84
  const inlineStyles = {
68
85
  borderWidth: 0,
69
86
  };
70
87
 
88
+ const searchIconStyles = {
89
+ '& .autocomplete__input.autocomplete__input--show-all-values': {
90
+ paddingLeft: '30px',
91
+ },
92
+ };
93
+
71
94
  const FormAutocomplete = React.forwardRef(
72
95
  (
73
96
  {
@@ -78,9 +101,12 @@ const FormAutocomplete = React.forwardRef(
78
101
  getOptionLabel,
79
102
  getOptionValue,
80
103
  onChange = () => {},
104
+ onInputChange,
81
105
  value,
82
106
  showAllValues = true,
107
+ searchIcon = false,
83
108
  displayMenu = 'overlay',
109
+ noOptionsMessage = () => 'No results found.',
84
110
  id = 'vip-autocomplete',
85
111
  className,
86
112
  ...props
@@ -122,13 +148,19 @@ const FormAutocomplete = React.forwardRef(
122
148
  [ onChange, getOptionByLabel ]
123
149
  );
124
150
 
151
+ const handleTypeChange = useCallback(
152
+ query =>
153
+ options.filter(
154
+ option => optionLabel( option ).toLowerCase().indexOf( query.toLowerCase() ) >= 0
155
+ ),
156
+ [ options ]
157
+ );
158
+
125
159
  const suggest = useCallback(
126
160
  ( query, populateResults ) => {
127
161
  let data = options;
128
162
  if ( isDirty ) {
129
- data = options.filter(
130
- option => optionLabel( option ).toLowerCase().indexOf( query.toLowerCase() ) >= 0
131
- );
163
+ data = onInputChange ? onInputChange( query ) : handleTypeChange( query );
132
164
  }
133
165
  populateResults( data.map( option => optionLabel( option ) ) );
134
166
  },
@@ -157,11 +189,18 @@ const FormAutocomplete = React.forwardRef(
157
189
  <div className={ classNames( 'vip-form-autocomplete-component', className ) }>
158
190
  { label && ! isInline && <SelectLabel /> }
159
191
 
160
- <div sx={ { ...defaultStyles, ...( isInline && inlineStyles ) } }>
192
+ <div
193
+ sx={ {
194
+ ...defaultStyles,
195
+ ...( isInline && inlineStyles ),
196
+ ...( searchIcon && searchIconStyles ),
197
+ } }
198
+ >
161
199
  <FormSelectContent
162
200
  isInline={ inlineLabel }
163
201
  label={ inlineLabel ? <SelectLabel /> : null }
164
202
  >
203
+ { searchIcon && <FormSelectSearch /> }
165
204
  <Autocomplete
166
205
  id={ id }
167
206
  showAllValues={ showAllValues }
@@ -170,6 +209,7 @@ const FormAutocomplete = React.forwardRef(
170
209
  defaultValue={ value }
171
210
  displayMenu={ displayMenu }
172
211
  onConfirm={ onValueChange }
212
+ tNoResults={ noOptionsMessage }
173
213
  { ...props }
174
214
  />
175
215
  <FormSelectArrow />
@@ -183,6 +223,7 @@ const FormAutocomplete = React.forwardRef(
183
223
  FormAutocomplete.propTypes = {
184
224
  id: PropTypes.string,
185
225
  showAllValues: PropTypes.bool,
226
+ searchIcon: PropTypes.bool,
186
227
  isInline: PropTypes.bool,
187
228
  forLabel: PropTypes.string,
188
229
  value: PropTypes.string,
@@ -191,6 +232,8 @@ FormAutocomplete.propTypes = {
191
232
  options: PropTypes.array,
192
233
  getOptionLabel: PropTypes.func,
193
234
  getOptionValue: PropTypes.func,
235
+ onInputChange: PropTypes.func,
236
+ noOptionsMessage: PropTypes.func,
194
237
  onChange: PropTypes.func,
195
238
  className: PropTypes.any,
196
239
  };
@@ -74,3 +74,30 @@ export const WithDefaultValue = () => {
74
74
  </>
75
75
  );
76
76
  };
77
+
78
+ export const WithSearchIcon = () => {
79
+ const customArgs = {
80
+ ...args,
81
+ searchIcon: true,
82
+ };
83
+
84
+ return (
85
+ <>
86
+ <DefaultComponent { ...customArgs } />
87
+ </>
88
+ );
89
+ };
90
+
91
+ export const WithCustomMessages = () => {
92
+ const customArgs = {
93
+ ...args,
94
+ noOptionsMessage: () => 'No data',
95
+ placeholder: 'Type to search',
96
+ };
97
+
98
+ return (
99
+ <>
100
+ <DefaultComponent { ...customArgs } />
101
+ </>
102
+ );
103
+ };
@@ -0,0 +1,24 @@
1
+ /** @jsxImportSource theme-ui */
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import React from 'react';
7
+ import { MdSearch } from 'react-icons/md';
8
+
9
+ export const FormSelectSearch = React.forwardRef( ( props, forwardRef ) => (
10
+ <MdSearch
11
+ ref={ forwardRef }
12
+ aria-hidden="true"
13
+ size={ 24 }
14
+ sx={ {
15
+ position: 'absolute',
16
+ paddingRight: 2,
17
+ left: 2,
18
+ pointerEvents: 'none',
19
+ } }
20
+ { ...props }
21
+ />
22
+ ) );
23
+
24
+ FormSelectSearch.displayName = 'FormSelectSearch';
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.ResourceItem = void 0;
7
-
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
- var _ = require("..");
11
-
12
- var _jsxRuntime = require("theme-ui/jsx-runtime");
13
-
14
- /** @jsxImportSource theme-ui */
15
-
16
- /**
17
- * External dependencies
18
- */
19
-
20
- /**
21
- * Internal dependencies
22
- */
23
- var ResourceItem = function ResourceItem(_ref) {
24
- var children = _ref.children,
25
- item = _ref.item,
26
- renderActions = _ref.renderActions,
27
- _ref$relativeTime = _ref.relativeTime,
28
- relativeTime = _ref$relativeTime === void 0 ? false : _ref$relativeTime,
29
- _ref$timeOnly = _ref.timeOnly,
30
- timeOnly = _ref$timeOnly === void 0 ? false : _ref$timeOnly,
31
- dateKey = _ref.dateKey,
32
- _ref$icon = _ref.icon,
33
- icon = _ref$icon === void 0 ? null : _ref$icon;
34
- return (0, _jsxRuntime.jsxs)(_.Flex, {
35
- sx: {
36
- alignItems: 'center',
37
- gap: 3
38
- },
39
- children: [icon, (0, _jsxRuntime.jsx)(_.Box, {
40
- sx: {
41
- flex: '1 1 auto'
42
- },
43
- children: children
44
- }), (0, _jsxRuntime.jsxs)(_.Flex, {
45
- sx: {
46
- flex: '0 0 auto',
47
- alignItems: 'center',
48
- gap: 3
49
- },
50
- children: [(0, _jsxRuntime.jsx)(_.Time, {
51
- className: "time",
52
- relativeTime: relativeTime,
53
- timeOnly: timeOnly,
54
- time: item[dateKey],
55
- sx: {
56
- color: 'muted',
57
- mb: 0,
58
- textAlign: 'right',
59
- flex: '0 0 auto'
60
- }
61
- }), renderActions && (0, _jsxRuntime.jsxs)(_.Flex, {
62
- className: "actions",
63
- sx: {
64
- alignItems: 'center',
65
- gap: 3
66
- },
67
- children: [(0, _jsxRuntime.jsx)(_.Box, {
68
- sx: {
69
- width: 4,
70
- height: 4,
71
- borderRadius: 4,
72
- bg: 'border'
73
- }
74
- }), renderActions(item)]
75
- })]
76
- })]
77
- });
78
- };
79
-
80
- exports.ResourceItem = ResourceItem;
81
- ResourceItem.propTypes = {
82
- children: _propTypes["default"].node,
83
- item: _propTypes["default"].object,
84
- icon: _propTypes["default"].node,
85
- relativeTime: _propTypes["default"].bool,
86
- timeOnly: _propTypes["default"].bool,
87
- dateKey: _propTypes["default"].string,
88
- renderActions: _propTypes["default"].func
89
- };
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.ResourceList = void 0;
7
-
8
- var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- var _react = require("react");
13
-
14
- var _ = require("..");
15
-
16
- var _jsxRuntime = require("theme-ui/jsx-runtime");
17
-
18
- /** @jsxImportSource theme-ui */
19
-
20
- /**
21
- * External dependencies
22
- */
23
-
24
- /**
25
- * Internal dependencies
26
- */
27
- var formatterOptions = {
28
- weekday: 'long',
29
- year: 'numeric',
30
- month: 'long',
31
- day: 'numeric'
32
- };
33
-
34
- var formatDate = function formatDate(date) {
35
- var today = new Date();
36
-
37
- if (date.getFullYear() !== today.getFullYear()) {
38
- return date.toLocaleDateString(formatterOptions);
39
- } else if (date.getMonth() !== today.getMonth()) {
40
- return date.toLocaleDateString(formatterOptions);
41
- } else if (date.getDate() < today.getDate() - 1) {
42
- return date.toLocaleDateString(formatterOptions);
43
- } else if (date.getDate() === today.getDate() - 1) {
44
- return 'Yesterday';
45
- }
46
-
47
- return 'Today';
48
- };
49
-
50
- var StyledListItem = function StyledListItem(props) {
51
- return (0, _jsxRuntime.jsx)(_.Box, (0, _extends3["default"])({
52
- as: "li",
53
- sx: {
54
- py: 2,
55
- borderBottom: '1px solid',
56
- borderColor: 'borders.2',
57
- listStyleType: 'none',
58
- margin: 0,
59
- px: 0
60
- }
61
- }, props));
62
- };
63
-
64
- var ResourceList = function ResourceList(_ref) {
65
- var _ref$groupedByDay = _ref.groupedByDay,
66
- groupedByDay = _ref$groupedByDay === void 0 ? false : _ref$groupedByDay,
67
- items = _ref.items,
68
- renderItem = _ref.renderItem,
69
- dateKey = _ref.dateKey;
70
- var groupedItems = {};
71
-
72
- if (groupedByDay) {
73
- groupedItems = items == null ? void 0 : items.reduce(function (itemGroups, item) {
74
- var _extends2;
75
-
76
- var formattedDate = formatDate(item[dateKey]);
77
- var itemsAtDate = itemGroups[formattedDate];
78
- return (0, _extends3["default"])({}, itemGroups, (_extends2 = {}, _extends2[formattedDate] = itemsAtDate ? [].concat(itemsAtDate, [item]) : [item], _extends2));
79
- }, {});
80
- }
81
-
82
- var renderItemList = function renderItemList(itemsList) {
83
- return itemsList.map(function (item, index) {
84
- return (0, _jsxRuntime.jsx)(StyledListItem, {
85
- children: renderItem(item)
86
- }, index);
87
- });
88
- };
89
-
90
- var renderGoupedItems = function renderGoupedItems() {
91
- return (0, _react.useMemo)(function () {
92
- return Object.keys(groupedItems).map(function (groupName, index) {
93
- return (0, _jsxRuntime.jsxs)(_.Box, {
94
- sx: {
95
- mb: 4
96
- },
97
- as: "li",
98
- children: [(0, _jsxRuntime.jsx)(_.Heading, {
99
- variant: "h4",
100
- as: "h4",
101
- sx: {
102
- mb: 3
103
- },
104
- children: groupName
105
- }), (0, _jsxRuntime.jsx)(_.Box, {
106
- as: "ul",
107
- sx: {
108
- listStyleType: 'none',
109
- m: 0,
110
- p: 0,
111
- borderTop: '1px solid',
112
- borderColor: 'border'
113
- },
114
- children: renderItemList(groupedItems[groupName])
115
- })]
116
- }, index);
117
- });
118
- }, [groupedItems]);
119
- };
120
-
121
- return (0, _jsxRuntime.jsx)(_.Box, {
122
- as: "ul",
123
- sx: {
124
- listStyleType: 'none',
125
- m: 0,
126
- p: 0
127
- },
128
- className: "vip-resource-list-component",
129
- children: groupedByDay ? renderGoupedItems(groupedItems) : renderItemList(items)
130
- });
131
- };
132
-
133
- exports.ResourceList = ResourceList;
134
- ResourceList.propTypes = {
135
- groupedByDay: _propTypes["default"].bool,
136
- items: _propTypes["default"].array,
137
- renderItem: _propTypes["default"].func,
138
- relativeTime: _propTypes["default"].bool,
139
- dateKey: _propTypes["default"].string
140
- };
@@ -1,379 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports["default"] = exports.Relative = exports.Grouped = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _bi = require("react-icons/bi");
11
-
12
- var _ = require("..");
13
-
14
- var _jsxRuntime = require("theme-ui/jsx-runtime");
15
-
16
- /** @jsxImportSource theme-ui */
17
-
18
- /**
19
- * External dependencies
20
- */
21
-
22
- /**
23
- * Internal dependencies
24
- */
25
- var _default = {
26
- title: 'ResourceList',
27
- component: _.ResourceList
28
- };
29
- exports["default"] = _default;
30
- var logs = [{
31
- actor: 'Saxon Fletcher',
32
- action: 'switched primary domain to',
33
- object: 'mydomain.com',
34
- date: new Date()
35
- }, {
36
- actor: 'Saxon Fletcher',
37
- action: 'switched primary domain to',
38
- object: 'mydomain.com',
39
- date: new Date(new Date().setHours(11))
40
- }, {
41
- actor: 'Simon Wheatley',
42
- action: 'deployed to',
43
- object: 'Production',
44
- showObject: true,
45
- date: new Date(new Date().setDate(15))
46
- }, {
47
- actor: 'Saxon Fletcher',
48
- action: 'created a backup on',
49
- object: 'Production',
50
- date: new Date(new Date().setDate(13))
51
- }];
52
-
53
- var Grouped = function Grouped() {
54
- return (0, _jsxRuntime.jsxs)(_.Box, {
55
- sx: {
56
- p: 5,
57
- pt: 2
58
- },
59
- children: [(0, _jsxRuntime.jsx)(_.Heading, {
60
- sx: {
61
- mb: 2
62
- },
63
- children: "Audit Log"
64
- }), (0, _jsxRuntime.jsx)(_.Text, {
65
- sx: {
66
- mb: 4
67
- },
68
- children: "A live trail of system and human events."
69
- }), (0, _jsxRuntime.jsx)(_.ResourceList, {
70
- items: logs,
71
- dateKey: "date",
72
- groupedByDay: true,
73
- renderItem: function renderItem(item) {
74
- return (0, _jsxRuntime.jsxs)(_.ResourceItem, {
75
- item: item,
76
- icon: (0, _jsxRuntime.jsx)(_bi.BiGlobe, {
77
- sx: {
78
- color: 'red'
79
- }
80
- }),
81
- dateKey: 'date',
82
- relativeTime: true,
83
- timeOnly: true,
84
- children: [(0, _jsxRuntime.jsxs)(_.Flex, {
85
- sx: {
86
- alignItems: 'center',
87
- gap: 3
88
- },
89
- children: [(0, _jsxRuntime.jsx)(_.Avatar, {
90
- name: item.actor,
91
- src: "https://uifaces.co/our-content/donated/1H_7AxP0.jpg",
92
- size: 16
93
- }), (0, _jsxRuntime.jsxs)(_.Heading, {
94
- variant: "h4",
95
- as: "p",
96
- sx: {
97
- mb: 0,
98
- fontWeight: 'normal'
99
- },
100
- children: [item.actor, ' ', (0, _jsxRuntime.jsx)(_.Text, {
101
- as: "span",
102
- sx: {
103
- color: 'muted',
104
- mb: 0
105
- },
106
- children: item.action
107
- }), ' ', item.object]
108
- })]
109
- }), item.showObject && (0, _jsxRuntime.jsxs)(_.Box, {
110
- variant: "indent",
111
- sx: {
112
- mt: 2,
113
- display: 'flex',
114
- flexWrap: 'wrap',
115
- gap: 3,
116
- alignItems: 'center'
117
- },
118
- children: [(0, _jsxRuntime.jsxs)(_.Heading, {
119
- variant: "h5",
120
- as: "div",
121
- sx: {
122
- mb: 0
123
- },
124
- children: ["Merge pull request", ' ', (0, _jsxRuntime.jsx)(_.Text, {
125
- as: "span",
126
- sx: {
127
- color: 'muted'
128
- },
129
- children: "#443"
130
- })]
131
- }), (0, _jsxRuntime.jsxs)(_.Text, {
132
- as: "div",
133
- sx: {
134
- mb: 0,
135
- fontSize: 1,
136
- display: 'flex',
137
- alignItems: 'center',
138
- gap: 1
139
- },
140
- children: [(0, _jsxRuntime.jsx)(_.Avatar, {
141
- name: item.actor,
142
- src: "https://uifaces.co/our-content/donated/n4Ngwvi7.jpg",
143
- size: 16
144
- }), item.actor]
145
- }), (0, _jsxRuntime.jsxs)(_.Text, {
146
- sx: {
147
- mb: 0,
148
- fontSize: 1,
149
- display: 'flex',
150
- alignItems: 'center',
151
- gap: 1
152
- },
153
- children: [(0, _jsxRuntime.jsx)(_bi.BiCheckCircle, {
154
- size: 16
155
- }), "Deployed in 31s"]
156
- })]
157
- })]
158
- });
159
- }
160
- })]
161
- });
162
- };
163
-
164
- exports.Grouped = Grouped;
165
- var deploys = [{
166
- title: 'Merge pull request',
167
- id: '#773',
168
- author: 'Saxon Fletcher',
169
- date: new Date(new Date().setHours(11)),
170
- status: 'running'
171
- }, {
172
- title: 'Update homepage',
173
- id: '#772',
174
- author: 'Saxon Fletcher',
175
- date: new Date(new Date().setHours(9))
176
- }, {
177
- title: 'Improve overall performance',
178
- id: '#771',
179
- author: 'Saxon Fletcher',
180
- date: new Date(new Date().setHours(8))
181
- }, {
182
- title: 'Merge pull request',
183
- id: '#770',
184
- author: 'Saxon Fletcher',
185
- date: new Date(new Date().setHours(5)),
186
- status: 'failed'
187
- }, {
188
- title: 'Merge pull request',
189
- id: '#773',
190
- author: 'Saxon Fletcher',
191
- date: new Date(new Date().setHours(11))
192
- }, {
193
- title: 'Update homepage',
194
- id: '#772',
195
- author: 'Saxon Fletcher',
196
- date: new Date(new Date().setHours(9))
197
- }, {
198
- title: 'Improve overall performance',
199
- id: '#771',
200
- author: 'Saxon Fletcher',
201
- date: new Date(new Date().setHours(8))
202
- }, {
203
- title: 'Merge pull request',
204
- id: '#770',
205
- author: 'Saxon Fletcher',
206
- date: new Date(new Date().setHours(5))
207
- }, {
208
- title: 'Merge pull request',
209
- id: '#773',
210
- author: 'Saxon Fletcher',
211
- date: new Date(new Date().setHours(11))
212
- }, {
213
- title: 'Update homepage',
214
- id: '#772',
215
- author: 'Saxon Fletcher',
216
- date: new Date(new Date().setHours(9))
217
- }, {
218
- title: 'Improve overall performance',
219
- id: '#771',
220
- author: 'Saxon Fletcher',
221
- date: new Date(new Date().setHours(8))
222
- }, {
223
- title: 'Merge pull request',
224
- id: '#770',
225
- author: 'Saxon Fletcher',
226
- date: new Date(new Date().setHours(5))
227
- }, {
228
- title: 'Merge pull request',
229
- id: '#773',
230
- author: 'Saxon Fletcher',
231
- date: new Date(new Date().setHours(11))
232
- }, {
233
- title: 'Update homepage',
234
- id: '#772',
235
- author: 'Saxon Fletcher',
236
- date: new Date(new Date().setHours(9))
237
- }, {
238
- title: 'Improve overall performance',
239
- id: '#771',
240
- author: 'Saxon Fletcher',
241
- date: new Date(new Date().setHours(8))
242
- }, {
243
- title: 'Merge pull request',
244
- id: '#770',
245
- author: 'Saxon Fletcher',
246
- date: new Date(new Date().setHours(5))
247
- }];
248
-
249
- var Relative = function Relative() {
250
- return (0, _jsxRuntime.jsxs)(_.Box, {
251
- sx: {
252
- p: 5,
253
- pt: 2
254
- },
255
- children: [(0, _jsxRuntime.jsx)(_.Heading, {
256
- sx: {
257
- mb: 2
258
- },
259
- children: "Deploys"
260
- }), (0, _jsxRuntime.jsx)(_.Text, {
261
- sx: {
262
- mb: 4
263
- },
264
- children: "View and manage application deployments."
265
- }), (0, _jsxRuntime.jsx)(_.Card, {
266
- variant: "indent",
267
- sx: {
268
- mb: 4,
269
- display: 'flex',
270
- flexDirection: 'row-reverse',
271
- gap: 1
272
- },
273
- children: deploys.map(function (deploy, index) {
274
- return (0, _jsxRuntime.jsx)(_.Box, {
275
- sx: {
276
- flex: '1 1 auto',
277
- width: 10,
278
- height: 4,
279
- backgroundColor: deploy.status === 'running' ? 'blue.50' : 'green.50',
280
- borderRadius: 1
281
- }
282
- }, index);
283
- })
284
- }), (0, _jsxRuntime.jsx)(_.ResourceList, {
285
- items: deploys,
286
- dateKey: "date",
287
- groupedByDay: false,
288
- renderItem: function renderItem(item) {
289
- return (0, _jsxRuntime.jsx)(_.ResourceItem, {
290
- item: item,
291
- dateKey: 'date',
292
- relativeTime: true,
293
- timeOnly: true,
294
- renderActions: function renderActions() {
295
- return (0, _jsxRuntime.jsx)(_.Flex, {
296
- sx: {
297
- alignItems: 'center'
298
- },
299
- children: (0, _jsxRuntime.jsx)(_.Button, {
300
- variant: "secondary",
301
- sx: {
302
- fontSize: 1
303
- },
304
- children: "Rollback"
305
- })
306
- });
307
- },
308
- children: (0, _jsxRuntime.jsxs)(_.Flex, {
309
- sx: {
310
- alignItems: 'center',
311
- gap: 4
312
- },
313
- children: [(0, _jsxRuntime.jsxs)(_.Flex, {
314
- sx: {
315
- alignItems: 'center',
316
- gap: 3,
317
- minWidth: 300
318
- },
319
- children: [(0, _jsxRuntime.jsxs)(_.Heading, {
320
- variant: "h4",
321
- as: "p",
322
- sx: {
323
- mb: 0,
324
- fontWeight: 'normal'
325
- },
326
- children: [item.title, ' ', (0, _jsxRuntime.jsx)(_.Text, {
327
- as: "span",
328
- sx: {
329
- color: 'muted',
330
- mb: 0
331
- },
332
- children: item.id
333
- })]
334
- }), item.status === 'running' && (0, _jsxRuntime.jsx)(_.Badge, {
335
- sx: {
336
- mb: 0
337
- },
338
- children: "Running"
339
- })]
340
- }), (0, _jsxRuntime.jsxs)(_.Text, {
341
- as: "div",
342
- sx: {
343
- mb: 0,
344
- color: 'muted',
345
- display: 'flex',
346
- alignItems: 'center',
347
- gap: 2
348
- },
349
- children: [(0, _jsxRuntime.jsx)(_.Avatar, {
350
- name: item.author,
351
- size: 16,
352
- src: "https://randomuser.me/api/portraits/men/46.jpg"
353
- }), item.author]
354
- }), (0, _jsxRuntime.jsx)(_.Text, {
355
- sx: {
356
- mb: 0,
357
- color: item.status === 'running' ? 'blue.60' : 'muted',
358
- display: 'flex',
359
- alignItems: 'center',
360
- gap: 1
361
- },
362
- children: item.status === 'running' ? (0, _jsxRuntime.jsxs)(_react["default"].Fragment, {
363
- children: [(0, _jsxRuntime.jsx)(_bi.BiRevision, {
364
- size: 16
365
- }), "Running for 31s"]
366
- }) : (0, _jsxRuntime.jsxs)(_react["default"].Fragment, {
367
- children: [(0, _jsxRuntime.jsx)(_bi.BiCheckCircle, {
368
- size: 16
369
- }), "Deployed in 31s"]
370
- })
371
- })]
372
- })
373
- });
374
- }
375
- })]
376
- });
377
- };
378
-
379
- exports.Relative = Relative;
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
-
5
- var _ResourceList = require("./ResourceList");
6
-
7
- exports.ResourceList = _ResourceList.ResourceList;
8
-
9
- var _ResourceItem = require("./ResourceItem");
10
-
11
- exports.ResourceItem = _ResourceItem.ResourceItem;