@talend/react-bootstrap
Version:
Bootstrap 3 components built with React
94 lines (91 loc) • 2.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _warning = _interopRequireDefault(require("warning"));
var _bootstrapUtils = require("./utils/bootstrapUtils");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/* eslint-disable jsx-a11y/label-has-for */
const propTypes = {
inline: _propTypes.default.bool,
disabled: _propTypes.default.bool,
title: _propTypes.default.string,
/**
* Only valid if `inline` is not set.
*/
validationState: _propTypes.default.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.default.func
};
const defaultProps = {
inline: false,
disabled: false,
title: ''
};
class Checkbox extends _react.default.Component {
render() {
const {
inline,
disabled,
validationState,
inputRef,
className,
style,
title,
children,
...props
} = this.props;
const [bsProps, elementProps] = (0, _bootstrapUtils.splitBsProps)(props);
const input = /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
...elementProps,
ref: inputRef,
type: "checkbox",
disabled: disabled
});
if (inline) {
const classes = {
[(0, _bootstrapUtils.prefix)(bsProps, 'inline')]: true,
disabled
};
// Use a warning here instead of in propTypes to get better-looking
// generated documentation.
(0, _warning.default)(!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__*/(0, _jsxRuntime.jsxs)("label", {
className: (0, _classnames.default)(className, classes),
style: style,
title: title,
children: [input, children]
});
}
const classes = {
...(0, _bootstrapUtils.getClassSet)(bsProps),
disabled
};
if (validationState) {
classes[`has-${validationState}`] = true;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _classnames.default)(className, classes),
style: style,
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
title: title,
children: [input, children]
})
});
}
}
Checkbox.propTypes = propTypes;
Checkbox.defaultProps = defaultProps;
var _default = exports.default = (0, _bootstrapUtils.bsClass)('checkbox', Checkbox);
//# sourceMappingURL=Checkbox.js.map