Debian Codegraph @

node/@patternfly/react-core/dist/js/components/Nav/NavExpandable.js

raw
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.NavExpandable = void 0;
4 const tslib_1 = require("tslib");
5 const jsx_runtime_1 = require("react/jsx-runtime");
6 const react_1 = require("react");
7 const nav_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Nav/nav"));
8 const react_styles_1 = require("@patternfly/react-styles");
9 const rh_microns_caret_down_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-microns-caret-down-icon'));
10 const Nav_1 = require("./Nav");
11 const PageSidebar_1 = require("../Page/PageSidebar");
12 const helpers_1 = require("../../helpers");
13 const SSRSafeIds_1 = require("../../helpers/SSRSafeIds/SSRSafeIds");
14 class NavExpandable extends react_1.Component {
15 constructor() {
16 super(...arguments);
17 this.state = {
18 expandedState: this.props.isExpanded
19 };
20 this.onExpand = (event, onToggle) => {
21 const { expandedState } = this.state;
22 if (this.props.onExpand) {
23 this.props.onExpand(event, !expandedState);
24 }
25 else {
26 this.setState((prevState) => ({ expandedState: !prevState.expandedState }));
27 const { groupId } = this.props;
28 onToggle(event, groupId, !expandedState);
29 }
30 };
31 }
32 componentDidMount() {
33 this.setState({ expandedState: this.props.isExpanded });
34 }
35 componentDidUpdate(prevProps) {
36 if (this.props.isExpanded !== prevProps.isExpanded) {
37 this.setState({ expandedState: this.props.isExpanded });
38 }
39 }
40 render() {
41 const _a = this.props, { icon, title, srText, children, className, isActive, ouiaId,
42 // eslint-disable-next-line @typescript-eslint/no-unused-vars
43 groupId, id,
44 // eslint-disable-next-line @typescript-eslint/no-unused-vars
45 isExpanded, buttonProps,
46 // eslint-disable-next-line @typescript-eslint/no-unused-vars
47 onExpand } = _a, props = tslib_1.__rest(_a, ["icon", "title", "srText", "children", "className", "isActive", "ouiaId", "groupId", "id", "isExpanded", "buttonProps", "onExpand"]);
48 const { expandedState } = this.state;
49 return ((0, jsx_runtime_1.jsx)(SSRSafeIds_1.SSRSafeIds, { prefix: "pf-nav-expandable-", ouiaComponentType: "NavExpandable", children: (generatedId, generatedOuiaId) => {
50 const navId = id || generatedId;
51 return ((0, jsx_runtime_1.jsx)(Nav_1.NavContext.Consumer, { children: (context) => ((0, jsx_runtime_1.jsxs)("li", Object.assign({ className: (0, react_styles_1.css)(nav_1.default.navItem, expandedState && nav_1.default.modifiers.expanded, isActive && nav_1.default.modifiers.current, className) }, (0, helpers_1.getOUIAProps)(NavExpandable.displayName, ouiaId !== undefined ? ouiaId : generatedOuiaId), props, { children: [(0, jsx_runtime_1.jsx)(PageSidebar_1.PageSidebarContext.Consumer, { children: ({ isSidebarOpen }) => ((0, jsx_runtime_1.jsxs)("button", Object.assign({ className: (0, react_styles_1.css)(nav_1.default.navLink), id: srText ? null : navId, onClick: (event) => this.onExpand(event, context.onToggle), "aria-expanded": expandedState, tabIndex: isSidebarOpen ? null : -1 }, buttonProps, { children: [icon && (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(nav_1.default.navLinkIcon), children: icon }), typeof title !== 'string' ? (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(nav_1.default.navLinkText), children: title }) : title, (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(nav_1.default.navToggle), children: (0, jsx_runtime_1.jsx)("span", { className: (0, react_styles_1.css)(nav_1.default.navToggleIcon), children: (0, jsx_runtime_1.jsx)(rh_microns_caret_down_icon_1.default, {}) }) })] }))) }), (0, jsx_runtime_1.jsxs)("section", Object.assign({ className: (0, react_styles_1.css)(nav_1.default.navSubnav), "aria-labelledby": navId, hidden: expandedState ? null : true }, (!expandedState && { inert: '' }), { children: [srText && ((0, jsx_runtime_1.jsx)("h2", { className: "pf-v6-screen-reader", id: navId, children: srText })), (0, jsx_runtime_1.jsx)("ul", { className: (0, react_styles_1.css)(nav_1.default.navList), role: "list", children: children })] }))] }))) }));
52 } }));
53 }
54 }
55 exports.NavExpandable = NavExpandable;
56 NavExpandable.displayName = 'NavExpandable';
57 NavExpandable.defaultProps = {
58 srText: '',
59 isExpanded: false,
60 children: '',
61 className: '',
62 groupId: null,
63 isActive: false,
64 id: ''
65 };
66 //# sourceMappingURL=NavExpandable.js.map