cozy-ui 111.13.0 → 111.15.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/assets/icons/ui/stop.svg +1 -0
  3. package/package.json +1 -1
  4. package/react/BottomSheet/BottomSheet.jsx +5 -1
  5. package/react/BottomSheet/README.md +2 -0
  6. package/react/BottomSheet/helpers.js +2 -0
  7. package/react/BottomSheet/helpers.spec.js +12 -0
  8. package/react/CozyDialogs/Readme.md +8 -1
  9. package/react/CozyDialogs/dialogPropTypes.js +1 -1
  10. package/react/CozyDialogs/useCozyDialog.js +4 -1
  11. package/react/Icon/Readme.md +3 -1
  12. package/react/Icons/Stop.jsx +12 -0
  13. package/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +4 -0
  14. package/react/SearchBar/Readme.md +56 -3
  15. package/react/SearchBar/index.jsx +105 -27
  16. package/react/SearchBar/locales/en.json +1 -1
  17. package/react/SearchBar/locales/fr.json +1 -1
  18. package/react/providers/DemoProvider.jsx +3 -9
  19. package/transpiled/react/BottomSheet/BottomSheet.js +7 -1
  20. package/transpiled/react/BottomSheet/helpers.js +3 -1
  21. package/transpiled/react/CozyDialogs/dialogPropTypes.js +1 -1
  22. package/transpiled/react/CozyDialogs/useCozyDialog.js +12 -7
  23. package/transpiled/react/Icon/icons-sprite.js +1 -1
  24. package/transpiled/react/Icons/Stop.js +13 -0
  25. package/transpiled/react/MuiCozyTheme/overrides/makeDarkInvertedOverrides.d.ts +4 -0
  26. package/transpiled/react/MuiCozyTheme/overrides/makeDarkNormalOverrides.d.ts +4 -0
  27. package/transpiled/react/MuiCozyTheme/overrides/makeLightInvertedOverrides.d.ts +4 -0
  28. package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.d.ts +4 -0
  29. package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +4 -0
  30. package/transpiled/react/SearchBar/index.js +113 -30
  31. package/transpiled/react/SearchBar/locales/withOnlyLocales.js +2 -2
  32. package/transpiled/react/providers/DemoProvider.js +5 -10
@@ -0,0 +1,13 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ // Automatically created, please run `scripts/generate-svgr-icon.sh assets/icons/ui/stop.svg` to regenerate;
3
+ import React from 'react';
4
+
5
+ function SvgStop(props) {
6
+ return /*#__PURE__*/React.createElement("svg", _extends({
7
+ viewBox: "0 0 12 12"
8
+ }, props), /*#__PURE__*/React.createElement("path", {
9
+ d: "M.75 1.5A.75.75 0 011.5.75h9a.75.75 0 01.75.75v9a.75.75 0 01-.75.75h-9a.75.75 0 01-.75-.75v-9z"
10
+ }));
11
+ }
12
+
13
+ export default SvgStop;
@@ -527,6 +527,10 @@ export function makeDarkInvertedOverrides(theme: any): {
527
527
  maxWidth: string;
528
528
  };
529
529
  };
530
+ '&.full': {
531
+ width: string;
532
+ maxWidth: string;
533
+ };
530
534
  '&.overflow': {
531
535
  overflowY: string;
532
536
  '& .cozyDialogContent': {
@@ -527,6 +527,10 @@ export function makeDarkNormalOverrides(theme: any): {
527
527
  maxWidth: string;
528
528
  };
529
529
  };
530
+ '&.full': {
531
+ width: string;
532
+ maxWidth: string;
533
+ };
530
534
  '&.overflow': {
531
535
  overflowY: string;
532
536
  '& .cozyDialogContent': {
@@ -527,6 +527,10 @@ export function makeLightInvertedOverrides(theme: any): {
527
527
  maxWidth: string;
528
528
  };
529
529
  };
530
+ '&.full': {
531
+ width: string;
532
+ maxWidth: string;
533
+ };
530
534
  '&.overflow': {
531
535
  overflowY: string;
532
536
  '& .cozyDialogContent': {
@@ -527,6 +527,10 @@ export function makeLightNormalOverrides(theme: any): {
527
527
  maxWidth: string;
528
528
  };
529
529
  };
530
+ '&.full': {
531
+ width: string;
532
+ maxWidth: string;
533
+ };
530
534
  '&.overflow': {
531
535
  overflowY: string;
532
536
  '& .cozyDialogContent': {
@@ -425,6 +425,10 @@ export var makeLightNormalOverrides = function makeLightNormalOverrides(theme) {
425
425
  width: '800px',
426
426
  maxWidth: '800px'
427
427
  }),
428
+ '&.full': {
429
+ width: '100%',
430
+ maxWidth: '100%'
431
+ },
428
432
  '&.overflow': {
429
433
  overflowY: 'visible !important',
430
434
  // Allow the icon to overflow the dialog, otherwise it will be cut off,
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- var _excluded = ["placeholder", "className", "defaultValue", "elevation", "disabled", "onChange", "onFocus", "onBlur"];
5
+ var _excluded = ["placeholder", "icon", "size", "type", "label", "componentsProps", "disabledClear", "className", "defaultValue", "value", "elevation", "disabled", "onChange", "onFocus", "onBlur"];
6
6
 
7
7
  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; }
8
8
 
@@ -12,15 +12,30 @@ import cx from 'classnames';
12
12
  import debounce from 'lodash/debounce';
13
13
  import PropTypes from 'prop-types';
14
14
  import React, { forwardRef, useState, useMemo } from 'react';
15
- import withOnlyLocales from "cozy-ui/transpiled/react/SearchBar/locales/withOnlyLocales";
15
+ import { locales } from "cozy-ui/transpiled/react/SearchBar/locales/withOnlyLocales";
16
+ import ButtonBase from "cozy-ui/transpiled/react/ButtonBase";
16
17
  import Icon from "cozy-ui/transpiled/react/Icon";
18
+ import { iconPropType } from "cozy-ui/transpiled/react/Icon";
17
19
  import IconButton from "cozy-ui/transpiled/react/IconButton";
18
20
  import CrossCircleIcon from "cozy-ui/transpiled/react/Icons/CrossCircle";
19
21
  import MagnifierIcon from "cozy-ui/transpiled/react/Icons/Magnifier";
20
22
  import InputBase from "cozy-ui/transpiled/react/InputBase";
21
23
  import Paper from "cozy-ui/transpiled/react/Paper";
22
- import { useI18n } from "cozy-ui/transpiled/react/providers/I18n";
24
+ import Typography from "cozy-ui/transpiled/react/Typography";
25
+ import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
23
26
  import { makeStyles } from "cozy-ui/transpiled/react/styles";
27
+ var sizeToPixel = {
28
+ small: 40,
29
+ medium: 48,
30
+ large: 56,
31
+ auto: 'auto'
32
+ };
33
+ var radiusBySize = {
34
+ small: 20,
35
+ medium: 24,
36
+ large: 28,
37
+ auto: 24
38
+ };
24
39
  var useStyles = makeStyles(function (theme) {
25
40
  return {
26
41
  root: {
@@ -28,9 +43,15 @@ var useStyles = makeStyles(function (theme) {
28
43
  boxSizing: 'border-box',
29
44
  position: 'relative',
30
45
  alignItems: 'center',
31
- height: 40,
46
+ height: function height(_ref) {
47
+ var size = _ref.size;
48
+ return sizeToPixel[size];
49
+ },
32
50
  flex: 1,
33
- borderRadius: 99,
51
+ borderRadius: function borderRadius(_ref2) {
52
+ var size = _ref2.size;
53
+ return radiusBySize[size];
54
+ },
34
55
  borderStyle: 'solid',
35
56
  borderWidth: 1,
36
57
  borderColor: 'transparent',
@@ -46,7 +67,25 @@ var useStyles = makeStyles(function (theme) {
46
67
  backgroundColor: theme.palette.background.contrast
47
68
  },
48
69
  inputBase: {
49
- flex: 1
70
+ flex: 1,
71
+ paddingLeft: function paddingLeft(_ref3) {
72
+ var icon = _ref3.icon;
73
+ return !icon && '1rem';
74
+ }
75
+ },
76
+ buttonBase: {
77
+ flex: 1,
78
+ justifyContent: 'start',
79
+ height: '100%',
80
+ borderRadius: 99
81
+ },
82
+ typography: {
83
+ color: 'currentColor',
84
+ opacity: 0.42,
85
+ paddingLeft: function paddingLeft(_ref4) {
86
+ var icon = _ref4.icon;
87
+ return !icon && '1rem';
88
+ }
50
89
  },
51
90
  icon: {
52
91
  color: theme.palette.text.secondary,
@@ -86,23 +125,34 @@ var useStyles = makeStyles(function (theme) {
86
125
  }
87
126
  };
88
127
  });
89
- var SearchBar = /*#__PURE__*/forwardRef(function (_ref, ref) {
128
+ var SearchBar = /*#__PURE__*/forwardRef(function (_ref5, ref) {
90
129
  var _cx;
91
130
 
92
- var placeholderProp = _ref.placeholder,
93
- className = _ref.className,
94
- defaultValue = _ref.defaultValue,
95
- elevation = _ref.elevation,
96
- disabled = _ref.disabled,
97
- onChange = _ref.onChange,
98
- onFocus = _ref.onFocus,
99
- onBlur = _ref.onBlur,
100
- props = _objectWithoutProperties(_ref, _excluded);
131
+ var placeholderProp = _ref5.placeholder,
132
+ icon = _ref5.icon,
133
+ size = _ref5.size,
134
+ type = _ref5.type,
135
+ labelProp = _ref5.label,
136
+ componentsProps = _ref5.componentsProps,
137
+ disabledClear = _ref5.disabledClear,
138
+ className = _ref5.className,
139
+ defaultValue = _ref5.defaultValue,
140
+ value = _ref5.value,
141
+ elevation = _ref5.elevation,
142
+ disabled = _ref5.disabled,
143
+ onChange = _ref5.onChange,
144
+ onFocus = _ref5.onFocus,
145
+ onBlur = _ref5.onBlur,
146
+ props = _objectWithoutProperties(_ref5, _excluded);
101
147
 
102
148
  var _useI18n = useI18n(),
103
149
  t = _useI18n.t;
104
150
 
105
- var classes = useStyles();
151
+ var classes = useStyles({
152
+ size: size,
153
+ type: type,
154
+ icon: icon
155
+ });
106
156
 
107
157
  var _useState = useState(defaultValue),
108
158
  _useState2 = _slicedToArray(_useState, 2),
@@ -114,19 +164,21 @@ var SearchBar = /*#__PURE__*/forwardRef(function (_ref, ref) {
114
164
  isFocused = _useState4[0],
115
165
  setIsFocused = _useState4[1];
116
166
 
117
- var placeholder = placeholderProp || t('search.placeholder');
167
+ var placeholder = placeholderProp || t('SearchBar.placeholder');
168
+ var label = labelProp || t('SearchBar.placeholder');
169
+ var spreadValue = value || currentValue;
170
+ var isSelfControlledComp = typeof value === 'undefined';
118
171
  var delayedOnChange = useMemo(function () {
119
- return debounce(function (event) {
120
- return onChange(event);
121
- }, 375);
172
+ return debounce(onChange, 375);
122
173
  }, [onChange]);
123
174
 
124
175
  var handleChange = function handleChange(ev) {
125
- var value = ev.target.value;
176
+ if (!isSelfControlledComp) return onChange(ev);
177
+ var _value = ev.target.value;
126
178
 
127
- if (value.length >= 1) {
179
+ if (_value.length >= 1) {
128
180
  delayedOnChange(ev);
129
- setCurrentValue(value);
181
+ setCurrentValue(_value);
130
182
  } else {
131
183
  handleClear(ev);
132
184
  }
@@ -156,19 +208,26 @@ var SearchBar = /*#__PURE__*/forwardRef(function (_ref, ref) {
156
208
  elevation: elevation ? 1 : 0,
157
209
  className: cx(className, classes.root, (_cx = {}, _defineProperty(_cx, classes.flat, !elevation), _defineProperty(_cx, classes.elevation, elevation), _defineProperty(_cx, classes.focused, isFocused), _defineProperty(_cx, classes.disabled, disabled), _cx)),
158
210
  ref: ref
159
- }, props), /*#__PURE__*/React.createElement(Icon, {
211
+ }, props), type === 'button' ? /*#__PURE__*/React.createElement(ButtonBase, {
212
+ className: classes.buttonBase
213
+ }, icon && /*#__PURE__*/React.createElement(Icon, {
160
214
  className: classes.icon,
161
- icon: MagnifierIcon
162
- }), /*#__PURE__*/React.createElement(InputBase, {
215
+ icon: icon
216
+ }), typeof label === 'string' ? /*#__PURE__*/React.createElement(Typography, {
217
+ className: classes.typography
218
+ }, label) : label) : /*#__PURE__*/React.createElement(React.Fragment, null, icon && /*#__PURE__*/React.createElement(Icon, {
219
+ className: classes.icon,
220
+ icon: icon
221
+ }), /*#__PURE__*/React.createElement(InputBase, _extends({}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.inputBase, {
163
222
  className: classes.inputBase,
164
223
  placeholder: disabled ? null : placeholder,
165
- value: disabled ? placeholder : currentValue,
224
+ value: disabled ? placeholder : spreadValue,
166
225
  disabled: disabled,
167
226
  "aria-label": placeholder,
168
227
  onChange: handleChange,
169
228
  onFocus: handleFocus,
170
229
  onBlur: handleBlur
171
- }), currentValue && /*#__PURE__*/React.createElement(IconButton, {
230
+ }))), spreadValue && !disabledClear && /*#__PURE__*/React.createElement(IconButton, {
172
231
  size: "medium",
173
232
  onClick: handleClear
174
233
  }, /*#__PURE__*/React.createElement(Icon, {
@@ -182,6 +241,10 @@ var SearchBar = /*#__PURE__*/forwardRef(function (_ref, ref) {
182
241
  SearchBar.displayName = 'SearchBar';
183
242
  SearchBar.defaultProps = {
184
243
  elevation: true,
244
+ icon: MagnifierIcon,
245
+ size: 'small',
246
+ type: 'search',
247
+ disabledClear: false,
185
248
  defaultValue: '',
186
249
  onChange: function onChange() {},
187
250
  onFocus: function onFocus() {},
@@ -189,12 +252,32 @@ SearchBar.defaultProps = {
189
252
  };
190
253
  SearchBar.propTypes = {
191
254
  className: PropTypes.string,
255
+ type: PropTypes.oneOf(['button', 'search']),
256
+ icon: iconPropType,
257
+ size: PropTypes.oneOf(['small', 'medium', 'large', 'auto']),
258
+ componentsProps: PropTypes.shape({
259
+ /** Props spread to InputBase component */
260
+ inputBase: PropTypes.object
261
+ }),
262
+
263
+ /** Used to control the component outside of it */
264
+ value: PropTypes.string,
265
+
266
+ /** Used only with self-controlled component */
192
267
  defaultValue: PropTypes.string,
268
+ disabledClear: PropTypes.bool,
193
269
  elevation: PropTypes.bool,
194
270
  placeholder: PropTypes.string,
271
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
195
272
  disabled: PropTypes.bool,
196
273
  onChange: PropTypes.func,
197
274
  onFocus: PropTypes.func,
198
275
  onBlur: PropTypes.func
199
276
  };
200
- export default withOnlyLocales(SearchBar);
277
+
278
+ var SearchBarWithLocales = function SearchBarWithLocales(props) {
279
+ useExtendI18n(locales);
280
+ return /*#__PURE__*/React.createElement(SearchBar, props);
281
+ };
282
+
283
+ export default SearchBarWithLocales;
@@ -1,10 +1,10 @@
1
1
  var en = {
2
- search: {
2
+ SearchBar: {
3
3
  placeholder: "Search"
4
4
  }
5
5
  };
6
6
  var fr = {
7
- search: {
7
+ SearchBar: {
8
8
  placeholder: "Rechercher"
9
9
  }
10
10
  };
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import { CozyProvider } from 'cozy-client';
3
3
  import { BreakpointsProvider } from "cozy-ui/transpiled/react/providers/Breakpoints";
4
4
  import CozyTheme from "cozy-ui/transpiled/react/providers/CozyTheme";
5
- import { I18nContext } from "cozy-ui/transpiled/react/providers/I18n";
5
+ import I18n from "cozy-ui/transpiled/react/providers/I18n";
6
6
  var defaultClient = {
7
7
  plugins: {
8
8
  realtime: {
@@ -30,15 +30,10 @@ var DemoProvider = function DemoProvider(_ref) {
30
30
  var lang = localStorage.getItem('lang') || 'en';
31
31
  return /*#__PURE__*/React.createElement(CozyProvider, {
32
32
  client: client || defaultClient
33
- }, /*#__PURE__*/React.createElement(BreakpointsProvider, null, /*#__PURE__*/React.createElement(I18nContext.Provider, {
34
- value: {
35
- t: function t(x) {
36
- return x;
37
- },
38
- f: function f() {
39
- return '01 Jan. 2022';
40
- },
41
- lang: lang
33
+ }, /*#__PURE__*/React.createElement(BreakpointsProvider, null, /*#__PURE__*/React.createElement(I18n, {
34
+ lang: lang,
35
+ dictRequire: function dictRequire() {
36
+ return {};
42
37
  }
43
38
  }, /*#__PURE__*/React.createElement(CozyTheme, {
44
39
  variant: variant