UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

60 lines (56 loc) 2.14 kB
"use client"; const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); const require_portal = require('../portal/portal.cjs'); const require_notice = require('./notice.cjs'); let react = require("react"); react = require_rolldown_runtime.__toESM(react); let react_jsx_runtime = require("react/jsx-runtime"); react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime); //#region src/components/notice/notice-provider.tsx const NoticeContext = (0, react.createContext)({}); const createController = () => ({ getLimit: (0, react.createRef)(), updateLimit: (0, react.createRef)() }); const createMethods = (id, refs, defaultLimit) => ({ getId: (placement) => { return `${id}-${placement}`; }, getLimit: (placement) => { const method = refs[placement]?.current.getLimit.current; return method?.(placement) ?? defaultLimit; }, updateLimit: (state) => { const { placement } = state; const method = refs[placement]?.current.updateLimit.current; method?.(state); } }); const NoticeProvider = ({ children, containerRef, expand = false, limit = 3 }) => { const placementMap = (0, react.useRef)({}); const id = (0, react.useId)(); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(NoticeContext, { value: (0, react.useMemo)(() => ({ ...createMethods(id, placementMap.current, limit) }), [id, limit]), children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_portal.Portal, { containerRef, children: (0, react.useMemo)(() => { return Object.keys(require_notice.PLACEMENT_MAP).map((placement) => { if (!placementMap.current[placement]) placementMap.current[placement] = { current: createController() }; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_notice.NoticeRoot, { ref: placementMap.current[placement], expand, limit, placement }, placement); }); }, [limit, expand]) })] }); }; const useNoticeContext = () => { return (0, react.use)(NoticeContext); }; //#endregion exports.NoticeProvider = NoticeProvider; exports.useNoticeContext = useNoticeContext; //# sourceMappingURL=notice-provider.cjs.map