@coreui/react-pro
Version:
UI Components Library for React.js
35 lines (31 loc) • 3.12 kB
JavaScript
;
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('../form/CFormControlWrapper.js');
const CPasswordInput = React.forwardRef((_a, ref) => {
var { children, ariaLabelToggler = 'Toggle password visibility', className, delay = false, feedback, feedbackInvalid, feedbackValid, floatingClassName, floatingLabel, id, invalid, label, onChange, showPassword: showPasswordProp = false, size, text, tooltipFeedback, valid } = _a, rest = tslib_es6.__rest(_a, ["children", "ariaLabelToggler", "className", "delay", "feedback", "feedbackInvalid", "feedbackValid", "floatingClassName", "floatingLabel", "id", "invalid", "label", "onChange", "showPassword", "size", "text", "tooltipFeedback", "valid"]);
const [value, setValue] = React.useState();
const [showPassword, setShowPassword] = React.useState(showPasswordProp);
React.useEffect(() => {
const timeOutId = setTimeout(() => value && onChange && onChange(value), typeof delay === 'number' ? delay : 500);
return () => clearTimeout(timeOutId);
}, [value]);
React.useEffect(() => {
setShowPassword(showPasswordProp);
}, [showPasswordProp]);
const renderInputAndButton = () => (React.createElement(React.Fragment, null,
React.createElement("input", Object.assign({ className: index.default('form-control', {
[`form-control-${size}`]: size,
'is-invalid': invalid,
'is-valid': valid,
}, className), id: id, type: showPassword ? 'text' : 'password', onChange: (event) => (delay ? setValue(event) : onChange === null || onChange === void 0 ? void 0 : onChange(event)) }, rest, { ref: ref }), children),
React.createElement("button", { type: "button", className: "form-password-action", "data-coreui-toggle": "password", "aria-label": ariaLabelToggler, onClick: () => setShowPassword((prev) => !prev) },
React.createElement("span", { className: "form-password-action-icon" }))));
return (React.createElement(CFormControlWrapper.CFormControlWrapper, { describedby: rest['aria-describedby'], feedback: feedback, feedbackInvalid: feedbackInvalid, feedbackValid: feedbackValid, floatingClassName: index.default('form-password', floatingClassName), floatingLabel: floatingLabel, id: id, invalid: invalid, label: label, text: text, tooltipFeedback: tooltipFeedback, valid: valid }, floatingLabel ? (renderInputAndButton()) : (React.createElement("div", { className: "form-password" }, renderInputAndButton()))));
});
CPasswordInput.propTypes = Object.assign({ ariaLabelToggler: PropTypes.string, className: PropTypes.string, id: PropTypes.string, delay: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]), showPassword: PropTypes.bool, size: PropTypes.oneOf(['sm', 'lg']) }, CFormControlWrapper.CFormControlWrapper.propTypes);
CPasswordInput.displayName = 'CPasswordInput';
exports.CPasswordInput = CPasswordInput;
//# sourceMappingURL=CPasswordInput.js.map