@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.
169 lines (167 loc) • 6.07 kB
JavaScript
;
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DialogPopup = void 0;
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react2 = require("@floating-ui/react");
var _useDialogPopup = require("./useDialogPopup");
var _DialogRootContext = require("../root/DialogRootContext");
var _useComponentRenderer = require("../../utils/useComponentRenderer");
var _proptypes = require("../../utils/proptypes");
var _popupStateMapping = require("../../utils/popupStateMapping");
var _useForkRef = require("../../utils/useForkRef");
var _styleHookMapping = require("../../utils/styleHookMapping");
var _DialogPopupCssVars = require("./DialogPopupCssVars");
var _DialogPopupDataAttributes = require("./DialogPopupDataAttributes");
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; }
const customStyleHookMapping = {
..._popupStateMapping.popupStateMapping,
..._styleHookMapping.transitionStatusMapping,
hasNestedDialogs(value) {
return value ? {
[_DialogPopupDataAttributes.DialogPopupDataAttributes.hasNestedDialogs]: ''
} : null;
}
};
/**
* A container for the dialog contents.
* Renders a `<div>` element.
*
* Documentation: [Base UI Dialog](https://base-ui.com/react/components/dialog)
*/
const DialogPopup = exports.DialogPopup = /*#__PURE__*/React.forwardRef(function DialogPopup(props, forwardedRef) {
const {
className,
finalFocus,
id,
initialFocus,
keepMounted = false,
render,
...other
} = props;
const {
descriptionElementId,
dismissible,
floatingRootContext,
getPopupProps,
modal,
mounted,
nested,
nestedOpenDialogCount,
setOpen,
open,
openMethod,
popupRef,
setPopupElement,
setPopupElementId,
titleElementId,
transitionStatus
} = (0, _DialogRootContext.useDialogRootContext)();
const mergedRef = (0, _useForkRef.useForkRef)(forwardedRef, popupRef);
const {
getRootProps,
floatingContext,
resolvedInitialFocus
} = (0, _useDialogPopup.useDialogPopup)({
descriptionElementId,
floatingRootContext,
getPopupProps,
id,
initialFocus,
modal,
mounted,
setOpen,
open,
openMethod,
ref: mergedRef,
setPopupElement,
setPopupElementId,
titleElementId
});
const state = {
open,
nested,
transitionStatus,
hasNestedDialogs: nestedOpenDialogCount > 0
};
const {
renderElement
} = (0, _useComponentRenderer.useComponentRenderer)({
render: render ?? 'div',
className,
state,
propGetter: getRootProps,
extraProps: {
...other,
style: {
...other.style,
[_DialogPopupCssVars.DialogPopupCssVars.nestedDialogs]: nestedOpenDialogCount
}
},
customStyleHookMapping
});
if (!keepMounted && !mounted) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.FloatingFocusManager, {
context: floatingContext,
modal: open,
disabled: !mounted,
closeOnFocusOut: dismissible,
initialFocus: resolvedInitialFocus,
returnFocus: finalFocus,
outsideElementsInert: modal,
children: renderElement()
});
});
process.env.NODE_ENV !== "production" ? DialogPopup.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: _propTypes.default.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
*/
className: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
/**
* Determines the element to focus when the dialog is closed.
* By default, focus returns to the trigger.
*/
finalFocus: _proptypes.refType,
/**
* @ignore
*/
id: _propTypes.default.string,
/**
* Determines the element to focus when the dialog is opened.
* By default, the first focusable element is focused.
*/
initialFocus: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.func, _proptypes.refType]),
/**
* Whether to keep the HTML element in the DOM while the dialog is hidden.
* @default false
*/
keepMounted: _propTypes.default.bool,
/**
* Allows you to replace the component’s HTML element
* with a different tag, or compose it with another component.
*
* Accepts a `ReactElement` or a function that returns the element to render.
*/
render: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func]),
/**
* @ignore
*/
style: _propTypes.default.object
} : void 0;