-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
InputGroup.js
88 lines (73 loc) · 1.99 KB
/
InputGroup.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import createWithBsPrefix from './createWithBsPrefix';
import { useBootstrapPrefix } from './ThemeProvider';
const propTypes = {
/** @default 'input-group' */
bsPrefix: PropTypes.string,
/**
* Control the size of buttons and form elements from the top-level .
*
* @type {('sm'|'lg')}
*/
size: PropTypes.string,
as: PropTypes.elementType,
};
/**
*
* @property {InputGroupAppend} Append
* @property {InputGroupPrepend} Prepend
* @property {InputGroupText} Text
* @property {InputGroupRadio} Radio
* @property {InputGroupCheckbox} Checkbox
*/
const InputGroup = React.forwardRef(
(
{
bsPrefix,
size,
className,
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'div',
...props
},
ref,
) => {
bsPrefix = useBootstrapPrefix(bsPrefix, 'input-group');
return (
<Component
ref={ref}
{...props}
className={classNames(
className,
bsPrefix,
size && `${bsPrefix}-${size}`,
)}
/>
);
},
);
const InputGroupAppend = createWithBsPrefix('input-group-append');
const InputGroupPrepend = createWithBsPrefix('input-group-prepend');
const InputGroupText = createWithBsPrefix('input-group-text', {
Component: 'span',
});
const InputGroupCheckbox = (props) => (
<InputGroupText>
<input type="checkbox" {...props} />
</InputGroupText>
);
const InputGroupRadio = (props) => (
<InputGroupText>
<input type="radio" {...props} />
</InputGroupText>
);
InputGroup.propTypes = propTypes;
InputGroup.displayName = 'InputGroup';
InputGroup.Text = InputGroupText;
InputGroup.Radio = InputGroupRadio;
InputGroup.Checkbox = InputGroupCheckbox;
InputGroup.Append = InputGroupAppend;
InputGroup.Prepend = InputGroupPrepend;
export default InputGroup;