@carbon-labs/react-ui-shell 0.3.0 → 0.5.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 +10 -0
- package/es/components/HeaderPanel.d.ts +35 -0
- package/es/components/HeaderPanel.js +104 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/lib/components/HeaderPanel.d.ts +35 -0
- package/lib/components/HeaderPanel.js +106 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/package.json +10 -4
- package/scss/styles/_side-nav.scss +0 -2
- package/telemetry.yml +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# @carbon-labs/react-ui-shell
|
|
2
|
+
|
|
3
|
+
## <picture><source height="20" width="20" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-dark.svg"><source height="20" width="20" media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-light.svg"><img height="20" width="20" alt="IBM Telemetry" src="https://raw.githubusercontent.com/ibm-telemetry/telemetry-js/main/docs/images/ibm-telemetry-light.svg"></picture> IBM Telemetry
|
|
4
|
+
|
|
5
|
+
This package uses IBM Telemetry to collect de-identified and anonymized metrics
|
|
6
|
+
data. By installing this package as a dependency you are agreeing to telemetry
|
|
7
|
+
collection. To opt out, see
|
|
8
|
+
[Opting out of IBM Telemetry data collection](https://github.com/ibm-telemetry/telemetry-js/tree/main#opting-out-of-ibm-telemetry-data-collection).
|
|
9
|
+
For more information on the data being collected, please see the
|
|
10
|
+
[IBM Telemetry documentation](https://github.com/ibm-telemetry/telemetry-js/tree/main#ibm-telemetry-collection-basics).
|
|
@@ -0,0 +1,35 @@
|
|
|
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>;
|
|
@@ -0,0 +1,104 @@
|
|
|
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 '@carbon/react/lib/internal/usePrefix';
|
|
13
|
+
import { keys } from '@carbon/react/lib/internal/keyboard/keys';
|
|
14
|
+
import { match } from '@carbon/react/lib/internal/keyboard/match';
|
|
15
|
+
import { useWindowEvent } from '@carbon/react/lib/internal/useEvent';
|
|
16
|
+
import { useMergedRefs } from '@carbon/react/lib/internal/useMergedRefs';
|
|
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, keys.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 };
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
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>;
|
|
@@ -0,0 +1,106 @@
|
|
|
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('@carbon/react/lib/internal/usePrefix');
|
|
15
|
+
var keys = require('@carbon/react/lib/internal/keyboard/keys');
|
|
16
|
+
var match = require('@carbon/react/lib/internal/keyboard/match');
|
|
17
|
+
var useEvent = require('@carbon/react/lib/internal/useEvent');
|
|
18
|
+
var useMergedRefs = require('@carbon/react/lib/internal/useMergedRefs');
|
|
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.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;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbon-labs/react-ui-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -18,14 +18,20 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"es",
|
|
20
20
|
"lib",
|
|
21
|
-
"scss"
|
|
21
|
+
"scss",
|
|
22
|
+
"telemetry.yml"
|
|
22
23
|
],
|
|
23
24
|
"scripts": {
|
|
24
25
|
"build": "node ../../../tasks/build.js",
|
|
25
|
-
"clean": "rm -rf {es,lib,scss}"
|
|
26
|
+
"clean": "rm -rf {es,lib,scss}",
|
|
27
|
+
"postinstall": "ibmtelemetry --config=telemetry.yml",
|
|
28
|
+
"telemetry:config": "npx -y @ibm/telemetry-js-config-generator generate --id 5b9dce15-eeda-4b53-8683-3e3aeb599fd1 --endpoint https://www-api.ibm.com/ibm-telemetry/v1/metrics --files ./components/**/*.(tsx|js|jsx)"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
31
|
"@carbon-labs/utilities": "canary"
|
|
29
32
|
},
|
|
30
|
-
"
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@ibm/telemetry-js": "^1.9.1"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "ddd5bb7c28f78a9a143e27c2e1fdf3fb8d463708"
|
|
31
37
|
}
|
package/telemetry.yml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://unpkg.com/@ibm/telemetry-config-schema@v1/dist/config.schema.json
|
|
2
|
+
|
|
3
|
+
version: 1
|
|
4
|
+
projectId: 5b9dce15-eeda-4b53-8683-3e3aeb599fd1
|
|
5
|
+
endpoint: https://www-api.ibm.com/ibm-telemetry/v1/metrics
|
|
6
|
+
collect:
|
|
7
|
+
jsx:
|
|
8
|
+
elements:
|
|
9
|
+
allowedAttributeNames:
|
|
10
|
+
# SideNav
|
|
11
|
+
- addFocusListeners
|
|
12
|
+
- addMouseListeners
|
|
13
|
+
- className
|
|
14
|
+
- defaultExpanded
|
|
15
|
+
- enterDelayMs
|
|
16
|
+
- expanded
|
|
17
|
+
- href
|
|
18
|
+
- inert
|
|
19
|
+
- isChildOfHeader
|
|
20
|
+
- isCollapsible
|
|
21
|
+
- isFixedNav
|
|
22
|
+
- isPersistent
|
|
23
|
+
- isRail
|
|
24
|
+
- onOverlayClick
|
|
25
|
+
- onSideNavBlur
|
|
26
|
+
- onToggle
|
|
27
|
+
# React
|
|
28
|
+
- key
|
|
29
|
+
- ref
|
|
30
|
+
allowedAttributeStringValues:
|
|
31
|
+
- 'true'
|
|
32
|
+
- 'false'
|
|
33
|
+
npm:
|
|
34
|
+
dependencies: null
|
|
35
|
+
js:
|
|
36
|
+
functions: {}
|
|
37
|
+
tokens: null
|