UNPKG

@coreui/react-pro

Version:

UI Components Library for React.js

38 lines (34 loc) 3.7 kB
'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('../form/CFormControlWrapper.js'); var CPasswordInput = React.forwardRef(function (_a, ref) { var children = _a.children, _b = _a.ariaLabelToggler, ariaLabelToggler = _b === void 0 ? 'Toggle password visibility' : _b, className = _a.className, _c = _a.delay, delay = _c === void 0 ? false : _c, feedback = _a.feedback, feedbackInvalid = _a.feedbackInvalid, feedbackValid = _a.feedbackValid, floatingClassName = _a.floatingClassName, floatingLabel = _a.floatingLabel, id = _a.id, invalid = _a.invalid, label = _a.label, onChange = _a.onChange, _d = _a.showPassword, showPasswordProp = _d === void 0 ? false : _d, size = _a.size, text = _a.text, tooltipFeedback = _a.tooltipFeedback, valid = _a.valid, rest = tslib_es6.__rest(_a, ["children", "ariaLabelToggler", "className", "delay", "feedback", "feedbackInvalid", "feedbackValid", "floatingClassName", "floatingLabel", "id", "invalid", "label", "onChange", "showPassword", "size", "text", "tooltipFeedback", "valid"]); var _e = React.useState(), value = _e[0], setValue = _e[1]; var _f = React.useState(showPasswordProp), showPassword = _f[0], setShowPassword = _f[1]; React.useEffect(function () { var timeOutId = setTimeout(function () { return value && onChange && onChange(value); }, typeof delay === 'number' ? delay : 500); return function () { return clearTimeout(timeOutId); }; }, [value]); React.useEffect(function () { setShowPassword(showPasswordProp); }, [showPasswordProp]); var renderInputAndButton = function () { var _a; return (React.createElement(React.Fragment, null, React.createElement("input", tslib_es6.__assign({ className: index.default('form-control', (_a = {}, _a["form-control-".concat(size)] = size, _a['is-invalid'] = invalid, _a['is-valid'] = valid, _a), className), id: id, type: showPassword ? 'text' : 'password', onChange: function (event) { return (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: function () { return setShowPassword(function (prev) { return !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 = tslib_es6.__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