cozy-ui 103.12.0 → 104.0.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 +46 -0
- package/package.json +1 -1
- package/react/Alert/index.jsx +25 -1
- package/react/Empty/Readme.md +1 -1
- package/react/Icon/Readme.md +0 -1
- package/react/Paywall/howto.md +2 -0
- package/react/Viewer/Panel/ActionMenuWrapper.jsx +14 -7
- package/react/Viewer/Readme.md +0 -1
- package/react/Viewer/ViewerContainer.jsx +3 -5
- package/react/Viewer/ViewersByFile/PdfMobileViewer.jsx +6 -1
- package/react/deprecated/readme.md +1 -1
- package/react/legacy/readme.md +1 -1
- package/react/providers/Alert/Readme.md +41 -4
- package/react/providers/Alert/index.jsx +27 -7
- package/react/providers/Readme.md +1 -1
- package/transpiled/react/Alert/index.js +32 -5
- package/transpiled/react/Viewer/Panel/ActionMenuWrapper.js +15 -5
- package/transpiled/react/Viewer/ViewerContainer.js +3 -4
- package/transpiled/react/Viewer/ViewersByFile/PdfMobileViewer.js +6 -1
- package/transpiled/react/providers/Alert/index.js +32 -11
- package/react/Viewer/providers/ViewerSnackbarProvider.jsx +0 -64
- package/react/Viewer/snackbar/ViewerSnackbar.jsx +0 -30
- package/transpiled/react/Viewer/providers/ViewerSnackbarProvider.js +0 -73
- package/transpiled/react/Viewer/snackbar/ViewerSnackbar.js +0 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
+
# [104.0.0](https://github.com/cozy/cozy-ui/compare/v103.12.0...v104.0.0) (2024-03-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Color & square props are ignored ([c37ad2f](https://github.com/cozy/cozy-ui/commit/c37ad2f)), closes [/github.com/mui/material-ui/blob/bda562b435a70e3e8f6d7fb04581c6816a5ba0c7/packages/material-ui/src/Snackbar/Snackbar.js#L235](https://github.com//github.com/mui/material-ui/blob/bda562b435a70e3e8f6d7fb04581c6816a5ba0c7/packages/material-ui/src/Snackbar/Snackbar.js/issues/L235) [#L193](https://github.com/cozy/cozy-ui/issues/L193)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add typedef to Alert component ([16f2097](https://github.com/cozy/cozy-ui/commit/16f2097))
|
|
12
|
+
* Improve AlertProvider ([723a627](https://github.com/cozy/cozy-ui/commit/723a627))
|
|
13
|
+
* Replace ViewerSnackbarProvider by AlertProvider ([374537a](https://github.com/cozy/cozy-ui/commit/374537a))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* The `showAlert` function returned by the `useAlert` hook changes signature.
|
|
19
|
+
|
|
20
|
+
Also, the `variant` was set to `filled`,
|
|
21
|
+
it now takes the default value of `Alert`, i.e. `standard`.
|
|
22
|
+
|
|
23
|
+
Before:
|
|
24
|
+
```
|
|
25
|
+
const { showAlert } = useAlert()
|
|
26
|
+
showAlert(t('foo.bar'), 'error',)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Now:
|
|
30
|
+
```
|
|
31
|
+
const { showAlert } = useAlert()
|
|
32
|
+
showAlert({ message: t('foo.bar'), severity: 'error' })
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Its options now support Alert component props.
|
|
36
|
+
Example:
|
|
37
|
+
```
|
|
38
|
+
showAlert({
|
|
39
|
+
message: t('foo.bar'),
|
|
40
|
+
severity: 'info',
|
|
41
|
+
icon: [secure],
|
|
42
|
+
color: 'blue',
|
|
43
|
+
square: true
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
1
47
|
# [103.12.0](https://github.com/cozy/cozy-ui/compare/v103.11.1...v103.12.0) (2024-03-07)
|
|
2
48
|
|
|
3
49
|
|
package/package.json
CHANGED
package/react/Alert/index.jsx
CHANGED
|
@@ -52,6 +52,7 @@ const Alert = forwardRef(
|
|
|
52
52
|
square,
|
|
53
53
|
action,
|
|
54
54
|
variant,
|
|
55
|
+
style,
|
|
55
56
|
children,
|
|
56
57
|
...props
|
|
57
58
|
},
|
|
@@ -65,10 +66,22 @@ const Alert = forwardRef(
|
|
|
65
66
|
const iconSize = icon?.props?.size || DEFAULT_ICON_SIZE
|
|
66
67
|
const styles = useStyles({ iconSize, block })
|
|
67
68
|
|
|
69
|
+
/*
|
|
70
|
+
When this component is the child of Snackbar, MUI injects a `style` prop
|
|
71
|
+
(https://github.com/mui/material-ui/blob/bda562b435a70e3e8f6d7fb04581c6816a5ba0c7/packages/material-ui/src/Snackbar/Snackbar.js#L235
|
|
72
|
+
=>
|
|
73
|
+
https://github.com/mui/material-ui/blob/1e80616d3dde536227af56d49f91b28f830bd33c/packages/mui-material/src/Grow/Grow.js #L193), our styles are overwritten.
|
|
74
|
+
*/
|
|
75
|
+
const computedStyles = {
|
|
76
|
+
backgroundColor: color,
|
|
77
|
+
borderRadius: square && 0,
|
|
78
|
+
...style
|
|
79
|
+
}
|
|
80
|
+
|
|
68
81
|
return (
|
|
69
82
|
<MuiAlert
|
|
70
83
|
ref={ref}
|
|
71
|
-
style={
|
|
84
|
+
style={computedStyles}
|
|
72
85
|
className={cx(
|
|
73
86
|
className,
|
|
74
87
|
`cozyStyles-${severity}-${variant}`,
|
|
@@ -91,6 +104,17 @@ const Alert = forwardRef(
|
|
|
91
104
|
|
|
92
105
|
Alert.displayName = 'Alert'
|
|
93
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @typedef {Object} AlertProps
|
|
109
|
+
* @property {string} className - Classname of the alert
|
|
110
|
+
* @property {React.FC<PropTypes.InferProps<typeof Icon.propTypes>>|false} icon - Icon component to display in the alert (or false to hide it)
|
|
111
|
+
* @property {'primary'|'secondary'|'success'|'error'|'warning'|'info'} severity - Severity of the alert (default: primary)
|
|
112
|
+
* @property {boolean} block - Block the alert to the full width of its container (default: false)
|
|
113
|
+
* @property {string} color - Background color of the alert
|
|
114
|
+
* @property {boolean} square - Square the alert corners (default: false)
|
|
115
|
+
* @property {'standard'|'outlined'|'filled'} variant - Variant of the alert (default: standard)
|
|
116
|
+
*/
|
|
117
|
+
|
|
94
118
|
export const AlertPropTypes = {
|
|
95
119
|
className: PropTypes.string,
|
|
96
120
|
icon: PropTypes.oneOfType([PropTypes.element, PropTypes.bool]),
|
package/react/Empty/Readme.md
CHANGED
package/react/Icon/Readme.md
CHANGED
|
@@ -7,7 +7,6 @@ to load your SVG (either explicitly or, better, implicitly in your `webpack.conf
|
|
|
7
7
|
|
|
8
8
|
Be aware that Icon forwards unknown props to the underlying `<svg />` element, such as onClick prop.
|
|
9
9
|
|
|
10
|
-
|
|
11
10
|
```jsx
|
|
12
11
|
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
13
12
|
import People from 'cozy-ui/transpiled/react/Icons/People'
|
package/react/Paywall/howto.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
A new variant is essentially a set of translations adapted to a specific context of use.
|
|
4
4
|
|
|
5
5
|
To create a new one, add your translation to the `src/react/Paywall/locales` directory. The translations for each case (default, premium or public) are grouped together under the name of your variant. A case includes a title, content and a label for the action.
|
|
6
|
+
|
|
6
7
|
```static
|
|
7
8
|
"variantNamePaywall": {
|
|
8
9
|
"premium": {
|
|
@@ -15,6 +16,7 @@ To create a new one, add your translation to the `src/react/Paywall/locales` dir
|
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
Next, we create a new component returning the `Paywall`, specifying the name of the new variant. You can also use `contentInterpolation` to insert variables into the content translation.
|
|
19
|
+
|
|
18
20
|
```js static
|
|
19
21
|
<Paywall
|
|
20
22
|
variant="variantName"
|
|
@@ -5,7 +5,7 @@ import { useAppLinkWithStoreFallback, useClient } from 'cozy-client'
|
|
|
5
5
|
|
|
6
6
|
import useBreakpoints from '../../providers/Breakpoints'
|
|
7
7
|
import { useI18n } from '../../providers/I18n'
|
|
8
|
-
import
|
|
8
|
+
import { useAlert } from '../../providers/Alert'
|
|
9
9
|
import {
|
|
10
10
|
buildEditAttributePath,
|
|
11
11
|
isEditableAttribute,
|
|
@@ -22,7 +22,7 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
|
|
|
22
22
|
const editPathByModelProps = useActionMenuContext()
|
|
23
23
|
const { isMobile } = useBreakpoints()
|
|
24
24
|
const { t } = useI18n()
|
|
25
|
-
const {
|
|
25
|
+
const { showAlert } = useAlert()
|
|
26
26
|
const client = useClient()
|
|
27
27
|
|
|
28
28
|
const currentModel = getCurrentModel(name)
|
|
@@ -42,12 +42,19 @@ const ActionMenuWrapper = forwardRef(({ onClose, file, optionFile }, ref) => {
|
|
|
42
42
|
const handleCopy = async () => {
|
|
43
43
|
try {
|
|
44
44
|
await navigator.clipboard.writeText(value)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
showAlert({
|
|
46
|
+
message: t(`Viewer.snackbar.copiedToClipboard.success`),
|
|
47
|
+
severity: 'success',
|
|
48
|
+
variant: 'filled',
|
|
49
|
+
icon: false
|
|
50
|
+
})
|
|
49
51
|
} catch (error) {
|
|
50
|
-
|
|
52
|
+
showAlert({
|
|
53
|
+
message: t(`Viewer.snackbar.copiedToClipboard.error`),
|
|
54
|
+
severity: 'error',
|
|
55
|
+
variant: 'filled',
|
|
56
|
+
icon: false
|
|
57
|
+
})
|
|
51
58
|
}
|
|
52
59
|
onClose()
|
|
53
60
|
}
|
package/react/Viewer/Readme.md
CHANGED
|
@@ -38,7 +38,6 @@ The `Viewer` can display an **information panel** to show additional information
|
|
|
38
38
|
* **showClose** : `<boolean>` – Whether to show close button in toolbar
|
|
39
39
|
* **showFilePath** : `<boolean>` – Whether to show file path below his name
|
|
40
40
|
|
|
41
|
-
|
|
42
41
|
### Demo
|
|
43
42
|
|
|
44
43
|
```jsx
|
|
@@ -12,8 +12,7 @@ import { isValidForPanel } from './helpers'
|
|
|
12
12
|
import Viewer from './Viewer'
|
|
13
13
|
import ViewerInformationsWrapper from './ViewerInformationsWrapper'
|
|
14
14
|
import EncryptedProvider from './providers/EncryptedProvider'
|
|
15
|
-
import
|
|
16
|
-
import ViewerSnackbar from './snackbar/ViewerSnackbar'
|
|
15
|
+
import AlertProvider from '../providers/Alert'
|
|
17
16
|
import { ActionMenuProvider } from './providers/ActionMenuProvider'
|
|
18
17
|
|
|
19
18
|
import styles from './styles.styl'
|
|
@@ -49,7 +48,7 @@ const ViewerContainer = props => {
|
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
return (
|
|
52
|
-
<
|
|
51
|
+
<AlertProvider>
|
|
53
52
|
<ActionMenuProvider editPathByModelProps={editPathByModelProps}>
|
|
54
53
|
<div
|
|
55
54
|
id="viewer-wrapper"
|
|
@@ -76,9 +75,8 @@ const ViewerContainer = props => {
|
|
|
76
75
|
{children}
|
|
77
76
|
</ViewerInformationsWrapper>
|
|
78
77
|
</div>
|
|
79
|
-
<ViewerSnackbar />
|
|
80
78
|
</ActionMenuProvider>
|
|
81
|
-
</
|
|
79
|
+
</AlertProvider>
|
|
82
80
|
)
|
|
83
81
|
}
|
|
84
82
|
|
|
@@ -36,7 +36,12 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => {
|
|
|
36
36
|
try {
|
|
37
37
|
await client.collection('io.cozy.files').download(file)
|
|
38
38
|
} catch (error) {
|
|
39
|
-
showAlert(
|
|
39
|
+
showAlert({
|
|
40
|
+
message: t('Viewer.error.generic'),
|
|
41
|
+
severity: 'error',
|
|
42
|
+
variant: 'filled',
|
|
43
|
+
icon: false
|
|
44
|
+
})
|
|
40
45
|
}
|
|
41
46
|
},
|
|
42
47
|
[client, showAlert, t]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<!-- For styleguidist, a .md file is needed in directories -->
|
|
1
|
+
<!-- For styleguidist, a .md file is needed in directories -->
|
package/react/legacy/readme.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!-- For styleguidist, a .md file is needed in directories -->
|
|
1
|
+
<!-- For styleguidist, a .md file is needed in directories -->
|
|
@@ -3,23 +3,60 @@ import Variants from 'cozy-ui/docs/components/Variants'
|
|
|
3
3
|
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
|
|
4
4
|
import AlertProvider, { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
|
|
5
5
|
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
6
|
+
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
7
|
+
import DeviceLaptopIcon from 'cozy-ui/transpiled/react/Icons/DeviceLaptop'
|
|
6
8
|
|
|
7
|
-
const initialVariants = [{
|
|
9
|
+
const initialVariants = [{
|
|
10
|
+
title: false,
|
|
11
|
+
block: false,
|
|
12
|
+
color: false,
|
|
13
|
+
largeIcon: false,
|
|
14
|
+
noIcon: false,
|
|
15
|
+
square: false,
|
|
16
|
+
filled: false,
|
|
17
|
+
outlined: false,
|
|
18
|
+
close: true
|
|
19
|
+
}]
|
|
8
20
|
|
|
9
21
|
const Component = ({ variant }) => {
|
|
10
22
|
const { showAlert } = useAlert()
|
|
11
23
|
|
|
12
|
-
return
|
|
24
|
+
return (
|
|
25
|
+
<Button
|
|
26
|
+
label="show alert"
|
|
27
|
+
onClick={() =>
|
|
28
|
+
showAlert({
|
|
29
|
+
title: variant.title ? 'Alert title' : undefined,
|
|
30
|
+
severity: 'success',
|
|
31
|
+
message: 'Alert message',
|
|
32
|
+
color: variant.color ? "#EFA82D" : undefined,
|
|
33
|
+
variant: variant.filled
|
|
34
|
+
? 'filled'
|
|
35
|
+
: variant.outlined
|
|
36
|
+
? 'outlined'
|
|
37
|
+
: undefined,
|
|
38
|
+
block: variant.block,
|
|
39
|
+
square: variant.square,
|
|
40
|
+
icon: variant.noIcon
|
|
41
|
+
? false
|
|
42
|
+
: variant.largeIcon
|
|
43
|
+
? <Icon icon={DeviceLaptopIcon} color="var(--errorColor)" size={32} />
|
|
44
|
+
: undefined,
|
|
45
|
+
onClose: variant.close ? () => {} : undefined
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
13
50
|
}
|
|
14
51
|
|
|
15
52
|
;
|
|
16
53
|
|
|
17
54
|
<BreakpointsProvider>
|
|
18
55
|
<AlertProvider>
|
|
19
|
-
<Variants initialVariants={initialVariants}
|
|
56
|
+
<Variants initialVariants={initialVariants}>
|
|
20
57
|
{variant => (
|
|
21
58
|
<>
|
|
22
|
-
<Component variant={
|
|
59
|
+
<Component variant={variant} />
|
|
23
60
|
</>
|
|
24
61
|
)}
|
|
25
62
|
</Variants>
|
|
@@ -2,9 +2,21 @@ import React, { createContext, useState, useContext, useMemo } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import Snackbar from '../../Snackbar'
|
|
4
4
|
import Alert from '../../Alert'
|
|
5
|
+
import AlertTitle from '../../AlertTitle'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {import('../../Alert').AlertProps & { message: string, title: string }} ShowAlertArgs
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {object} UseAlertReturn
|
|
12
|
+
* @property {(args: ShowAlertArgs) => void} showAlert
|
|
13
|
+
*/
|
|
5
14
|
|
|
6
15
|
export const AlertContext = createContext()
|
|
7
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @returns {UseAlertReturn}
|
|
19
|
+
*/
|
|
8
20
|
export const useAlert = () => {
|
|
9
21
|
const context = useContext(AlertContext)
|
|
10
22
|
|
|
@@ -14,18 +26,26 @@ export const useAlert = () => {
|
|
|
14
26
|
return context
|
|
15
27
|
}
|
|
16
28
|
|
|
17
|
-
const defaultState = {
|
|
29
|
+
const defaultState = {
|
|
30
|
+
title: '',
|
|
31
|
+
message: '',
|
|
32
|
+
open: false
|
|
33
|
+
}
|
|
18
34
|
const handleClose = (state, setState) => () => {
|
|
19
35
|
return setState({ ...state, open: false })
|
|
20
36
|
}
|
|
21
37
|
|
|
22
38
|
const AlertProvider = ({ children }) => {
|
|
23
39
|
const [state, setState] = useState(defaultState)
|
|
40
|
+
const { open, message, title, ...alertProps } = state
|
|
24
41
|
|
|
25
42
|
const value = useMemo(
|
|
26
43
|
() => ({
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
/**
|
|
45
|
+
* @param {ShowAlertArgs} args
|
|
46
|
+
*/
|
|
47
|
+
showAlert: args => {
|
|
48
|
+
setState({ open: true, ...args })
|
|
29
49
|
}
|
|
30
50
|
}),
|
|
31
51
|
[]
|
|
@@ -34,14 +54,14 @@ const AlertProvider = ({ children }) => {
|
|
|
34
54
|
return (
|
|
35
55
|
<AlertContext.Provider value={value}>
|
|
36
56
|
{children}
|
|
37
|
-
<Snackbar open={
|
|
57
|
+
<Snackbar open={open} onClose={handleClose(state, setState)}>
|
|
38
58
|
<Alert
|
|
39
|
-
variant="filled"
|
|
40
59
|
elevation={6}
|
|
41
|
-
severity={state.severity}
|
|
42
60
|
onClose={handleClose(state, setState)}
|
|
61
|
+
{...alertProps}
|
|
43
62
|
>
|
|
44
|
-
{
|
|
63
|
+
{title && <AlertTitle>{title}</AlertTitle>}
|
|
64
|
+
{message}
|
|
45
65
|
</Alert>
|
|
46
66
|
</Snackbar>
|
|
47
67
|
</AlertContext.Provider>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<!-- For styleguidist, a .md file is needed in directories -->
|
|
1
|
+
<!-- For styleguidist, a .md file is needed in directories -->
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["className", "classes", "icon", "severity", "block", "color", "square", "action", "variant", "children"];
|
|
4
|
+
var _excluded = ["className", "classes", "icon", "severity", "block", "color", "square", "action", "variant", "style", "children"];
|
|
5
|
+
|
|
6
|
+
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; }
|
|
7
|
+
|
|
8
|
+
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; }
|
|
9
|
+
|
|
4
10
|
import React, { forwardRef } from 'react';
|
|
5
11
|
import PropTypes from 'prop-types';
|
|
6
12
|
import cx from 'classnames';
|
|
@@ -60,6 +66,7 @@ var Alert = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
60
66
|
square = _ref2.square,
|
|
61
67
|
action = _ref2.action,
|
|
62
68
|
variant = _ref2.variant,
|
|
69
|
+
style = _ref2.style,
|
|
63
70
|
children = _ref2.children,
|
|
64
71
|
props = _objectWithoutProperties(_ref2, _excluded);
|
|
65
72
|
|
|
@@ -71,12 +78,21 @@ var Alert = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
71
78
|
iconSize: iconSize,
|
|
72
79
|
block: block
|
|
73
80
|
});
|
|
81
|
+
/*
|
|
82
|
+
When this component is the child of Snackbar, MUI injects a `style` prop
|
|
83
|
+
(https://github.com/mui/material-ui/blob/bda562b435a70e3e8f6d7fb04581c6816a5ba0c7/packages/material-ui/src/Snackbar/Snackbar.js#L235
|
|
84
|
+
=>
|
|
85
|
+
https://github.com/mui/material-ui/blob/1e80616d3dde536227af56d49f91b28f830bd33c/packages/mui-material/src/Grow/Grow.js #L193), our styles are overwritten.
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
var computedStyles = _objectSpread({
|
|
89
|
+
backgroundColor: color,
|
|
90
|
+
borderRadius: square && 0
|
|
91
|
+
}, style);
|
|
92
|
+
|
|
74
93
|
return /*#__PURE__*/React.createElement(MuiAlert, _extends({
|
|
75
94
|
ref: ref,
|
|
76
|
-
style:
|
|
77
|
-
backgroundColor: color,
|
|
78
|
-
borderRadius: square && 0
|
|
79
|
-
},
|
|
95
|
+
style: computedStyles,
|
|
80
96
|
className: cx(className, "cozyStyles-".concat(severity, "-").concat(variant), {
|
|
81
97
|
block: block
|
|
82
98
|
}, {
|
|
@@ -91,6 +107,17 @@ var Alert = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
91
107
|
}, props), children);
|
|
92
108
|
});
|
|
93
109
|
Alert.displayName = 'Alert';
|
|
110
|
+
/**
|
|
111
|
+
* @typedef {Object} AlertProps
|
|
112
|
+
* @property {string} className - Classname of the alert
|
|
113
|
+
* @property {React.FC<PropTypes.InferProps<typeof Icon.propTypes>>|false} icon - Icon component to display in the alert (or false to hide it)
|
|
114
|
+
* @property {'primary'|'secondary'|'success'|'error'|'warning'|'info'} severity - Severity of the alert (default: primary)
|
|
115
|
+
* @property {boolean} block - Block the alert to the full width of its container (default: false)
|
|
116
|
+
* @property {string} color - Background color of the alert
|
|
117
|
+
* @property {boolean} square - Square the alert corners (default: false)
|
|
118
|
+
* @property {'standard'|'outlined'|'filled'} variant - Variant of the alert (default: standard)
|
|
119
|
+
*/
|
|
120
|
+
|
|
94
121
|
export var AlertPropTypes = {
|
|
95
122
|
className: PropTypes.string,
|
|
96
123
|
icon: PropTypes.oneOfType([PropTypes.element, PropTypes.bool]),
|
|
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
|
|
|
5
5
|
import { useAppLinkWithStoreFallback, useClient } from 'cozy-client';
|
|
6
6
|
import useBreakpoints from "cozy-ui/transpiled/react/providers/Breakpoints";
|
|
7
7
|
import { useI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
8
|
-
import
|
|
8
|
+
import { useAlert } from "cozy-ui/transpiled/react/providers/Alert";
|
|
9
9
|
import { buildEditAttributePath, isEditableAttribute, getCurrentModel } from "cozy-ui/transpiled/react/Viewer/helpers";
|
|
10
10
|
import useActionMenuContext from "cozy-ui/transpiled/react/Viewer/providers/ActionMenuProvider";
|
|
11
11
|
import ActionMenuMobile from "cozy-ui/transpiled/react/Viewer/Panel/ActionMenuMobile";
|
|
@@ -25,8 +25,8 @@ var ActionMenuWrapper = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
25
25
|
var _useI18n = useI18n(),
|
|
26
26
|
t = _useI18n.t;
|
|
27
27
|
|
|
28
|
-
var
|
|
29
|
-
|
|
28
|
+
var _useAlert = useAlert(),
|
|
29
|
+
showAlert = _useAlert.showAlert;
|
|
30
30
|
|
|
31
31
|
var client = useClient();
|
|
32
32
|
var currentModel = getCurrentModel(name);
|
|
@@ -49,14 +49,24 @@ var ActionMenuWrapper = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
49
49
|
return navigator.clipboard.writeText(value);
|
|
50
50
|
|
|
51
51
|
case 3:
|
|
52
|
-
|
|
52
|
+
showAlert({
|
|
53
|
+
message: t("Viewer.snackbar.copiedToClipboard.success"),
|
|
54
|
+
severity: 'success',
|
|
55
|
+
variant: 'filled',
|
|
56
|
+
icon: false
|
|
57
|
+
});
|
|
53
58
|
_context.next = 9;
|
|
54
59
|
break;
|
|
55
60
|
|
|
56
61
|
case 6:
|
|
57
62
|
_context.prev = 6;
|
|
58
63
|
_context.t0 = _context["catch"](0);
|
|
59
|
-
|
|
64
|
+
showAlert({
|
|
65
|
+
message: t("Viewer.snackbar.copiedToClipboard.error"),
|
|
66
|
+
severity: 'error',
|
|
67
|
+
variant: 'filled',
|
|
68
|
+
icon: false
|
|
69
|
+
});
|
|
60
70
|
|
|
61
71
|
case 9:
|
|
62
72
|
onClose();
|
|
@@ -20,8 +20,7 @@ import { isValidForPanel } from "cozy-ui/transpiled/react/Viewer/helpers";
|
|
|
20
20
|
import Viewer from "cozy-ui/transpiled/react/Viewer/Viewer";
|
|
21
21
|
import ViewerInformationsWrapper from "cozy-ui/transpiled/react/Viewer/ViewerInformationsWrapper";
|
|
22
22
|
import EncryptedProvider from "cozy-ui/transpiled/react/Viewer/providers/EncryptedProvider";
|
|
23
|
-
import
|
|
24
|
-
import ViewerSnackbar from "cozy-ui/transpiled/react/Viewer/snackbar/ViewerSnackbar";
|
|
23
|
+
import AlertProvider from "cozy-ui/transpiled/react/providers/Alert";
|
|
25
24
|
import { ActionMenuProvider } from "cozy-ui/transpiled/react/Viewer/providers/ActionMenuProvider";
|
|
26
25
|
var styles = {
|
|
27
26
|
"viewer-wrapper": "styles__viewer-wrapper___2GIXH",
|
|
@@ -61,7 +60,7 @@ var ViewerContainer = function ViewerContainer(props) {
|
|
|
61
60
|
}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.toolbarProps)
|
|
62
61
|
});
|
|
63
62
|
|
|
64
|
-
return /*#__PURE__*/React.createElement(
|
|
63
|
+
return /*#__PURE__*/React.createElement(AlertProvider, null, /*#__PURE__*/React.createElement(ActionMenuProvider, {
|
|
65
64
|
editPathByModelProps: editPathByModelProps
|
|
66
65
|
}, /*#__PURE__*/React.createElement("div", {
|
|
67
66
|
id: "viewer-wrapper",
|
|
@@ -81,7 +80,7 @@ var ViewerContainer = function ViewerContainer(props) {
|
|
|
81
80
|
validForPanel: validForPanel,
|
|
82
81
|
currentFile: currentFile,
|
|
83
82
|
toolbarRef: toolbarRef
|
|
84
|
-
}, children))
|
|
83
|
+
}, children))));
|
|
85
84
|
};
|
|
86
85
|
|
|
87
86
|
ViewerContainer.propTypes = {
|
|
@@ -76,7 +76,12 @@ export var PdfMobileViewer = function PdfMobileViewer(_ref) {
|
|
|
76
76
|
case 5:
|
|
77
77
|
_context.prev = 5;
|
|
78
78
|
_context.t0 = _context["catch"](0);
|
|
79
|
-
showAlert(
|
|
79
|
+
showAlert({
|
|
80
|
+
message: t('Viewer.error.generic'),
|
|
81
|
+
severity: 'error',
|
|
82
|
+
variant: 'filled',
|
|
83
|
+
icon: false
|
|
84
|
+
});
|
|
80
85
|
|
|
81
86
|
case 8:
|
|
82
87
|
case "end":
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
1
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
+
var _excluded = ["open", "message", "title"];
|
|
3
6
|
|
|
4
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; }
|
|
5
8
|
|
|
@@ -8,7 +11,21 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
8
11
|
import React, { createContext, useState, useContext, useMemo } from 'react';
|
|
9
12
|
import Snackbar from "cozy-ui/transpiled/react/Snackbar";
|
|
10
13
|
import Alert from "cozy-ui/transpiled/react/Alert";
|
|
14
|
+
import AlertTitle from "cozy-ui/transpiled/react/AlertTitle";
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {import('../../Alert').AlertProps & { message: string, title: string }} ShowAlertArgs
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {object} UseAlertReturn
|
|
21
|
+
* @property {(args: ShowAlertArgs) => void} showAlert
|
|
22
|
+
*/
|
|
23
|
+
|
|
11
24
|
export var AlertContext = /*#__PURE__*/createContext();
|
|
25
|
+
/**
|
|
26
|
+
* @returns {UseAlertReturn}
|
|
27
|
+
*/
|
|
28
|
+
|
|
12
29
|
export var useAlert = function useAlert() {
|
|
13
30
|
var context = useContext(AlertContext);
|
|
14
31
|
|
|
@@ -19,8 +36,8 @@ export var useAlert = function useAlert() {
|
|
|
19
36
|
return context;
|
|
20
37
|
};
|
|
21
38
|
var defaultState = {
|
|
39
|
+
title: '',
|
|
22
40
|
message: '',
|
|
23
|
-
severity: 'primary',
|
|
24
41
|
open: false
|
|
25
42
|
};
|
|
26
43
|
|
|
@@ -40,28 +57,32 @@ var AlertProvider = function AlertProvider(_ref) {
|
|
|
40
57
|
state = _useState2[0],
|
|
41
58
|
setState = _useState2[1];
|
|
42
59
|
|
|
60
|
+
var open = state.open,
|
|
61
|
+
message = state.message,
|
|
62
|
+
title = state.title,
|
|
63
|
+
alertProps = _objectWithoutProperties(state, _excluded);
|
|
64
|
+
|
|
43
65
|
var value = useMemo(function () {
|
|
44
66
|
return {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
67
|
+
/**
|
|
68
|
+
* @param {ShowAlertArgs} args
|
|
69
|
+
*/
|
|
70
|
+
showAlert: function showAlert(args) {
|
|
71
|
+
setState(_objectSpread({
|
|
49
72
|
open: true
|
|
50
|
-
});
|
|
73
|
+
}, args));
|
|
51
74
|
}
|
|
52
75
|
};
|
|
53
76
|
}, []);
|
|
54
77
|
return /*#__PURE__*/React.createElement(AlertContext.Provider, {
|
|
55
78
|
value: value
|
|
56
79
|
}, children, /*#__PURE__*/React.createElement(Snackbar, {
|
|
57
|
-
open:
|
|
80
|
+
open: open,
|
|
58
81
|
onClose: handleClose(state, setState)
|
|
59
|
-
}, /*#__PURE__*/React.createElement(Alert, {
|
|
60
|
-
variant: "filled",
|
|
82
|
+
}, /*#__PURE__*/React.createElement(Alert, _extends({
|
|
61
83
|
elevation: 6,
|
|
62
|
-
severity: state.severity,
|
|
63
84
|
onClose: handleClose(state, setState)
|
|
64
|
-
},
|
|
85
|
+
}, alertProps), title && /*#__PURE__*/React.createElement(AlertTitle, null, title), message)));
|
|
65
86
|
};
|
|
66
87
|
|
|
67
88
|
export default /*#__PURE__*/React.memo(AlertProvider);
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {('primary'|'secondary'|'success'|'error'|'warning'|'info')} enumSeverity
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {object} useViewerSnackbarReturn
|
|
8
|
-
* @property {boolean} isViewerSnackbarOpen
|
|
9
|
-
* @property {string} viewerSnackbarMessage
|
|
10
|
-
* @property {enumSeverity} viewerSnackbarSeverity
|
|
11
|
-
* @property {(severity: enumSeverity, message: string) => void} showViewerSnackbar
|
|
12
|
-
* @property {(message: string) => void} hideViewerSnackbar
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const ViewerSnackbarContext = createContext()
|
|
16
|
-
|
|
17
|
-
const ViewerSnackbarProvider = ({ children }) => {
|
|
18
|
-
const [isViewerSnackbarOpen, setIsViewerSnackbarOpen] = useState(false)
|
|
19
|
-
const [viewerSnackbarMessage, setViewerSnackbarMessage] = useState('')
|
|
20
|
-
const [viewerSnackbarSeverity, setViewerSnackbarSeverity] = useState(
|
|
21
|
-
'primary'
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const showViewerSnackbar = (severity, message) => {
|
|
25
|
-
setIsViewerSnackbarOpen(true)
|
|
26
|
-
setViewerSnackbarMessage(message)
|
|
27
|
-
setViewerSnackbarSeverity(severity)
|
|
28
|
-
}
|
|
29
|
-
const hideViewerSnackbar = () => {
|
|
30
|
-
setIsViewerSnackbarOpen(false)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const result = {
|
|
34
|
-
isViewerSnackbarOpen,
|
|
35
|
-
viewerSnackbarMessage,
|
|
36
|
-
viewerSnackbarSeverity,
|
|
37
|
-
showViewerSnackbar,
|
|
38
|
-
hideViewerSnackbar
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<ViewerSnackbarContext.Provider value={result}>
|
|
43
|
-
{children}
|
|
44
|
-
</ViewerSnackbarContext.Provider>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @returns {useViewerSnackbarReturn}
|
|
50
|
-
*/
|
|
51
|
-
const useViewerSnackbar = () => {
|
|
52
|
-
const viewerSnackbar = useContext(ViewerSnackbarContext)
|
|
53
|
-
if (!viewerSnackbar) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
'ViewerSnackbarContext must be used within a ViewerSnackbarProvider'
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return viewerSnackbar
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default useViewerSnackbar
|
|
63
|
-
|
|
64
|
-
export { ViewerSnackbarProvider }
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
|
|
3
|
-
import Snackbar from '../../Snackbar'
|
|
4
|
-
import Alert from '../../Alert'
|
|
5
|
-
import useViewerSnackbar from '../providers/ViewerSnackbarProvider'
|
|
6
|
-
|
|
7
|
-
const ViewerSnackbar = () => {
|
|
8
|
-
const {
|
|
9
|
-
isViewerSnackbarOpen,
|
|
10
|
-
viewerSnackbarMessage,
|
|
11
|
-
viewerSnackbarSeverity,
|
|
12
|
-
hideViewerSnackbar
|
|
13
|
-
} = useViewerSnackbar()
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<Snackbar open={isViewerSnackbarOpen} onClose={hideViewerSnackbar}>
|
|
17
|
-
<Alert
|
|
18
|
-
variant="filled"
|
|
19
|
-
elevation={6}
|
|
20
|
-
onClose={hideViewerSnackbar}
|
|
21
|
-
severity={viewerSnackbarSeverity}
|
|
22
|
-
icon={false}
|
|
23
|
-
>
|
|
24
|
-
{viewerSnackbarMessage}
|
|
25
|
-
</Alert>
|
|
26
|
-
</Snackbar>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default ViewerSnackbar
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import React, { createContext, useContext, useState } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {('primary'|'secondary'|'success'|'error'|'warning'|'info')} enumSeverity
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @typedef {object} useViewerSnackbarReturn
|
|
9
|
-
* @property {boolean} isViewerSnackbarOpen
|
|
10
|
-
* @property {string} viewerSnackbarMessage
|
|
11
|
-
* @property {enumSeverity} viewerSnackbarSeverity
|
|
12
|
-
* @property {(severity: enumSeverity, message: string) => void} showViewerSnackbar
|
|
13
|
-
* @property {(message: string) => void} hideViewerSnackbar
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
var ViewerSnackbarContext = /*#__PURE__*/createContext();
|
|
17
|
-
|
|
18
|
-
var ViewerSnackbarProvider = function ViewerSnackbarProvider(_ref) {
|
|
19
|
-
var children = _ref.children;
|
|
20
|
-
|
|
21
|
-
var _useState = useState(false),
|
|
22
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
-
isViewerSnackbarOpen = _useState2[0],
|
|
24
|
-
setIsViewerSnackbarOpen = _useState2[1];
|
|
25
|
-
|
|
26
|
-
var _useState3 = useState(''),
|
|
27
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
28
|
-
viewerSnackbarMessage = _useState4[0],
|
|
29
|
-
setViewerSnackbarMessage = _useState4[1];
|
|
30
|
-
|
|
31
|
-
var _useState5 = useState('primary'),
|
|
32
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
33
|
-
viewerSnackbarSeverity = _useState6[0],
|
|
34
|
-
setViewerSnackbarSeverity = _useState6[1];
|
|
35
|
-
|
|
36
|
-
var showViewerSnackbar = function showViewerSnackbar(severity, message) {
|
|
37
|
-
setIsViewerSnackbarOpen(true);
|
|
38
|
-
setViewerSnackbarMessage(message);
|
|
39
|
-
setViewerSnackbarSeverity(severity);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
var hideViewerSnackbar = function hideViewerSnackbar() {
|
|
43
|
-
setIsViewerSnackbarOpen(false);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
var result = {
|
|
47
|
-
isViewerSnackbarOpen: isViewerSnackbarOpen,
|
|
48
|
-
viewerSnackbarMessage: viewerSnackbarMessage,
|
|
49
|
-
viewerSnackbarSeverity: viewerSnackbarSeverity,
|
|
50
|
-
showViewerSnackbar: showViewerSnackbar,
|
|
51
|
-
hideViewerSnackbar: hideViewerSnackbar
|
|
52
|
-
};
|
|
53
|
-
return /*#__PURE__*/React.createElement(ViewerSnackbarContext.Provider, {
|
|
54
|
-
value: result
|
|
55
|
-
}, children);
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* @returns {useViewerSnackbarReturn}
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var useViewerSnackbar = function useViewerSnackbar() {
|
|
63
|
-
var viewerSnackbar = useContext(ViewerSnackbarContext);
|
|
64
|
-
|
|
65
|
-
if (!viewerSnackbar) {
|
|
66
|
-
throw new Error('ViewerSnackbarContext must be used within a ViewerSnackbarProvider');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return viewerSnackbar;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export default useViewerSnackbar;
|
|
73
|
-
export { ViewerSnackbarProvider };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Snackbar from "cozy-ui/transpiled/react/Snackbar";
|
|
3
|
-
import Alert from "cozy-ui/transpiled/react/Alert";
|
|
4
|
-
import useViewerSnackbar from "cozy-ui/transpiled/react/Viewer/providers/ViewerSnackbarProvider";
|
|
5
|
-
|
|
6
|
-
var ViewerSnackbar = function ViewerSnackbar() {
|
|
7
|
-
var _useViewerSnackbar = useViewerSnackbar(),
|
|
8
|
-
isViewerSnackbarOpen = _useViewerSnackbar.isViewerSnackbarOpen,
|
|
9
|
-
viewerSnackbarMessage = _useViewerSnackbar.viewerSnackbarMessage,
|
|
10
|
-
viewerSnackbarSeverity = _useViewerSnackbar.viewerSnackbarSeverity,
|
|
11
|
-
hideViewerSnackbar = _useViewerSnackbar.hideViewerSnackbar;
|
|
12
|
-
|
|
13
|
-
return /*#__PURE__*/React.createElement(Snackbar, {
|
|
14
|
-
open: isViewerSnackbarOpen,
|
|
15
|
-
onClose: hideViewerSnackbar
|
|
16
|
-
}, /*#__PURE__*/React.createElement(Alert, {
|
|
17
|
-
variant: "filled",
|
|
18
|
-
elevation: 6,
|
|
19
|
-
onClose: hideViewerSnackbar,
|
|
20
|
-
severity: viewerSnackbarSeverity,
|
|
21
|
-
icon: false
|
|
22
|
-
}, viewerSnackbarMessage));
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default ViewerSnackbar;
|