UNPKG

1.59 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 /** Remove borders to make the list appear flush */
12 flush: PropTypes.bool,
13 /** Make the list horizontal instead of vertical */
14 horizontal: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
15 /** Add number to the ListItems */
16 numbered: PropTypes.bool,
17 /** Set a custom element for this component */
18 tag: tagPropType,
19};
20
21const getHorizontalClass = (horizontal) => {
22 if (horizontal === false) {
23 return false;
24 }
25 if (horizontal === true || horizontal === 'xs') {
26 return 'list-group-horizontal';
27 }
28 return `list-group-horizontal-${horizontal}`;
29};
30
31function ListGroup(props) {
32 const {
33 className,
34 cssModule,
35 tag: Tag = 'ul',
36 flush,
37 horizontal = false,
38 numbered = false,
39 ...attributes
40 } = props;
41 const classes = mapToCssModules(
42 classNames(
43 className,
44 'list-group',
45 // list-group-horizontal cannot currently be mixed with list-group-flush
46 // we only try to apply horizontal classes if flush is false
47 flush ? 'list-group-flush' : getHorizontalClass(horizontal),
48 {
49 'list-group-numbered': numbered,
50 },
51 ),
52 cssModule,
53 );
54
55 return <Tag {...attributes} className={classes} />;
56}
57
58ListGroup.propTypes = propTypes;
59
60export default ListGroup;
61
\No newline at end of file