@pantheon-systems/design-toolkit-react
Version:
Pantheon's React Design Toolkit
66 lines (63 loc) • 3.31 kB
JavaScript
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import { asField, BasicText } from 'informed';
import PropTypes from 'prop-types';
import { useState, Fragment } from 'react';
import { ButtonSecondary } from '../Buttons/index.js';
import InputGroup from './InputGroup.js';
import { jsxs, jsx } from 'react/jsx-runtime';
var _excluded = ["i18n"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var PasswordInput = asField(function (props) {
var i18n = props.i18n,
rest = _objectWithoutProperties(props, _excluded);
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isPasswordShown = _useState2[0],
setIsPasswordShown = _useState2[1];
var toggleShow = function toggleShow() {
return setIsPasswordShown(!isPasswordShown);
};
var field = props.field,
fieldState = props.fieldState;
var error = fieldState.error,
value = fieldState.value;
var strings = {
hiddenDescription: i18n.hiddenDescription(),
hideButtonText: i18n.hideButtonText(),
showButtonText: i18n.showButtonText(),
shownDescription: i18n.shownDescription()
};
return /*#__PURE__*/jsxs(Fragment, {
children: [/*#__PURE__*/jsxs(InputGroup, {
children: [/*#__PURE__*/jsx(BasicText, _objectSpread(_objectSpread({}, rest), {}, {
"aria-invalid": !!error,
autoComplete: "off",
className: "custom-text-input ".concat(value && !error ? 'success' : value && error && 'error'),
id: field,
type: isPasswordShown ? 'text' : 'password'
})), /*#__PURE__*/jsx(ButtonSecondary, {
"aria-label": isPasswordShown ? strings.shownDescription : strings.hiddenDescription,
className: "button-secondary dt-button",
onClick: toggleShow,
children: isPasswordShown ? strings.hideButtonText : strings.showButtonText
})]
}), error && /*#__PURE__*/jsx("small", {
className: "text-red-3",
children: error
})]
});
});
PasswordInput.propTypes = {
i18n: PropTypes.shape({
hiddenDescription: PropTypes.func.isRequired,
hideButtonText: PropTypes.func.isRequired,
showButtonText: PropTypes.func.isRequired,
shownDescription: PropTypes.func.isRequired
}).isRequired
};
var PasswordInput$1 = PasswordInput;
export { PasswordInput$1 as default };
//# sourceMappingURL=PasswordInput.js.map