cozy-ui 93.3.0 → 93.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,17 @@
1
+ # [93.5.0](https://github.com/cozy/cozy-ui/compare/v93.4.0...v93.5.0) (2023-09-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * **Viewer:** On mobile, the title benefits well from the midEllipsis ([5bfd8b3](https://github.com/cozy/cozy-ui/commit/5bfd8b3))
7
+
8
+ # [93.4.0](https://github.com/cozy/cozy-ui/compare/v93.3.0...v93.4.0) (2023-09-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * Add Alert provider ([ebccf42](https://github.com/cozy/cozy-ui/commit/ebccf42))
14
+
1
15
  # [93.3.0](https://github.com/cozy/cozy-ui/compare/v93.2.0...v93.3.0) (2023-09-28)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "93.3.0",
3
+ "version": "93.5.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -55,7 +55,7 @@ initialState = { open: isTesting() }
55
55
 
56
56
  const handleToggle = () => {setState(state => ({ open: !state.open }))}
57
57
 
58
- const initialVariants = [{ primary: true, secondary: true, success: false, error: false, warning: false, info: false }]
58
+ const initialVariants = [{ primary: true, secondary: false, success: false, error: false, warning: false, info: false }]
59
59
 
60
60
  ;
61
61
 
@@ -20,6 +20,7 @@ import { useEncrypted } from '../providers/EncryptedProvider'
20
20
  import { ToolbarFilePath } from './ToolbarFilePath'
21
21
 
22
22
  import styles from './styles.styl'
23
+ import MidEllipsis from '../../MidEllipsis'
23
24
 
24
25
  const useClasses = makeStyles(theme => ({
25
26
  iconButton: {
@@ -64,13 +65,13 @@ const Toolbar = ({
64
65
  <Icon icon={PreviousIcon} />
65
66
  </IconButton>
66
67
  )}
67
- <div className="u-pl-half">
68
+ <div className="u-pl-half u-ov-auto u-w-100">
68
69
  <Typography
69
70
  variant="h3"
70
71
  color={isDesktop ? 'inherit' : 'textPrimary'}
71
72
  noWrap
72
73
  >
73
- {file.name}
74
+ <MidEllipsis text={file.name} />
74
75
  </Typography>
75
76
  {showFilePath ? <ToolbarFilePath file={file} /> : null}
76
77
  </div>
package/react/index.js CHANGED
@@ -131,3 +131,4 @@ export { default as TimelineDot } from './TimelineDot'
131
131
  export { default as TimelineItem } from './TimelineItem'
132
132
  export { default as TimelineOppositeContent } from './TimelineOppositeContent'
133
133
  export { default as TimelineSeparator } from './TimelineSeparator'
134
+ export { default as AlertProvider, useAlert } from './Alert'
@@ -0,0 +1,28 @@
1
+ ```jsx
2
+ import Variants from 'cozy-ui/docs/components/Variants'
3
+ import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
4
+ import AlertProvider, { useAlert } from 'cozy-ui/transpiled/react/providers/Alert'
5
+ import Button from 'cozy-ui/transpiled/react/Buttons'
6
+
7
+ const initialVariants = [{ primary: true, secondary: false, success: false, error: false, warning: false, info: false }]
8
+
9
+ const Component = ({ variant }) => {
10
+ const { showAlert } = useAlert()
11
+
12
+ return <Button label="show alert" onClick={() => showAlert('Alert message', variant)}/>
13
+ }
14
+
15
+ ;
16
+
17
+ <BreakpointsProvider>
18
+ <AlertProvider>
19
+ <Variants initialVariants={initialVariants} radio>
20
+ {variant => (
21
+ <>
22
+ <Component variant={Object.keys(variant).find(key => variant[key])} />
23
+ </>
24
+ )}
25
+ </Variants>
26
+ </AlertProvider>
27
+ </BreakpointsProvider>
28
+ ```
@@ -0,0 +1,51 @@
1
+ import React, { createContext, useState, useContext, useMemo } from 'react'
2
+
3
+ import Snackbar from '../../Snackbar'
4
+ import Alert from '../../Alert'
5
+
6
+ export const AlertContext = createContext()
7
+
8
+ export const useAlert = () => {
9
+ const context = useContext(AlertContext)
10
+
11
+ if (!context) {
12
+ throw new Error('useAlert must be used within a AlertProvider')
13
+ }
14
+ return context
15
+ }
16
+
17
+ const defaultState = { message: '', severity: 'primary', open: false }
18
+ const handleClose = (state, setState) => () => {
19
+ return setState({ ...state, open: false })
20
+ }
21
+
22
+ const AlertProvider = ({ children }) => {
23
+ const [state, setState] = useState(defaultState)
24
+
25
+ const value = useMemo(
26
+ () => ({
27
+ showAlert: (message, severity) => {
28
+ setState({ message, severity, open: true })
29
+ }
30
+ }),
31
+ []
32
+ )
33
+
34
+ return (
35
+ <AlertContext.Provider value={value}>
36
+ {children}
37
+ <Snackbar open={state.open} onClose={handleClose(state, setState)}>
38
+ <Alert
39
+ variant="filled"
40
+ elevation={6}
41
+ severity={state.severity}
42
+ onClose={handleClose(state, setState)}
43
+ >
44
+ {state.message}
45
+ </Alert>
46
+ </Snackbar>
47
+ </AlertContext.Provider>
48
+ )
49
+ }
50
+
51
+ export default React.memo(AlertProvider)
@@ -29,6 +29,7 @@ var styles = {
29
29
  "viewer-toolbar--hidden": "styles__viewer-toolbar--hidden___3r3Sj",
30
30
  "viewer-footer": "styles__viewer-footer___2ieQS"
31
31
  };
32
+ import MidEllipsis from "cozy-ui/transpiled/react/MidEllipsis";
32
33
  var useClasses = makeStyles(function (theme) {
33
34
  return {
34
35
  iconButton: _defineProperty({}, theme.breakpoints.down('md'), {
@@ -68,12 +69,14 @@ var Toolbar = function Toolbar(_ref) {
68
69
  }, /*#__PURE__*/React.createElement(Icon, {
69
70
  icon: PreviousIcon
70
71
  })), /*#__PURE__*/React.createElement("div", {
71
- className: "u-pl-half"
72
+ className: "u-pl-half u-ov-auto u-w-100"
72
73
  }, /*#__PURE__*/React.createElement(Typography, {
73
74
  variant: "h3",
74
75
  color: isDesktop ? 'inherit' : 'textPrimary',
75
76
  noWrap: true
76
- }, file.name), showFilePath ? /*#__PURE__*/React.createElement(ToolbarFilePath, {
77
+ }, /*#__PURE__*/React.createElement(MidEllipsis, {
78
+ text: file.name
79
+ })), showFilePath ? /*#__PURE__*/React.createElement(ToolbarFilePath, {
77
80
  file: file
78
81
  }) : null), /*#__PURE__*/React.createElement("div", {
79
82
  className: "u-ml-auto u-ph-1"
@@ -104,4 +104,5 @@ export { default as TimelineContent } from './TimelineContent';
104
104
  export { default as TimelineDot } from './TimelineDot';
105
105
  export { default as TimelineItem } from './TimelineItem';
106
106
  export { default as TimelineOppositeContent } from './TimelineOppositeContent';
107
- export { default as TimelineSeparator } from './TimelineSeparator';
107
+ export { default as TimelineSeparator } from './TimelineSeparator';
108
+ export { default as AlertProvider, useAlert } from './Alert';
@@ -0,0 +1,67 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+
4
+ 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
+
6
+ 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; }
7
+
8
+ import React, { createContext, useState, useContext, useMemo } from 'react';
9
+ import Snackbar from "cozy-ui/transpiled/react/Snackbar";
10
+ import Alert from "cozy-ui/transpiled/react/Alert";
11
+ export var AlertContext = /*#__PURE__*/createContext();
12
+ export var useAlert = function useAlert() {
13
+ var context = useContext(AlertContext);
14
+
15
+ if (!context) {
16
+ throw new Error('useAlert must be used within a AlertProvider');
17
+ }
18
+
19
+ return context;
20
+ };
21
+ var defaultState = {
22
+ message: '',
23
+ severity: 'primary',
24
+ open: false
25
+ };
26
+
27
+ var handleClose = function handleClose(state, setState) {
28
+ return function () {
29
+ return setState(_objectSpread(_objectSpread({}, state), {}, {
30
+ open: false
31
+ }));
32
+ };
33
+ };
34
+
35
+ var AlertProvider = function AlertProvider(_ref) {
36
+ var children = _ref.children;
37
+
38
+ var _useState = useState(defaultState),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ state = _useState2[0],
41
+ setState = _useState2[1];
42
+
43
+ var value = useMemo(function () {
44
+ return {
45
+ showAlert: function showAlert(message, severity) {
46
+ setState({
47
+ message: message,
48
+ severity: severity,
49
+ open: true
50
+ });
51
+ }
52
+ };
53
+ }, []);
54
+ return /*#__PURE__*/React.createElement(AlertContext.Provider, {
55
+ value: value
56
+ }, children, /*#__PURE__*/React.createElement(Snackbar, {
57
+ open: state.open,
58
+ onClose: handleClose(state, setState)
59
+ }, /*#__PURE__*/React.createElement(Alert, {
60
+ variant: "filled",
61
+ elevation: 6,
62
+ severity: state.severity,
63
+ onClose: handleClose(state, setState)
64
+ }, state.message)));
65
+ };
66
+
67
+ export default /*#__PURE__*/React.memo(AlertProvider);