-
Notifications
You must be signed in to change notification settings - Fork 0
/
5217-5220a6cfcb5e48415b62.js
1 lines (1 loc) · 14.7 KB
/
5217-5220a6cfcb5e48415b62.js
1
(self.webpackChunkzent_docs=self.webpackChunkzent_docs||[]).push([[5217],{25217:(n,a,t)=>{"use strict";t.r(a),t.d(a,{default:()=>h});var s=t(73450),e=t(27378),o=t(57318),p=t(54630),c=t(24246);function i(n,a){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);a&&(s=s.filter((function(a){return Object.getOwnPropertyDescriptor(n,a).enumerable}))),t.push.apply(t,s)}return t}function r(n){for(var a=1;a<arguments.length;a++){var t=null!=arguments[a]?arguments[a]:{};a%2?i(Object(t),!0).forEach((function(a){(0,s.Z)(n,a,t[a])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(a){Object.defineProperty(n,a,Object.getOwnPropertyDescriptor(t,a))}))}return n}var l=function(){var n=["http://img.yzcdn.cn/public_files/2017/6/30/b0717bad7ad3ebd025e175d624ade39f.png","http://img.yzcdn.cn/public_files/2017/6/30/8a0536db89fafaa1269afeaa807a579b.png","http://img.yzcdn.cn/public_files/2017/6/30/7fe46674b697a514d9b6e2e155e88f1c.png","http://img.yzcdn.cn/public_files/2017/6/30/b7a98d721698fe8dc93689683706db45.png"];class a extends e.Component{constructor(...a){super(...a),(0,s.Z)(this,"handlePreview",(a=>{(0,p.E)({images:n,index:n.indexOf(a.target.src),parentComponent:this,scaleRatio:3})}))}render(){return(0,c.jsx)("div",{className:"image-preview-demo",children:n.map(((n,a)=>(0,c.jsx)("img",{src:n,onClick:this.handlePreview,alt:"",width:"160"},a)))})}}return(0,c.jsx)(a,{})};function u(n){return(0,c.jsx)(n.tag,r(r({},n.attributes),{},{dangerouslySetInnerHTML:{__html:n.html}}))}function d(n){return(0,c.jsx)(u,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function m(n){return(0,c.jsx)(u,{tag:"style",html:n.style})}function k(n,a){for(;n;)return n.offsetTop&&"static"!==getComputedStyle(n).position&&(a+=n.offsetTop),k(n.parentNode,a);return a}class g extends e.Component{constructor(...n){super(...n),(0,s.Z)(this,"state",{showCode:!1}),(0,s.Z)(this,"toggle",(()=>{this.setState({showCode:!this.state.showCode})}))}render(){var n=this.state.showCode,a=this.props,t=a.title,s=a.src,e=a.children;return(0,c.jsxs)("div",{className:"zandoc-react-demo",children:[(0,c.jsx)("div",{className:"zandoc-react-demo__preview",children:e}),(0,c.jsxs)("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle,children:[(0,c.jsx)("div",{className:"zandoc-react-demo__title",children:(0,c.jsx)("p",{children:t||""})}),(0,c.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,c.jsx)("pre",{className:"zandoc-react-demo__code",children:(0,c.jsx)(u,{tag:"code",html:s,attributes:{className:"language-jsx"}})})]})}}class h extends e.Component{componentDidMount(){var n=location.hash;if(n){var a=document.querySelector('a[href="'.concat(n,'"]'));a&&(0,o.l)(document.documentElement,0,k(a,-9))}}render(){return e.createElement("div",{className:"zandoc-react-container"},e.createElement(m,{style:""}),e.createElement(d,{html:'<h2 class="anchor-heading"><a href="#previewimage">¶</a><a href="javascript:void(0)" id="previewimage" class="anchor-point"></a>previewImage</h2>\n<p>This component is used to preview images.</p>\n<h3 class="anchor-heading"><a href="#guide">¶</a><a href="javascript:void(0)" id="guide" class="anchor-point"></a>Guide</h3>\n<ul>\n<li>It\'s used to zoom thumbnail.</li>\n<li>Next image and previous image can be selected.</li>\n<li>Images can be rotated.</li>\n</ul>\n<h3 class="anchor-heading"><a href="#demos">¶</a><a href="javascript:void(0)" id="demos" class="anchor-point"></a>Demos</h3>'}),e.createElement(g,{title:"Basic Usage",id:"Demobasic",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> previewImage <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> imgArr <span class="token operator">=</span> <span class="token punctuation">[</span>\n <span class="token string">\'http://img.yzcdn.cn/public_files/2017/6/30/b0717bad7ad3ebd025e175d624ade39f.png\'</span><span class="token punctuation">,</span>\n <span class="token string">\'http://img.yzcdn.cn/public_files/2017/6/30/8a0536db89fafaa1269afeaa807a579b.png\'</span><span class="token punctuation">,</span>\n <span class="token string">\'http://img.yzcdn.cn/public_files/2017/6/30/7fe46674b697a514d9b6e2e155e88f1c.png\'</span><span class="token punctuation">,</span>\n <span class="token string">\'http://img.yzcdn.cn/public_files/2017/6/30/b7a98d721698fe8dc93689683706db45.png\'</span>\n<span class="token punctuation">]</span><span class="token punctuation">;</span>\n\n<span class="token keyword">class</span> <span class="token class-name">Simple</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 <span class="token function-variable function">handlePreview</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">previewImage</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n images<span class="token operator">:</span> imgArr<span class="token punctuation">,</span>\n index<span class="token operator">:</span> imgArr<span class="token punctuation">.</span><span class="token method function property-access">indexOf</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">src</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n parentComponent<span class="token operator">:</span> <span class="token keyword">this</span><span class="token punctuation">,</span>\n scaleRatio<span class="token operator">:</span> <span class="token number">3</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <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>image-preview-demo<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>\n imgArr<span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">image<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>image<span class="token punctuation">}</span></span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>index<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 keyword">this</span><span class="token punctuation">.</span><span class="token property-access">handlePreview</span><span class="token punctuation">}</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span> <span class="token attr-name">width</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>160<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></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>\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>\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">Simple</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>'},e.createElement(l)),e.createElement(d,{html:'<h2 class="anchor-heading"><a href="#api">¶</a><a href="javascript:void(0)" id="api" class="anchor-point"></a>API</h2>\n<table class="table">\n<thead>\n<tr>\n<th>Property</th>\n<th>Description</th>\n<th>Type</th>\n<th>Default</th>\n<th>Alternative</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>images</td>\n<td>Urls for images</td>\n<td>array</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>index</td>\n<td>Start index</td>\n<td>number</td>\n<td>0</td>\n<td></td>\n</tr>\n<tr>\n<td>showRotateBtn</td>\n<td>Show rotate button</td>\n<td>bool</td>\n<td>true</td>\n<td>true,false</td>\n</tr>\n<tr>\n<td>scaleRatio</td>\n<td>Custom scale Ratio</td>\n<td>number</td>\n<td>1.5</td>\n<td></td>\n</tr>\n<tr>\n<td>parentComponent</td>\n<td>Parent component instance,i18n needs this to pass context through</td>\n<td>ReactInstance</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>className</td>\n<td>Optional. Custom class name</td>\n<td>string</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n</tbody>\n</table>'}))}}},54630:(n,a,t)=>{"use strict";t.d(a,{Z:()=>v,E:()=>h});var s=t(59312),e=t(24246),o=t(31542),p=t.t(o,2),c=t(14805),i=t(27378),r=t(60042),l=t.n(r),u=t(49566),d=t(52074),m=t(53552),k=t(27036),g=function(n){function a(){var a=null!==n&&n.apply(this,arguments)||this;return a.state={imageIndex:a.props.index||0,imageStyle:{},rotateIndex:0,scaleTag:!1},a.onMaskClick=function(n){n.target===n.currentTarget&&a.props.onClose()},a.onClose=function(){a.props.onClose()},a.handlePreviousAction=function(){var n=a.props.images.length,t=a.state.imageIndex;t=(t-1+n)%n,a.setState({imageIndex:t,imageStyle:{transform:"rotate(0deg)"},rotateIndex:0,scaleTag:!1})},a.handleNextAction=function(){var n=a.props.images.length,t=a.state.imageIndex;t=(t+1)%n,a.setState({imageIndex:t,imageStyle:{transform:"rotate(0deg)"},rotateIndex:0,scaleTag:!1})},a.handleRotate=function(){var n=a.state.scaleTag,t=a.props.scaleRatio;if(t<1)throw new Error("Invalid prop `scaleRatio` in previewImage, it should be greater than 1.");var s=a.state.rotateIndex,e=90+90*s;s++;var o=n?"rotate("+e+"deg) scale("+t+")":"rotate("+e+"deg) scale(1)";a.setState({imageStyle:{transform:o,transitionDuration:"500ms"},rotateIndex:s})},a.handleScale=function(){var n=a.state,t=n.rotateIndex,s=n.scaleTag,e=a.props.scaleRatio;if(e<1)throw new Error("Invalid prop `scaleRatio` in previewImage, it should be greater than 1.");var o=90*t,p=s?"rotate("+o+"deg) scale(1)":"rotate("+o+"deg) scale("+e+")";a.setState({imageStyle:{transform:p,transitionDuration:"500ms"},scaleTag:!s})},a}return(0,s.ZT)(a,n),a.prototype.render=function(){var n=this,a=this.props,t=a.images,o=a.showRotateBtn,p=a.className,c=this.state,i=c.scaleTag,r=c.imageIndex,g=c.imageStyle,h=l()("zent-image-p-show-image",{"zent-image-p-is-zooming":i});return(0,e.jsx)(m.ZP,(0,s.pi)({visible:!0,onClose:this.onClose,className:l()("zent-image-p-anchor",p),closeOnESC:!0,blockPageScroll:!0},{children:(0,e.jsx)("div",(0,s.pi)({className:"zent-image-p-backdrop","data-zv":"9.12.16"},{children:(0,e.jsxs)("div",(0,s.pi)({className:"zent-image-p-wrap","data-zv":"9.12.16"},{children:[(0,e.jsx)("div",(0,s.pi)({className:"zent-image-p-close",onClick:this.onClose,"data-zv":"9.12.16"},{children:(0,e.jsx)(k.Z,{type:"close"},void 0)}),void 0),(0,e.jsx)(d.Z,(0,s.pi)({componentName:"PreviewImage"},{children:function(a){return(0,e.jsx)("div",(0,s.pi)({className:"zent-image-p-body",onClick:n.onMaskClick,"data-zv":"9.12.16"},{children:t.map((function(t,s){return s===r?(0,e.jsx)("img",{className:h,onClick:n.handleScale,style:g,src:t,alt:a.alt,"data-zv":"9.12.16"},s):null}))}),void 0)}}),void 0),(0,e.jsx)(d.Z,(0,s.pi)({componentName:"PreviewImage"},{children:function(a){var p=t.length>1,c=l()("zent-image-p-footer",{"zent-image-p-show-rotate-btn":o,"zent-image-p-footer-paging":p}),i=l()("zent-image-p-action",{"zent-image-p-rotate-action":!p});return(0,e.jsxs)("div",(0,s.pi)({className:c,"data-zv":"9.12.16"},{children:[p&&(0,e.jsx)("span",(0,s.pi)({className:"zent-image-p-action",onClick:n.handlePreviousAction,"data-zv":"9.12.16"},{children:a.prev}),void 0),o&&(0,e.jsx)("span",(0,s.pi)({className:i,onClick:(0,u.Z)(n.handleRotate,500,{immediate:!0}),"data-zv":"9.12.16"},{children:a.rotate}),void 0),p&&(0,e.jsx)("span",(0,s.pi)({className:"zent-image-p-action",onClick:n.handleNextAction,"data-zv":"9.12.16"},{children:a.next}),void 0)]}),void 0)}}),void 0)]}),void 0)}),void 0)}),void 0)},a.defaultProps={className:"",showRotateBtn:!0,images:[],index:0,scaleRatio:1.5},a}(i.Component);function h(n){void 0===n&&(n={});var a=n.parentComponent,t=(0,s._T)(n,["parentComponent"]),i=(0,c.Z)("div"),r=(0,s.pi)((0,s.pi)({},t),{onClose:function(){i&&(o.unmountComponentAtNode(i),i=null)}});(a?o.unstable_renderSubtreeIntoContainer.bind(p,a):o.render)((0,e.jsx)(g,(0,s.pi)({},r),void 0),i)}var v=h}}]);