@base-ui-components/react
Version:
Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.
58 lines (57 loc) • 3.14 kB
JavaScript
;
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FieldValidity = void 0;
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _FieldRootContext = require("../root/FieldRootContext");
var _getCombinedFieldValidityData = require("../utils/getCombinedFieldValidityData");
var _jsxRuntime = require("react/jsx-runtime");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/**
* Used to display a custom message based on the field’s validity.
* Requires `children` to be a function that accepts field validity state as an argument.
*
* Documentation: [Base UI Field](https://base-ui.com/react/components/field)
*/
const FieldValidity = exports.FieldValidity = function FieldValidity(props) {
const {
children
} = props;
const {
validityData,
invalid
} = (0, _FieldRootContext.useFieldRootContext)(false);
const fieldValidityState = React.useMemo(() => {
const combinedFieldValidityData = (0, _getCombinedFieldValidityData.getCombinedFieldValidityData)(validityData, invalid);
return {
...combinedFieldValidityData,
validity: combinedFieldValidityData.state
};
}, [validityData, invalid]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
children: children(fieldValidityState)
});
};
process.env.NODE_ENV !== "production" ? FieldValidity.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* A function that accepts the field validity state as an argument.
*
* ```jsx
* <Field.Validity>
* {(validity) => {
* return <div>...</div>
* }}
* </Field.Validity>
* ```
*/
children: _propTypes.default.func.isRequired
} : void 0;