| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx } from "react/jsx-runtime"; |
| 3 |
import { Component, createContext, createRef } from 'react'; |
| 4 |
import styles from '@patternfly/react-styles/css/components/Nav/nav.mjs'; |
| 5 |
import { css } from '@patternfly/react-styles'; |
| 6 |
import { getOUIAProps } from '../../helpers'; |
| 7 |
import { SSRSafeIds } from '../../helpers/SSRSafeIds/SSRSafeIds'; |
| 8 |
export const navContextDefaults = {}; |
| 9 |
export const NavContext = createContext(navContextDefaults); |
| 10 |
class Nav extends Component { |
| 11 |
constructor() { |
| 12 |
super(...arguments); |
| 13 |
this.state = { |
| 14 |
isScrollable: false, |
| 15 |
flyoutRef: null |
| 16 |
}; |
| 17 |
this.navRef = createRef(); |
| 18 |
} |
| 19 |
// Callback from NavItem |
| 20 |
onSelect(event, groupId, itemId, to, preventDefault, onClick) { |
| 21 |
if (preventDefault) { |
| 22 |
event.preventDefault(); |
| 23 |
} |
| 24 |
this.props.onSelect(event, { groupId, itemId, to }); |
| 25 |
if (onClick) { |
| 26 |
onClick(event, itemId, groupId, to); |
| 27 |
} |
| 28 |
} |
| 29 |
// Callback from NavExpandable |
| 30 |
onToggle(event, groupId, toggleValue) { |
| 31 |
this.props.onToggle(event, { |
| 32 |
groupId, |
| 33 |
isExpanded: toggleValue |
| 34 |
}); |
| 35 |
} |
| 36 |
render() { |
| 37 |
const _a = this.props, { 'aria-label': ariaLabel, children, className, |
| 38 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 39 |
onSelect, |
| 40 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 41 |
onToggle, ouiaId, ouiaSafe, variant, isTextExpanded = false } = _a, props = __rest(_a, ['aria-label', "children", "className", "onSelect", "onToggle", "ouiaId", "ouiaSafe", "variant", "isTextExpanded"]); |
| 42 |
const isHorizontal = ['horizontal', 'horizontal-subnav'].includes(variant); |
| 43 |
const isDocked = variant === 'docked'; |
| 44 |
return (_jsx(SSRSafeIds, { prefix: "pf-", ouiaComponentType: `Nav${variant ? `-${variant}` : ''}`, children: (_, generatedOuiaId) => (_jsx(NavContext.Provider, { value: { |
| 45 |
onSelect: (event, groupId, itemId, to, preventDefault, onClick) => this.onSelect(event, groupId, itemId, to, preventDefault, onClick), |
| 46 |
onToggle: (event, groupId, expanded) => this.onToggle(event, groupId, expanded), |
| 47 |
updateIsScrollable: (isScrollable) => this.setState({ isScrollable }), |
| 48 |
isHorizontal: ['horizontal', 'horizontal-subnav'].includes(variant), |
| 49 |
flyoutRef: this.state.flyoutRef, |
| 50 |
setFlyoutRef: (flyoutRef) => this.setState({ flyoutRef }), |
| 51 |
navRef: this.navRef |
| 52 |
}, children: _jsx("nav", Object.assign({ className: css(styles.nav, isHorizontal && styles.modifiers.horizontal, isDocked && styles.modifiers.docked, variant === 'horizontal-subnav' && styles.modifiers.subnav, isDocked && isTextExpanded && styles.modifiers.textExpanded, this.state.isScrollable && styles.modifiers.scrollable, className), "aria-label": ariaLabel || (variant === 'horizontal-subnav' ? 'Local' : 'Global'), ref: this.navRef }, getOUIAProps(Nav.displayName, ouiaId !== undefined ? ouiaId : generatedOuiaId, ouiaSafe), props, { children: children })) })) })); |
| 53 |
} |
| 54 |
} |
| 55 |
Nav.displayName = 'Nav'; |
| 56 |
Nav.defaultProps = { |
| 57 |
onSelect: () => undefined, |
| 58 |
onToggle: () => undefined, |
| 59 |
ouiaSafe: true |
| 60 |
}; |
| 61 |
export { Nav }; |
| 62 |
//# sourceMappingURL=Nav.js.map |