UNPKG

@meonode/ui

Version:

A structured approach to component composition, direct CSS-first prop styling, built-in theming, smart prop handling (including raw property pass-through), and dynamic children.

3 lines (2 loc) 746 B
"use client"; import{createContext as e,useState as r,useRef as t,useCallback as o,useMemo as n}from"react";import{Node as l}from"../core.node.js";import{createDataChannel as d}from"../helper/data-channel.helper.js";const i=e(null);function c({children:e}){const[c,a]=r([]),s=t(0),h=o((e,r)=>{const t=++s.current,o=d(r);return a(r=>[...r,{id:t,Component:e,channel:o}]),{id:t,updateData:e=>o.set(e),close:()=>a(e=>e.filter(e=>e.id!==t))}},[]),p=o(()=>{a(e=>e.slice(0,-1))},[]),m=o(e=>{a(r=>r.filter(r=>r.id!==e))},[]),u=o(()=>{a([])},[]),f=n(()=>({stack:c,showPortal:h,hidePortal:p,hidePortalById:m,hideAll:u}),[c,h,p,m,u]);return l(i.Provider,{value:f,children:e}).render()}c.__meonodeAcceptsServerCss=!0;export{i as PortalContext,c as default};