@vertigis/react-ui 15.2.3 → 15.4.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/Chip/Chip.d.ts +7 -0
- package/Chip/Chip.js +20 -0
- package/Chip/index.d.ts +2 -2
- package/Chip/index.js +2 -2
- package/Notification/Notification.d.ts +22 -0
- package/Notification/Notification.js +27 -0
- package/Notification/index.d.ts +2 -0
- package/Notification/index.js +2 -0
- package/Snackbar/Snackbar.d.ts +12 -0
- package/Snackbar/Snackbar.js +72 -0
- package/Snackbar/index.d.ts +2 -2
- package/Snackbar/index.js +2 -2
- package/package.json +1 -1
package/Chip/Chip.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChipProps as MuiChipProps } from "@mui/material/Chip";
|
|
2
|
+
export * from "@mui/material/Chip";
|
|
3
|
+
export interface ChipProps extends MuiChipProps {
|
|
4
|
+
deleteLabel?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const Chip: import("react").ForwardRefExoticComponent<Omit<ChipProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export default Chip;
|
package/Chip/Chip.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import MuiChip from "@mui/material/Chip";
|
|
3
|
+
import { forwardRef, useEffect, useMemo, useState } from "react";
|
|
4
|
+
import IconButton from "../IconButton/index.js";
|
|
5
|
+
import Typography from "../Typography/index.js";
|
|
6
|
+
import Clear from "../icons/Clear.js";
|
|
7
|
+
export * from "@mui/material/Chip";
|
|
8
|
+
const Chip = forwardRef(({ deleteIcon, label, deleteLabel = "", onClick, onDelete, ...props }, ref) => {
|
|
9
|
+
// Replace the close button as it is not WCAG compliant by default.
|
|
10
|
+
const deleteChipButton = useMemo(() => (_jsx(IconButton, { size: "small", "aria-label": deleteLabel, title: deleteLabel, children: deleteIcon ? deleteIcon : _jsx(Clear, { fontSize: "small" }) })), [deleteLabel, deleteIcon]);
|
|
11
|
+
const [title, setTitle] = useState();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setTitle(typeof label === "string" ? label : undefined);
|
|
14
|
+
}, [label]);
|
|
15
|
+
return (_jsx(MuiChip, { ref: ref, "aria-label": onClick ? title : undefined, deleteIcon: onDelete ? deleteChipButton : undefined, label: _jsx(Typography, { children: label }), title: title, onClick: onClick, onDelete: onDelete,
|
|
16
|
+
// The chip should only have the button role and be focusable if
|
|
17
|
+
// it is clickable.
|
|
18
|
+
role: onClick ? "button" : undefined, tabIndex: onClick ? 0 : -1, ...props }));
|
|
19
|
+
});
|
|
20
|
+
export default Chip;
|
package/Chip/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "
|
|
2
|
-
export * from "
|
|
1
|
+
export { default } from "./Chip.js";
|
|
2
|
+
export * from "./Chip.js";
|
package/Chip/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "
|
|
2
|
-
export * from "
|
|
1
|
+
export { default } from "./Chip.js";
|
|
2
|
+
export * from "./Chip.js";
|
|
@@ -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,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;
|
package/Snackbar/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "
|
|
2
|
-
export * from "
|
|
1
|
+
export { default } from "./Snackbar.js";
|
|
2
|
+
export * from "./Snackbar.js";
|
package/Snackbar/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "
|
|
2
|
-
export * from "
|
|
1
|
+
export { default } from "./Snackbar.js";
|
|
2
|
+
export * from "./Snackbar.js";
|