-
Notifications
You must be signed in to change notification settings - Fork 0
/
47-a28f22da2d828c0b81f9.js
1 lines (1 loc) · 29.9 KB
/
47-a28f22da2d828c0b81f9.js
1
webpackJsonp([47],{1531:function(n,t,a){"use strict";function s(n){return n&&n.__esModule?n:{default:n}}function o(n){return b.default.createElement(n.tag,(0,d.default)({},n.attributes,{dangerouslySetInnerHTML:{__html:n.html}}))}function e(n){return b.default.createElement(o,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function p(n){return b.default.createElement(o,{tag:"style",html:n.style})}function c(n,t){for(;n;)return n.offsetTop&&"static"!==getComputedStyle(n).position&&(t+=n.offsetTop),c(n.parentNode,t);return t}Object.defineProperty(t,"__esModule",{value:!0});var l=a(7),d=s(l),r=a(1),u=s(r),i=a(4),k=s(i),h=a(2),f=s(h),g=a(3),m=s(g),y=a(0),b=s(y),P=a(232),v=s(P),w=a(359),C=function(){var n=w.Portal.PurePortal,t=w.Portal.withNonScrollable(w.Portal.withESCToClose(w.Portal)),a=function(a){function s(){var n,t,a,o;(0,u.default)(this,s);for(var e=arguments.length,p=Array(e),c=0;c<e;c++)p[c]=arguments[c];return t=a=(0,f.default)(this,(n=s.__proto__||Object.getPrototypeOf(s)).call.apply(n,[this].concat(p))),a.state={bodyPortalVisible:!1,purePortalVisible:!1},a.togglePurePortal=function(){return a.setState({purePortalVisible:!a.state.purePortalVisible})},a.showBodyPortal=function(){return a.setState({bodyPortalVisible:!0})},a.hideBodyPortal=function(){return a.setState({bodyPortalVisible:!1})},o=t,(0,f.default)(a,o)}return(0,m.default)(s,a),(0,k.default)(s,[{key:"render",value:function(){return b.default.createElement("div",{className:"zent-doc-portal-container"},b.default.createElement("div",{className:"zent-doc-portal-mount-node"},"这里是原来就有的内容"),b.default.createElement(w.Portal,{selector:".zent-doc-portal-mount-node"},b.default.createElement("div",{className:"zent-doc-portal-content"},"这里是 Portal 动态插入的内容")),b.default.createElement("div",{className:"zent-doc-pure-portal-mount-node",key:this.state.purePortalVisible},"content to be overwritten"),this.state.purePortalVisible?b.default.createElement(n,{selector:".zent-doc-pure-portal-mount-node"},b.default.createElement("div",{className:"zent-doc-portal-content"},"这里是 PurePortal 动态插入的内容, 覆盖容器内原有内容")):null,b.default.createElement(w.Button,{onClick:this.togglePurePortal},"Toggle PurePortal"),b.default.createElement(w.Button,{onClick:this.showBodyPortal},"添加带遮罩的Portal到body"),b.default.createElement(t,{visible:this.state.bodyPortalVisible,onClickAway:this.hideBodyPortal,onClose:this.hideBodyPortal,className:"layer",style:{background:"rgba(0, 0, 0, 0.2)"},useLayerForClickAway:!0},b.default.createElement("div",{className:"zent-doc-portal-content",style:{position:"absolute",left:"50%",top:"50%",transform:"translate3d(-50%, -50%, 0)",border:"1px solid #d3d3d3",borderRadius:"3px",padding:"50px",background:"white"}},"默认插入到body最后,并设置为拥有遮罩用于关闭")))}}]),s}(y.Component);return b.default.createElement(a,null)},z=function(n){function t(){var n,a,s,o;(0,u.default)(this,t);for(var e=arguments.length,p=Array(e),c=0;c<e;c++)p[c]=arguments[c];return a=s=(0,f.default)(this,(n=t.__proto__||Object.getPrototypeOf(t)).call.apply(n,[this].concat(p))),s.state={showCode:!1},s.toggle=function(){s.setState({showCode:!s.state.showCode})},o=a,(0,f.default)(s,o)}return(0,m.default)(t,n),(0,k.default)(t,[{key:"render",value:function(){var n=this.state.showCode,t=this.props,a=t.title,s=t.src,e=t.children;return b.default.createElement("div",{className:"zandoc-react-demo"},b.default.createElement("div",{className:"zandoc-react-demo__preview"},e),b.default.createElement("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle},b.default.createElement("div",{className:"zandoc-react-demo__title"},b.default.createElement("p",null,a||"")),b.default.createElement("i",{className:"zenticon zenticon-caret-up zandoc-react-demo__toggle "+(n?"zandoc-react-demo__toggle-on":"zandoc-react-demo__toggle-off")})),n&&b.default.createElement("pre",{className:"zandoc-react-demo__code"},b.default.createElement(o,{tag:"code",html:s,attributes:{className:"language-jsx"}})))}}]),t}(y.Component),E=function(n){function t(){return(0,u.default)(this,t),(0,f.default)(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return(0,m.default)(t,n),(0,k.default)(t,[{key:"componentDidMount",value:function(){var n=location.hash;if(n){var t=document.querySelector('a[href="'+n+'"]');t&&(0,v.default)(document.documentElement,0,c(t,-9))}}},{key:"render",value:function(){return b.default.createElement("div",{className:"zandoc-react-container",key:null},b.default.createElement(p,{style:""}),b.default.createElement(e,{html:'<h2 class="anchor-heading"><a href="#portal-chuan-song-men">¶</a><a href="javascript:void(0)" id="portal-chuan-song-men" class="anchor-point"></a>Portal 传送门</h2>\n<p>传送门组件。</p>\n<h3 class="anchor-heading"><a href="#shi-yong-chang-jing">¶</a><a href="javascript:void(0)" id="shi-yong-chang-jing" class="anchor-point"></a>使用场景</h3>\n<p>这个组件不提供样式,但它是所有弹层组件的基石。使用 <code>Portal</code> 的好处是不需要自己管理动态插入的节点,防止内存泄露。</p>\n<h3 class="anchor-heading"><a href="#dai-ma-yan-shi">¶</a><a href="javascript:void(0)" id="dai-ma-yan-shi" class="anchor-point"></a>代码演示</h3>'}),b.default.createElement(z,{title:"基本用法,第二行是 `Portal` 插入的,可以在浏览器里审查元素观察Html结构",id:"Demobasic",src:'<span class="token keyword">import</span> <span class="token punctuation">{</span> Portal<span class="token punctuation">,</span> Button <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> PurePortal <span class="token operator">=</span> Portal<span class="token punctuation">.</span>PurePortal<span class="token punctuation">;</span>\n<span class="token keyword">const</span> WrappedPortal <span class="token operator">=</span> Portal<span class="token punctuation">.</span><span class="token function">withNonScrollable</span><span class="token punctuation">(</span>Portal<span class="token punctuation">.</span><span class="token function">withESCToClose</span><span class="token punctuation">(</span>Portal<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token keyword">class</span> <span class="token class-name">PortalBasic</span> <span class="token keyword">extends</span> <span class="token class-name">Component</span> <span class="token punctuation">{</span>\n state <span class="token operator">=</span> <span class="token punctuation">{</span>\n bodyPortalVisible<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>\n purePortalVisible<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span>\n <span class="token function-variable function">togglePurePortal</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> purePortalVisible<span class="token punctuation">:</span> <span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>purePortalVisible<span class="token punctuation">}</span><span class="token punctuation">)</span>\n <span class="token function-variable function">showBodyPortal</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> bodyPortalVisible<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>\n <span class="token function-variable function">hideBodyPortal</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> bodyPortalVisible<span class="token punctuation">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>\n <span class="token function">render</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>zent-doc-portal-container<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>zent-doc-portal-mount-node<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>这里是原来就有的内容<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>Portal</span> <span class="token attr-name">selector</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>.zent-doc-portal-mount-node<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>zent-doc-portal-content<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>这里是 Portal 动态插入的内容<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>Portal</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>zent-doc-pure-portal-mount-node<span class="token punctuation">"</span></span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>purePortalVisible<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>content to be overwritten<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>purePortalVisible <span class="token operator">?</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>PurePortal</span> <span class="token attr-name">selector</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>.zent-doc-pure-portal-mount-node<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>zent-doc-portal-content<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>这里是 PurePortal 动态插入的内容<span class="token punctuation">,</span> 覆盖容器内原有内容<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>PurePortal</span><span class="token punctuation">></span></span> <span class="token punctuation">:</span> <span class="token keyword">null</span> <span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>Button</span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>togglePurePortal<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>Toggle PurePortal<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>Button</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>Button</span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>showBodyPortal<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>添加带遮罩的Portal到body<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>Button</span><span class="token punctuation">></span></span>\n <span class="token operator"><</span>WrappedPortal\n visible<span class="token operator">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>state<span class="token punctuation">.</span>bodyPortalVisible<span class="token punctuation">}</span>\n onClickAway<span class="token operator">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>hideBodyPortal<span class="token punctuation">}</span>\n onClose<span class="token operator">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span>hideBodyPortal<span class="token punctuation">}</span>\n className<span class="token operator">=</span><span class="token string">"layer"</span>\n style<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> background<span class="token punctuation">:</span> <span class="token string">\'rgba(0, 0, 0, 0.2)\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span>\n useLayerForClickAway\n <span class="token operator">></span>\n <span class="token operator"><</span>div className<span class="token operator">=</span><span class="token string">"zent-doc-portal-content"</span> style<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n position<span class="token punctuation">:</span> <span class="token string">\'absolute\'</span><span class="token punctuation">,</span>\n left<span class="token punctuation">:</span> <span class="token string">\'50%\'</span><span class="token punctuation">,</span>\n top<span class="token punctuation">:</span> <span class="token string">\'50%\'</span><span class="token punctuation">,</span>\n transform<span class="token punctuation">:</span> <span class="token string">\'translate3d(-50%, -50%, 0)\'</span><span class="token punctuation">,</span>\n border<span class="token punctuation">:</span> <span class="token string">\'1px solid #d3d3d3\'</span><span class="token punctuation">,</span>\n borderRadius<span class="token punctuation">:</span> <span class="token string">\'3px\'</span><span class="token punctuation">,</span>\n padding<span class="token punctuation">:</span> <span class="token string">\'50px\'</span><span class="token punctuation">,</span>\n background<span class="token punctuation">:</span> <span class="token string">\'white\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator">></span>默认插入到body最后,并设置为拥有遮罩用于关闭<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>WrappedPortal</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span>\n\nReactDOM<span class="token punctuation">.</span><span class="token function">render</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>PortalBasic</span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span>\n mountNode<span class="token punctuation">,</span>\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},b.default.createElement(C)),b.default.createElement(e,{html:'<h3 class="anchor-heading"><a href="#api">¶</a><a href="javascript:void(0)" id="api" class="anchor-point"></a>API</h3>\n<table class="table">\n<thead>\n<tr>\n<th>参数</th>\n<th>说明</th>\n<th>类型</th>\n<th>是否必须</th>\n<th>默认值</th>\n<th>备选值</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>children</td>\n<td>只支持一个child</td>\n<td>string</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>selector</td>\n<td>渲染child的DOM节点</td>\n<td>string or DOM Element</td>\n<td>否</td>\n<td><code>\'body\'</code></td>\n<td>合法的CSS selector或者某个DOM节点</td>\n</tr>\n<tr>\n<td>visible</td>\n<td>是否渲染child</td>\n<td>bool</td>\n<td>否</td>\n<td><code>true</code></td>\n<td></td>\n</tr>\n<tr>\n<td>onMount</td>\n<td><code>children</code>\n 被 mount 之后的回调函数</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onUnmount</td>\n<td><code>children</code>\n 被 unmount 之后的回调函数</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>layer</td>\n<td>遮罩的标签名</td>\n<td>string</td>\n<td>否</td>\n<td><code>div</code></td>\n<td></td>\n</tr>\n<tr>\n<td>useLayerForClickAway</td>\n<td>是否使用遮罩来触发\n<code>Portal</code>\n关闭</td>\n<td>boolean</td>\n<td>否</td>\n<td>false</td>\n<td></td>\n</tr>\n<tr>\n<td>onClickAway</td>\n<td>点击到非\n<code>Portal</code>\n处的回调</td>\n<td>function</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onLayerReady</td>\n<td>遮罩准备好时的hook</td>\n<td>function</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>className</td>\n<td>遮罩的className</td>\n<td>string</td>\n<td>否</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>style</td>\n<td>遮罩的style</td>\n<td>object</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>css</td>\n<td>(已废弃, 请使用style)额外的css样式. 例如, \n<code>{ \'margin-left\': \'10px\' }</code></td>\n<td>object</td>\n<td>否</td>\n<td><code>{}</code></td>\n<td></td>\n</tr>\n<tr>\n<td>prefix</td>\n<td>自定义前缀</td>\n<td>string</td>\n<td>否</td>\n<td><code>\'zent\'</code></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<p><code>Portal</code> 另外还提供了几个高阶组件(HOC),提供了一些弹层常用的逻辑。</p>\n<h4 class="anchor-heading"><a href="#withesctoclose">¶</a><a href="javascript:void(0)" id="withesctoclose" class="anchor-point"></a>withESCToClose</h4>\n<p>封装了按ESC关闭的逻辑.</p>\n<table class="table">\n<thead>\n<tr>\n<th>参数</th>\n<th>说明</th>\n<th>类型</th>\n<th>是否必须</th>\n<th>默认值</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>visible</td>\n<td>注意这个属性原始的Portal是可选的</td>\n<td>bool</td>\n<td>是</td>\n<td><code>true</code></td>\n</tr>\n<tr>\n<td>onClose</td>\n<td>ESC按下是的回调函数</td>\n<td>func</td>\n<td>是</td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<pre><code class="language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> Portal <span class="token keyword">as</span> _Portal <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n<span class="token keyword">const</span> <span class="token punctuation">{</span> withESCToClose <span class="token punctuation">}</span> <span class="token operator">=</span> _Portal<span class="token punctuation">;</span>\n<span class="token keyword">const</span> Portal <span class="token operator">=</span> <span class="token function">withESCToClose</span><span class="token punctuation">(</span>_Portal<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>\n<h4 class="anchor-heading"><a href="#withnonscrollable">¶</a><a href="javascript:void(0)" id="withnonscrollable" class="anchor-point"></a>withNonScrollable</h4>\n<p>封装了禁止container滚动的逻辑.</p>\n<table class="table">\n<thead>\n<tr>\n<th>参数</th>\n<th>说明</th>\n<th>类型</th>\n<th>是否必须</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>visible</td>\n<td>注意这个属性原始的Portal是可选的</td>\n<td>bool</td>\n<td>是</td>\n</tr>\n</tbody>\n</table>\n<pre><code class="language-jsx"><span class="token keyword">import</span> <span class="token punctuation">{</span> Portal <span class="token keyword">as</span> _Portal <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n<span class="token keyword">const</span> <span class="token punctuation">{</span> withNonScrollable <span class="token punctuation">}</span> <span class="token operator">=</span> _Portal<span class="token punctuation">;</span>\n<span class="token keyword">const</span> Portal <span class="token operator">=</span> <span class="token function">withNonScrollable</span><span class="token punctuation">(</span>_Portal<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>\n<h3 class="anchor-heading"><a href="#zu-jian-yuan-li">¶</a><a href="javascript:void(0)" id="zu-jian-yuan-li" class="anchor-point"></a>组件原理</h3>\n<ul>\n<li>组件的主要功能是把其 <code>child</code> 插入到一个给定的 DOM node中, 并且在组件被 <code>unmount</code> 的时候将其 <code>child</code> 属性对应的 DOM 节点删除.</li>\n<li>任意 props 被修改后会触发一定程度的重绘, <code>children</code>, <code>selector</code>被修改会导致组件 <code>unmount</code> 再 <code>mount</code>;其它props被修改仅更新现有 DOM node 的属性.</li>\n</ul>\n<h3 class="anchor-heading"><a href="#yi-zhi-wen-ti">¶</a><a href="javascript:void(0)" id="yi-zhi-wen-ti" class="anchor-point"></a>已知问题</h3>\n<ul>\n<li>\n<p>在 Portal 的 <code>children</code> 上使用字符串形式的 <code>ref</code> 会报错, 可以使用函数形式的 <code>ref</code> 绕过这个问题. 其原因是 Portal 的 <code>children</code> 没有owner, 使用函数形式的<code>ref</code>可以绕过这个问题的原因参见<a href="https://github.com/facebook/react/blob/v15.0.2/src/renderers/shared/reconciler/ReactRef.js#L18"> Here</a>. 此外官方也不鼓励使用字符串形式的 <code>ref</code>.</p>\n</li>\n<li>\n<p><code>15.0.2</code> 版本的 React 有个 bug 会导致某些情况下依赖 <code>state</code> 的 <code>context</code> 不更新 (参考 example: 02-context), 请等待 React 版本的统一升级.</p>\n</li>\n</ul>\n<h2 class="anchor-heading"><a href="#layeredportal-zhe-zhao-chuan-song-men">¶</a><a href="javascript:void(0)" id="layeredportal-zhe-zhao-chuan-song-men" class="anchor-point"></a>LayeredPortal 遮罩传送门</h2>\n<p>遮罩传送门组件。</p>\n<h3 class="anchor-heading"><a href="#shi-yong-chang-jing">¶</a><a href="javascript:void(0)" id="shi-yong-chang-jing" class="anchor-point"></a>使用场景</h3>\n<p>这个组件是<code>Portal</code>依赖的内部实现,与<code>Portal</code>不同的地方在于<code>LayeredPortal</code>没有预设的任何样式,例如prefix等。</p>\n<h3 class="anchor-heading"><a href="#layeredportal-api">¶</a><a href="javascript:void(0)" id="layeredportal-api" class="anchor-point"></a>LayeredPortal-API</h3>\n<table class="table">\n<thead>\n<tr>\n<th>参数</th>\n<th>说明</th>\n<th>类型</th>\n<th>是否必须</th>\n<th>默认值</th>\n<th>备选值</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>children</td>\n<td>只支持一个child</td>\n<td>string</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>render</td>\n<td>返回传送门需要渲染的内容,优先级高于children</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>selector</td>\n<td>渲染child的DOM节点</td>\n<td>string or DOM Element</td>\n<td>否</td>\n<td><code>\'body\'</code></td>\n<td>合法的CSS selector或者某个DOM节点</td>\n</tr>\n<tr>\n<td>visible</td>\n<td>是否渲染child</td>\n<td>bool</td>\n<td>否</td>\n<td><code>true</code></td>\n<td></td>\n</tr>\n<tr>\n<td>onMount</td>\n<td><code>children</code>\n 被 mount 之后的回调函数</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onUnmount</td>\n<td><code>children</code>\n 被 unmount 之后的回调函数</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>layer</td>\n<td>遮罩的标签名</td>\n<td>string</td>\n<td>否</td>\n<td><code>div</code></td>\n<td></td>\n</tr>\n<tr>\n<td>useLayerForClickAway</td>\n<td>是否使用遮罩来触发\n<code>Portal</code>\n关闭</td>\n<td>boolean</td>\n<td>否</td>\n<td>false</td>\n<td></td>\n</tr>\n<tr>\n<td>onClickAway</td>\n<td>点击到非\n<code>Portal</code>\n处的回调</td>\n<td>function</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onLayerReady</td>\n<td>遮罩准备好时的hook</td>\n<td>function</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>className</td>\n<td>遮罩的className</td>\n<td>string</td>\n<td>否</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>style</td>\n<td>遮罩的style</td>\n<td>object</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h2 class="anchor-heading"><a href="#pureportal-fu-gai-shi-chuan-song-men">¶</a><a href="javascript:void(0)" id="pureportal-fu-gai-shi-chuan-song-men" class="anchor-point"></a>PurePortal 覆盖式传送门</h2>\n<p>覆盖式传送门组件。</p>\n<h3 class="anchor-heading"><a href="#shi-yong-chang-jing">¶</a><a href="javascript:void(0)" id="shi-yong-chang-jing" class="anchor-point"></a>使用场景</h3>\n<p>纯粹的Portal,行为同 React 16 的Portal相同,会将容器中的所有内容覆盖掉。</p>\n<h3 class="anchor-heading"><a href="#pureportal-api">¶</a><a href="javascript:void(0)" id="pureportal-api" class="anchor-point"></a>PurePortal-API</h3>\n<table class="table">\n<thead>\n<tr>\n<th>参数</th>\n<th>说明</th>\n<th>类型</th>\n<th>是否必须</th>\n<th>默认值</th>\n<th>备选值</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>children</td>\n<td>只支持一个child</td>\n<td>string</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>render</td>\n<td>返回传送门需要渲染的内容,优先级高于children</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>selector</td>\n<td>渲染child的DOM节点</td>\n<td>string or DOM Element</td>\n<td>是</td>\n<td><code>\'body\'</code></td>\n<td>合法的CSS selector或者某个DOM节点</td>\n</tr>\n<tr>\n<td>onMount</td>\n<td><code>children</code>\n 被 mount 之后的回调函数</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onUnmount</td>\n<td><code>children</code>\n 被 unmount 之后的回调函数</td>\n<td>func</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>'}))}}]),t}(y.Component);t.default=E}});