@automattic/vip-design-system 0.26.0 → 0.26.1

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.
@@ -79,6 +79,9 @@ var defaultStyles = {
79
79
  '&.autocomplete__input--focused': {
80
80
  outlineWidth: 0,
81
81
  boxShadow: 'none'
82
+ },
83
+ '&.autocomplete__input--show-all-values': {
84
+ paddingRight: '40px'
82
85
  }
83
86
  },
84
87
  '& .autocomplete__menu': {
@@ -93,8 +96,7 @@ var defaultStyles = {
93
96
  fontSize: 'inherit'
94
97
  },
95
98
  '& .autocomplete__wrapper': {
96
- width: '100%',
97
- paddingRight: '40px'
99
+ width: '100%'
98
100
  },
99
101
  '& .autocomplete__input--show-all-values': {
100
102
  paddingRight: 0
@@ -122,6 +124,10 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
122
124
  id = _ref$id === void 0 ? 'vip-autocomplete' : _ref$id,
123
125
  props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
124
126
 
127
+ var _useState = (0, _react.useState)(false),
128
+ isDirty = _useState[0],
129
+ setIsDirty = _useState[1];
130
+
125
131
  var SelectLabel = function SelectLabel() {
126
132
  return (0, _jsxRuntime.jsx)(_Label.Label, {
127
133
  htmlFor: forLabel || id,
@@ -155,19 +161,29 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
155
161
  }
156
162
  }, [onChange, getOptionByLabel]);
157
163
  var suggest = (0, _react.useCallback)(function (query, populateResults) {
158
- var data = options.filter(function (option) {
159
- return optionLabel(option).toLowerCase().indexOf(query.toLowerCase()) >= 0;
160
- });
164
+ var data = options;
165
+
166
+ if (isDirty) {
167
+ data = options.filter(function (option) {
168
+ return optionLabel(option).toLowerCase().indexOf(query.toLowerCase()) >= 0;
169
+ });
170
+ }
171
+
161
172
  populateResults(data.map(function (option) {
162
173
  return optionLabel(option);
163
174
  }));
164
- }, [options]);
175
+ }, [options, isDirty]);
165
176
  (0, _react.useEffect)(function () {
166
177
  global.document.querySelector('.autocomplete__input').setAttribute('aria-activedescendant', '');
167
178
  }, []);
168
179
  (0, _react.useEffect)(function () {
169
180
  global.document.querySelector('.autocomplete__menu').setAttribute('aria-label', label + " list");
170
181
  }, [label]);
182
+ (0, _react.useEffect)(function () {
183
+ global.document.querySelector("#" + id).addEventListener('keydown', function () {
184
+ setIsDirty(true);
185
+ });
186
+ }, [setIsDirty]);
171
187
  return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
172
188
  children: [label && !isInline && (0, _jsxRuntime.jsx)(SelectLabel, {}), (0, _jsxRuntime.jsx)("div", {
173
189
  sx: (0, _extends2["default"])({}, defaultStyles, isInline && inlineStyles),
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports["default"] = exports.Inline = exports.Default = void 0;
6
+ exports["default"] = exports.WithDefaultValue = exports.Inline = exports.Default = void 0;
7
7
 
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
 
@@ -96,4 +96,15 @@ var Inline = function Inline() {
96
96
  });
97
97
  };
98
98
 
99
- exports.Inline = Inline;
99
+ exports.Inline = Inline;
100
+
101
+ var WithDefaultValue = function WithDefaultValue() {
102
+ var customArgs = (0, _extends2["default"])({}, args, {
103
+ value: 'Chocolate'
104
+ });
105
+ return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
106
+ children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
107
+ });
108
+ };
109
+
110
+ exports.WithDefaultValue = WithDefaultValue;
@@ -9,6 +9,8 @@ var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
+ var _react = require("react");
13
+
12
14
  var _ = require("..");
13
15
 
14
16
  var _jsxRuntime = require("theme-ui/jsx-runtime");
@@ -51,7 +53,7 @@ var StyledListItem = function StyledListItem(props) {
51
53
  sx: {
52
54
  py: 2,
53
55
  borderBottom: '1px solid',
54
- borderColor: 'border',
56
+ borderColor: 'borders.2',
55
57
  listStyleType: 'none',
56
58
  margin: 0,
57
59
  px: 0
@@ -85,6 +87,37 @@ var ResourceList = function ResourceList(_ref) {
85
87
  });
86
88
  };
87
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
+
88
121
  return (0, _jsxRuntime.jsx)(_.Box, {
89
122
  as: "ul",
90
123
  sx: {
@@ -93,31 +126,7 @@ var ResourceList = function ResourceList(_ref) {
93
126
  p: 0
94
127
  },
95
128
  className: "vip-resource-list-component",
96
- children: groupedByDay ? Object.keys(groupedItems).map(function (groupName, index) {
97
- return (0, _jsxRuntime.jsxs)(_.Box, {
98
- sx: {
99
- mb: 4
100
- },
101
- children: [(0, _jsxRuntime.jsx)(_.Heading, {
102
- variant: "h4",
103
- as: "h4",
104
- sx: {
105
- mb: 3
106
- },
107
- children: groupName
108
- }), (0, _jsxRuntime.jsx)(_.Box, {
109
- as: "ul",
110
- sx: {
111
- listStyleType: 'none',
112
- m: 0,
113
- p: 0,
114
- borderTop: '1px solid',
115
- borderColor: 'border'
116
- },
117
- children: renderItemList(groupedItems[groupName])
118
- })]
119
- }, index);
120
- }) : renderItemList(items)
129
+ children: groupedByDay ? renderGoupedItems(groupedItems) : renderItemList(items)
121
130
  });
122
131
  };
123
132
 
@@ -129,6 +129,7 @@ var Grouped = function Grouped() {
129
129
  children: "#443"
130
130
  })]
131
131
  }), (0, _jsxRuntime.jsxs)(_.Text, {
132
+ as: "div",
132
133
  sx: {
133
134
  mb: 0,
134
135
  fontSize: 1,
@@ -337,6 +338,7 @@ var Relative = function Relative() {
337
338
  children: "Running"
338
339
  })]
339
340
  }), (0, _jsxRuntime.jsxs)(_.Text, {
341
+ as: "div",
340
342
  sx: {
341
343
  mb: 0,
342
344
  color: 'muted',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "build-storybook",
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
- import React, { useCallback, useEffect, useMemo } from 'react';
6
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
7
7
  import PropTypes from 'prop-types';
8
8
  import { Label } from '../Form/Label';
9
9
  import Autocomplete from 'accessible-autocomplete/react';
@@ -42,6 +42,7 @@ const defaultStyles = {
42
42
  '&:focus-visible': { outlineWidth: 0, boxShadow: 'none' },
43
43
  '&:focus-within': { outlineWidth: 0, boxShadow: 'none' },
44
44
  '&.autocomplete__input--focused': { outlineWidth: 0, boxShadow: 'none' },
45
+ '&.autocomplete__input--show-all-values': { paddingRight: '40px' },
45
46
  },
46
47
  '& .autocomplete__menu': {
47
48
  borderWidth: '1px',
@@ -56,7 +57,6 @@ const defaultStyles = {
56
57
  },
57
58
  '& .autocomplete__wrapper': {
58
59
  width: '100%',
59
- paddingRight: '40px',
60
60
  },
61
61
  '& .autocomplete__input--show-all-values': {
62
62
  paddingRight: 0,
@@ -85,6 +85,8 @@ const FormAutocomplete = React.forwardRef(
85
85
  },
86
86
  forwardRef
87
87
  ) => {
88
+ const [ isDirty, setIsDirty ] = useState( false );
89
+
88
90
  const SelectLabel = () => <Label htmlFor={ forLabel || id }>{ label }</Label>;
89
91
 
90
92
  const inlineLabel = !! ( isInline && label );
@@ -120,12 +122,15 @@ const FormAutocomplete = React.forwardRef(
120
122
 
121
123
  const suggest = useCallback(
122
124
  ( query, populateResults ) => {
123
- const data = options.filter(
124
- option => optionLabel( option ).toLowerCase().indexOf( query.toLowerCase() ) >= 0
125
- );
125
+ let data = options;
126
+ if ( isDirty ) {
127
+ data = options.filter(
128
+ option => optionLabel( option ).toLowerCase().indexOf( query.toLowerCase() ) >= 0
129
+ );
130
+ }
126
131
  populateResults( data.map( option => optionLabel( option ) ) );
127
132
  },
128
- [ options ]
133
+ [ options, isDirty ]
129
134
  );
130
135
 
131
136
  useEffect( () => {
@@ -140,6 +145,12 @@ const FormAutocomplete = React.forwardRef(
140
145
  .setAttribute( 'aria-label', `${ label } list` );
141
146
  }, [ label ] );
142
147
 
148
+ useEffect( () => {
149
+ global.document.querySelector( `#${ id }` ).addEventListener( 'keydown', () => {
150
+ setIsDirty( true );
151
+ } );
152
+ }, [ setIsDirty ] );
153
+
143
154
  return (
144
155
  <>
145
156
  { label && ! isInline && <SelectLabel /> }
@@ -61,3 +61,16 @@ export const Inline = () => {
61
61
  </>
62
62
  );
63
63
  };
64
+
65
+ export const WithDefaultValue = () => {
66
+ const customArgs = {
67
+ ...args,
68
+ value: 'Chocolate',
69
+ };
70
+
71
+ return (
72
+ <>
73
+ <DefaultComponent { ...customArgs } />
74
+ </>
75
+ );
76
+ };