All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.providers.environment.environment-provider.js Maven / Gradle / Ivy

Go to download

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