UNPKG

1.09 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5
6const propTypes = {
7 /** Add custom class */
8 className: PropTypes.string,
9 /** Change underlying component's CSS base class name */
10 cssModule: PropTypes.object,
11 /** Set a custom element for this component */
12 tag: tagPropType,
13 type: PropTypes.string,
14 /** Pass children so this component can wrap the child elements */
15 children: PropTypes.node,
16};
17
18function NavbarToggler(props) {
19 const {
20 className,
21 cssModule,
22 children,
23 tag: Tag = 'button',
24 ...attributes
25 } = props;
26
27 const classes = mapToCssModules(
28 classNames(className, 'navbar-toggler'),
29 cssModule,
30 );
31
32 return (
33 <Tag
34 aria-label="Toggle navigation"
35 {...{ type: 'button', ...attributes }}
36 className={classes}
37 >
38 {children || (
39 <span className={mapToCssModules('navbar-toggler-icon', cssModule)} />
40 )}
41 </Tag>
42 );
43}
44
45NavbarToggler.propTypes = propTypes;
46
47export default NavbarToggler;