1 | import classNames from 'classnames';
|
2 | import * as React from 'react';
|
3 | import { useContext } from 'react';
|
4 | import useEventCallback from '@restart/hooks/useEventCallback';
|
5 | import { useBootstrapPrefix } from './ThemeProvider';
|
6 | import NavbarContext from './NavbarContext';
|
7 | import { jsx as _jsx } from "react/jsx-runtime";
|
8 | const defaultProps = {
|
9 | label: 'Toggle navigation'
|
10 | };
|
11 | const NavbarToggle = React.forwardRef(({
|
12 | bsPrefix,
|
13 | className,
|
14 | children,
|
15 | label,
|
16 |
|
17 | as: Component = 'button',
|
18 | onClick,
|
19 | ...props
|
20 | }, ref) => {
|
21 | bsPrefix = useBootstrapPrefix(bsPrefix, 'navbar-toggler');
|
22 | const {
|
23 | onToggle,
|
24 | expanded
|
25 | } = useContext(NavbarContext) || {};
|
26 | const handleClick = useEventCallback(e => {
|
27 | if (onClick) onClick(e);
|
28 | if (onToggle) onToggle();
|
29 | });
|
30 |
|
31 | if (Component === 'button') {
|
32 | props.type = 'button';
|
33 | }
|
34 |
|
35 | return _jsx(Component, { ...props,
|
36 | ref: ref,
|
37 | onClick: handleClick,
|
38 | "aria-label": label,
|
39 | className: classNames(className, bsPrefix, !expanded && 'collapsed'),
|
40 | children: children || _jsx("span", {
|
41 | className: `${bsPrefix}-icon`
|
42 | })
|
43 | });
|
44 | });
|
45 | NavbarToggle.displayName = 'NavbarToggle';
|
46 | NavbarToggle.defaultProps = defaultProps;
|
47 | export default NavbarToggle; |
\ | No newline at end of file |