forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListGroup.js
More file actions
67 lines (60 loc) · 1.64 KB
/
Copy pathListGroup.js
File metadata and controls
67 lines (60 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
const propTypes = {
/** Add custom class */
className: PropTypes.string,
/** Change underlying component's CSS base class name */
cssModule: PropTypes.object,
/** Remove borders to make the list appear flush */
flush: PropTypes.bool,
/** Make the list horizontal instead of vertical */
horizontal: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
/** Add number to the ListItems */
numbered: PropTypes.bool,
/** Set a custom element for this component */
tag: tagPropType,
};
const defaultProps = {
tag: 'ul',
horizontal: false,
numbered: false,
};
const getHorizontalClass = (horizontal) => {
if (horizontal === false) {
return false;
}
if (horizontal === true || horizontal === 'xs') {
return 'list-group-horizontal';
}
return `list-group-horizontal-${horizontal}`;
};
function ListGroup(props) {
const {
className,
cssModule,
tag: Tag,
flush,
horizontal,
numbered,
...attributes
} = props;
const classes = mapToCssModules(
classNames(
className,
'list-group',
// list-group-horizontal cannot currently be mixed with list-group-flush
// we only try to apply horizontal classes if flush is false
flush ? 'list-group-flush' : getHorizontalClass(horizontal),
{
'list-group-numbered': numbered,
},
),
cssModule,
);
return <Tag {...attributes} className={classes} />;
}
ListGroup.propTypes = propTypes;
ListGroup.defaultProps = defaultProps;
export default ListGroup;