@coreui/react-pro
Version:
UI Components Library for React.js
29 lines (25 loc) • 2.37 kB
JavaScript
'use strict';
var tslib_es6 = require('../../node_modules/tslib/tslib.es6.js');
var React = require('react');
var PropTypes = require('prop-types');
var index = require('../../_virtual/index.js');
var CFormControlWrapper = require('./CFormControlWrapper.js');
const CFormInput = React.forwardRef((_a, ref) => {
var { children, className, delay = false, feedback, feedbackInvalid, feedbackValid, floatingClassName, floatingLabel, id, invalid, label, onChange, plainText, size, text, tooltipFeedback, type = 'text', valid } = _a, rest = tslib_es6.__rest(_a, ["children", "className", "delay", "feedback", "feedbackInvalid", "feedbackValid", "floatingClassName", "floatingLabel", "id", "invalid", "label", "onChange", "plainText", "size", "text", "tooltipFeedback", "type", "valid"]);
const [value, setValue] = React.useState();
React.useEffect(() => {
const timeOutId = setTimeout(() => value && onChange && onChange(value), typeof delay === 'number' ? delay : 500);
return () => clearTimeout(timeOutId);
}, [value]);
return (React.createElement(CFormControlWrapper.CFormControlWrapper, { describedby: rest['aria-describedby'], feedback: feedback, feedbackInvalid: feedbackInvalid, feedbackValid: feedbackValid, floatingClassName: floatingClassName, floatingLabel: floatingLabel, id: id, invalid: invalid, label: label, text: text, tooltipFeedback: tooltipFeedback, valid: valid },
React.createElement("input", Object.assign({ className: index.default(plainText ? 'form-control-plaintext' : 'form-control', {
[`form-control-${size}`]: size,
'form-control-color': type === 'color',
'is-invalid': invalid,
'is-valid': valid,
}, className), id: id, type: type, onChange: (event) => (delay ? setValue(event) : onChange && onChange(event)) }, rest, { ref: ref }), children)));
});
CFormInput.propTypes = Object.assign({ className: PropTypes.string, id: PropTypes.string, delay: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]), plainText: PropTypes.bool, size: PropTypes.oneOf(['sm', 'lg']), type: PropTypes.oneOfType([PropTypes.oneOf(['color', 'file', 'text']), PropTypes.string]) }, CFormControlWrapper.CFormControlWrapper.propTypes);
CFormInput.displayName = 'CFormInput';
exports.CFormInput = CFormInput;
//# sourceMappingURL=CFormInput.js.map