@codebit-programando-solucoes/codebit-web-antd 1.1.30 → 1.1.32
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/dist/contexts/CodebitConfigContext.d.ts +16 -17
- package/dist/index.cjs +17 -6
- package/package.json +1 -1
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { MenuProps } from 'antd';
|
|
3
2
|
import type { ItemType } from 'antd/es/menu/interface';
|
|
4
3
|
|
|
4
|
+
/** The configuration context for Codebit application, providing access to session and UI settings. */
|
|
5
|
+
export const CodebitConfigContext: React.Context<CodebitConfigContextType | null>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Provider component for Codebit configuration and session management.
|
|
9
|
+
*
|
|
10
|
+
* @param props - Configuration provider properties.
|
|
11
|
+
*/
|
|
12
|
+
export function CodebitConfigProvider(
|
|
13
|
+
props: CodebitConfigProviderProps,
|
|
14
|
+
): React.ReactElement;
|
|
15
|
+
|
|
5
16
|
/** Menu item configuration */
|
|
6
17
|
export type MenuItem = ItemType & {
|
|
7
18
|
/** Array of roles that can access this item */
|
|
@@ -20,9 +31,6 @@ export interface LoggedUser {
|
|
|
20
31
|
roles?: string[];
|
|
21
32
|
}
|
|
22
33
|
|
|
23
|
-
/** The configuration context for Codebit application, providing access to session and UI settings. */
|
|
24
|
-
export const CodebitConfigContext: React.Context<CodebitConfigContextType | null>;
|
|
25
|
-
|
|
26
34
|
/** Context type definition for Codebit configuration. */
|
|
27
35
|
export interface CodebitConfigContextType {
|
|
28
36
|
/**
|
|
@@ -49,8 +57,8 @@ export interface CodebitConfigContextType {
|
|
|
49
57
|
secondarySidebar?: (user?: LoggedUser) => React.ReactNode | null;
|
|
50
58
|
/** Width of the secondary sidebar in pixels (default: 280). */
|
|
51
59
|
secondarySidebarWidth?: number;
|
|
52
|
-
/**
|
|
53
|
-
bottomMenuItems?:
|
|
60
|
+
/** Function that returns menu items configuration for items displayed above the logout button in the bottom menu. */
|
|
61
|
+
bottomMenuItems?: (user?: LoggedUser) => MenuItem[];
|
|
54
62
|
/**
|
|
55
63
|
* Function invoked when a menu item is clicked. Receives the item's key and **must return a boolean**.
|
|
56
64
|
*
|
|
@@ -60,15 +68,6 @@ export interface CodebitConfigContextType {
|
|
|
60
68
|
onMenuClick?: (key: string) => boolean;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
|
-
/**
|
|
64
|
-
* Provider component for Codebit configuration and session management.
|
|
65
|
-
*
|
|
66
|
-
* @param props - Configuration provider properties.
|
|
67
|
-
*/
|
|
68
|
-
export function CodebitConfigProvider(
|
|
69
|
-
props: CodebitConfigProviderProps,
|
|
70
|
-
): React.ReactElement;
|
|
71
|
-
|
|
72
71
|
/** Properties for the CodebitConfigProvider component. */
|
|
73
72
|
export interface CodebitConfigProviderProps {
|
|
74
73
|
/** Child components that will have access to the configuration context. */
|
|
@@ -83,8 +82,8 @@ export interface CodebitConfigProviderProps {
|
|
|
83
82
|
secondarySidebar?: (user: LoggedUser) => React.ReactNode | null;
|
|
84
83
|
/** Width of the secondary sidebar in pixels (default: 280). */
|
|
85
84
|
secondarySidebarWidth?: number;
|
|
86
|
-
/**
|
|
87
|
-
bottomMenuItems?:
|
|
85
|
+
/** Function that returns bottom‑menu items. */
|
|
86
|
+
bottomMenuItems?: (user?: LoggedUser) => MenuItem[];
|
|
88
87
|
/** Function to handle user logout. */
|
|
89
88
|
doLogout: () => Promise<void>;
|
|
90
89
|
/** Function to check login status and return user data. */
|
package/dist/index.cjs
CHANGED
|
@@ -329,7 +329,7 @@ var __webpack_exports__ = {};
|
|
|
329
329
|
const codebit_web_namespaceObject = require("@codebit-programando-solucoes/codebit-web");
|
|
330
330
|
const logger = new codebit_web_namespaceObject.Logger('CodebitConfigContext');
|
|
331
331
|
const CodebitConfigContext = /*#__PURE__*/ (0, external_react_.createContext)(null);
|
|
332
|
-
function CodebitConfigProvider({ children, menuItems, version = '1.0', showVersion = ()=>true, secondarySidebar, secondarySidebarWidth = 280, bottomMenuItems
|
|
332
|
+
function CodebitConfigProvider({ children, menuItems, version = '1.0', showVersion = ()=>true, secondarySidebar, secondarySidebarWidth = 280, bottomMenuItems, doLogout, checkLogin, onMenuClick }) {
|
|
333
333
|
const [isLogged, setIsLogged] = (0, external_react_.useState)(null);
|
|
334
334
|
const [user, setUser] = (0, external_react_.useState)(null);
|
|
335
335
|
const logout = async ()=>{
|
|
@@ -398,7 +398,7 @@ var __webpack_exports__ = {};
|
|
|
398
398
|
showVersion: external_prop_types_default().func,
|
|
399
399
|
secondarySidebar: external_prop_types_default().func,
|
|
400
400
|
secondarySidebarWidth: external_prop_types_default().number,
|
|
401
|
-
bottomMenuItems: external_prop_types_default().
|
|
401
|
+
bottomMenuItems: external_prop_types_default().func,
|
|
402
402
|
doLogout: external_prop_types_default().func.isRequired,
|
|
403
403
|
checkLogin: external_prop_types_default().func.isRequired,
|
|
404
404
|
onMenuClick: external_prop_types_default().func
|
|
@@ -1100,12 +1100,12 @@ var __webpack_exports__ = {};
|
|
|
1100
1100
|
const navigate = (0, external_react_router_namespaceObject.useNavigate)();
|
|
1101
1101
|
const location = (0, external_react_router_namespaceObject.useLocation)();
|
|
1102
1102
|
if (!configCodebit || !configTheme) throw new Error('LoggedContainer must be used within CodebitConfigProvider and CodebitThemeContext');
|
|
1103
|
-
const { logout, user, menuItems, version, showVersion, secondarySidebar, secondarySidebarWidth = 280, bottomMenuItems
|
|
1103
|
+
const { logout, user, menuItems, version, showVersion, secondarySidebar, secondarySidebarWidth = 280, bottomMenuItems, onMenuClick } = configCodebit;
|
|
1104
1104
|
const { isDarkMode } = configTheme;
|
|
1105
1105
|
const theme = isDarkMode ? 'dark' : 'light';
|
|
1106
1106
|
const allMenuItems = (0, external_react_.useMemo)(()=>[
|
|
1107
1107
|
...menuItems(user),
|
|
1108
|
-
...bottomMenuItems
|
|
1108
|
+
...bottomMenuItems?.(user) ?? []
|
|
1109
1109
|
], [
|
|
1110
1110
|
menuItems,
|
|
1111
1111
|
user,
|
|
@@ -1119,8 +1119,19 @@ var __webpack_exports__ = {};
|
|
|
1119
1119
|
menuItems,
|
|
1120
1120
|
user
|
|
1121
1121
|
]);
|
|
1122
|
+
const filteredBottomMenuItems = (0, external_react_.useMemo)(()=>{
|
|
1123
|
+
if (!bottomMenuItems) return [];
|
|
1124
|
+
return bottomMenuItems(user).filter((item)=>{
|
|
1125
|
+
if (!item.roles) return true;
|
|
1126
|
+
if (!user?.roles) return false;
|
|
1127
|
+
return item.roles.some((role)=>user.roles.includes(role));
|
|
1128
|
+
});
|
|
1129
|
+
}, [
|
|
1130
|
+
bottomMenuItems,
|
|
1131
|
+
user
|
|
1132
|
+
]);
|
|
1122
1133
|
const memoizedBottomMenuItems = (0, external_react_.useMemo)(()=>[
|
|
1123
|
-
...
|
|
1134
|
+
...filteredBottomMenuItems,
|
|
1124
1135
|
{
|
|
1125
1136
|
key: MENU_KEY_APP_LOGOUT,
|
|
1126
1137
|
icon: /*#__PURE__*/ (0, jsx_runtime.jsx)(icons_namespaceObject.LogoutOutlined, {}),
|
|
@@ -1128,7 +1139,7 @@ var __webpack_exports__ = {};
|
|
|
1128
1139
|
danger: true
|
|
1129
1140
|
}
|
|
1130
1141
|
], [
|
|
1131
|
-
|
|
1142
|
+
filteredBottomMenuItems,
|
|
1132
1143
|
t
|
|
1133
1144
|
]);
|
|
1134
1145
|
const [selectedKeys, setSelectedKeys] = (0, external_react_.useState)('');
|