forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputGroup.js
More file actions
45 lines (38 loc) · 1.2 KB
/
InputGroup.js
File metadata and controls
45 lines (38 loc) · 1.2 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
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { mapToCssModules, tagPropType } from './utils';
import Dropdown from './Dropdown';
import { InputGroupContext } from './InputGroupContext';
const propTypes = {
/** Add custom class */
className: PropTypes.string,
/** Change underlying component's CSS base class name */
cssModule: PropTypes.object,
/** Sets size of InputGroup */
size: PropTypes.string,
/** Set a custom element for this component */
tag: tagPropType,
type: PropTypes.string,
};
const defaultProps = {
tag: 'div',
};
function InputGroup(props) {
const { className, cssModule, tag: Tag, type, size, ...attributes } = props;
const classes = mapToCssModules(
classNames(className, 'input-group', size ? `input-group-${size}` : null),
cssModule,
);
if (props.type === 'dropdown') {
return <Dropdown {...attributes} className={classes} />;
}
return (
<InputGroupContext.Provider value={{ insideInputGroup: true }}>
<Tag {...attributes} className={classes} />
</InputGroupContext.Provider>
);
}
InputGroup.propTypes = propTypes;
InputGroup.defaultProps = defaultProps;
export default InputGroup;