UNPKG

@talend/react-bootstrap

Version:

Bootstrap 3 components built with React

87 lines (85 loc) 2.44 kB
/* eslint-disable jsx-a11y/label-has-for */ import classNames from 'classnames'; import React from 'react'; import PropTypes from 'prop-types'; import warning from 'warning'; import { bsClass, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const propTypes = { inline: PropTypes.bool, disabled: PropTypes.bool, title: PropTypes.string, /** * Only valid if `inline` is not set. */ validationState: PropTypes.oneOf(['success', 'warning', 'error', null]), /** * Attaches a ref to the `<input>` element. Only functions can be used here. * * ```js * <Checkbox inputRef={ref => { this.input = ref; }} /> * ``` */ inputRef: PropTypes.func }; const defaultProps = { inline: false, disabled: false, title: '' }; class Checkbox extends React.Component { render() { const { inline, disabled, validationState, inputRef, className, style, title, children, ...props } = this.props; const [bsProps, elementProps] = splitBsProps(props); const input = /*#__PURE__*/_jsx("input", { ...elementProps, ref: inputRef, type: "checkbox", disabled: disabled }); if (inline) { const classes = { [prefix(bsProps, 'inline')]: true, disabled }; // Use a warning here instead of in propTypes to get better-looking // generated documentation. warning(!validationState, '`validationState` is ignored on `<Checkbox inline>`. To display ' + 'validation state on an inline checkbox, set `validationState` on a ' + 'parent `<FormGroup>` or other element instead.'); return /*#__PURE__*/_jsxs("label", { className: classNames(className, classes), style: style, title: title, children: [input, children] }); } const classes = { ...getClassSet(bsProps), disabled }; if (validationState) { classes[`has-${validationState}`] = true; } return /*#__PURE__*/_jsx("div", { className: classNames(className, classes), style: style, children: /*#__PURE__*/_jsxs("label", { title: title, children: [input, children] }) }); } } Checkbox.propTypes = propTypes; Checkbox.defaultProps = defaultProps; export default bsClass('checkbox', Checkbox); //# sourceMappingURL=Checkbox.js.map