@ftdata/ui 0.0.7 → 0.0.8
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.
|
@@ -6,7 +6,7 @@ export interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
|
6
6
|
helpText?: string;
|
|
7
7
|
success?: boolean;
|
|
8
8
|
width?: string | number;
|
|
9
|
-
icon
|
|
9
|
+
icon?: IconsNames | JSX.Element;
|
|
10
10
|
textField?: string;
|
|
11
11
|
margin?: string;
|
|
12
12
|
required?: boolean;
|
|
@@ -7,6 +7,7 @@ interface MenuProps {
|
|
|
7
7
|
logo: JSX.Element;
|
|
8
8
|
items: MenuItemData[];
|
|
9
9
|
translate: (key: string) => string;
|
|
10
|
+
active?: string;
|
|
10
11
|
}
|
|
11
|
-
export default function Menu({ background, fontcolor, subMenusBackground, logo, items, translate, }: MenuProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default function Menu({ background, fontcolor, subMenusBackground, logo, items, translate, active, }: MenuProps): import("react/jsx-runtime").JSX.Element;
|
|
12
13
|
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
3
|
import { ContainerLogo, ItemMenu, ItemsContainer, MenuAside, MenuHeader, SubItemsContainer, SubItemsHeader, SubItemsWrapper, SubMenuItem } from "./styles.js";
|
|
4
4
|
import createMenus from "./helpers/createMenus.js";
|
|
5
5
|
import { Icon } from "@ftdata/f-icons";
|
|
6
|
-
function Menu({ background, fontcolor, subMenusBackground, logo, items, translate }) {
|
|
6
|
+
function Menu({ background, fontcolor, subMenusBackground, logo, items, translate, active }) {
|
|
7
7
|
const [expand, setExpand] = useState(false);
|
|
8
8
|
const [submenus, setSubmenus] = useState([]);
|
|
9
9
|
const [isClosingSubmenu, setIsClosingSubmenu] = useState(false);
|
|
10
|
+
const menuRef = useRef(null);
|
|
10
11
|
const menus = createMenus(items, translate);
|
|
11
12
|
const toggleMenu = ()=>{
|
|
12
13
|
if (expand) return void setTimeout(()=>{
|
|
@@ -32,7 +33,22 @@ function Menu({ background, fontcolor, subMenusBackground, logo, items, translat
|
|
|
32
33
|
setIsClosingSubmenu(false);
|
|
33
34
|
}, 400);
|
|
34
35
|
};
|
|
36
|
+
useEffect(()=>{
|
|
37
|
+
const handleClickOutside = (event)=>{
|
|
38
|
+
if (expand && menuRef.current && !menuRef.current.contains(event.target)) {
|
|
39
|
+
setExpand(false);
|
|
40
|
+
setSubmenus([]);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
if (expand) document.addEventListener("mousedown", handleClickOutside);
|
|
44
|
+
return ()=>{
|
|
45
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
46
|
+
};
|
|
47
|
+
}, [
|
|
48
|
+
expand
|
|
49
|
+
]);
|
|
35
50
|
return /*#__PURE__*/ jsxs(MenuAside, {
|
|
51
|
+
ref: menuRef,
|
|
36
52
|
background: background,
|
|
37
53
|
onClick: expand ? ()=>null : toggleMenu,
|
|
38
54
|
$expand: expand,
|
|
@@ -51,7 +67,7 @@ function Menu({ background, fontcolor, subMenusBackground, logo, items, translat
|
|
|
51
67
|
})
|
|
52
68
|
}),
|
|
53
69
|
/*#__PURE__*/ jsx("span", {
|
|
54
|
-
children: translate("
|
|
70
|
+
children: translate("menu")
|
|
55
71
|
})
|
|
56
72
|
]
|
|
57
73
|
}),
|
|
@@ -66,6 +82,7 @@ function Menu({ background, fontcolor, subMenusBackground, logo, items, translat
|
|
|
66
82
|
fontcolor: fontcolor,
|
|
67
83
|
onClick: (event)=>handleClickItem(event, menu.submenus, menu.callback),
|
|
68
84
|
$expand: expand || void 0,
|
|
85
|
+
$active: menu.label === translate(active || ""),
|
|
69
86
|
children: [
|
|
70
87
|
/*#__PURE__*/ jsx("div", {
|
|
71
88
|
children: menu.icon
|
|
@@ -61,7 +61,7 @@ const MenuAside = styled_components.aside`
|
|
|
61
61
|
flex-direction: column;
|
|
62
62
|
gap: 1.5rem;
|
|
63
63
|
height: 100vh;
|
|
64
|
-
padding:
|
|
64
|
+
padding: 0.5rem;
|
|
65
65
|
position: relative;
|
|
66
66
|
transition: width 0.3s ease-in-out;
|
|
67
67
|
width: ${({ $expand })=>$expand ? "18.75rem" : "3.5rem"};
|
|
@@ -86,7 +86,7 @@ const ContainerLogo = styled_components.div`
|
|
|
86
86
|
align-items: center;
|
|
87
87
|
display: flex;
|
|
88
88
|
justify-content: center;
|
|
89
|
-
max-height:
|
|
89
|
+
max-height: 8rem;
|
|
90
90
|
max-width: 100%;
|
|
91
91
|
}
|
|
92
92
|
`;
|