@capillarytech/cap-ui-utils 3.0.18 → 3.0.20
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/index.js +1 -0
- package/package.json +1 -1
- package/utils/MFEModuleHeader.js +17 -0
- package/utils/useMFEModuleHeader.js +7 -3
package/index.js
CHANGED
|
@@ -14,3 +14,4 @@ export { default as getEnvVariable } from "./utils/getEnvVariables";
|
|
|
14
14
|
export { formatDateWithTimezone, getTimezoneTooltip, hasTimezoneFeatureAccess } from "./utils/timezone";
|
|
15
15
|
export { default as MFEEventBus } from "./utils/mfeEventBus";
|
|
16
16
|
export { default as useMFEModuleHeader } from "./utils/useMFEModuleHeader";
|
|
17
|
+
export { default as MFEModuleHeader } from "./utils/MFEModuleHeader";
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import useMFEModuleHeader from './useMFEModuleHeader';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MFEModuleHeader
|
|
5
|
+
*
|
|
6
|
+
* Headless component wrapper around useMFEModuleHeader for class components
|
|
7
|
+
* (which cannot call hooks). Render it anywhere inside a class component and
|
|
8
|
+
* pass the same config the hook takes; it runs the hook and renders nothing.
|
|
9
|
+
*
|
|
10
|
+
* Functional components should call useMFEModuleHeader directly instead.
|
|
11
|
+
*
|
|
12
|
+
* <MFEModuleHeader history={this.props.history} header={...} landingRoutes={[...]} />
|
|
13
|
+
*/
|
|
14
|
+
export default function MFEModuleHeader(props) {
|
|
15
|
+
useMFEModuleHeader(props);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
@@ -145,14 +145,18 @@ export default function useMFEModuleHeader(config) {
|
|
|
145
145
|
});
|
|
146
146
|
}, [history, navigate, settingsRoute, hasSettingsClick]);
|
|
147
147
|
|
|
148
|
-
// Back button
|
|
148
|
+
// Back button. Subscribe the default goBack whenever navigation is available,
|
|
149
|
+
// unless the caller overrides module:back-click via `listeners`. The host only
|
|
150
|
+
// emits this when it actually renders a back button, so an unused subscription
|
|
151
|
+
// is a harmless no-op.
|
|
152
|
+
const hasCustomBack = Boolean(listeners && listeners['module:back-click']);
|
|
149
153
|
useEffect(() => {
|
|
150
|
-
if (!
|
|
154
|
+
if ((!history && !navigate) || hasCustomBack) return undefined;
|
|
151
155
|
return MFEEventBus.on('module:back-click', () => {
|
|
152
156
|
if (history) history.goBack();
|
|
153
157
|
else if (navigate) navigate(-1);
|
|
154
158
|
});
|
|
155
|
-
}, [history, navigate,
|
|
159
|
+
}, [history, navigate, hasCustomBack]);
|
|
156
160
|
|
|
157
161
|
// Arbitrary custom event listeners. Handlers read from the ref so they can be
|
|
158
162
|
// inline; re-subscribes only when the set of event names changes.
|