-
Notifications
You must be signed in to change notification settings - Fork 0
/
3425-7d3ec8f793e71581e402.js
1 lines (1 loc) · 48.7 KB
/
3425-7d3ec8f793e71581e402.js
1
(self.webpackChunkzent_docs=self.webpackChunkzent_docs||[]).push([[3425],{93425:(n,s,a)=>{"use strict";a.r(s),a.d(s,{default:()=>f});var t=a(73450),p=a(27378),o=a(57318),e=a(80499),c=a(96681),l=a(24246);function i(n,s){var a=Object.keys(n);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(n);s&&(t=t.filter((function(s){return Object.getOwnPropertyDescriptor(n,s).enumerable}))),a.push.apply(a,t)}return a}function u(n){for(var s=1;s<arguments.length;s++){var a=null!=arguments[s]?arguments[s]:{};s%2?i(Object(a),!0).forEach((function(s){(0,t.Z)(n,s,a[s])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(a)):i(Object(a)).forEach((function(s){Object.defineProperty(n,s,Object.getOwnPropertyDescriptor(a,s))}))}return n}var r=function(){return(0,l.jsxs)(e.J,{className:"zent-doc-popover",position:e.J.Position.BottomLeft,cushion:5,children:[(0,l.jsx)(e.J.Trigger.Click,{children:(0,l.jsx)(c.z,{type:"primary",children:"点击打开"})}),(0,l.jsxs)(e.J.Content,{children:[(0,l.jsx)("div",{children:"Popover 弹层内容"}),(0,l.jsx)("div",{children:"可以添加任意内容"})]})]})},k=function(){class n extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{visible:!1})}render(){return(0,l.jsxs)("div",{className:"zent-doc-popover-container",children:[(0,l.jsxs)(e.J,{className:"zent-doc-popover",visible:this.state.visible,onVisibleChange:n=>this.setState({visible:n}),position:e.J.Position.BottomLeft,cushion:5,children:[(0,l.jsx)(e.J.Trigger.Base,{children:(0,l.jsx)(c.z,{type:"primary",onClick:()=>this.setState({visible:!0}),children:"点击打开"})}),(0,l.jsxs)(e.J.Content,{children:[(0,l.jsx)("div",{children:"Popover 弹层内容"}),(0,l.jsx)("div",{children:"可以添加任意内容"})]})]}),(0,l.jsx)(c.z,{onClick:()=>this.setState({visible:!1}),children:"关闭"})]})}}return(0,l.jsx)(n,{})},d=function(){class n extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{visible:!0}),(0,t.Z)(this,"onVisibleChange",(n=>{this.setState({visible:n})}))}render(){return(0,l.jsxs)(e.J,{className:"zent-doc-popover",position:e.J.Position.BottomLeft,cushion:5,children:[(0,l.jsx)(e.J.Trigger.Click,{children:(0,l.jsx)(c.z,{type:"primary",children:"点击打开"})}),(0,l.jsxs)(e.J.Content,{children:[(0,l.jsx)("div",{children:"Popover 弹层内容"}),(0,l.jsxs)(e.J,{className:"zent-doc-popover",position:e.J.Position.BottomLeft,cushion:5,visible:this.state.visible,onVisibleChange:this.onVisibleChange,children:[(0,l.jsx)(e.J.Trigger.Click,{children:(0,l.jsx)(c.z,{type:"primary",children:"点击打开"})}),(0,l.jsx)(e.J.Content,{children:(0,l.jsx)("div",{children:"嵌套弹层内容"})})]})]})]})}}return(0,l.jsx)(n,{})},m=function(){var n=e.J.withPopover((function({popover:n}){return(0,l.jsxs)("div",{children:[(0,l.jsx)("div",{children:"弹层内容"}),(0,l.jsx)(c.z,{onClick:n.close,children:"关闭"})]})}));return(0,l.jsxs)(e.J,{className:"zent-doc-popover",position:e.J.Position.BottomLeft,cushion:5,children:[(0,l.jsx)(e.J.Trigger.Click,{children:(0,l.jsx)(c.z,{type:"primary",children:"点击打开"})}),(0,l.jsx)(e.J.Content,{children:(0,l.jsx)(n,{})})]})};function g(n){return(0,l.jsx)(n.tag,u(u({},n.attributes),{},{dangerouslySetInnerHTML:{__html:n.html}}))}function h(n){return(0,l.jsx)(g,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function v(n){return(0,l.jsx)(g,{tag:"style",html:n.style})}function y(n,s){for(;n;)return n.offsetTop&&"static"!==getComputedStyle(n).position&&(s+=n.offsetTop),y(n.parentNode,s);return s}class b extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{showCode:!1}),(0,t.Z)(this,"toggle",(()=>{this.setState({showCode:!this.state.showCode})}))}render(){var n=this.state.showCode,s=this.props,a=s.title,t=s.src,p=s.children;return(0,l.jsxs)("div",{className:"zandoc-react-demo",children:[(0,l.jsx)("div",{className:"zandoc-react-demo__preview",children:p}),(0,l.jsxs)("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle,children:[(0,l.jsx)("div",{className:"zandoc-react-demo__title",children:(0,l.jsx)("p",{children:a||""})}),(0,l.jsx)("i",{className:"zenticon zenticon-caret-up zandoc-react-demo__toggle ".concat(n?"zandoc-react-demo__toggle-on":"zandoc-react-demo__toggle-off")})]}),n&&(0,l.jsx)("pre",{className:"zandoc-react-demo__code",children:(0,l.jsx)(g,{tag:"code",html:t,attributes:{className:"language-jsx"}})})]})}}class f extends p.Component{componentDidMount(){var n=location.hash;if(n){var s=document.querySelector('a[href="'.concat(n,'"]'));s&&(0,o.l)(document.documentElement,0,y(s,-9))}}render(){return p.createElement("div",{className:"zandoc-react-container"},p.createElement(v,{style:".zent-doc-popover {\n\tborder: 1px solid #e5e5e5;\n\tpadding: 10px;\n\tborder-radius: 4px;\n\tbackground: #fff;\n\tfont-size: 14px;\n}\n\n.zent-doc-popover-container .zent-popover-wrapper {\n\t\tmargin-right: 10px;\n\t}"}),p.createElement(h,{html:'<h2 class="anchor-heading"><a href="#popover-dan-ceng">¶</a><a href="javascript:void(0)" id="popover-dan-ceng" class="anchor-point"></a>Popover 弹层</h2>\n<p>通用的触发式弹层组件, 可以自定义定位算法、触发方式以及弹层显示方式。</p>\n<p>组件支持自身多层嵌套。</p>\n<p><strong>这个组件不提供样式, 气泡提示组件请使用 <code>Pop</code>。</strong></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<ul>\n<li>如果 <code>Pop</code> 组件提供的功能无法满足你的需求,需要实现自定义的触发式弹层时可以使用 <code>Popover</code> 来简化开发。</li>\n<li>可以当做 <code>Dropdown</code> 使用。</li>\n</ul>\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>'}),p.createElement(b,{title:"基本使用方式",id:"Demobasic",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Popover</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Button</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-doc-popover<span class="token punctuation">"</span></span>\n <span class="token attr-name">position</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">Popover</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Position</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">BottomLeft</span></span><span class="token punctuation">}</span></span>\n <span class="token attr-name">cushion</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<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><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Content</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 punctuation">></span></span><span class="token maybe-class-name">Popover</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>div</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><span class="token class-name">Popover.Content</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover</span></span><span class="token punctuation">></span></span><span class="token punctuation">,</span>\n mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},p.createElement(r)),p.createElement(b,{title:"外部控制打开/关闭",id:"Democontrolled",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Popover</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Button</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">class</span> <span class="token class-name">PopoverDemo</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 visible<span class="token operator">:</span> <span class="token boolean">false</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n\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 control-flow">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 attr-equals">=</span><span class="token punctuation">"</span>zent-doc-popover-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><span class="token class-name">Popover</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-doc-popover<span class="token punctuation">"</span></span>\n <span class="token attr-name">visible</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">state</span><span class="token punctuation">.</span><span class="token property-access">visible</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onVisibleChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token parameter">v</span> <span class="token arrow operator">=></span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> visible<span class="token operator">:</span> v <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">position</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">Popover</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Position</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">BottomLeft</span></span><span class="token punctuation">}</span></span>\n <span class="token attr-name">cushion</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">5</span><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><span class="token class-name">Popover.Trigger.Base</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> visible<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><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><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover.Trigger.Base</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Content</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 punctuation">></span></span><span class="token maybe-class-name">Popover</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>div</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><span class="token class-name">Popover.Content</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover</span></span><span class="token punctuation">></span></span>\n\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span> visible<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><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><span class="token class-name">Button</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 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\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">PopoverDemo</span></span> <span class="token punctuation">/></span></span>\n <span class="token punctuation">,</span> mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},p.createElement(k)),p.createElement(b,{title:"嵌套",id:"Demonested",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Popover</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Button</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">class</span> <span class="token class-name">Demo</span> <span class="token keyword">extends</span> <span class="token class-name">React<span class="token punctuation">.</span>Component</span> <span class="token punctuation">{</span>\n state <span class="token operator">=</span> <span class="token punctuation">{</span>\n visible<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n <span class="token function-variable function">onVisibleChange</span> <span class="token operator">=</span> <span class="token parameter">visible</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token method function property-access">setState</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n visible<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n\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 control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-doc-popover<span class="token punctuation">"</span></span>\n <span class="token attr-name">position</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">Popover</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Position</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">BottomLeft</span></span><span class="token punctuation">}</span></span>\n <span class="token attr-name">cushion</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<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><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Content</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 punctuation">></span></span><span class="token maybe-class-name">Popover</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><span class="token class-name">Popover</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-doc-popover<span class="token punctuation">"</span></span>\n <span class="token attr-name">position</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">Popover</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Position</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">BottomLeft</span></span><span class="token punctuation">}</span></span>\n <span class="token attr-name">cushion</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">visible</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">state</span><span class="token punctuation">.</span><span class="token property-access">visible</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onVisibleChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token property-access">onVisibleChange</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<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><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Content</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 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><span class="token class-name">Popover.Content</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover.Content</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover</span></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\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Demo</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},p.createElement(d)),p.createElement(b,{title:"withPopover 高阶组件",id:"Demohoc",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Popover</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Button</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token maybe-class-name">Content</span> <span class="token operator">=</span> <span class="token maybe-class-name">Popover</span><span class="token punctuation">.</span><span class="token method function property-access">withPopover</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Content</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> popover <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">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 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>弹层内容<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><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>popover<span class="token punctuation">.</span><span class="token property-access">close</span><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><span class="token class-name">Button</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 punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-doc-popover<span class="token punctuation">"</span></span>\n <span class="token attr-name">position</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">Popover</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Position</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">BottomLeft</span></span><span class="token punctuation">}</span></span>\n <span class="token attr-name">cushion</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">5</span><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><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<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><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover.Trigger.Click</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Popover.Content</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Content</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover.Content</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Popover</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">,</span> mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},p.createElement(m)),p.createElement(h,{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>position</td>\n<td>定位的方式, 参见 \n<code>Popover.Position</code></td>\n<td>Positon</td>\n<td></td>\n<td></td>\n<td>是</td>\n</tr>\n<tr>\n<td>cushion</td>\n<td>定位的偏移量, 通常用来预留空间给小箭头等东西</td>\n<td>number</td>\n<td><code>0</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onShow</td>\n<td>弹层显示后的回调函数</td>\n<td>func</td>\n<td><code>noop</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onClose</td>\n<td>弹层关闭后的回调函数</td>\n<td>func</td>\n<td><code>noop</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onBeforeShow</td>\n<td>弹层打开前的回调函数, 只有用户触发的打开操作才会调用, 外部设置 \n<code>visible</code>\n 不会调用</td>\n<td>func</td>\n<td><code>noop</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onBeforeClose</td>\n<td>弹层关闭后的回调函数, 只有用户触发的关闭操作才会调用, 外部设置 \n<code>visible</code>\n 不会调用</td>\n<td>func</td>\n<td><code>noop</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>containerSelector</td>\n<td>弹层的父节点CSS selector</td>\n<td>string</td>\n<td><code>\'body\'</code></td>\n<td>所有合法的CSS selector</td>\n<td>否</td>\n</tr>\n<tr>\n<td>visible</td>\n<td>手动控制弹层的显示隐藏, 必须和 \n<code>onVisibleChange</code>\n 一起使用</td>\n<td>bool</td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onVisibleChange</td>\n<td>手动控制时的回调函数, 必须和\n<code>visible</code>\n一起使用, 只有用户手动触发的打开/关闭操作才会调用</td>\n<td>func</td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onPositionUpdated</td>\n<td>位置更新时的回调,不保证调用这个函数时位置一定变化</td>\n<td>func</td>\n<td><code>noop</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onPositionReady</td>\n<td>content 在第一次屏幕内可见时的回调,组件生命周期内只调用一次</td>\n<td>func</td>\n<td><code>noop</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>className</td>\n<td>弹层的自定义类名</td>\n<td>string</td>\n<td><code>\'\'</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>style</td>\n<td>弹层的自定义样式</td>\n<td><code>CssProperties</code></td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n</tbody>\n</table>\n<p><code>onBeforeShow</code> 和 <code>onBeforeClose</code> 可以返回一个 <code>Promise</code>,<code>Popover</code> 会在 <code>Promise</code> resolve 后打开/关闭,如果 <code>Promise</code> reject 的话打开/关闭操作终止。</p>\n<p>如果你不使用 <code>Promise</code>,<code>onBeforeShow</code> 和 <code>onBeforeClose</code> 也提供两个可选的参数 <code>callback</code> 以及 <code>escapse</code>,如果有这两参数的话,你必须在 <code>onBeforeShow</code> 和 <code>onBeforeClose</code> 里面手动调用 <code>callback</code> 才会打开/关闭,如果要终止打开/关闭操作需要手动调用 <code>escape</code>。</p>\n<p><code>onBeforeShow(callback: ?function, escape: ?escape): ?Promise</code></p>\n<p>每种 trigger 都有特有的 API 来控制组件行为, 自定义 trigger 可以按需指定 trigger 的参数.</p>\n<h4 class="anchor-heading"><a href="#trigger-click">¶</a><a href="javascript:void(0)" id="trigger-click" class="anchor-point"></a>Trigger.Click</h4>\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>closeOnClickOutside</td>\n<td>是否点击‘外面’自动关闭弹层</td>\n<td>boolean</td>\n<td><code>true</code></td>\n<td>否</td>\n</tr>\n<tr>\n<td>toggle</td>\n<td>开关模式 | boolean</td>\n<td><code>false</code></td>\n<td>否</td>\n<td></td>\n</tr>\n<tr>\n<td>getElement</td>\n<td>自定义 trigger 的 DOM 节点</td>\n<td>(node: Element</td>\n<td>Text</td>\n<td>null) => Element</td>\n</tr>\n</tbody>\n</table>\n<h4 class="anchor-heading"><a href="#trigger-hover">¶</a><a href="javascript:void(0)" id="trigger-hover" class="anchor-point"></a>Trigger.Hover</h4>\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>showDelay</td>\n<td>打开弹层前的延迟(单位毫秒), 如果在这段时间内鼠标移出弹层范围, 弹层不会打开</td>\n<td>number</td>\n<td><code>150</code></td>\n<td>否</td>\n</tr>\n<tr>\n<td>hideDelay</td>\n<td>关闭弹层前的延迟(单位毫秒), 如果在这段时间内鼠标重新移入弹层范围, 弹层不会关闭</td>\n<td>number</td>\n<td><code>150</code></td>\n<td>否</td>\n</tr>\n<tr>\n<td>getElement</td>\n<td>自定义 trigger 的 DOM 节点</td>\n<td>(node: Element</td>\n<td>Text</td>\n<td>null) => Element</td>\n</tr>\n<tr>\n<td>anchorOnly</td>\n<td>仅考虑 Trigger 作为触发区域</td>\n<td>boolean</td>\n<td><code>false</code></td>\n<td>否</td>\n</tr>\n<tr>\n<td>fixMouseEventsOnDisabledChildren</td>\n<td>兼容禁用 Input/Button 的鼠标事件</td>\n<td>boolean</td>\n<td><code>false</code></td>\n<td>否</td>\n</tr>\n</tbody>\n</table>\n<p>关于禁用元素的鼠标事件问题请参考 <a href="https://github.com/youzan/zent/issues/142">https://github.com/youzan/zent/issues/142</a></p>\n<h4 class="anchor-heading"><a href="#trigger-focus">¶</a><a href="javascript:void(0)" id="trigger-focus" class="anchor-point"></a>Trigger.Focus</h4>\n<p>当获取焦点时显示,失去焦点时关闭。</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>getElement</td>\n<td>自定义 trigger 的 DOM 节点</td>\n<td>(node: Element</td>\n<td>Text</td>\n<td>null) => Element</td>\n</tr>\n</tbody>\n</table>\n<h4 class="anchor-heading"><a href="#trigger-base-yi-fei-qi">¶</a><a href="javascript:void(0)" id="trigger-base-yi-fei-qi" class="anchor-point"></a>Trigger.Base(已废弃)</h4>\n<p>请使用 <code>PopoverAnchor</code> 实现自定义的 trigger,请参考 <code>ClickTrigger</code> 的源码。</p>\n<h3 class="anchor-heading"><a href="#position-api">¶</a><a href="javascript:void(0)" id="position-api" class="anchor-point"></a>Position API</h3>\n<p>Positon用于给弹层提供定位的, 内置12种基础定位, 可以添加自定义定位算法. Popover 上的 <code>cushion</code> 参数会影响定位, 通常用来提供一定量的偏移量。</p>\n<pre><code class="language-text"><span class="token comment">// 基础定位</span>\n\n <span class="token maybe-class-name">TopLeft</span> <span class="token maybe-class-name">TopCenter</span> <span class="token maybe-class-name">TopRight</span>\n\n<span class="token maybe-class-name">LeftTop</span> <span class="token maybe-class-name">RightTop</span>\n\n\n<span class="token maybe-class-name">LeftCenter</span> <span class="token maybe-class-name">RightCenter</span>\n\n\n<span class="token maybe-class-name">LeftBottom</span> <span class="token maybe-class-name">RightBottom</span>\n\n <span class="token maybe-class-name">BottomLeft</span> <span class="token maybe-class-name">BottomCenter</span> <span class="token maybe-class-name">BottomRight</span></code></pre>\n<p>除了这12种基础定位算法外,还提供了6个会自动根据屏幕剩余空间自动判断合适位置的定位算法: <code>AutoBottomLeft</code>,<code>AutoBottomCenter</code>, <code>AutoBottomRight</code>, <code>AutoTopLeft</code>, <code>AutoTopCenter</code> 以及 <code>AutoTopRight</code>,这些算法适用于下拉式组件。</p>\n<h4 class="anchor-heading"><a href="#zi-ding-yi-ding-wei">¶</a><a href="javascript:void(0)" id="zi-ding-yi-ding-wei" class="anchor-point"></a>自定义定位</h4>\n<p>定位函数是个纯函数,示例:</p>\n<pre><code class="language-ts"><span class="token keyword">const</span> TopCenter<span class="token operator">:</span> <span class="token function-variable function">IPositionFunction</span> <span class="token operator">=</span> <span class="token punctuation">(</span>options<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> <span class="token punctuation">{</span> contentRect<span class="token punctuation">,</span> relativeRect<span class="token punctuation">,</span> cushion <span class="token punctuation">}</span> <span class="token operator">=</span> options<span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token punctuation">{</span> right<span class="token punctuation">,</span> left<span class="token punctuation">,</span> top <span class="token punctuation">}</span> <span class="token operator">=</span> relativeRect<span class="token punctuation">;</span>\n <span class="token keyword">const</span> middle <span class="token operator">=</span> <span class="token punctuation">(</span>left <span class="token operator">+</span> right<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> x <span class="token operator">=</span> middle <span class="token operator">-</span> contentRect<span class="token punctuation">.</span>width <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> y <span class="token operator">=</span> top <span class="token operator">-</span> contentRect<span class="token punctuation">.</span>height <span class="token operator">-</span> cushion<span class="token punctuation">;</span>\n\n <span class="token keyword">return</span> <span class="token punctuation">{</span>\n style<span class="token operator">:</span> <span class="token punctuation">{</span>\n position<span class="token operator">:</span> <span class="token string">\'absolute\'</span><span class="token punctuation">,</span>\n left<span class="token operator">:</span> x<span class="token punctuation">,</span>\n top<span class="token operator">:</span> y<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n\n className<span class="token operator">:</span> <span class="token function">prefix</span><span class="token punctuation">(</span><span class="token string">\'position-top-center\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span></code></pre>\n<p>anchor 是指 trigger,container 是指离弹层最近的有定位的父节点。</p>\n<p><code>options</code> 的重要属性说明:</p>\n<ul>\n<li><code>relativeRect</code> 是 anchor 相对于 container 为原点的坐标系的坐标,一般计算位置都是相对于这个做的</li>\n<li><code>cushion</code> 定位的偏移量</li>\n<li><code>anchor</code> anchor 的 DOM 节点</li>\n<li><code>container</code> container 的 DOM 节点</li>\n<li><code>content</code> content 的 DOM 节点</li>\n<li><code>anchorRect</code> anchor 相对于 viewport 的坐标、大小信息</li>\n<li><code>containerRect</code> container 相对于 viewport 的坐标、大小信息</li>\n<li><code>contentRect</code> content 相对于 viewport 的坐标、大小信息</li>\n</ul>\n<h4 class="anchor-heading"><a href="#withpopover-gao-jie-zu-jian">¶</a><a href="javascript:void(0)" id="withpopover-gao-jie-zu-jian" class="anchor-point"></a>withPopover 高阶组件</h4>\n<p>这个高阶组件暴露了 <code>Popover</code> 内部的几个重要方法, 可能的使用场景: 在 <code>Content</code> 内部手动关闭弹层.</p>\n<table class="table">\n<thead>\n<tr>\n<th>参数</th>\n<th>说明</th>\n<th>类型</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>open</td>\n<td>打开弹层</td>\n<td><code>() => void</code></td>\n</tr>\n<tr>\n<td>close</td>\n<td>关闭弹层</td>\n<td><code>() => void</code></td>\n</tr>\n<tr>\n<td>adjustPosition</td>\n<td>重新定位弹层</td>\n<td><code>() => void</code></td>\n</tr>\n</tbody>\n</table>\n<h4 class="anchor-heading"><a href="#adjustposition-fang-fa">¶</a><a href="javascript:void(0)" id="adjustposition-fang-fa" class="anchor-point"></a><code>adjustPosition</code> 方法</h4>\n<p>可以通过这个方法调整 <code>Popover</code> 的位置。</p>\n<p>一般是用于某些特殊场合,<code>Popover</code> 无法自动更新位置时手动调用。</p>'}))}}}}]);