@vertigis/react-ui 15.3.0 → 15.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.
@@ -0,0 +1,22 @@
1
+ import { type AlertProps } from "@mui/material";
2
+ import type { FC } from "react";
3
+ import type { SnackbarProps } from "../Snackbar";
4
+ /**
5
+ * Properties for the Notification component.
6
+ */
7
+ export interface NotificationProperties extends SnackbarProps {
8
+ /**
9
+ * The title for the close button.
10
+ */
11
+ closeButtonTitle: string;
12
+ /**
13
+ * Optional alert properties.
14
+ */
15
+ alertProps?: AlertProps;
16
+ }
17
+ /**
18
+ * A Helper component that wraps a Mui Snackbar and displays a circular progress
19
+ * representing the current auto hide duration.
20
+ */
21
+ declare const Notification: FC<NotificationProperties>;
22
+ export default Notification;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Alert, CircularProgress, useTheme } from "@mui/material";
3
+ import { useState } from "react";
4
+ import IconButton from "../IconButton/index.js";
5
+ import Snackbar from "../Snackbar/index.js";
6
+ import CloseIcon from "../icons/Close.js";
7
+ /**
8
+ * A Helper component that wraps a Mui Snackbar and displays a circular progress
9
+ * representing the current auto hide duration.
10
+ */
11
+ const Notification = ({ alertProps, closeButtonTitle, children, ...props }) => {
12
+ const [progress, setProgress] = useState(100);
13
+ const { spacing } = useTheme();
14
+ return (_jsx(Snackbar, { ...props, timeoutProgress: remaining => {
15
+ if (props.autoHideDuration) {
16
+ setProgress((remaining / props.autoHideDuration) * 100);
17
+ }
18
+ }, children: _jsx(Alert, { ...alertProps, action: [
19
+ props.autoHideDuration && (_jsx(CircularProgress, { variant: "determinate", value: progress, color: "inherit", sx: {
20
+ position: "absolute",
21
+ },
22
+ // Magic size to match the close icon button perfectly.
23
+ size: spacing(4.8) }, "progress")),
24
+ _jsx(IconButton, { title: closeButtonTitle, color: "inherit", onClick: () => props.onClose?.({}, "escapeKeyDown"), children: _jsx(CloseIcon, { fontSize: "small" }) }, "close"),
25
+ ], children: children }) }));
26
+ };
27
+ export default Notification;
@@ -0,0 +1,2 @@
1
+ export * from "./Notification.js";
2
+ export { default } from "./Notification.js";
@@ -0,0 +1,2 @@
1
+ export * from "./Notification.js";
2
+ export { default } from "./Notification.js";
@@ -0,0 +1,12 @@
1
+ import { type SnackbarProps as MUISnackbarProps } from "@mui/material/Snackbar";
2
+ import type { FC } from "react";
3
+ export * from "@mui/material/Snackbar";
4
+ export interface SnackbarProps extends MUISnackbarProps {
5
+ /**
6
+ * Optionally specify a callback for the snackbar timeout progress. Only
7
+ * takes effect when 'autoHideDuration' is defined.
8
+ */
9
+ timeoutProgress?: (remaining: number) => void;
10
+ }
11
+ declare const Snackbar: FC<SnackbarProps>;
12
+ export default Snackbar;
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import SnackbarMUI, {} from "@mui/material/Snackbar";
3
+ import { useEffect, useRef } from "react";
4
+ // MUST be the first export, since some of the exports are overridden below.
5
+ export * from "@mui/material/Snackbar";
6
+ const UPDATE_TIME = 100;
7
+ const Snackbar = ({ open, onBlur, onClose, onClick, onFocus, onMouseEnter, onTouchStart, onMouseLeave, autoHideDuration: autoHideDurationInitial, timeoutProgress, ...others }) => {
8
+ const timeoutHandle = useRef();
9
+ const autoHideDuration = useRef(autoHideDurationInitial);
10
+ const useTimeout = !!autoHideDurationInitial;
11
+ const cancelTimeout = () => {
12
+ if (useTimeout) {
13
+ timeoutHandle.current?.remove();
14
+ timeoutHandle.current = undefined;
15
+ autoHideDuration.current = 0;
16
+ timeoutProgress?.(0);
17
+ }
18
+ };
19
+ const pauseTimeout = () => {
20
+ timeoutHandle.current?.remove();
21
+ timeoutHandle.current = undefined;
22
+ };
23
+ const resumeTimeout = () => {
24
+ if (open && useTimeout && autoHideDuration.current) {
25
+ const timeout = window.setInterval(() => {
26
+ if (autoHideDuration.current) {
27
+ autoHideDuration.current = Math.max(autoHideDuration.current - UPDATE_TIME, 0);
28
+ timeoutProgress?.(autoHideDuration.current);
29
+ }
30
+ else {
31
+ cancelTimeout();
32
+ onClose?.({}, "timeout");
33
+ }
34
+ }, UPDATE_TIME);
35
+ timeoutHandle.current = {
36
+ remove: () => {
37
+ window.clearInterval(timeout);
38
+ },
39
+ };
40
+ }
41
+ };
42
+ useEffect(() => {
43
+ if (open && useTimeout) {
44
+ // reset initial timeout.
45
+ autoHideDuration.current = autoHideDurationInitial;
46
+ timeoutProgress?.(autoHideDurationInitial);
47
+ resumeTimeout();
48
+ }
49
+ return cancelTimeout;
50
+ // eslint-disable-next-line react-hooks/exhaustive-deps
51
+ }, [open, autoHideDurationInitial]);
52
+ return (_jsx(SnackbarMUI, { open: open, onClose: onClose, onTouchStart: event => {
53
+ cancelTimeout();
54
+ onTouchStart?.(event);
55
+ }, onMouseEnter: event => {
56
+ pauseTimeout();
57
+ onMouseEnter?.(event);
58
+ }, onMouseLeave: event => {
59
+ resumeTimeout();
60
+ onMouseLeave?.(event);
61
+ }, onFocus: event => {
62
+ pauseTimeout();
63
+ onFocus?.(event);
64
+ }, onBlur: event => {
65
+ resumeTimeout();
66
+ onBlur?.(event);
67
+ }, onClick: event => {
68
+ cancelTimeout();
69
+ onClick?.(event);
70
+ }, ...others }));
71
+ };
72
+ export default Snackbar;
@@ -1,2 +1,2 @@
1
- export { default } from "@mui/material/Snackbar";
2
- export * from "@mui/material/Snackbar";
1
+ export { default } from "./Snackbar.js";
2
+ export * from "./Snackbar.js";
package/Snackbar/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { default } from "@mui/material/Snackbar";
2
- export * from "@mui/material/Snackbar";
1
+ export { default } from "./Snackbar.js";
2
+ export * from "./Snackbar.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertigis/react-ui",
3
- "version": "15.3.0",
3
+ "version": "15.5.0",
4
4
  "description": "Utilities and React components used in VertiGIS applications.",
5
5
  "keywords": [
6
6
  "vertigis",