UNPKG

1.19 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5import Dropdown from './Dropdown';
6import { InputGroupContext } from './InputGroupContext';
7
8const propTypes = {
9 /** Add custom class */
10 className: PropTypes.string,
11 /** Change underlying component's CSS base class name */
12 cssModule: PropTypes.object,
13 /** Sets size of InputGroup */
14 size: PropTypes.string,
15 /** Set a custom element for this component */
16 tag: tagPropType,
17 type: PropTypes.string,
18};
19
20function InputGroup(props) {
21 const {
22 className,
23 cssModule,
24 tag: Tag = 'div',
25 type,
26 size,
27 ...attributes
28 } = props;
29 const classes = mapToCssModules(
30 classNames(className, 'input-group', size ? `input-group-${size}` : null),
31 cssModule,
32 );
33
34 if (props.type === 'dropdown') {
35 return <Dropdown {...attributes} className={classes} />;
36 }
37
38 return (
39 <InputGroupContext.Provider value={{ insideInputGroup: true }}>
40 <Tag {...attributes} className={classes} />
41 </InputGroupContext.Provider>
42 );
43}
44
45InputGroup.propTypes = propTypes;
46
47export default InputGroup;