UNPKG

@pantheon-systems/design-toolkit-react

Version:
50 lines (47 loc) 2.56 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; import { asField, BasicText } from 'informed'; import PropTypes from 'prop-types'; import { Fragment } from 'react'; import { jsxs, jsx } from 'react/jsx-runtime'; var _excluded = ["noBorder", "validationSuccessText"]; 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 TextInput = asField(function (props) { var noBorder = props.noBorder, validationSuccessText = props.validationSuccessText, informedProps = _objectWithoutProperties(props, _excluded); var field = informedProps.field, fieldState = informedProps.fieldState; var error = fieldState.error, value = fieldState.value; var success = value && !error; var statusClass = success ? 'success' : error && 'error'; return /*#__PURE__*/jsxs(Fragment, { children: [/*#__PURE__*/jsx(BasicText, _objectSpread(_objectSpread({}, informedProps), {}, { "aria-invalid": !!error, className: "custom-field ".concat(noBorder ? 'no-border' : '', " ").concat(statusClass || ''), id: field })), success && validationSuccessText ? /*#__PURE__*/jsx("small", { className: "text-green-3", children: validationSuccessText }) : null, error && /*#__PURE__*/jsx("small", { className: "text-red-3", children: error })] }); }); TextInput.defaultProps = { noBorder: false, type: 'text', validationSuccessText: '' }; TextInput.propTypes = { field: PropTypes.string.isRequired, noBorder: PropTypes.bool, type: PropTypes.string, validationSuccessText: PropTypes.string }; var TextInput$1 = TextInput; export { TextInput$1 as default }; //# sourceMappingURL=TextInput.js.map