@carbon-labs/react-ui-shell 0.57.0 → 0.59.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/README.md +0 -1
- package/es/components/HeaderContainer.d.ts +1 -2
- package/es/components/HeaderContainer.js +15 -2
- package/es/index.d.ts +0 -1
- package/es/index.js +0 -1
- package/lib/components/HeaderContainer.d.ts +1 -2
- package/lib/components/HeaderContainer.js +14 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -2
- package/package.json +2 -2
- package/scss/styles/_profile.scss +3 -1
- package/es/components/HeaderPanel.d.ts +0 -35
- package/es/components/HeaderPanel.js +0 -104
- package/lib/components/HeaderPanel.d.ts +0 -35
- package/lib/components/HeaderPanel.js +0 -106
package/README.md
CHANGED
|
@@ -24,8 +24,7 @@ export type HeaderContainerProps<P extends HeaderContainerRenderProps> = {
|
|
|
24
24
|
} & {
|
|
25
25
|
[K in keyof Omit<P, keyof HeaderContainerRenderProps>]: P[K];
|
|
26
26
|
};
|
|
27
|
-
export declare function HeaderContainer<P extends HeaderContainerRenderProps>({ render: Children, isSideNavExpanded, isSwitcherExpanded, isProfileExpanded, themeSetting,
|
|
28
|
-
...rest }: HeaderContainerProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare function HeaderContainer<P extends HeaderContainerRenderProps>({ render: Children, isSideNavExpanded, isSwitcherExpanded, isProfileExpanded, themeSetting, ...rest }: HeaderContainerProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
29
28
|
export declare namespace HeaderContainer {
|
|
30
29
|
var propTypes: {
|
|
31
30
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import PropTypes from 'prop-types';
|
|
10
|
-
import React, { useState, useCallback, useLayoutEffect } from 'react';
|
|
10
|
+
import React, { useState, useCallback, useLayoutEffect, useEffect } from 'react';
|
|
11
11
|
import { Escape } from '../internal/keyboard/keys.js';
|
|
12
12
|
import { match } from '../internal/keyboard/match.js';
|
|
13
13
|
import { useWindowEvent } from '../internal/useEvent.js';
|
|
@@ -20,7 +20,6 @@ function HeaderContainer(_ref) {
|
|
|
20
20
|
isSwitcherExpanded = false,
|
|
21
21
|
isProfileExpanded = false,
|
|
22
22
|
themeSetting,
|
|
23
|
-
// <-- pass this in from the story
|
|
24
23
|
...rest
|
|
25
24
|
} = _ref;
|
|
26
25
|
const prefix = usePrefix();
|
|
@@ -50,6 +49,20 @@ function HeaderContainer(_ref) {
|
|
|
50
49
|
document.querySelector(`.${prefix}--profile .${prefix}--content-switcher--selected`).focus();
|
|
51
50
|
});
|
|
52
51
|
}, [themeSetting]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
function handleProfileClosing(event) {
|
|
54
|
+
const profile = document.querySelector(`.${prefix}--profile.${prefix}--popover--open`);
|
|
55
|
+
if (profile && !profile.contains(event.target)) {
|
|
56
|
+
setIsProfileExpandedState(false);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
document.addEventListener('focusin', handleProfileClosing);
|
|
60
|
+
document.addEventListener('mousedown', handleProfileClosing);
|
|
61
|
+
return () => {
|
|
62
|
+
document.removeEventListener('mousedown', handleProfileClosing);
|
|
63
|
+
document.removeEventListener('focusin', handleProfileClosing);
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
53
66
|
return /*#__PURE__*/React.createElement(Children, _extends({}, rest, {
|
|
54
67
|
isSideNavExpanded: isSideNavExpandedState,
|
|
55
68
|
isSwitcherExpanded: isSwitcherExpandedState,
|
package/es/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export { SideNavMenu } from './components/SideNavMenu';
|
|
|
14
14
|
export { SideNavMenuItem } from './components/SideNavMenuItem';
|
|
15
15
|
export { HeaderContainer } from './components/HeaderContainer';
|
|
16
16
|
export { HeaderPopover, HeaderPopoverActions, HeaderPopoverButton, HeaderPopoverContent, } from './components/HeaderPopover';
|
|
17
|
-
export { HeaderPanel } from './components/HeaderPanel';
|
|
18
17
|
export { SharkFinIcon } from './components/SharkFinIcon';
|
|
19
18
|
export { HeaderDivider } from './components/HeaderDivider';
|
|
20
19
|
export { TrialCountdown } from './components/TrialCountdown';
|
package/es/index.js
CHANGED
|
@@ -13,7 +13,6 @@ export { SideNavMenu } from './components/SideNavMenu.js';
|
|
|
13
13
|
export { SideNavMenuItem } from './components/SideNavMenuItem.js';
|
|
14
14
|
export { HeaderContainer } from './components/HeaderContainer.js';
|
|
15
15
|
export { HeaderPopover, HeaderPopoverActions, HeaderPopoverButton, HeaderPopoverContent } from './components/HeaderPopover.js';
|
|
16
|
-
export { HeaderPanel } from './components/HeaderPanel.js';
|
|
17
16
|
export { SharkFinIcon } from './components/SharkFinIcon.js';
|
|
18
17
|
export { HeaderDivider } from './components/HeaderDivider.js';
|
|
19
18
|
export { TrialCountdown } from './components/TrialCountdown.js';
|
|
@@ -24,8 +24,7 @@ export type HeaderContainerProps<P extends HeaderContainerRenderProps> = {
|
|
|
24
24
|
} & {
|
|
25
25
|
[K in keyof Omit<P, keyof HeaderContainerRenderProps>]: P[K];
|
|
26
26
|
};
|
|
27
|
-
export declare function HeaderContainer<P extends HeaderContainerRenderProps>({ render: Children, isSideNavExpanded, isSwitcherExpanded, isProfileExpanded, themeSetting,
|
|
28
|
-
...rest }: HeaderContainerProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare function HeaderContainer<P extends HeaderContainerRenderProps>({ render: Children, isSideNavExpanded, isSwitcherExpanded, isProfileExpanded, themeSetting, ...rest }: HeaderContainerProps<P>): import("react/jsx-runtime").JSX.Element;
|
|
29
28
|
export declare namespace HeaderContainer {
|
|
30
29
|
var propTypes: {
|
|
31
30
|
/**
|
|
@@ -24,7 +24,6 @@ function HeaderContainer(_ref) {
|
|
|
24
24
|
isSwitcherExpanded = false,
|
|
25
25
|
isProfileExpanded = false,
|
|
26
26
|
themeSetting,
|
|
27
|
-
// <-- pass this in from the story
|
|
28
27
|
...rest
|
|
29
28
|
} = _ref;
|
|
30
29
|
const prefix = usePrefix.usePrefix();
|
|
@@ -54,6 +53,20 @@ function HeaderContainer(_ref) {
|
|
|
54
53
|
document.querySelector(`.${prefix}--profile .${prefix}--content-switcher--selected`).focus();
|
|
55
54
|
});
|
|
56
55
|
}, [themeSetting]);
|
|
56
|
+
React.useEffect(() => {
|
|
57
|
+
function handleProfileClosing(event) {
|
|
58
|
+
const profile = document.querySelector(`.${prefix}--profile.${prefix}--popover--open`);
|
|
59
|
+
if (profile && !profile.contains(event.target)) {
|
|
60
|
+
setIsProfileExpandedState(false);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
document.addEventListener('focusin', handleProfileClosing);
|
|
64
|
+
document.addEventListener('mousedown', handleProfileClosing);
|
|
65
|
+
return () => {
|
|
66
|
+
document.removeEventListener('mousedown', handleProfileClosing);
|
|
67
|
+
document.removeEventListener('focusin', handleProfileClosing);
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
57
70
|
return /*#__PURE__*/React.createElement(Children, _rollupPluginBabelHelpers.extends({}, rest, {
|
|
58
71
|
isSideNavExpanded: isSideNavExpandedState,
|
|
59
72
|
isSwitcherExpanded: isSwitcherExpandedState,
|
package/lib/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export { SideNavMenu } from './components/SideNavMenu';
|
|
|
14
14
|
export { SideNavMenuItem } from './components/SideNavMenuItem';
|
|
15
15
|
export { HeaderContainer } from './components/HeaderContainer';
|
|
16
16
|
export { HeaderPopover, HeaderPopoverActions, HeaderPopoverButton, HeaderPopoverContent, } from './components/HeaderPopover';
|
|
17
|
-
export { HeaderPanel } from './components/HeaderPanel';
|
|
18
17
|
export { SharkFinIcon } from './components/SharkFinIcon';
|
|
19
18
|
export { HeaderDivider } from './components/HeaderDivider';
|
|
20
19
|
export { TrialCountdown } from './components/TrialCountdown';
|
package/lib/index.js
CHANGED
|
@@ -15,7 +15,6 @@ var SideNavMenu = require('./components/SideNavMenu.js');
|
|
|
15
15
|
var SideNavMenuItem = require('./components/SideNavMenuItem.js');
|
|
16
16
|
var HeaderContainer = require('./components/HeaderContainer.js');
|
|
17
17
|
var HeaderPopover = require('./components/HeaderPopover.js');
|
|
18
|
-
var HeaderPanel = require('./components/HeaderPanel.js');
|
|
19
18
|
var SharkFinIcon = require('./components/SharkFinIcon.js');
|
|
20
19
|
var HeaderDivider = require('./components/HeaderDivider.js');
|
|
21
20
|
var TrialCountdown = require('./components/TrialCountdown.js');
|
|
@@ -36,7 +35,6 @@ exports.HeaderPopover = HeaderPopover.HeaderPopover;
|
|
|
36
35
|
exports.HeaderPopoverActions = HeaderPopover.HeaderPopoverActions;
|
|
37
36
|
exports.HeaderPopoverButton = HeaderPopover.HeaderPopoverButton;
|
|
38
37
|
exports.HeaderPopoverContent = HeaderPopover.HeaderPopoverContent;
|
|
39
|
-
exports.HeaderPanel = HeaderPanel.HeaderPanel;
|
|
40
38
|
exports.SharkFinIcon = SharkFinIcon.SharkFinIcon;
|
|
41
39
|
exports.HeaderDivider = HeaderDivider.HeaderDivider;
|
|
42
40
|
exports.TrialCountdown = TrialCountdown.TrialCountdown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon-labs/react-ui-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@ibm/telemetry-js": "^1.9.1"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "eaacfa9c007e1d4f54cd64e30f5d176f8ed2b1e1"
|
|
46
46
|
}
|
|
@@ -22,14 +22,16 @@ $prefix: 'cds' !default;
|
|
|
22
22
|
.#{$prefix}--profile .#{$prefix}--toggletip-content {
|
|
23
23
|
padding: 0;
|
|
24
24
|
background-color: $background;
|
|
25
|
+
border-block-end: 1px solid $border-subtle;
|
|
25
26
|
border-inline-start: 1px solid $border-subtle;
|
|
26
27
|
gap: 0;
|
|
28
|
+
inline-size: convert.to-rem(256px);
|
|
27
29
|
max-block-size: 100vh;
|
|
28
30
|
overflow-y: scroll;
|
|
29
31
|
|
|
30
32
|
> * {
|
|
31
33
|
padding: $spacing-05;
|
|
32
|
-
|
|
34
|
+
outline: convert.to-rem(0.5px) solid $border-subtle;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2025
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import React, { ReactNode } from 'react';
|
|
8
|
-
export interface HeaderPanelProps {
|
|
9
|
-
/**
|
|
10
|
-
* Specify whether focus and blur listeners are added. They are by default.
|
|
11
|
-
*/
|
|
12
|
-
addFocusListeners?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* The content that will render inside of the `HeaderPanel`
|
|
15
|
-
*/
|
|
16
|
-
children?: ReactNode;
|
|
17
|
-
/**
|
|
18
|
-
* Optionally provide a custom class to apply to the underlying `<li>` node
|
|
19
|
-
*/
|
|
20
|
-
className?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Specify whether the panel is expanded
|
|
23
|
-
*/
|
|
24
|
-
expanded?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Provide the `href` to the id of the element on your package that could
|
|
27
|
-
* be target.
|
|
28
|
-
*/
|
|
29
|
-
href?: string;
|
|
30
|
-
/**
|
|
31
|
-
* An optional listener that is called a callback to collapse the HeaderPanel
|
|
32
|
-
*/
|
|
33
|
-
onHeaderPanelFocus?: () => void;
|
|
34
|
-
}
|
|
35
|
-
export declare const HeaderPanel: React.FC<HeaderPanelProps>;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2024
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import cx from '../_virtual/index.js';
|
|
10
|
-
import PropTypes from 'prop-types';
|
|
11
|
-
import React, { useRef, useState } from 'react';
|
|
12
|
-
import { usePrefix } from '../internal/usePrefix.js';
|
|
13
|
-
import { Escape } from '../internal/keyboard/keys.js';
|
|
14
|
-
import { match } from '../internal/keyboard/match.js';
|
|
15
|
-
import { useWindowEvent } from '../internal/useEvent.js';
|
|
16
|
-
import { useMergedRefs } from '../internal/useMergedRefs.js';
|
|
17
|
-
|
|
18
|
-
const noopFn = () => {};
|
|
19
|
-
const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel(_ref, ref) {
|
|
20
|
-
let {
|
|
21
|
-
children,
|
|
22
|
-
className: customClassName,
|
|
23
|
-
expanded,
|
|
24
|
-
addFocusListeners = true,
|
|
25
|
-
onHeaderPanelFocus = noopFn,
|
|
26
|
-
href,
|
|
27
|
-
...rest
|
|
28
|
-
} = _ref;
|
|
29
|
-
const prefix = usePrefix();
|
|
30
|
-
const headerPanelReference = useRef(null);
|
|
31
|
-
const headerPanelRef = useMergedRefs([headerPanelReference, ref]);
|
|
32
|
-
const controlled = useRef(expanded !== undefined).current;
|
|
33
|
-
const [expandedState, setExpandedState] = useState(expanded);
|
|
34
|
-
const expandedProp = controlled ? expanded : expandedState;
|
|
35
|
-
const [lastClickedElement, setLastClickedElement] = useState(null);
|
|
36
|
-
const className = cx(`${prefix}--header-panel`, {
|
|
37
|
-
[`${prefix}--header-panel--expanded`]: expandedProp,
|
|
38
|
-
[customClassName]: !!customClassName
|
|
39
|
-
});
|
|
40
|
-
const eventHandlers = {};
|
|
41
|
-
if (addFocusListeners) {
|
|
42
|
-
eventHandlers.onBlur = event => {
|
|
43
|
-
if (!event.currentTarget.contains(event.relatedTarget) && !lastClickedElement?.classList?.contains(`${prefix}--switcher__item-link`)) {
|
|
44
|
-
setExpandedState(false);
|
|
45
|
-
setLastClickedElement(null);
|
|
46
|
-
if (expanded) {
|
|
47
|
-
onHeaderPanelFocus();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
eventHandlers.onKeyDown = event => {
|
|
52
|
-
if (match(event, Escape)) {
|
|
53
|
-
setExpandedState(false);
|
|
54
|
-
onHeaderPanelFocus();
|
|
55
|
-
if (href) {
|
|
56
|
-
window.location.href = href;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
useWindowEvent('click', () => {
|
|
62
|
-
const focusedElement = document.activeElement;
|
|
63
|
-
setLastClickedElement(focusedElement);
|
|
64
|
-
const childJsxElement = children;
|
|
65
|
-
if (childJsxElement?.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelReference?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
|
|
66
|
-
setExpandedState(false);
|
|
67
|
-
onHeaderPanelFocus();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
71
|
-
className: className,
|
|
72
|
-
ref: headerPanelRef
|
|
73
|
-
}, eventHandlers), children);
|
|
74
|
-
});
|
|
75
|
-
HeaderPanel.propTypes = {
|
|
76
|
-
/**
|
|
77
|
-
* Specify whether focus and blur listeners are added. They are by default.
|
|
78
|
-
*/
|
|
79
|
-
addFocusListeners: PropTypes.bool,
|
|
80
|
-
/**
|
|
81
|
-
* The content that will render inside of the `HeaderPanel`
|
|
82
|
-
*/
|
|
83
|
-
children: PropTypes.any,
|
|
84
|
-
/**
|
|
85
|
-
* Optionally provide a custom class to apply to the underlying `<li>` node
|
|
86
|
-
*/
|
|
87
|
-
className: PropTypes.string,
|
|
88
|
-
/**
|
|
89
|
-
* Specify whether the panel is expanded
|
|
90
|
-
*/
|
|
91
|
-
expanded: PropTypes.bool,
|
|
92
|
-
/**
|
|
93
|
-
* Provide the `href` to the id of the element on your package that could
|
|
94
|
-
* be target.
|
|
95
|
-
*/
|
|
96
|
-
href: PropTypes.string,
|
|
97
|
-
/**
|
|
98
|
-
* An optional listener that is called a callback to collapse the HeaderPanel
|
|
99
|
-
*/
|
|
100
|
-
onHeaderPanelFocus: PropTypes.func
|
|
101
|
-
};
|
|
102
|
-
HeaderPanel.displayName = 'HeaderPanel';
|
|
103
|
-
|
|
104
|
-
export { HeaderPanel };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2025
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import React, { ReactNode } from 'react';
|
|
8
|
-
export interface HeaderPanelProps {
|
|
9
|
-
/**
|
|
10
|
-
* Specify whether focus and blur listeners are added. They are by default.
|
|
11
|
-
*/
|
|
12
|
-
addFocusListeners?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* The content that will render inside of the `HeaderPanel`
|
|
15
|
-
*/
|
|
16
|
-
children?: ReactNode;
|
|
17
|
-
/**
|
|
18
|
-
* Optionally provide a custom class to apply to the underlying `<li>` node
|
|
19
|
-
*/
|
|
20
|
-
className?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Specify whether the panel is expanded
|
|
23
|
-
*/
|
|
24
|
-
expanded?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Provide the `href` to the id of the element on your package that could
|
|
27
|
-
* be target.
|
|
28
|
-
*/
|
|
29
|
-
href?: string;
|
|
30
|
-
/**
|
|
31
|
-
* An optional listener that is called a callback to collapse the HeaderPanel
|
|
32
|
-
*/
|
|
33
|
-
onHeaderPanelFocus?: () => void;
|
|
34
|
-
}
|
|
35
|
-
export declare const HeaderPanel: React.FC<HeaderPanelProps>;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright IBM Corp. 2024
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
|
|
11
|
-
var index = require('../_virtual/index.js');
|
|
12
|
-
var PropTypes = require('prop-types');
|
|
13
|
-
var React = require('react');
|
|
14
|
-
var usePrefix = require('../internal/usePrefix.js');
|
|
15
|
-
var keys = require('../internal/keyboard/keys.js');
|
|
16
|
-
var match = require('../internal/keyboard/match.js');
|
|
17
|
-
var useEvent = require('../internal/useEvent.js');
|
|
18
|
-
var useMergedRefs = require('../internal/useMergedRefs.js');
|
|
19
|
-
|
|
20
|
-
const noopFn = () => {};
|
|
21
|
-
const HeaderPanel = /*#__PURE__*/React.forwardRef(function HeaderPanel(_ref, ref) {
|
|
22
|
-
let {
|
|
23
|
-
children,
|
|
24
|
-
className: customClassName,
|
|
25
|
-
expanded,
|
|
26
|
-
addFocusListeners = true,
|
|
27
|
-
onHeaderPanelFocus = noopFn,
|
|
28
|
-
href,
|
|
29
|
-
...rest
|
|
30
|
-
} = _ref;
|
|
31
|
-
const prefix = usePrefix.usePrefix();
|
|
32
|
-
const headerPanelReference = React.useRef(null);
|
|
33
|
-
const headerPanelRef = useMergedRefs.useMergedRefs([headerPanelReference, ref]);
|
|
34
|
-
const controlled = React.useRef(expanded !== undefined).current;
|
|
35
|
-
const [expandedState, setExpandedState] = React.useState(expanded);
|
|
36
|
-
const expandedProp = controlled ? expanded : expandedState;
|
|
37
|
-
const [lastClickedElement, setLastClickedElement] = React.useState(null);
|
|
38
|
-
const className = index.default(`${prefix}--header-panel`, {
|
|
39
|
-
[`${prefix}--header-panel--expanded`]: expandedProp,
|
|
40
|
-
[customClassName]: !!customClassName
|
|
41
|
-
});
|
|
42
|
-
const eventHandlers = {};
|
|
43
|
-
if (addFocusListeners) {
|
|
44
|
-
eventHandlers.onBlur = event => {
|
|
45
|
-
if (!event.currentTarget.contains(event.relatedTarget) && !lastClickedElement?.classList?.contains(`${prefix}--switcher__item-link`)) {
|
|
46
|
-
setExpandedState(false);
|
|
47
|
-
setLastClickedElement(null);
|
|
48
|
-
if (expanded) {
|
|
49
|
-
onHeaderPanelFocus();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
eventHandlers.onKeyDown = event => {
|
|
54
|
-
if (match.match(event, keys.Escape)) {
|
|
55
|
-
setExpandedState(false);
|
|
56
|
-
onHeaderPanelFocus();
|
|
57
|
-
if (href) {
|
|
58
|
-
window.location.href = href;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
useEvent.useWindowEvent('click', () => {
|
|
64
|
-
const focusedElement = document.activeElement;
|
|
65
|
-
setLastClickedElement(focusedElement);
|
|
66
|
-
const childJsxElement = children;
|
|
67
|
-
if (childJsxElement?.type?.displayName === 'Switcher' && !focusedElement?.closest(`.${prefix}--header-panel--expanded`) && !focusedElement?.closest(`.${prefix}--header__action`) && !headerPanelReference?.current?.classList.contains(`${prefix}--switcher`) && expanded) {
|
|
68
|
-
setExpandedState(false);
|
|
69
|
-
onHeaderPanelFocus();
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
return /*#__PURE__*/React.createElement("div", _rollupPluginBabelHelpers.extends({}, rest, {
|
|
73
|
-
className: className,
|
|
74
|
-
ref: headerPanelRef
|
|
75
|
-
}, eventHandlers), children);
|
|
76
|
-
});
|
|
77
|
-
HeaderPanel.propTypes = {
|
|
78
|
-
/**
|
|
79
|
-
* Specify whether focus and blur listeners are added. They are by default.
|
|
80
|
-
*/
|
|
81
|
-
addFocusListeners: PropTypes.bool,
|
|
82
|
-
/**
|
|
83
|
-
* The content that will render inside of the `HeaderPanel`
|
|
84
|
-
*/
|
|
85
|
-
children: PropTypes.any,
|
|
86
|
-
/**
|
|
87
|
-
* Optionally provide a custom class to apply to the underlying `<li>` node
|
|
88
|
-
*/
|
|
89
|
-
className: PropTypes.string,
|
|
90
|
-
/**
|
|
91
|
-
* Specify whether the panel is expanded
|
|
92
|
-
*/
|
|
93
|
-
expanded: PropTypes.bool,
|
|
94
|
-
/**
|
|
95
|
-
* Provide the `href` to the id of the element on your package that could
|
|
96
|
-
* be target.
|
|
97
|
-
*/
|
|
98
|
-
href: PropTypes.string,
|
|
99
|
-
/**
|
|
100
|
-
* An optional listener that is called a callback to collapse the HeaderPanel
|
|
101
|
-
*/
|
|
102
|
-
onHeaderPanelFocus: PropTypes.func
|
|
103
|
-
};
|
|
104
|
-
HeaderPanel.displayName = 'HeaderPanel';
|
|
105
|
-
|
|
106
|
-
exports.HeaderPanel = HeaderPanel;
|