@movalib/movalib-commons 1.0.0 → 1.0.2

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/PV_README.md ADDED
@@ -0,0 +1,15 @@
1
+ # 1. build this movalib commons lib
2
+
3
+ ### `npm build`
4
+
5
+ # 2. publish this movalib commons lib (public)
6
+
7
+ ### `npm login`
8
+ ### `npm publish --access=public`
9
+
10
+ # 3. publish this movalib commons lib (private)
11
+
12
+ Make shure that "private=true" in your package.json
13
+
14
+ ### `npm login`
15
+ ### `npm publish --access=restricted`
@@ -0,0 +1,15 @@
1
+ import { FunctionComponent } from 'react';
2
+ interface MovaSnackbarProps {
3
+ snackbar: {
4
+ open: boolean;
5
+ message: string;
6
+ severity: 'success' | 'info' | 'warning' | 'error' | undefined;
7
+ };
8
+ setSnackbar: (snackbar: {
9
+ open: boolean;
10
+ message: string;
11
+ severity: 'success' | 'info' | 'warning' | 'error' | undefined;
12
+ }) => void;
13
+ }
14
+ declare const MovaSnackbar: FunctionComponent<MovaSnackbarProps>;
15
+ export default MovaSnackbar;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const material_1 = require("@mui/material");
8
+ const CloseRounded_1 = __importDefault(require("@mui/icons-material/CloseRounded"));
9
+ const MovaSnackbar = ({ snackbar, setSnackbar }) => {
10
+ /**
11
+ * Gestion de la fermeture de la snackbar. Si la raison de cette fermeture est
12
+ * un clic en dehors de la zone de contenu on intercepte et annule la fermeture 'clickaway'.
13
+ * @param event Evénnement de fermeture
14
+ * @param reason Origine de l'événnement de fermeture
15
+ * @returns
16
+ */
17
+ const handleClose = (event, reason) => {
18
+ if (reason === 'clickaway')
19
+ return;
20
+ setSnackbar({ open: false, message: '', severity: undefined });
21
+ };
22
+ const handleCloseAlert = (event) => {
23
+ setSnackbar({ open: false, message: '', severity: undefined });
24
+ };
25
+ return ((0, jsx_runtime_1.jsx)(material_1.Snackbar, Object.assign({ open: snackbar.open, autoHideDuration: 5000, onClose: handleClose }, { children: (0, jsx_runtime_1.jsx)(material_1.Alert, Object.assign({ severity: snackbar.severity, variant: "filled", sx: { width: '100%' }, action: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({ size: "small", "aria-label": "close", color: "inherit", onClick: handleCloseAlert }, { children: (0, jsx_runtime_1.jsx)(CloseRounded_1.default, { fontSize: "small" }) })) }) }, { children: snackbar.message })) })));
26
+ };
27
+ exports.default = MovaSnackbar;
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { default as TestButton } from './TestButton';
2
+ export { default as MovaSnackBar } from './MovaSnackbar';
package/dist/index.js CHANGED
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TestButton = void 0;
6
+ exports.MovaSnackBar = exports.TestButton = void 0;
7
7
  // src/index.ts
8
8
  var TestButton_1 = require("./TestButton");
9
9
  Object.defineProperty(exports, "TestButton", { enumerable: true, get: function () { return __importDefault(TestButton_1).default; } });
10
+ var MovaSnackbar_1 = require("./MovaSnackbar");
11
+ Object.defineProperty(exports, "MovaSnackBar", { enumerable: true, get: function () { return __importDefault(MovaSnackbar_1).default; } });
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "private": false,
8
8
  "scripts": {
9
9
  "build": "tsc",
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "clean": "rm -rf dist node_modules package-lock.json"
11
12
  },
12
13
  "keywords": [],
13
14
  "author": "",
@@ -17,6 +18,8 @@
17
18
  "react-dom": "^18.2.0"
18
19
  },
19
20
  "devDependencies": {
21
+ "@mui/material": "^5.13.5",
22
+ "@mui/icons-material": "^5.11.16",
20
23
  "@types/react": "^18.2.22",
21
24
  "@types/react-dom": "^18.2.7",
22
25
  "typescript": "^4.9.5"
@@ -0,0 +1,65 @@
1
+ // MovaSnackbar.tsx
2
+ import React, { FunctionComponent } from 'react';
3
+ import { Snackbar, Alert, IconButton, SnackbarCloseReason } from '@mui/material';
4
+ import CloseIcon from '@mui/icons-material/CloseRounded';
5
+
6
+ interface MovaSnackbarProps {
7
+ snackbar: {
8
+ open: boolean;
9
+ message: string;
10
+ severity: 'success' | 'info' | 'warning' | 'error' | undefined;
11
+ };
12
+ setSnackbar: (snackbar: {
13
+ open: boolean;
14
+ message: string;
15
+ severity: 'success' | 'info' | 'warning' | 'error' | undefined;
16
+ }) => void;
17
+ }
18
+
19
+ const MovaSnackbar: FunctionComponent<MovaSnackbarProps> = ({ snackbar, setSnackbar }) => {
20
+
21
+ /**
22
+ * Gestion de la fermeture de la snackbar. Si la raison de cette fermeture est
23
+ * un clic en dehors de la zone de contenu on intercepte et annule la fermeture 'clickaway'.
24
+ * @param event Evénnement de fermeture
25
+ * @param reason Origine de l'événnement de fermeture
26
+ * @returns
27
+ */
28
+ const handleClose = (event: globalThis.Event | React.SyntheticEvent<any, globalThis.Event>,
29
+ reason: SnackbarCloseReason) => {
30
+
31
+ if (reason === 'clickaway') return;
32
+
33
+ setSnackbar({ open: false, message: '', severity: undefined });
34
+ };
35
+
36
+ const handleCloseAlert = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
37
+ setSnackbar({ open: false, message: '', severity: undefined });
38
+ };
39
+
40
+ return (
41
+ <Snackbar open={snackbar.open} autoHideDuration={5000} onClose={handleClose}>
42
+ <Alert severity={snackbar.severity} variant="filled" sx={{ width: '100%' }}
43
+ action={
44
+ <>
45
+ {/* TODO : possiblité d'annuler l'action qui vient d'avoir lieu */}
46
+ {/* <Button color="inherit" size="small" onClick={handleCancelAction}>
47
+ Annuler
48
+ </Button> */}
49
+ <IconButton
50
+ size="small"
51
+ aria-label="close"
52
+ color="inherit"
53
+ onClick={handleCloseAlert}
54
+ >
55
+ <CloseIcon fontSize="small" />
56
+ </IconButton>
57
+ </>
58
+ }>
59
+ {snackbar.message}
60
+ </Alert>
61
+ </Snackbar>
62
+ );
63
+ };
64
+
65
+ export default MovaSnackbar;
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  // src/index.ts
2
2
  export { default as TestButton } from './TestButton';
3
+ export { default as MovaSnackBar } from './MovaSnackbar';