cozy-ui 111.12.0 → 111.14.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 +25 -0
- package/package.json +1 -1
- package/react/AppSections/Sections.jsx +8 -8
- package/react/AppSections/__snapshots__/index.spec.jsx.snap +2 -2
- package/react/AppSections/categories.spec.js +2 -2
- package/react/AppSections/components/__snapshots__/AppsSection.spec.jsx.snap +1 -1
- package/react/AppSections/locales/en.json +2 -2
- package/react/AppSections/locales/fr.json +2 -2
- package/react/AppTile/index.jsx +3 -8
- package/react/AppTile/locales/fr.json +1 -1
- package/react/BottomSheet/BottomSheet.jsx +5 -1
- package/react/BottomSheet/README.md +2 -0
- package/react/BottomSheet/helpers.js +2 -0
- package/react/BottomSheet/helpers.spec.js +12 -0
- package/react/CozyDialogs/Readme.md +8 -1
- package/react/CozyDialogs/dialogPropTypes.js +1 -1
- package/react/CozyDialogs/useCozyDialog.js +4 -1
- package/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +4 -0
- package/react/SearchBar/Readme.md +56 -3
- package/react/SearchBar/index.jsx +105 -27
- package/react/SearchBar/locales/en.json +1 -1
- package/react/SearchBar/locales/fr.json +1 -1
- package/react/providers/DemoProvider.jsx +3 -9
- package/react/providers/I18n/index.jsx +2 -1
- package/react/providers/I18n/translation.jsx +1 -32
- package/react/providers/I18n/useExtendI18n.jsx +37 -0
- package/transpiled/react/AppSections/Sections.js +17 -11
- package/transpiled/react/AppTile/index.js +3 -11
- package/transpiled/react/BottomSheet/BottomSheet.js +7 -1
- package/transpiled/react/BottomSheet/helpers.js +3 -1
- package/transpiled/react/CozyDialogs/dialogPropTypes.js +1 -1
- package/transpiled/react/CozyDialogs/useCozyDialog.js +12 -7
- package/transpiled/react/MuiCozyTheme/overrides/makeDarkInvertedOverrides.d.ts +4 -0
- package/transpiled/react/MuiCozyTheme/overrides/makeDarkNormalOverrides.d.ts +4 -0
- package/transpiled/react/MuiCozyTheme/overrides/makeLightInvertedOverrides.d.ts +4 -0
- package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.d.ts +4 -0
- package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +4 -0
- package/transpiled/react/SearchBar/index.js +113 -30
- package/transpiled/react/SearchBar/locales/withOnlyLocales.js +2 -2
- package/transpiled/react/providers/DemoProvider.js +5 -10
- package/transpiled/react/providers/I18n/index.js +2 -1
- package/transpiled/react/providers/I18n/translation.js +1 -32
- package/transpiled/react/providers/I18n/useExtendI18n.js +42 -0
|
@@ -4,7 +4,7 @@ import { CozyProvider } from 'cozy-client'
|
|
|
4
4
|
|
|
5
5
|
import { BreakpointsProvider } from './Breakpoints'
|
|
6
6
|
import CozyTheme from './CozyTheme'
|
|
7
|
-
import
|
|
7
|
+
import I18n from '../providers/I18n'
|
|
8
8
|
|
|
9
9
|
const defaultClient = {
|
|
10
10
|
plugins: {
|
|
@@ -28,15 +28,9 @@ const DemoProvider = ({ client, variant, children }) => {
|
|
|
28
28
|
return (
|
|
29
29
|
<CozyProvider client={client || defaultClient}>
|
|
30
30
|
<BreakpointsProvider>
|
|
31
|
-
<
|
|
32
|
-
value={{
|
|
33
|
-
t: x => x,
|
|
34
|
-
f: () => '01 Jan. 2022',
|
|
35
|
-
lang
|
|
36
|
-
}}
|
|
37
|
-
>
|
|
31
|
+
<I18n lang={lang} dictRequire={() => ({})}>
|
|
38
32
|
<CozyTheme variant={variant}>{children}</CozyTheme>
|
|
39
|
-
</
|
|
33
|
+
</I18n>
|
|
40
34
|
</BreakpointsProvider>
|
|
41
35
|
</CozyProvider>
|
|
42
36
|
)
|
|
@@ -89,8 +89,9 @@ I18n.childContextTypes = {
|
|
|
89
89
|
lang: PropTypes.string
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export { initTranslation, extend
|
|
92
|
+
export { initTranslation, extend } from './translation'
|
|
93
93
|
export { default as translate } from './translate'
|
|
94
94
|
export { default as createUseI18n } from './createUseI18n'
|
|
95
|
+
export { default as useExtendI18n } from './useExtendI18n'
|
|
95
96
|
|
|
96
97
|
export default I18n
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Polyglot from 'node-polyglot'
|
|
2
2
|
|
|
3
|
-
import { DEFAULT_LANG
|
|
3
|
+
import { DEFAULT_LANG } from '.'
|
|
4
4
|
|
|
5
5
|
export let _polyglot
|
|
6
6
|
|
|
@@ -40,34 +40,3 @@ export const initTranslation = (
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export const extend = (dict, polyglot) => (polyglot || _polyglot)?.extend(dict)
|
|
43
|
-
|
|
44
|
-
// Use to determine if we need to merge locales again, and to avoid useless calls
|
|
45
|
-
let useExtendI18nLang = ''
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Hook to merge app locales with cozy-ui locales
|
|
49
|
-
* @param {object} locales - Locales sorted by lang `{ fr: {...}, en: {...} }`
|
|
50
|
-
* @returns {void}
|
|
51
|
-
*/
|
|
52
|
-
export const useExtendI18n = locales => {
|
|
53
|
-
const { lang, polyglot } = useI18n()
|
|
54
|
-
|
|
55
|
-
if (!locales || !lang || !polyglot) return
|
|
56
|
-
|
|
57
|
-
// To simplify code we use Polyglot.extend to merge
|
|
58
|
-
// locales from object and from polyglot.phrases
|
|
59
|
-
// rather than native JS or lodash. this is why we have two extend.
|
|
60
|
-
if (useExtendI18nLang !== lang) {
|
|
61
|
-
const _polyglot = new Polyglot({
|
|
62
|
-
phrases: locales[lang],
|
|
63
|
-
locale: lang
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
// merge locales from app and cozy-ui, without replacing existing one in app
|
|
67
|
-
extend(polyglot.phrases, _polyglot)
|
|
68
|
-
// use merged locales in app
|
|
69
|
-
extend(_polyglot.phrases, polyglot)
|
|
70
|
-
// set the sitch to avoid useless merge
|
|
71
|
-
useExtendI18nLang = lang
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Polyglot from 'node-polyglot'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { useI18n } from '.'
|
|
5
|
+
import { extend } from './translation'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook to merge app locales with cozy-ui locales
|
|
9
|
+
* @param {object} locales - Locales sorted by lang `{ fr: {...}, en: {...} }`
|
|
10
|
+
* @returns {void}
|
|
11
|
+
*/
|
|
12
|
+
const useExtendI18n = locales => {
|
|
13
|
+
const { lang, polyglot } = useI18n()
|
|
14
|
+
// Use to determine if we need to merge locales again, and to avoid useless calls
|
|
15
|
+
const [useExtendI18nLang, setUseExtendI18nLang] = useState('')
|
|
16
|
+
|
|
17
|
+
if (!locales || !lang || !polyglot) return
|
|
18
|
+
|
|
19
|
+
// To simplify code we use Polyglot.extend to merge
|
|
20
|
+
// locales from object and from polyglot.phrases
|
|
21
|
+
// rather than native JS or lodash. this is why we have two extend.
|
|
22
|
+
if (useExtendI18nLang !== lang) {
|
|
23
|
+
const _polyglot = new Polyglot({
|
|
24
|
+
phrases: locales[lang],
|
|
25
|
+
locale: lang
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// merge locales from app and cozy-ui, without replacing existing one in app
|
|
29
|
+
extend(polyglot.phrases, _polyglot)
|
|
30
|
+
// use merged locales in app
|
|
31
|
+
extend(_polyglot.phrases, polyglot)
|
|
32
|
+
// set the switch to avoid useless merge
|
|
33
|
+
setUseExtendI18nLang(lang)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default useExtendI18n
|
|
@@ -14,7 +14,6 @@ import cx from 'classnames';
|
|
|
14
14
|
import PropTypes from 'prop-types';
|
|
15
15
|
import React, { Component } from 'react';
|
|
16
16
|
import flag from 'cozy-flags';
|
|
17
|
-
import { useExtendI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
18
17
|
var styles = {
|
|
19
18
|
"Sections__section": "Sections__Sections__section___2onYy"
|
|
20
19
|
};
|
|
@@ -53,12 +52,12 @@ var en = {
|
|
|
53
52
|
telecom: "Telecom",
|
|
54
53
|
transport: "Transportation",
|
|
55
54
|
pro: "Work",
|
|
56
|
-
shortcuts: "
|
|
55
|
+
shortcuts: "Additional apps"
|
|
57
56
|
},
|
|
58
57
|
sections: {
|
|
59
58
|
applications: "Applications",
|
|
60
59
|
konnectors: "Services",
|
|
61
|
-
shortcuts: "
|
|
60
|
+
shortcuts: "Additional apps"
|
|
62
61
|
}
|
|
63
62
|
};
|
|
64
63
|
var fr = {
|
|
@@ -90,19 +89,19 @@ var fr = {
|
|
|
90
89
|
telecom: "Mobile",
|
|
91
90
|
transport: "Voyage et transport",
|
|
92
91
|
pro: "Travail",
|
|
93
|
-
shortcuts: "
|
|
92
|
+
shortcuts: "App suppl\xE9mentaires"
|
|
94
93
|
},
|
|
95
94
|
sections: {
|
|
96
95
|
applications: "Applications",
|
|
97
96
|
konnectors: "Services",
|
|
98
|
-
shortcuts: "
|
|
97
|
+
shortcuts: "App suppl\xE9mentaires"
|
|
99
98
|
}
|
|
100
99
|
};
|
|
101
100
|
import * as searchUtils from "cozy-ui/transpiled/react/AppSections/search";
|
|
102
101
|
import Typography from "cozy-ui/transpiled/react/Typography";
|
|
103
|
-
import
|
|
104
|
-
import {
|
|
105
|
-
import
|
|
102
|
+
import { useBreakpoints } from "cozy-ui/transpiled/react/providers/Breakpoints";
|
|
103
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
104
|
+
import withOnlyLocales from "cozy-ui/transpiled/react/providers/I18n/withOnlyLocales";
|
|
106
105
|
var locales = {
|
|
107
106
|
en: en,
|
|
108
107
|
fr: fr
|
|
@@ -291,7 +290,15 @@ var SectionsWrapper = function SectionsWrapper(props) {
|
|
|
291
290
|
var config = flag('store.alternative-source');
|
|
292
291
|
var i18nConfig = generateI18nConfig(config === null || config === void 0 ? void 0 : config.categories);
|
|
293
292
|
useExtendI18n(i18nConfig);
|
|
294
|
-
|
|
293
|
+
|
|
294
|
+
var _useI18n = useI18n(),
|
|
295
|
+
t = _useI18n.t;
|
|
296
|
+
|
|
297
|
+
var breakpoints = useBreakpoints();
|
|
298
|
+
return /*#__PURE__*/React.createElement(Sections, _extends({}, props, {
|
|
299
|
+
breakpoints: breakpoints,
|
|
300
|
+
t: t
|
|
301
|
+
}));
|
|
295
302
|
};
|
|
296
303
|
|
|
297
304
|
Sections.propTypes = {
|
|
@@ -334,5 +341,4 @@ Sections.defaultProps = {
|
|
|
334
341
|
})
|
|
335
342
|
})
|
|
336
343
|
};
|
|
337
|
-
export
|
|
338
|
-
export default withLocales(locales)(translate()(Untranslated));
|
|
344
|
+
export default withOnlyLocales(locales)(SectionsWrapper);
|
|
@@ -19,7 +19,7 @@ var fr = {
|
|
|
19
19
|
installed: "Install\xE9e",
|
|
20
20
|
maintenance: "En maintenance",
|
|
21
21
|
update: "Mise \xE0 jour dispo.",
|
|
22
|
-
favorite: "Ajout\xE9 sur
|
|
22
|
+
favorite: "Ajout\xE9 sur l'accueil"
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
var styles = {
|
|
@@ -36,7 +36,6 @@ import { ShortcutTile } from "cozy-ui/transpiled/react/ShortcutTile";
|
|
|
36
36
|
import Tile, { TileTitle, TileSubtitle, TileFooter, TileIcon, TileDescription } from "cozy-ui/transpiled/react/Tile";
|
|
37
37
|
import palette from "cozy-ui/transpiled/react/palette";
|
|
38
38
|
import { AppDoctype } from "cozy-ui/transpiled/react/proptypes";
|
|
39
|
-
import useBreakpoints from "cozy-ui/transpiled/react/providers/Breakpoints";
|
|
40
39
|
import { createUseI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
41
40
|
var locales = {
|
|
42
41
|
en: en,
|
|
@@ -60,8 +59,6 @@ var getAppIconProps = function getAppIconProps() {
|
|
|
60
59
|
|
|
61
60
|
var useI18n = createUseI18n(locales);
|
|
62
61
|
export var AppTile = function AppTile(_ref) {
|
|
63
|
-
var _app$metadata;
|
|
64
|
-
|
|
65
62
|
var app = _ref.app,
|
|
66
63
|
nameProp = _ref.name,
|
|
67
64
|
namePrefix = _ref.namePrefix,
|
|
@@ -76,17 +73,12 @@ export var AppTile = function AppTile(_ref) {
|
|
|
76
73
|
|
|
77
74
|
var _app$developer = app.developer,
|
|
78
75
|
developer = _app$developer === void 0 ? {} : _app$developer;
|
|
79
|
-
|
|
80
|
-
var _useBreakpoints = useBreakpoints(),
|
|
81
|
-
isMobile = _useBreakpoints.isMobile;
|
|
82
|
-
|
|
83
76
|
var name = nameProp || app.name;
|
|
84
77
|
var statusLabel = getCurrentStatusLabel(app);
|
|
85
78
|
var isStatusArray = Array.isArray(showStatus);
|
|
86
|
-
var statusToDisplay = isShortcutFile(app) && statusLabel === APP_STATUS.installed
|
|
79
|
+
var statusToDisplay = isShortcutFile(app) && statusLabel === APP_STATUS.installed ? 'favorite' : isStatusArray ? showStatus.indexOf(statusLabel) > -1 && statusLabel : showStatus && statusLabel;
|
|
87
80
|
var IconComponent = IconComponentProp || AppIcon;
|
|
88
81
|
var isInMaintenanceWithSpecificDisplay = displaySpecificMaintenanceStyle && statusLabel === APP_STATUS.maintenance;
|
|
89
|
-
var tileSubtitle = isShortcutFile(app) ? (_app$metadata = app.metadata) === null || _app$metadata === void 0 ? void 0 : _app$metadata.source : developer.name;
|
|
90
82
|
return /*#__PURE__*/React.createElement(Tile, {
|
|
91
83
|
tag: "button",
|
|
92
84
|
type: "button",
|
|
@@ -107,7 +99,7 @@ export var AppTile = function AppTile(_ref) {
|
|
|
107
99
|
className: styles["AppTile-description"]
|
|
108
100
|
}, /*#__PURE__*/React.createElement(TileTitle, {
|
|
109
101
|
isMultiline: !statusLabel
|
|
110
|
-
}, namePrefix ? "".concat(namePrefix, " ").concat(name) : name), showDeveloper && /*#__PURE__*/React.createElement(TileSubtitle, null, "".concat(t('app_item.by'), " ").concat(
|
|
102
|
+
}, namePrefix ? "".concat(namePrefix, " ").concat(name) : name), developer.name && showDeveloper && /*#__PURE__*/React.createElement(TileSubtitle, null, "".concat(t('app_item.by'), " ").concat(developer.name)), statusToDisplay && /*#__PURE__*/React.createElement(TileFooter, {
|
|
111
103
|
isAccent: statusLabel === APP_STATUS.update
|
|
112
104
|
}, t("app_item.".concat(statusToDisplay)))));
|
|
113
105
|
};
|
|
@@ -126,6 +126,7 @@ export var defaultBottomSheetSpringConfig = {
|
|
|
126
126
|
var defaultSettings = {
|
|
127
127
|
mediumHeightRatio: 0.75,
|
|
128
128
|
mediumHeight: null,
|
|
129
|
+
hasMinHeightOffset: false,
|
|
129
130
|
isOpenMin: false
|
|
130
131
|
};
|
|
131
132
|
var BottomSheet = /*#__PURE__*/memo(function (_ref3) {
|
|
@@ -140,7 +141,8 @@ var BottomSheet = /*#__PURE__*/memo(function (_ref3) {
|
|
|
140
141
|
var _defaultSettings$sett = _objectSpread(_objectSpread({}, defaultSettings), settings),
|
|
141
142
|
mediumHeightRatio = _defaultSettings$sett.mediumHeightRatio,
|
|
142
143
|
mediumHeight = _defaultSettings$sett.mediumHeight,
|
|
143
|
-
isOpenMin = _defaultSettings$sett.isOpenMin
|
|
144
|
+
isOpenMin = _defaultSettings$sett.isOpenMin,
|
|
145
|
+
hasMinHeightOffset = _defaultSettings$sett.hasMinHeightOffset;
|
|
144
146
|
|
|
145
147
|
var innerContentRef = useRef();
|
|
146
148
|
var headerRef = useRef();
|
|
@@ -269,6 +271,7 @@ var BottomSheet = /*#__PURE__*/memo(function (_ref3) {
|
|
|
269
271
|
isClosable: isClosable,
|
|
270
272
|
isOpenMin: isOpenMin,
|
|
271
273
|
headerRef: headerRef,
|
|
274
|
+
offset: hasMinHeightOffset ? offset : 0,
|
|
272
275
|
actionButtonsHeight: actionButtonsHeight,
|
|
273
276
|
actionButtonsBottomMargin: actionButtonsBottomMargin
|
|
274
277
|
});
|
|
@@ -409,6 +412,9 @@ BottomSheet.propTypes = {
|
|
|
409
412
|
/** Height of the middle snap point, expressed as a percentage of the viewport height */
|
|
410
413
|
mediumHeightRatio: PropTypes.number,
|
|
411
414
|
|
|
415
|
+
/** To include the offset in the min height value */
|
|
416
|
+
hasMinHeightOffset: PropTypes.bool,
|
|
417
|
+
|
|
412
418
|
/** To open the BottomSheet at the minimum height, if have an header */
|
|
413
419
|
isOpenMin: PropTypes.bool
|
|
414
420
|
}),
|
|
@@ -45,10 +45,12 @@ export var computeMinHeight = function computeMinHeight(_ref2) {
|
|
|
45
45
|
var isClosable = _ref2.isClosable,
|
|
46
46
|
isOpenMin = _ref2.isOpenMin,
|
|
47
47
|
headerRef = _ref2.headerRef,
|
|
48
|
+
_ref2$offset = _ref2.offset,
|
|
49
|
+
offset = _ref2$offset === void 0 ? 0 : _ref2$offset,
|
|
48
50
|
actionButtonsHeight = _ref2.actionButtonsHeight,
|
|
49
51
|
actionButtonsBottomMargin = _ref2.actionButtonsBottomMargin;
|
|
50
52
|
if (isClosable && !isOpenMin) return 0;
|
|
51
|
-
return headerRef.current.offsetHeight + actionButtonsHeight + actionButtonsBottomMargin + (getFlagshipMetadata().navbarHeight || 0) + getSafeAreaValue('bottom');
|
|
53
|
+
return headerRef.current.offsetHeight + offset + actionButtonsHeight + actionButtonsBottomMargin + (getFlagshipMetadata().navbarHeight || 0) + getSafeAreaValue('bottom');
|
|
52
54
|
};
|
|
53
55
|
export var makeOverridenChildren = function makeOverridenChildren(children, headerContentRef) {
|
|
54
56
|
return React.Children.map(children, function (child) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
export default {
|
|
3
|
-
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
3
|
+
size: PropTypes.oneOf(['small', 'medium', 'large', 'full']),
|
|
4
4
|
open: PropTypes.bool.isRequired,
|
|
5
5
|
disableTitleAutoPadding: PropTypes.bool,
|
|
6
6
|
background: PropTypes.string,
|
|
@@ -13,7 +13,7 @@ import DialogTransition from "cozy-ui/transpiled/react/CozyDialogs/DialogTransit
|
|
|
13
13
|
import useBreakpoints from "cozy-ui/transpiled/react/providers/Breakpoints";
|
|
14
14
|
import { makeStyles } from "cozy-ui/transpiled/react/styles";
|
|
15
15
|
var globalId = 0;
|
|
16
|
-
var modalSizes = ['small', 'medium', 'large'];
|
|
16
|
+
var modalSizes = ['small', 'medium', 'large', 'full'];
|
|
17
17
|
var useStyles = makeStyles({
|
|
18
18
|
paper: {
|
|
19
19
|
background: function background(_ref) {
|
|
@@ -97,25 +97,30 @@ var useCozyDialog = function useCozyDialog(props) {
|
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
var dividerClassName = 'divider--dialog';
|
|
100
|
-
|
|
100
|
+
|
|
101
|
+
var dividerProps = _objectSpread(_objectSpread({}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.divider), {}, {
|
|
101
102
|
classes: {
|
|
102
103
|
root: dividerClassName
|
|
103
104
|
}
|
|
104
|
-
};
|
|
105
|
+
});
|
|
106
|
+
|
|
105
107
|
var dialogActionsClassName = 'cozyDialogActions';
|
|
106
|
-
|
|
108
|
+
|
|
109
|
+
var dialogActionsProps = _objectSpread(_objectSpread({}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.dialogActions), {}, {
|
|
107
110
|
classes: {
|
|
108
111
|
root: dialogActionsClassName
|
|
109
112
|
}
|
|
110
|
-
};
|
|
111
|
-
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
var dialogContentProps = _objectSpread(_objectSpread({}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.dialogContent), {}, {
|
|
112
116
|
classes: {
|
|
113
117
|
root: cx({
|
|
114
118
|
disableGutters: disableGutters
|
|
115
119
|
})
|
|
116
120
|
},
|
|
117
121
|
className: 'cozyDialogContent'
|
|
118
|
-
};
|
|
122
|
+
});
|
|
123
|
+
|
|
119
124
|
return {
|
|
120
125
|
dialogProps: dialogProps,
|
|
121
126
|
dialogTitleProps: dialogTitleProps,
|
|
@@ -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
|
|
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
|
|
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:
|
|
46
|
+
height: function height(_ref) {
|
|
47
|
+
var size = _ref.size;
|
|
48
|
+
return sizeToPixel[size];
|
|
49
|
+
},
|
|
32
50
|
flex: 1,
|
|
33
|
-
borderRadius:
|
|
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 (
|
|
128
|
+
var SearchBar = /*#__PURE__*/forwardRef(function (_ref5, ref) {
|
|
90
129
|
var _cx;
|
|
91
130
|
|
|
92
|
-
var placeholderProp =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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('
|
|
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(
|
|
120
|
-
return onChange(event);
|
|
121
|
-
}, 375);
|
|
172
|
+
return debounce(onChange, 375);
|
|
122
173
|
}, [onChange]);
|
|
123
174
|
|
|
124
175
|
var handleChange = function handleChange(ev) {
|
|
125
|
-
|
|
176
|
+
if (!isSelfControlledComp) return onChange(ev);
|
|
177
|
+
var _value = ev.target.value;
|
|
126
178
|
|
|
127
|
-
if (
|
|
179
|
+
if (_value.length >= 1) {
|
|
128
180
|
delayedOnChange(ev);
|
|
129
|
-
setCurrentValue(
|
|
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(
|
|
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:
|
|
162
|
-
}), /*#__PURE__*/React.createElement(
|
|
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 :
|
|
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
|
-
}),
|
|
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
|
-
|
|
277
|
+
|
|
278
|
+
var SearchBarWithLocales = function SearchBarWithLocales(props) {
|
|
279
|
+
useExtendI18n(locales);
|
|
280
|
+
return /*#__PURE__*/React.createElement(SearchBar, props);
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export default SearchBarWithLocales;
|