UNPKG

1.44 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType, deprecated } from './utils';
5
6const rowColWidths = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
7const rowColsPropType = PropTypes.oneOfType([
8 PropTypes.number,
9 PropTypes.string,
10]);
11
12const propTypes = {
13 tag: tagPropType,
14 noGutters: deprecated(
15 PropTypes.bool,
16 'Please use Bootstrap 5 gutter utility classes. https://getbootstrap.com/docs/5.0/layout/gutters/',
17 ),
18 className: PropTypes.string,
19 cssModule: PropTypes.object,
20 xs: rowColsPropType,
21 sm: rowColsPropType,
22 md: rowColsPropType,
23 lg: rowColsPropType,
24 xl: rowColsPropType,
25 xxl: rowColsPropType,
26 widths: PropTypes.array,
27};
28
29function Row(props) {
30 const {
31 className,
32 cssModule,
33 noGutters,
34 tag: Tag = 'div',
35 widths = rowColWidths,
36 ...attributes
37 } = props;
38
39 const colClasses = [];
40
41 widths.forEach((colWidth, i) => {
42 let colSize = props[colWidth];
43
44 delete attributes[colWidth];
45
46 if (!colSize) {
47 return;
48 }
49
50 const isXs = !i;
51 colClasses.push(
52 isXs ? `row-cols-${colSize}` : `row-cols-${colWidth}-${colSize}`,
53 );
54 });
55
56 const classes = mapToCssModules(
57 classNames(className, noGutters ? 'gx-0' : null, 'row', colClasses),
58 cssModule,
59 );
60
61 return <Tag {...attributes} className={classes} />;
62}
63
64Row.propTypes = propTypes;
65
66export default Row;
67
\No newline at end of file