@codebit-programando-solucoes/codebit-web-antd 1.1.30 → 1.1.33

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.
@@ -139,4 +139,10 @@ import { FC } from 'react';
139
139
  * }
140
140
  * ```;
141
141
  */
142
- export const CssTokenBridge: FC;
142
+ export interface CssTokenBridgeProps {
143
+ /** Optional ID of the container element to receive the CSS variables. */
144
+ containerId?: string;
145
+ }
146
+
147
+ /** CssTokenBridge component definition. */
148
+ export const CssTokenBridge: FC<CssTokenBridgeProps>;
@@ -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
- /** Array of menu items displayed above the logout button in the bottom menu. */
53
- bottomMenuItems?: MenuProps['items'];
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
- /** **New**: Array of bottom‑menu items (Ant Design `MenuItemType`). */
87
- bottomMenuItems?: ItemType[];
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. */
@@ -23,4 +23,8 @@ type CodebitThemeProviderProps = {
23
23
  children: React.ReactNode;
24
24
  /** Whether to persist theme preference in localStorage (default: `true`) */
25
25
  storeThemeInLocalStorage?: boolean;
26
+ /** ID of the root container element where theme classes are applied (default: `'root'`) */
27
+ containerId?: string;
28
+ /** Optional explicit theme override. When set, the provider uses this value instead of internal detection. */
29
+ forcedTheme?: 'dark' | 'light' | null;
26
30
  } & ConfigProviderProps;
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 = [], doLogout, checkLogin, onMenuClick }) {
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().array,
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
@@ -797,10 +797,10 @@ var __webpack_exports__ = {};
797
797
  tableContainer: null,
798
798
  actions: null
799
799
  };
800
- const CssTokenBridge = ()=>{
800
+ const CssTokenBridge = ({ containerId })=>{
801
801
  const { token } = external_antd_namespaceObject.theme.useToken();
802
802
  (0, external_react_.useLayoutEffect)(()=>{
803
- const root = document.documentElement;
803
+ const root = containerId ? document.getElementById(containerId) ?? document.documentElement : document.documentElement;
804
804
  root.style.setProperty('--antd-color-bg-base', token['colorBgBase']);
805
805
  root.style.setProperty('--antd-color-bg-container', token['colorBgContainer']);
806
806
  root.style.setProperty('--antd-color-bg-elevated', token['colorBgElevated']);
@@ -888,10 +888,14 @@ var __webpack_exports__ = {};
888
888
  root.style.setProperty('--antd-border-radius', `${token['borderRadius']}px`);
889
889
  root.style.setProperty('--antd-border-radius-lg', `${token['borderRadiusLG']}px`);
890
890
  }, [
891
+ containerId,
891
892
  token
892
893
  ]);
893
894
  return null;
894
895
  };
896
+ CssTokenBridge.propTypes = {
897
+ containerId: external_prop_types_default().string
898
+ };
895
899
  const TableContainer_module = {
896
900
  tableContainer: "tableContainer-EhNwOm"
897
901
  };
@@ -980,9 +984,10 @@ var __webpack_exports__ = {};
980
984
  ...external_antd_namespaceObject.Card.propTypes
981
985
  };
982
986
  const CodebitThemeContext = /*#__PURE__*/ (0, external_react_.createContext)(null);
983
- const CodebitThemeProvider = ({ children, storeThemeInLocalStorage = true, ...props })=>{
987
+ const CodebitThemeProvider = ({ children, storeThemeInLocalStorage = true, containerId = 'root', forcedTheme = null, ...props })=>{
984
988
  const hasLoaded = (0, external_react_.useRef)(false);
985
989
  const [isDarkMode, setIsDarkMode] = (0, external_react_.useState)(()=>{
990
+ if (forcedTheme) return 'dark' === forcedTheme;
986
991
  try {
987
992
  if (storeThemeInLocalStorage) {
988
993
  const savedTheme = localStorage?.getItem('theme');
@@ -993,27 +998,39 @@ var __webpack_exports__ = {};
993
998
  hasLoaded.current = true;
994
999
  }
995
1000
  });
1001
+ (0, external_react_.useEffect)(()=>{
1002
+ if (forcedTheme) {
1003
+ const mode = 'dark' === forcedTheme;
1004
+ setIsDarkMode(mode);
1005
+ }
1006
+ }, [
1007
+ forcedTheme
1008
+ ]);
996
1009
  const toggleTheme = ()=>{
997
1010
  setIsDarkMode((prev)=>!prev);
998
1011
  };
999
1012
  (0, external_react_.useEffect)(()=>{
1000
- const rootElement = document.getElementById('root');
1013
+ const target = document.getElementById(containerId);
1014
+ if (!target) return;
1001
1015
  if (isDarkMode) {
1002
1016
  document.documentElement.classList.add('dark-theme');
1003
- rootElement.classList.add('dark-theme');
1017
+ target.classList.add('dark-theme');
1004
1018
  } else {
1005
1019
  document.documentElement.classList.remove('dark-theme');
1006
- rootElement.classList.remove('dark-theme');
1020
+ target.classList.remove('dark-theme');
1007
1021
  }
1008
1022
  document.documentElement.style.setProperty('--color-primary', isDarkMode ? '#589C75' : '#29D266');
1009
1023
  }, [
1010
- isDarkMode
1024
+ isDarkMode,
1025
+ containerId
1011
1026
  ]);
1012
1027
  (0, external_react_.useEffect)(()=>{
1013
1028
  if (hasLoaded.current && storeThemeInLocalStorage) localStorage.setItem('theme', isDarkMode ? 'dark' : 'light');
1029
+ if (hasLoaded.current && storeThemeInLocalStorage && !forcedTheme) localStorage.setItem('theme', isDarkMode ? 'dark' : 'light');
1014
1030
  }, [
1015
1031
  isDarkMode,
1016
- storeThemeInLocalStorage
1032
+ storeThemeInLocalStorage,
1033
+ forcedTheme
1017
1034
  ]);
1018
1035
  const themeContextValue = (0, external_react_.useMemo)(()=>({
1019
1036
  isDarkMode,
@@ -1056,7 +1073,9 @@ var __webpack_exports__ = {};
1056
1073
  },
1057
1074
  ...props,
1058
1075
  children: [
1059
- /*#__PURE__*/ (0, jsx_runtime.jsx)(CssTokenBridge, {}),
1076
+ /*#__PURE__*/ (0, jsx_runtime.jsx)(CssTokenBridge, {
1077
+ containerId: containerId
1078
+ }),
1060
1079
  children
1061
1080
  ]
1062
1081
  })
@@ -1064,7 +1083,13 @@ var __webpack_exports__ = {};
1064
1083
  };
1065
1084
  CodebitThemeProvider.propTypes = {
1066
1085
  children: external_prop_types_default().node.isRequired,
1067
- storeThemeInLocalStorage: external_prop_types_default().bool
1086
+ storeThemeInLocalStorage: external_prop_types_default().bool,
1087
+ containerId: external_prop_types_default().string,
1088
+ forcedTheme: external_prop_types_default().oneOf([
1089
+ 'dark',
1090
+ 'light',
1091
+ null
1092
+ ])
1068
1093
  };
1069
1094
  const LoggedMainContainer_module = {
1070
1095
  layout: "layout-mL5o6I",
@@ -1100,12 +1125,12 @@ var __webpack_exports__ = {};
1100
1125
  const navigate = (0, external_react_router_namespaceObject.useNavigate)();
1101
1126
  const location = (0, external_react_router_namespaceObject.useLocation)();
1102
1127
  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 = [], onMenuClick } = configCodebit;
1128
+ const { logout, user, menuItems, version, showVersion, secondarySidebar, secondarySidebarWidth = 280, bottomMenuItems, onMenuClick } = configCodebit;
1104
1129
  const { isDarkMode } = configTheme;
1105
1130
  const theme = isDarkMode ? 'dark' : 'light';
1106
1131
  const allMenuItems = (0, external_react_.useMemo)(()=>[
1107
1132
  ...menuItems(user),
1108
- ...bottomMenuItems
1133
+ ...bottomMenuItems?.(user) ?? []
1109
1134
  ], [
1110
1135
  menuItems,
1111
1136
  user,
@@ -1119,8 +1144,19 @@ var __webpack_exports__ = {};
1119
1144
  menuItems,
1120
1145
  user
1121
1146
  ]);
1147
+ const filteredBottomMenuItems = (0, external_react_.useMemo)(()=>{
1148
+ if (!bottomMenuItems) return [];
1149
+ return bottomMenuItems(user).filter((item)=>{
1150
+ if (!item.roles) return true;
1151
+ if (!user?.roles) return false;
1152
+ return item.roles.some((role)=>user.roles.includes(role));
1153
+ });
1154
+ }, [
1155
+ bottomMenuItems,
1156
+ user
1157
+ ]);
1122
1158
  const memoizedBottomMenuItems = (0, external_react_.useMemo)(()=>[
1123
- ...bottomMenuItems,
1159
+ ...filteredBottomMenuItems,
1124
1160
  {
1125
1161
  key: MENU_KEY_APP_LOGOUT,
1126
1162
  icon: /*#__PURE__*/ (0, jsx_runtime.jsx)(icons_namespaceObject.LogoutOutlined, {}),
@@ -1128,7 +1164,7 @@ var __webpack_exports__ = {};
1128
1164
  danger: true
1129
1165
  }
1130
1166
  ], [
1131
- bottomMenuItems,
1167
+ filteredBottomMenuItems,
1132
1168
  t
1133
1169
  ]);
1134
1170
  const [selectedKeys, setSelectedKeys] = (0, external_react_.useState)('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebit-programando-solucoes/codebit-web-antd",
3
- "version": "1.1.30",
3
+ "version": "1.1.33",
4
4
  "main": "./dist/index.cjs",
5
5
  "type": "module",
6
6
  "types": "./src/index.d.ts",