Debian Codegraph @

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

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