package.dist.providers.environment.environment-provider.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react Show documentation
Show all versions of react Show documentation
A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.
The newest version!
'use client';
import { jsxs, jsx } from 'react/jsx-runtime';
import { getWindow, getDocument } from '@zag-js/dom-query';
import { useState, useMemo } from 'react';
import { runIfFn } from '../../utils/run-if-fn.js';
import { EnvironmentContextProvider } from './use-environment-context.js';
const EnvironmentProvider = (props) => {
const { value, children } = props;
const [spanRef, setSpanRef] = useState();
const getRootNode = useMemo(() => {
return () => runIfFn(value) ?? spanRef?.ownerDocument ?? document;
}, [value, spanRef]);
const environment = useMemo(
() => ({
getRootNode,
getWindow: () => getWindow(getRootNode()),
getDocument: () => getDocument(getRootNode())
}),
[getRootNode]
);
return /* @__PURE__ */ jsxs(EnvironmentContextProvider, { value: environment, children: [
children,
!value && /* @__PURE__ */ jsx("span", { hidden: true, ref: setSpanRef })
] });
};
export { EnvironmentProvider };
© 2015 - 2025 Weber Informatics LLC | Privacy Policy