@coreui/react-pro
Version:
UI Components Library for React.js
27 lines (24 loc) • 2.31 kB
JavaScript
import { __rest } from '../../node_modules/tslib/tslib.es6.js';
import React, { forwardRef, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import classNames from '../../_virtual/index.js';
import { CFormControlWrapper } from './CFormControlWrapper.js';
const CFormInput = 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 = __rest(_a, ["children", "className", "delay", "feedback", "feedbackInvalid", "feedbackValid", "floatingClassName", "floatingLabel", "id", "invalid", "label", "onChange", "plainText", "size", "text", "tooltipFeedback", "type", "valid"]);
const [value, setValue] = useState();
useEffect(() => {
const timeOutId = setTimeout(() => value && onChange && onChange(value), typeof delay === 'number' ? delay : 500);
return () => clearTimeout(timeOutId);
}, [value]);
return (React.createElement(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: classNames(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.propTypes);
CFormInput.displayName = 'CFormInput';
export { CFormInput };
//# sourceMappingURL=CFormInput.js.map