@vertigis/react-ui 15.2.2 → 15.3.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/IconMenu/IconMenu.d.ts +10 -0
- package/IconMenu/IconMenu.js +4 -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";
|
package/IconMenu/IconMenu.d.ts
CHANGED
|
@@ -24,6 +24,16 @@ export interface IconMenuProps extends BoxProps {
|
|
|
24
24
|
* The icon to show.
|
|
25
25
|
*/
|
|
26
26
|
icon: ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* A ref for the menu element
|
|
29
|
+
*/
|
|
30
|
+
menuRef?: React.MutableRefObject<HTMLDivElement>;
|
|
31
|
+
/**
|
|
32
|
+
* A 'virtual anchor' that can be provided to override the default behavior.
|
|
33
|
+
* Use if the component hosting this could be destroyed while the menu is
|
|
34
|
+
* open.
|
|
35
|
+
*/
|
|
36
|
+
virtualAnchor?: DOMRect;
|
|
27
37
|
/**
|
|
28
38
|
* Attributes applied to the `IconButton` component.
|
|
29
39
|
*/
|
package/IconMenu/IconMenu.js
CHANGED
|
@@ -11,7 +11,7 @@ export const iconMenuClasses = {
|
|
|
11
11
|
root: `${PREFIX}-root`,
|
|
12
12
|
iconButton: `${PREFIX}-iconButton`,
|
|
13
13
|
};
|
|
14
|
-
const IconMenu = forwardRef(({ id: idProp, children, icon, className, classes: classesProp, disabled, IconButtonProps, MenuProps, ...others }, ref) => {
|
|
14
|
+
const IconMenu = forwardRef(({ id: idProp, children, icon, className, classes: classesProp, disabled, menuRef, virtualAnchor, IconButtonProps, MenuProps, ...others }, ref) => {
|
|
15
15
|
const anchorRef = useRef();
|
|
16
16
|
const [open, setOpen] = useState(false);
|
|
17
17
|
const id = useId(idProp);
|
|
@@ -19,7 +19,9 @@ const IconMenu = forwardRef(({ id: idProp, children, icon, className, classes: c
|
|
|
19
19
|
return (_jsxs(Box, { className: clsx(classes.root, className), ref: ref, ...others, children: [_jsx(IconButton, { ...IconButtonProps, "aria-label": "More", "aria-owns": open ? id : undefined, "aria-haspopup": "true", "data-test": "IconMenu-btn", disabled: disabled, className: clsx(classes.iconButton, IconButtonProps?.className), onClick: event => {
|
|
20
20
|
setOpen(true);
|
|
21
21
|
IconButtonProps?.onClick?.(event);
|
|
22
|
-
}, ref: ref => (anchorRef.current = anchorRef.current ?? ref), children: icon }), _jsx(Menu, { ...MenuProps, open: MenuProps?.open ?? open, id: id, "data-test": "IconMenu-menu", anchorEl:
|
|
22
|
+
}, ref: ref => (anchorRef.current = anchorRef.current ?? ref), children: icon }), _jsx(Menu, { ...MenuProps, open: MenuProps?.open ?? open, id: id, ref: menuRef, "data-test": "IconMenu-menu", anchorEl: virtualAnchor
|
|
23
|
+
? { nodeType: 1, getBoundingClientRect: () => virtualAnchor }
|
|
24
|
+
: anchorRef.current, onClose: (event, reason) => {
|
|
23
25
|
setOpen(false);
|
|
24
26
|
MenuProps?.onClose?.(event, reason);
|
|
25
27
|
}, onClick: event => {
|