/
FormCheckLabel.js
49 lines (41 loc) · 1.16 KB
/
FormCheckLabel.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
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { createBootstrapComponent } from './ThemeProvider';
import FormContext from './FormContext';
const propTypes = {
/**
* @default 'form-check-input'
*/
bsPrefix: PropTypes.string,
/**
* @private
*/
innerRef: PropTypes.any,
/** The HTML for attribute for associating the label with an input */
htmlFor: PropTypes.string,
};
const defaultProps = {
type: 'checkbox',
};
function FormCheckLabel({ bsPrefix, className, innerRef, htmlFor, ...props }) {
return (
<FormContext.Consumer>
{({ controlId, custom }) => (
<label // eslint-disable-line jsx-a11y/label-has-associated-control
{...props}
ref={innerRef}
htmlFor={htmlFor || controlId}
className={classNames(
className,
!custom && bsPrefix,
custom && 'custom-control-label',
)}
/>
)}
</FormContext.Consumer>
);
}
FormCheckLabel.propTypes = propTypes;
FormCheckLabel.defaultProps = defaultProps;
export default createBootstrapComponent(FormCheckLabel, 'form-check-label');