cozy-ui 85.3.1 → 85.5.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [85.5.0](https://github.com/cozy/cozy-ui/compare/v85.4.0...v85.5.0) (2023-05-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * Add InputBase component ([aef4a77](https://github.com/cozy/cozy-ui/commit/aef4a77))
7
+ * Add SearchBar component ([a46e3ee](https://github.com/cozy/cozy-ui/commit/a46e3ee))
8
+
9
+ # [85.4.0](https://github.com/cozy/cozy-ui/compare/v85.3.1...v85.4.0) (2023-05-30)
10
+
11
+
12
+ ### Features
13
+
14
+ * **Viewer:** To be consistent with recent wording changes ([36d7d78](https://github.com/cozy/cozy-ui/commit/36d7d78))
15
+
1
16
  ## [85.3.1](https://github.com/cozy/cozy-ui/compare/v85.3.0...v85.3.1) (2023-05-24)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "85.3.1",
3
+ "version": "85.5.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -0,0 +1 @@
1
+ Re-export of @material-ui. See [the official API](https://v4.mui.com/api/input-base/).
@@ -0,0 +1,3 @@
1
+ import InputBase from '@material-ui/core/InputBase'
2
+
3
+ export default InputBase
@@ -0,0 +1,23 @@
1
+ ```jsx
2
+ import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
3
+ import Variants from 'cozy-ui/docs/components/Variants'
4
+ import SearchBar from 'cozy-ui/transpiled/react/SearchBar'
5
+ import Typography from 'cozy-ui/transpiled/react/Typography'
6
+
7
+ const initialVariants = [{ elevation: true }]
8
+
9
+ ;
10
+
11
+ <DemoProvider>
12
+ <Variants initialVariants={initialVariants} screenshotAllVariants>
13
+ {variant => (
14
+ <>
15
+ <Typography className="u-mb-half">Normal</Typography>
16
+ <SearchBar className="u-mb-2" elevation={variant.elevation} />
17
+ <Typography className="u-mb-half">Disabled</Typography>
18
+ <SearchBar elevation={variant.elevation} disabled />
19
+ </>
20
+ )}
21
+ </Variants>
22
+ </DemoProvider>
23
+ ```
@@ -0,0 +1,193 @@
1
+ import React, { forwardRef, useState, useMemo } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import cx from 'classnames'
4
+ import debounce from 'lodash/debounce'
5
+
6
+ import withLocales from './locales/withLocales'
7
+ import { makeStyles } from '../styles'
8
+ import Paper from '../Paper'
9
+ import InputBase from '../InputBase'
10
+ import IconButton from '../IconButton'
11
+ import Icon from '../Icon'
12
+ import MagnifierIcon from '../Icons/Magnifier'
13
+ import CrossCircleIcon from '../Icons/CrossCircle'
14
+
15
+ const useStyles = makeStyles(theme => ({
16
+ root: {
17
+ display: 'flex',
18
+ boxSizing: 'border-box',
19
+ position: 'relative',
20
+ alignItems: 'center',
21
+ height: 40,
22
+ flex: 1,
23
+ borderRadius: 99,
24
+ borderStyle: 'solid',
25
+ borderWidth: 1,
26
+ borderColor: 'transparent',
27
+ '&:hover': {
28
+ '&:not($disabled):not($focused)': {
29
+ '& $focusHighlight': {
30
+ opacity: 1
31
+ }
32
+ }
33
+ }
34
+ },
35
+ flat: {
36
+ backgroundColor: theme.palette.background.contrast
37
+ },
38
+ inputBase: {
39
+ flex: 1
40
+ },
41
+ icon: {
42
+ color: theme.palette.text.secondary,
43
+ padding: '0 1rem'
44
+ },
45
+ commonHighlight: {
46
+ overflow: 'hidden',
47
+ position: 'absolute',
48
+ top: -1,
49
+ right: -1,
50
+ bottom: -1,
51
+ left: -1,
52
+ borderRadius: 'inherit',
53
+ opacity: 0,
54
+ transition: theme.transitions.create('opacity', {
55
+ duration: theme.transitions.duration.short
56
+ })
57
+ },
58
+ focusHighlight: {
59
+ pointerEvents: 'none',
60
+ backgroundColor: theme.palette.action.hover
61
+ },
62
+ disableHighlight: {
63
+ backgroundColor: theme.palette.action.disabled
64
+ },
65
+ focused: {
66
+ borderColor: theme.palette.primary.main,
67
+ backgroundColor: theme.palette.background.paper
68
+ },
69
+ disabled: {
70
+ '& $icon': {
71
+ color: theme.palette.text.disabled
72
+ },
73
+ '& $disableHighlight': {
74
+ opacity: 1
75
+ }
76
+ }
77
+ }))
78
+
79
+ const SearchBar = forwardRef(
80
+ (
81
+ {
82
+ t,
83
+ placeholder: placeholderProp,
84
+ className,
85
+ defaultValue,
86
+ elevation,
87
+ disabled,
88
+ onChange,
89
+ onFocus,
90
+ onBlur,
91
+ ...props
92
+ },
93
+ ref
94
+ ) => {
95
+ const classes = useStyles()
96
+ const [currentValue, setCurrentValue] = useState(defaultValue)
97
+ const [isFocused, setIsFocused] = useState(false)
98
+
99
+ const placeholder = placeholderProp || t('search.placeholder')
100
+
101
+ const delayedOnChange = useMemo(
102
+ () => debounce(event => onChange(event), 375),
103
+ [onChange]
104
+ )
105
+
106
+ const handleChange = ev => {
107
+ const value = ev.target.value
108
+
109
+ if (value.length >= 1) {
110
+ delayedOnChange(ev)
111
+ setCurrentValue(value)
112
+ } else {
113
+ handleClear(ev)
114
+ }
115
+ }
116
+
117
+ const handleClear = ev => {
118
+ onChange({ ...ev, target: { ...ev.target, value: '' } })
119
+ setCurrentValue('')
120
+ }
121
+
122
+ const handleFocus = ev => {
123
+ onFocus(ev)
124
+ setIsFocused(true)
125
+ }
126
+
127
+ const handleBlur = ev => {
128
+ onBlur(ev)
129
+ setIsFocused(false)
130
+ }
131
+
132
+ return (
133
+ <Paper
134
+ component="form"
135
+ elevation={elevation ? 1 : 0}
136
+ className={cx(className, classes.root, {
137
+ [classes.flat]: !elevation,
138
+ [classes.elevation]: elevation,
139
+ [classes.focused]: isFocused,
140
+ [classes.disabled]: disabled
141
+ })}
142
+ ref={ref}
143
+ {...props}
144
+ >
145
+ <Icon className={classes.icon} icon={MagnifierIcon} />
146
+ <InputBase
147
+ className={classes.inputBase}
148
+ placeholder={disabled ? null : placeholder}
149
+ value={disabled ? placeholder : currentValue}
150
+ disabled={disabled}
151
+ aria-label={placeholder}
152
+ onChange={handleChange}
153
+ onFocus={handleFocus}
154
+ onBlur={handleBlur}
155
+ />
156
+ {currentValue && (
157
+ <IconButton size="medium" onClick={handleClear}>
158
+ <Icon icon={CrossCircleIcon} />
159
+ </IconButton>
160
+ )}
161
+ <span className={cx(classes.commonHighlight, classes.focusHighlight)} />
162
+ {disabled && (
163
+ <span
164
+ className={cx(classes.commonHighlight, classes.disableHighlight)}
165
+ />
166
+ )}
167
+ </Paper>
168
+ )
169
+ }
170
+ )
171
+
172
+ SearchBar.displayName = 'SearchBar'
173
+
174
+ SearchBar.defaultProps = {
175
+ elevation: true,
176
+ defaultValue: '',
177
+ onChange: () => {},
178
+ onFocus: () => {},
179
+ onBlur: () => {}
180
+ }
181
+
182
+ SearchBar.propTypes = {
183
+ className: PropTypes.string,
184
+ defaultValue: PropTypes.string,
185
+ elevation: PropTypes.bool,
186
+ placeholder: PropTypes.string,
187
+ disabled: PropTypes.bool,
188
+ onChange: PropTypes.func,
189
+ onFocus: PropTypes.func,
190
+ onBlur: PropTypes.func
191
+ }
192
+
193
+ export default withLocales(SearchBar)
@@ -0,0 +1,5 @@
1
+ {
2
+ "search": {
3
+ "placeholder": "Search"
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "search": {
3
+ "placeholder": "Rechercher"
4
+ }
5
+ }
@@ -0,0 +1,11 @@
1
+ import withLocales from '../../I18n/withLocales'
2
+
3
+ import en from './en.json'
4
+ import fr from './fr.json'
5
+
6
+ export const locales = {
7
+ en,
8
+ fr
9
+ }
10
+
11
+ export default withLocales(locales)
@@ -2,7 +2,7 @@
2
2
  "Viewer": {
3
3
  "actions": {
4
4
  "download": "Download",
5
- "forward": "Forward"
5
+ "forward": "Send"
6
6
  },
7
7
  "alert": {
8
8
  "preparing": "Preparing your files…"
@@ -2,7 +2,7 @@
2
2
  "Viewer": {
3
3
  "actions": {
4
4
  "download": "Télécharger",
5
- "forward": "Transférer"
5
+ "forward": "Envoyer"
6
6
  },
7
7
  "alert": {
8
8
  "preparing": "Preparation de vos fichiers…"
package/react/index.js CHANGED
@@ -118,3 +118,5 @@ export { default as Tab } from './Tab'
118
118
  export { default as CircularChart } from './CircularChart'
119
119
  export { default as Skeleton } from './Skeleton'
120
120
  export { default as InputAdornment } from './InputAdornment'
121
+ export { default as InputBase } from './InputBase'
122
+ export { default as SearchBar } from './SearchBar'
@@ -0,0 +1,2 @@
1
+ import InputBase from '@material-ui/core/InputBase';
2
+ export default InputBase;
@@ -0,0 +1,197 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
+ var _excluded = ["t", "placeholder", "className", "defaultValue", "elevation", "disabled", "onChange", "onFocus", "onBlur"];
6
+
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
+
9
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
+
11
+ import React, { forwardRef, useState, useMemo } from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import cx from 'classnames';
14
+ import debounce from 'lodash/debounce';
15
+ import withLocales from "cozy-ui/transpiled/react/SearchBar/locales/withLocales";
16
+ import { makeStyles } from "cozy-ui/transpiled/react/styles";
17
+ import Paper from "cozy-ui/transpiled/react/Paper";
18
+ import InputBase from "cozy-ui/transpiled/react/InputBase";
19
+ import IconButton from "cozy-ui/transpiled/react/IconButton";
20
+ import Icon from "cozy-ui/transpiled/react/Icon";
21
+ import MagnifierIcon from "cozy-ui/transpiled/react/Icons/Magnifier";
22
+ import CrossCircleIcon from "cozy-ui/transpiled/react/Icons/CrossCircle";
23
+ var useStyles = makeStyles(function (theme) {
24
+ return {
25
+ root: {
26
+ display: 'flex',
27
+ boxSizing: 'border-box',
28
+ position: 'relative',
29
+ alignItems: 'center',
30
+ height: 40,
31
+ flex: 1,
32
+ borderRadius: 99,
33
+ borderStyle: 'solid',
34
+ borderWidth: 1,
35
+ borderColor: 'transparent',
36
+ '&:hover': {
37
+ '&:not($disabled):not($focused)': {
38
+ '& $focusHighlight': {
39
+ opacity: 1
40
+ }
41
+ }
42
+ }
43
+ },
44
+ flat: {
45
+ backgroundColor: theme.palette.background.contrast
46
+ },
47
+ inputBase: {
48
+ flex: 1
49
+ },
50
+ icon: {
51
+ color: theme.palette.text.secondary,
52
+ padding: '0 1rem'
53
+ },
54
+ commonHighlight: {
55
+ overflow: 'hidden',
56
+ position: 'absolute',
57
+ top: -1,
58
+ right: -1,
59
+ bottom: -1,
60
+ left: -1,
61
+ borderRadius: 'inherit',
62
+ opacity: 0,
63
+ transition: theme.transitions.create('opacity', {
64
+ duration: theme.transitions.duration.short
65
+ })
66
+ },
67
+ focusHighlight: {
68
+ pointerEvents: 'none',
69
+ backgroundColor: theme.palette.action.hover
70
+ },
71
+ disableHighlight: {
72
+ backgroundColor: theme.palette.action.disabled
73
+ },
74
+ focused: {
75
+ borderColor: theme.palette.primary.main,
76
+ backgroundColor: theme.palette.background.paper
77
+ },
78
+ disabled: {
79
+ '& $icon': {
80
+ color: theme.palette.text.disabled
81
+ },
82
+ '& $disableHighlight': {
83
+ opacity: 1
84
+ }
85
+ }
86
+ };
87
+ });
88
+ var SearchBar = /*#__PURE__*/forwardRef(function (_ref, ref) {
89
+ var _cx;
90
+
91
+ var t = _ref.t,
92
+ 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);
101
+
102
+ var classes = useStyles();
103
+
104
+ var _useState = useState(defaultValue),
105
+ _useState2 = _slicedToArray(_useState, 2),
106
+ currentValue = _useState2[0],
107
+ setCurrentValue = _useState2[1];
108
+
109
+ var _useState3 = useState(false),
110
+ _useState4 = _slicedToArray(_useState3, 2),
111
+ isFocused = _useState4[0],
112
+ setIsFocused = _useState4[1];
113
+
114
+ var placeholder = placeholderProp || t('search.placeholder');
115
+ var delayedOnChange = useMemo(function () {
116
+ return debounce(function (event) {
117
+ return onChange(event);
118
+ }, 375);
119
+ }, [onChange]);
120
+
121
+ var handleChange = function handleChange(ev) {
122
+ var value = ev.target.value;
123
+
124
+ if (value.length >= 1) {
125
+ delayedOnChange(ev);
126
+ setCurrentValue(value);
127
+ } else {
128
+ handleClear(ev);
129
+ }
130
+ };
131
+
132
+ var handleClear = function handleClear(ev) {
133
+ onChange(_objectSpread(_objectSpread({}, ev), {}, {
134
+ target: _objectSpread(_objectSpread({}, ev.target), {}, {
135
+ value: ''
136
+ })
137
+ }));
138
+ setCurrentValue('');
139
+ };
140
+
141
+ var handleFocus = function handleFocus(ev) {
142
+ onFocus(ev);
143
+ setIsFocused(true);
144
+ };
145
+
146
+ var handleBlur = function handleBlur(ev) {
147
+ onBlur(ev);
148
+ setIsFocused(false);
149
+ };
150
+
151
+ return /*#__PURE__*/React.createElement(Paper, _extends({
152
+ component: "form",
153
+ elevation: elevation ? 1 : 0,
154
+ 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)),
155
+ ref: ref
156
+ }, props), /*#__PURE__*/React.createElement(Icon, {
157
+ className: classes.icon,
158
+ icon: MagnifierIcon
159
+ }), /*#__PURE__*/React.createElement(InputBase, {
160
+ className: classes.inputBase,
161
+ placeholder: disabled ? null : placeholder,
162
+ value: disabled ? placeholder : currentValue,
163
+ disabled: disabled,
164
+ "aria-label": placeholder,
165
+ onChange: handleChange,
166
+ onFocus: handleFocus,
167
+ onBlur: handleBlur
168
+ }), currentValue && /*#__PURE__*/React.createElement(IconButton, {
169
+ size: "medium",
170
+ onClick: handleClear
171
+ }, /*#__PURE__*/React.createElement(Icon, {
172
+ icon: CrossCircleIcon
173
+ })), /*#__PURE__*/React.createElement("span", {
174
+ className: cx(classes.commonHighlight, classes.focusHighlight)
175
+ }), disabled && /*#__PURE__*/React.createElement("span", {
176
+ className: cx(classes.commonHighlight, classes.disableHighlight)
177
+ }));
178
+ });
179
+ SearchBar.displayName = 'SearchBar';
180
+ SearchBar.defaultProps = {
181
+ elevation: true,
182
+ defaultValue: '',
183
+ onChange: function onChange() {},
184
+ onFocus: function onFocus() {},
185
+ onBlur: function onBlur() {}
186
+ };
187
+ SearchBar.propTypes = {
188
+ className: PropTypes.string,
189
+ defaultValue: PropTypes.string,
190
+ elevation: PropTypes.bool,
191
+ placeholder: PropTypes.string,
192
+ disabled: PropTypes.bool,
193
+ onChange: PropTypes.func,
194
+ onFocus: PropTypes.func,
195
+ onBlur: PropTypes.func
196
+ };
197
+ export default withLocales(SearchBar);
@@ -0,0 +1,16 @@
1
+ import withLocales from "cozy-ui/transpiled/react/I18n/withLocales";
2
+ var en = {
3
+ search: {
4
+ placeholder: "Search"
5
+ }
6
+ };
7
+ var fr = {
8
+ search: {
9
+ placeholder: "Rechercher"
10
+ }
11
+ };
12
+ export var locales = {
13
+ en: en,
14
+ fr: fr
15
+ };
16
+ export default withLocales(locales);
@@ -3,7 +3,7 @@ var en = {
3
3
  Viewer: {
4
4
  actions: {
5
5
  download: "Download",
6
- forward: "Forward"
6
+ forward: "Send"
7
7
  },
8
8
  alert: {
9
9
  preparing: "Preparing your files\u2026"
@@ -132,7 +132,7 @@ var fr = {
132
132
  Viewer: {
133
133
  actions: {
134
134
  download: "T\xE9l\xE9charger",
135
- forward: "Transf\xE9rer"
135
+ forward: "Envoyer"
136
136
  },
137
137
  alert: {
138
138
  preparing: "Preparation de vos fichiers\u2026"
@@ -91,4 +91,6 @@ export { default as Tabs } from './Tabs';
91
91
  export { default as Tab } from './Tab';
92
92
  export { default as CircularChart } from './CircularChart';
93
93
  export { default as Skeleton } from './Skeleton';
94
- export { default as InputAdornment } from './InputAdornment';
94
+ export { default as InputAdornment } from './InputAdornment';
95
+ export { default as InputBase } from './InputBase';
96
+ export { default as SearchBar } from './SearchBar';