UNPKG

2.18 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5
6const propTypes = {
7 /** Adding card prop adds `.card-header-tabs` or `.card-header-pills` class */
8 card: PropTypes.bool,
9 /** Add custom class */
10 className: PropTypes.string,
11 /** Change underlying component's CSS base class name */
12 cssModule: PropTypes.object,
13 /** fills the nav to extend to full available width */
14 fill: PropTypes.bool,
15 /** Change the horizontal alignment of your nav */
16 horizontal: PropTypes.oneOf(['center', 'end']),
17 /** All horizontal space will be occupied by nav links, but unlike the `fill` above, every nav item will be the same width. */
18 justified: PropTypes.bool,
19 /** Add navbar for a full-height and lightweight navigation */
20 navbar: PropTypes.bool,
21 /** Make NavItems look like pills */
22 pills: PropTypes.bool,
23 /** Make NavItems look like tabs */
24 tabs: PropTypes.bool,
25 /** Set a custom element for this component */
26 tag: tagPropType,
27 /** Stack your navigation by changing the flex item direction */
28 vertical: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
29};
30
31const getVerticalClass = (vertical) => {
32 if (vertical === false) {
33 return false;
34 }
35 if (vertical === true || vertical === 'xs') {
36 return 'flex-column';
37 }
38
39 return `flex-${vertical}-column`;
40};
41
42function Nav(props) {
43 const {
44 className,
45 cssModule,
46 tabs,
47 pills,
48 vertical = false,
49 horizontal,
50 justified,
51 fill,
52 navbar,
53 card,
54 tag: Tag = 'ul',
55 ...attributes
56 } = props;
57
58 const classes = mapToCssModules(
59 classNames(
60 className,
61 navbar ? 'navbar-nav' : 'nav',
62 horizontal ? `justify-content-${horizontal}` : false,
63 getVerticalClass(vertical),
64 {
65 'nav-tabs': tabs,
66 'card-header-tabs': card && tabs,
67 'nav-pills': pills,
68 'card-header-pills': card && pills,
69 'nav-justified': justified,
70 'nav-fill': fill,
71 },
72 ),
73 cssModule,
74 );
75
76 return <Tag {...attributes} className={classes} />;
77}
78
79Nav.propTypes = propTypes;
80
81export default Nav;
82
\No newline at end of file