UNPKG

1.32 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5
6const propTypes = {
7 children: PropTypes.node,
8 row: PropTypes.bool,
9 check: PropTypes.bool,
10 switch: PropTypes.bool,
11 inline: PropTypes.bool,
12 floating: PropTypes.bool,
13 noMargin: PropTypes.bool,
14 disabled: PropTypes.bool,
15 tag: tagPropType,
16 className: PropTypes.string,
17 cssModule: PropTypes.object,
18};
19
20function FormGroup(props) {
21 const {
22 className,
23 cssModule,
24 row,
25 disabled,
26 check,
27 inline,
28 floating,
29 noMargin,
30 tag: Tag = 'div',
31 switch: switchProp,
32 ...attributes
33 } = props;
34
35 const formCheck = check || switchProp;
36
37 const classes = mapToCssModules(
38 classNames(
39 className,
40 row ? 'row' : false,
41 formCheck ? 'form-check' : false,
42 switchProp ? 'form-switch' : false,
43 formCheck || noMargin ? false : 'mb-3',
44 formCheck && inline ? 'form-check-inline' : false,
45 formCheck && disabled ? 'disabled' : false,
46 floating && 'form-floating',
47 ),
48 cssModule,
49 );
50
51 if (Tag === 'fieldset') {
52 attributes.disabled = disabled;
53 }
54
55 return <Tag {...attributes} className={classes} />;
56}
57
58FormGroup.propTypes = propTypes;
59
60export default FormGroup;
61
\No newline at end of file