-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path113-a28f22da2d828c0b81f9.js
1 lines (1 loc) · 42.6 KB
/
113-a28f22da2d828c0b81f9.js
1
webpackJsonp([113],{1542:function(n,a,s){"use strict";function t(n){return n&&n.__esModule?n:{default:n}}function p(n){return y.default.createElement(n.tag,(0,l.default)({},n.attributes,{dangerouslySetInnerHTML:{__html:n.html}}))}function o(n){return y.default.createElement(p,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function e(n){return y.default.createElement(p,{tag:"style",html:n.style})}function c(n,a){for(;n;)return n.offsetTop&&"static"!==getComputedStyle(n).position&&(a+=n.offsetTop),c(n.parentNode,a);return a}Object.defineProperty(a,"__esModule",{value:!0});var u=s(7),l=t(u),i=s(1),k=t(i),r=s(4),d=t(r),g=s(2),v=t(g),f=s(3),h=t(f),m=s(0),y=t(m),S=s(232),C=t(S),w=s(359),b=function(){var n=function(n){function a(){var n,s,t,p;(0,k.default)(this,a);for(var o=arguments.length,e=Array(o),c=0;c<o;c++)e[c]=arguments[c];return s=t=(0,v.default)(this,(n=a.__proto__||Object.getPrototypeOf(a)).call.apply(n,[this].concat(e))),t.state={data:[]},t.onSelect=function(n){},t.onSearch=function(n){t.setState({data:n?[n,n+n,n+n+n]:[]})},t.onChange=function(n){},p=s,(0,v.default)(t,p)}return(0,h.default)(a,n),(0,d.default)(a,[{key:"render",value:function(){return y.default.createElement(w.AutoComplete,{data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),a}(m.Component);return y.default.createElement("div",null,y.default.createElement(n,null))},_=function(){var n=function(n){function a(){var n,s,t,p;(0,k.default)(this,a);for(var o=arguments.length,e=Array(o),c=0;c<o;c++)e[c]=arguments[c];return s=t=(0,v.default)(this,(n=a.__proto__||Object.getPrototypeOf(a)).call.apply(n,[this].concat(e))),t.state={value:"controlled",data:["controlled","controlledcontrolled","controlledcontrolledcontrolled"]},t.onSelect=function(n){},t.onSearch=function(n){t.setState({data:n?[{value:n,content:n},{value:n+n,content:n+n},{value:n+n+n,content:n+n+n}]:[]})},t.onChange=function(n){t.setState({value:n})},p=s,(0,v.default)(t,p)}return(0,h.default)(a,n),(0,d.default)(a,[{key:"render",value:function(){return y.default.createElement(w.AutoComplete,{value:this.state.value,data:this.state.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),a}(m.Component);return y.default.createElement("div",null,y.default.createElement(n,null))},E=function(){var n=function(n){function a(){var n,s,t,p;(0,k.default)(this,a);for(var o=arguments.length,e=Array(o),c=0;c<o;c++)e[c]=arguments[c];return s=t=(0,v.default)(this,(n=a.__proto__||Object.getPrototypeOf(a)).call.apply(n,[this].concat(e))),t.state={value:"",data:[]},t.data=[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},"绍兴","温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"],t.onSelect=function(n){},t.onSearch=function(n){},t.onChange=function(n){t.setState({value:n})},p=s,(0,v.default)(t,p)}return(0,h.default)(a,n),(0,d.default)(a,[{key:"render",value:function(){return y.default.createElement(w.AutoComplete,{placeholder:"输入值不受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange})}}]),a}(m.Component),a=function(n){function a(){var n,s,t,p;(0,k.default)(this,a);for(var o=arguments.length,e=Array(o),c=0;c<o;c++)e[c]=arguments[c];return s=t=(0,v.default)(this,(n=a.__proto__||Object.getPrototypeOf(a)).call.apply(n,[this].concat(e))),t.state={value:"",data:[]},t.data=[{isGroup:!0,content:"浙江"},{value:"hz",content:"杭州"},{value:"绍兴",content:y.default.createElement("div",null,y.default.createElement("div",null,"绍!兴!"),y.default.createElement("div",null,"这是第二行"))},"温州","金华",{isDivider:!0},{isGroup:!0,content:"江苏"},"南京","苏州","无锡","常州"],t.onSelect=function(n){},t.onSearch=function(n){},t.onChange=function(n){t.setState({value:n})},p=s,(0,v.default)(t,p)}return(0,h.default)(a,n),(0,d.default)(a,[{key:"render",value:function(){return y.default.createElement(w.AutoComplete,{placeholder:"输入值受限...",value:this.state.value,data:this.data,onSelect:this.onSelect,onSearch:this.onSearch,onChange:this.onChange,valueFromOptions:!0})}}]),a}(m.Component);return y.default.createElement("div",null,y.default.createElement("div",null,y.default.createElement("div",{style:{display:"inline-block",fontSize:"12px",margin:"5px 0"}},"输入值不受限:"),y.default.createElement(n,null)),y.default.createElement("div",{style:{marginTop:"5px"}},y.default.createElement("div",{style:{display:"inline-block",fontSize:"12px",margin:"5px 0"}},"输入值必须来自于选项:"),y.default.createElement(a,null)))},j=function(n){function a(){var n,s,t,p;(0,k.default)(this,a);for(var o=arguments.length,e=Array(o),c=0;c<o;c++)e[c]=arguments[c];return s=t=(0,v.default)(this,(n=a.__proto__||Object.getPrototypeOf(a)).call.apply(n,[this].concat(e))),t.state={showCode:!1},t.toggle=function(){t.setState({showCode:!t.state.showCode})},p=s,(0,v.default)(t,p)}return(0,h.default)(a,n),(0,d.default)(a,[{key:"render",value:function(){var n=this.state.showCode,a=this.props,s=a.title,t=a.src,o=a.children;return y.default.createElement("div",{className:"zandoc-react-demo"},y.default.createElement("div",{className:"zandoc-react-demo__preview"},o),y.default.createElement("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle},y.default.createElement("div",{className:"zandoc-react-demo__title"},y.default.createElement("p",null,s||"")),y.default.createElement("i",{className:"zenticon zenticon-caret-up zandoc-react-demo__toggle "+(n?"zandoc-react-demo__toggle-on":"zandoc-react-demo__toggle-off")})),n&&y.default.createElement("pre",{className:"zandoc-react-demo__code"},y.default.createElement(p,{tag:"code",html:t,attributes:{className:"language-jsx"}})))}}]),a}(m.Component),z=function(n){function a(){return(0,k.default)(this,a),(0,v.default)(this,(a.__proto__||Object.getPrototypeOf(a)).apply(this,arguments))}return(0,h.default)(a,n),(0,d.default)(a,[{key:"componentDidMount",value:function(){var n=location.hash;if(n){var a=document.querySelector('a[href="'+n+'"]');a&&(0,C.default)(document.documentElement,0,c(a,-9))}}},{key:"render",value:function(){return y.default.createElement("div",{className:"zandoc-react-container",key:null},y.default.createElement(e,{style:""}),y.default.createElement(o,{html:'<h2 class="anchor-heading"><a href="#autocomplete-zi-dong-wan-cheng">¶</a><a href="javascript:void(0)" id="autocomplete-zi-dong-wan-cheng" class="anchor-point"></a>AutoComplete 自动完成</h2>\n<p>输入框自动完成功能。</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>'}),y.default.createElement(j,{title:"基础用法",id:"Demobasic",src:'<span class="token keyword">import</span> <span class="token punctuation">{</span> AutoComplete <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">class</span> <span class="token class-name">Complete</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 data<span class="token punctuation">:</span> <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-variable function">onSelect</span> <span class="token operator">=</span> v <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> v <span class="token operator">=></span> <span class="token punctuation">{</span>\n <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>\n data<span class="token punctuation">:</span> v <span class="token operator">?</span> <span class="token punctuation">[</span>v<span class="token punctuation">,</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span> v <span class="token operator">+</span> v <span class="token operator">+</span> v<span class="token punctuation">]</span> <span class="token punctuation">:</span> <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><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> v <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<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">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>AutoComplete</span>\n <span class="token attr-name">data</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>data<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</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>onSelect<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</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>onSearch<span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</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>onChange<span class="token punctuation">}</span></span>\n <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>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>Complete</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 punctuation">,</span>\n mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},y.default.createElement(b)),y.default.createElement(j,{title:"受控组件",id:"Democontrolled",src:'<span class="token keyword">import</span> <span class="token punctuation">{</span> AutoComplete <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">class</span> <span class="token class-name">ControlledComplete</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 value<span class="token punctuation">:</span> <span class="token string">\'controlled\'</span><span class="token punctuation">,</span>\n data<span class="token punctuation">:</span> <span class="token punctuation">[</span> <span class="token string">\'controlled\'</span><span class="token punctuation">,</span> <span class="token string">\'controlledcontrolled\'</span><span class="token punctuation">,</span> <span class="token string">\'controlledcontrolledcontrolled\'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span>\n\n <span class="token function-variable function">onSelect</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>\n <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>\n data<span class="token punctuation">:</span> v <span class="token operator">?</span> <span class="token punctuation">[</span> <span class="token punctuation">{</span>\n value<span class="token punctuation">:</span> v<span class="token punctuation">,</span>\n content<span class="token punctuation">:</span> v<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>\n value<span class="token punctuation">:</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n content<span class="token punctuation">:</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>\n value<span class="token punctuation">:</span> v <span class="token operator">+</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n content<span class="token punctuation">:</span> v <span class="token operator">+</span> v <span class="token operator">+</span> v<span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">]</span> <span class="token punctuation">:</span> <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 <span class="token punctuation">}</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>\n console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <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>\n value<span class="token punctuation">:</span> v\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">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>AutoComplete</span>\n <span class="token attr-name">value</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>value<span class="token punctuation">}</span></span>\n <span class="token attr-name">data</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>data<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</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>onSelect<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</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>onSearch<span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</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>onChange<span class="token punctuation">}</span></span>\n <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>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ControlledComplete</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 punctuation">,</span>\n mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},y.default.createElement(_)),y.default.createElement(j,{title:"高级菜单项",id:"Demoadvanced",src:'<span class="token keyword">import</span> <span class="token punctuation">{</span> AutoComplete <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">class</span> <span class="token class-name">ControlledComplete</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 value<span class="token punctuation">:</span> <span class="token string">\'\'</span><span class="token punctuation">,</span>\n data<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>\n <span class="token punctuation">}</span>\n\n data <span class="token operator">=</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span> isGroup<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token punctuation">:</span> <span class="token string">\'浙江\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> value<span class="token punctuation">:</span> <span class="token string">\'hz\'</span><span class="token punctuation">,</span> content<span class="token punctuation">:</span> <span class="token string">\'杭州\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'绍兴\'</span><span class="token punctuation">,</span>\n <span class="token string">\'温州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'金华\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> isDivider<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 punctuation">{</span> isGroup<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token punctuation">:</span> <span class="token string">\'江苏\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'南京\'</span><span class="token punctuation">,</span>\n <span class="token string">\'苏州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'无锡\'</span><span class="token punctuation">,</span>\n <span class="token string">\'常州\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span>\n\n <span class="token function-variable function">onSelect</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onSearch\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>\n console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <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>\n value<span class="token punctuation">:</span> v\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">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>AutoComplete</span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>输入值不受限...<span class="token punctuation">"</span></span>\n <span class="token attr-name">value</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>value<span class="token punctuation">}</span></span>\n <span class="token attr-name">data</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>data<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</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>onSelect<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</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>onSearch<span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</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>onChange<span class="token punctuation">}</span></span>\n <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 keyword">class</span> <span class="token class-name">SelectComplete</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 value<span class="token punctuation">:</span> <span class="token string">\'\'</span><span class="token punctuation">,</span>\n data<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>\n <span class="token punctuation">}</span>\n\n data <span class="token operator">=</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span> isGroup<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token punctuation">:</span> <span class="token string">\'浙江\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> value<span class="token punctuation">:</span> <span class="token string">\'hz\'</span><span class="token punctuation">,</span> content<span class="token punctuation">:</span> <span class="token string">\'杭州\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> value<span class="token punctuation">:</span> <span class="token string">\'绍兴\'</span><span class="token punctuation">,</span> content<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><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>绍<span class="token operator">!</span>兴<span class="token operator">!</span><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>这是第二行<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> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'温州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'金华\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> isDivider<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 punctuation">{</span> isGroup<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> content<span class="token punctuation">:</span> <span class="token string">\'江苏\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token string">\'南京\'</span><span class="token punctuation">,</span>\n <span class="token string">\'苏州\'</span><span class="token punctuation">,</span>\n <span class="token string">\'无锡\'</span><span class="token punctuation">,</span>\n <span class="token string">\'常州\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span>\n\n <span class="token function-variable function">onSelect</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onSelect\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onSearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onSearch\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>\n console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>\n <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>\n value<span class="token punctuation">:</span> v\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">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>AutoComplete</span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">"</span>输入值受限...<span class="token punctuation">"</span></span>\n <span class="token attr-name">value</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>value<span class="token punctuation">}</span></span>\n <span class="token attr-name">data</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>data<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSelect</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>onSelect<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSearch</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>onSearch<span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</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>onChange<span class="token punctuation">}</span></span>\n <span class="token attr-name">valueFromOptions</span>\n <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\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>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>\n <span class="token operator"><</span>div style<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> display<span class="token punctuation">:</span> <span class="token string">\'inline-block\'</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">:</span> <span class="token string">\'12px\'</span><span class="token punctuation">,</span> margin<span class="token punctuation">:</span> <span class="token string">\'5px 0\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator">></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>ControlledComplete</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 operator"><</span>div style<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginTop<span class="token punctuation">:</span> <span class="token string">\'5px\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator">></span>\n <span class="token operator"><</span>div style<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> display<span class="token punctuation">:</span> <span class="token string">\'inline-block\'</span><span class="token punctuation">,</span> fontSize<span class="token punctuation">:</span> <span class="token string">\'12px\'</span><span class="token punctuation">,</span> margin<span class="token punctuation">:</span> <span class="token string">\'5px 0\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token operator">></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>SelectComplete</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 tag"><span class="token tag"><span class="token punctuation"></</span>div</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>'},y.default.createElement(E)),y.default.createElement(o,{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>value</td>\n<td>选中值</td>\n<td>any</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>initialValue</td>\n<td>初始值</td>\n<td>any</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>placeholder</td>\n<td>输入框的placeholder</td>\n<td>string</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>data</td>\n<td>选项数据</td>\n<td>array</td>\n<td>否</td>\n<td>[]</td>\n<td></td>\n</tr>\n<tr>\n<td>onChange</td>\n<td>当value改变时的callback</td>\n<td>function (value) {}</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onSearch</td>\n<td>当输入值改变时的callback</td>\n<td>function (searchText) {}</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>onSelect</td>\n<td>当选中某个选项时的callback</td>\n<td>function (value) {}</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>filterOption</td>\n<td>根据输入值过滤选项的function</td>\n<td>function (searchText, { value, content }) {}</td>\n<td>否</td>\n<td>caselessMatch</td>\n<td></td>\n</tr>\n<tr>\n<td>valueFromOptions</td>\n<td>是否只能选中选项中存在的值</td>\n<td>bool</td>\n<td>否</td>\n<td><code>false</code></td>\n<td></td>\n</tr>\n<tr>\n<td>className</td>\n<td>可选,自定义输入框容器额外类名</td>\n<td>string</td>\n<td>否</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>popupClassName</td>\n<td>可选,自定义popup的类名</td>\n<td>string</td>\n<td>否</td>\n<td><code>\'\'</code></td>\n<td></td>\n</tr>\n<tr>\n<td>width</td>\n<td>输入框宽度</td>\n<td>string or number</td>\n<td>否</td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<h3 class="anchor-heading"><a href="#data-jie-gou">¶</a><a href="javascript:void(0)" id="data-jie-gou" class="anchor-point"></a>data 结构</h3>\n<ul>\n<li>使用方式 1: string array, 此时选项显示内容和选项value相同, 推荐使用</li>\n<li>使用方式 2: object array, 其中每项的结构是:</li>\n</ul>\n<pre><code class="language-text"><span class="token punctuation">{</span>\n value<span class="token punctuation">:</span> <span class="token string">\'value\'</span><span class="token punctuation">,</span> <span class="token comment">// 必填, 作为选项 value; 当 content 未传入时, 同时作为 content 使用; 当 content 未传入, 或者 content 不是 string 类型时, 用于默认的过滤匹配</span>\n content<span class="token punctuation">:</span> <span class="token string">\'content\'</span><span class="token punctuation">,</span> <span class="token comment">// 选填, 作为选项显示内容,可以填入 react node, 当 content 是 string 类型时, 会被优先用于过滤匹配</span>\n isGroup<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 选填, 此项作为分组头部渲染, 显示内容是content的值, 不可被点击选择</span>\n isDivider<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">// 选填, 此项作为分割线渲染, 不可被点击选择</span>\n<span class="token punctuation">}</span></code></pre>\n<p>注意此时的 <code>value</code> 和 <code>content</code> 是可以不同的。用户输入的值会通过 <code>onSearch</code> 返回,用于 <code>value</code> 和 <code>content</code> 值的匹配,其优先级: string 类型的 <code>content</code> > <code>value</code>。 当用户选中某个选项时,其 value 会被通过 <code>onSelect</code> 返回。无论是选中选项,还是直接用户输入,当输入框中的值变化时,新的 value 都会通过 <code>onChange</code> 返回。特别的,当 <code>valueFromOptions</code> 为 true 时,输入框失焦时会检查当前value是否在选项值中,如果不在则会重置,触发 <code>onSelect</code> 和 <code>onChange</code> 传入 null 值。</p>'}))}}]),a}(m.Component);a.default=z}});