1 | import React from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import classNames from 'classnames';
|
4 | import { mapToCssModules, tagPropType } from './utils';
|
5 |
|
6 | const propTypes = {
|
7 |
|
8 | className: PropTypes.string,
|
9 |
|
10 | cssModule: PropTypes.object,
|
11 |
|
12 | flush: PropTypes.bool,
|
13 |
|
14 | horizontal: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
15 |
|
16 | numbered: PropTypes.bool,
|
17 |
|
18 | tag: tagPropType,
|
19 | };
|
20 |
|
21 | const 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 |
|
31 | function 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 |
|
46 |
|
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 |
|
58 | ListGroup.propTypes = propTypes;
|
59 |
|
60 | export default ListGroup;
|
61 |
|
\ | No newline at end of file |