Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import classNames from 'classnames';
  4. import all from 'prop-types-extra/lib/all';
  5. import React, { useContext, useMemo } from 'react';
  6. import Feedback from './Feedback';
  7. import FormCheckInput from './FormCheckInput';
  8. import FormCheckLabel from './FormCheckLabel';
  9. import FormContext from './FormContext';
  10. import { useBootstrapPrefix } from './ThemeProvider';
  11. var defaultProps = {
  12. type: 'checkbox',
  13. inline: false,
  14. disabled: false,
  15. isValid: false,
  16. isInvalid: false,
  17. title: ''
  18. };
  19. var FormCheck = React.forwardRef(function (_ref, ref) {
  20. var id = _ref.id,
  21. bsPrefix = _ref.bsPrefix,
  22. bsCustomPrefix = _ref.bsCustomPrefix,
  23. inline = _ref.inline,
  24. disabled = _ref.disabled,
  25. isValid = _ref.isValid,
  26. isInvalid = _ref.isInvalid,
  27. feedback = _ref.feedback,
  28. className = _ref.className,
  29. style = _ref.style,
  30. title = _ref.title,
  31. type = _ref.type,
  32. label = _ref.label,
  33. children = _ref.children,
  34. propCustom = _ref.custom,
  35. _ref$as = _ref.as,
  36. as = _ref$as === void 0 ? 'input' : _ref$as,
  37. props = _objectWithoutPropertiesLoose(_ref, ["id", "bsPrefix", "bsCustomPrefix", "inline", "disabled", "isValid", "isInvalid", "feedback", "className", "style", "title", "type", "label", "children", "custom", "as"]);
  38. var custom = type === 'switch' ? true : propCustom;
  39. bsPrefix = custom ? useBootstrapPrefix(bsCustomPrefix, 'custom-control') : useBootstrapPrefix(bsPrefix, 'form-check');
  40. var _useContext = useContext(FormContext),
  41. controlId = _useContext.controlId;
  42. var innerFormContext = useMemo(function () {
  43. return {
  44. controlId: id || controlId,
  45. custom: custom
  46. };
  47. }, [controlId, custom, id]);
  48. var hasLabel = label != null && label !== false && !children;
  49. var input = React.createElement(FormCheckInput, _extends({}, props, {
  50. type: type === 'switch' ? 'checkbox' : type,
  51. ref: ref,
  52. isValid: isValid,
  53. isInvalid: isInvalid,
  54. isStatic: !hasLabel,
  55. disabled: disabled,
  56. as: as
  57. }));
  58. return React.createElement(FormContext.Provider, {
  59. value: innerFormContext
  60. }, React.createElement("div", {
  61. style: style,
  62. className: classNames(className, bsPrefix, custom && "custom-" + type, inline && bsPrefix + "-inline")
  63. }, children || React.createElement(React.Fragment, null, input, hasLabel && React.createElement(FormCheckLabel, {
  64. title: title
  65. }, label), (isValid || isInvalid) && React.createElement(Feedback, {
  66. type: isValid ? 'valid' : 'invalid'
  67. }, feedback))));
  68. });
  69. FormCheck.displayName = 'FormCheck';
  70. FormCheck.defaultProps = defaultProps;
  71. FormCheck.Input = FormCheckInput;
  72. FormCheck.Label = FormCheckLabel;
  73. export default FormCheck;