-
Notifications
You must be signed in to change notification settings - Fork 0
/
5071-85399f42514ccdb9602d.js
1 lines (1 loc) · 45.1 KB
/
5071-85399f42514ccdb9602d.js
1
(self.webpackChunkzent_docs=self.webpackChunkzent_docs||[]).push([[5071],{35071:(n,a,s)=>{"use strict";s.r(a),s.d(a,{default:()=>w});var t=s(73450),p=s(27378),e=s(57318),o=s(80964),c=s(96681),u=s(24246);function l(n,a){var s=Object.keys(n);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(n);a&&(t=t.filter((function(a){return Object.getOwnPropertyDescriptor(n,a).enumerable}))),s.push.apply(s,t)}return s}function i(n){for(var a=1;a<arguments.length;a++){var s=null!=arguments[a]?arguments[a]:{};a%2?l(Object(s),!0).forEach((function(a){(0,t.Z)(n,a,s[a])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(s)):l(Object(s)).forEach((function(a){Object.defineProperty(n,a,Object.getOwnPropertyDescriptor(s,a))}))}return n}var r=function(){return(0,u.jsxs)("div",{children:[(0,u.jsx)(o.Y,{value:2,placeholder:"请输入数字"}),(0,u.jsx)(o.Y,{value:2,placeholder:"请输入数字",addonBefore:"$"}),(0,u.jsx)(o.Y,{value:2,showStepper:!0,placeholder:"请输入数字"}),(0,u.jsx)(o.Y,{value:2,showCounter:!0,placeholder:"请输入数字"}),(0,u.jsx)(o.Y,{value:2,showCounter:!0,placeholder:"请输入数字"})]})},k=function(){return(0,u.jsxs)("div",{children:[(0,u.jsx)(o.Y,{value:2,decimal:2,placeholder:"请输入数字"}),(0,u.jsx)(o.Y,{value:2,showStepper:!0,decimal:2,step:1,placeholder:"请输入数字"}),(0,u.jsx)(o.Y,{value:2,showCounter:!0,decimal:2,placeholder:"请输入数字"})]})},d=function(){return(0,u.jsxs)("div",{children:[(0,u.jsx)(o.Y,{value:3,min:-2,max:6,decimal:2,placeholder:"请输入数字"}),(0,u.jsx)(o.Y,{value:3,showStepper:!0,min:2,max:6,decimal:2,placeholder:"请输入数字"}),(0,u.jsx)(o.Y,{value:3,showCounter:!0,min:2,max:6,decimal:2,placeholder:"请输入数字"})]})},m=function(){return(0,u.jsxs)("div",{children:[(0,u.jsx)(o.Y,{value:3,disabled:!0}),(0,u.jsx)(o.Y,{value:3,disabled:!0,showStepper:!0}),(0,u.jsx)(o.Y,{value:3,disabled:!0,showCounter:!0})]})},h=function(){class n extends p.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{value:""}),(0,t.Z)(this,"onChange",(n=>{this.setState({value:n})})),(0,t.Z)(this,"setToThree",(()=>{this.setState({value:3})})),(0,t.Z)(this,"onPressEnter",(()=>{}))}render(){return(0,u.jsxs)("div",{children:[(0,u.jsx)(o.Y,{showStepper:!0,value:this.state.value,onChange:this.onChange,onPressEnter:this.onPressEnter}),(0,u.jsx)(c.z,{onClick:this.setToThree,children:"设置值为 3"})]})}}return(0,u.jsx)(n,{})},v=function(){return(0,u.jsxs)("div",{children:[(0,u.jsx)(o.Y,{value:3,min:-2,max:6,integer:!0,placeholder:"请输入整数"}),(0,u.jsx)(o.Y,{value:Number.MAX_SAFE_INTEGER,showStepper:!0,integer:!0,placeholder:"请输入整数"}),(0,u.jsx)(o.Y,{value:3,integer:!0,showCounter:!0,min:2,max:6,placeholder:"请输入整数"})]})};function g(n){return(0,u.jsx)(n.tag,i(i({},n.attributes),{},{dangerouslySetInnerHTML:{__html:n.html}}))}function b(n){return(0,u.jsx)(g,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function f(n){return(0,u.jsx)(g,{tag:"style",html:n.style})}function j(n,a){for(;n;)return n.offsetTop&&"static"!==getComputedStyle(n).position&&(a+=n.offsetTop),j(n.parentNode,a);return a}class x 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,a=this.props,s=a.title,t=a.src,p=a.children;return(0,u.jsxs)("div",{className:"zandoc-react-demo",children:[(0,u.jsx)("div",{className:"zandoc-react-demo__preview",children:p}),(0,u.jsxs)("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle,children:[(0,u.jsx)("div",{className:"zandoc-react-demo__title",children:(0,u.jsx)("p",{children:s||""})}),(0,u.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,u.jsx)("pre",{className:"zandoc-react-demo__code",children:(0,u.jsx)(g,{tag:"code",html:t,attributes:{className:"language-jsx"}})})]})}}class w extends p.Component{componentDidMount(){var n=location.hash;if(n){var a=document.querySelector('a[href="'.concat(n,'"]'));a&&(0,e.l)(document.documentElement,0,j(a,-9))}}render(){return p.createElement("div",{className:"zandoc-react-container"},p.createElement(f,{style:".zent-number-input {\n width: 200px;\n margin-bottom: 20px;\n}"}),p.createElement(b,{html:'<h2 class="anchor-heading"><a href="#numberinput-shu-zhi-shu-ru-kuang">¶</a><a href="javascript:void(0)" id="numberinput-shu-zhi-shu-ru-kuang" class="anchor-point"></a>NumberInput 数值输入框</h2>\n<p>数字输入组件,通过鼠标或键盘输入内容。\n默认值类型是 string,在整数模式下是 number,且有默认上限<code>Number.MAX_SAFE_INTEGER</code>,默认下限<code>Number.MIN_SAFE_INTEGER</code>。</p>\n<h3 class="anchor-heading"><a href="#shi-yong-zhi-nan">¶</a><a href="javascript:void(0)" id="shi-yong-zhi-nan" class="anchor-point"></a>使用指南</h3>\n<ul>\n<li>输入内容仅为数字时,使用数字输入框比普通文本输入框更方便。</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(x,{title:"基础用法",id:"Demo1",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NumberInput</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>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">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span> <span class="token attr-name">placeholder</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 punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span> <span class="token attr-name">placeholder</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">addonBefore</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 punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span> <span class="token attr-name">showStepper</span> <span class="token attr-name">placeholder</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 punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span> <span class="token attr-name">showCounter</span> <span class="token attr-name">placeholder</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 punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span> <span class="token attr-name">showCounter</span> <span class="token attr-name">placeholder</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 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>'},p.createElement(r)),p.createElement(x,{title:"指定小数点精度",id:"Demo2",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NumberInput</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>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">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span> <span class="token attr-name">decimal</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span> <span class="token attr-name">placeholder</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 punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">showStepper</span>\n <span class="token attr-name">decimal</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">step</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">showCounter</span>\n <span class="token attr-name">decimal</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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>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>'},p.createElement(k)),p.createElement(x,{title:"控制可输入的数字范围",id:"Demo3",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NumberInput</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>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">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">min</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">max</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">6</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">decimal</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">showStepper</span>\n <span class="token attr-name">min</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">max</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">6</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">decimal</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">showCounter</span>\n <span class="token attr-name">min</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">max</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">6</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">decimal</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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>div</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(d)),p.createElement(x,{title:"disable状态",id:"Demo4",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NumberInput</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>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">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span> <span class="token attr-name">disabled</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">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span> <span class="token attr-name">disabled</span> <span class="token attr-name">showStepper</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">NumberInput</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span> <span class="token attr-name">disabled</span> <span class="token attr-name">showCounter</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> mountNode\n<span class="token punctuation">)</span><span class="token punctuation">;</span>'},p.createElement(m)),p.createElement(x,{title:"事件处理",id:"Demo5",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NumberInput</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">EventTest</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 value<span class="token operator">:</span> <span class="token string">\'\'</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n <span class="token function-variable function">onChange</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onChange\'</span><span class="token punctuation">)</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> value <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-variable function">setToThree</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</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> value<span class="token operator">:</span> <span class="token number">3</span> <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-variable function">onPressEnter</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'pressed enter\'</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 punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span>\n <span class="token attr-name">showStepper</span>\n <span class="token attr-name">value</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">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</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">onChange</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onPressEnter</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">onPressEnter</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">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 keyword">this</span><span class="token punctuation">.</span><span class="token property-access">setToThree</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>设置值为 <span class="token number">3</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">EventTest</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(h)),p.createElement(x,{title:"整数模式",id:"Demo6",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">NumberInput</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>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">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">min</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">max</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">6</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">integer</span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token known-class-name class-name">Number</span><span class="token punctuation">.</span><span class="token constant">MAX_SAFE_INTEGER</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">showStepper</span>\n <span class="token attr-name">integer</span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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">NumberInput</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">integer</span>\n <span class="token attr-name">showCounter</span>\n <span class="token attr-name">min</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">max</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">6</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</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>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>'},p.createElement(v)),p.createElement(b,{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><code>integer === true ? number : string</code></td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onChange</td>\n<td>值改变的回调函数</td>\n<td><code>(value: typeof value) => void</code></td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>onInput</td>\n<td>用户输入的回调函数</td>\n<td><code>(value: string) => void</code></td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>showStepper</td>\n<td>是否开启记步器</td>\n<td><code>boolean</code></td>\n<td><code>false</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>showCounter</td>\n<td>是否开启加减号</td>\n<td><code>boolean</code></td>\n<td><code>false</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>integer</td>\n<td>整数模式</td>\n<td><code>boolean</code></td>\n<td><code>false</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>decimal</td>\n<td>数值精度</td>\n<td><code>number</code></td>\n<td><code>0</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>step</td>\n<td>步进</td>\n<td><code>number</code></td>\n<td>整数模式为 \n<code>1</code>\n,小数模式根据精度而定</td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>min</td>\n<td>数值范围最小值</td>\n<td><code>number</code></td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>max</td>\n<td>数值范围最大值</td>\n<td><code>number</code></td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>placeholder</td>\n<td>原生 placeholder 文案</td>\n<td><code>string</code></td>\n<td><code>\'\'</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>disabled</td>\n<td>是否禁用</td>\n<td><code>boolean</code></td>\n<td><code>false</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>className</td>\n<td>自定义额外类名</td>\n<td><code>string</code></td>\n<td><code>\'\'</code></td>\n<td></td>\n<td>否</td>\n</tr>\n<tr>\n<td>width</td>\n<td>宽度</td>\n<td><code>string</code>\n \n|\n \n<code>number</code></td>\n<td></td>\n<td></td>\n<td>否</td>\n</tr>\n</tbody>\n</table>\n<h4 class="anchor-heading"><a href="#onchange-he-oninput-de-qu-bie">¶</a><a href="javascript:void(0)" id="onchange-he-oninput-de-qu-bie" class="anchor-point"></a><code>onChange</code> 和 <code>onInput</code> 的区别</h4>\n<ul>\n<li>由于 <code>NumberInput</code> 可以设置数字的格式,所以它的 <code>onChange</code> 和 <code>onInput</code> 行为是有区别的,这点和普通的 <code>Input</code> 不同</li>\n<li>绝大部分时候应该使用 <code>onChange</code>,当需要实时获取用户输入的内容时才需要使用 <code>onInput</code>,且 <code>onInput</code> 的参数类型永远是 <code>string</code></li>\n<li>\n<p><code>onInput</code> 和 <code>onChange</code> 的参数值可能不一致</p>\n<ul>\n<li>小数模式下设置精度为小数点后两位,当输入 <code>1.0</code> 的时候,在 <code>onInput</code> 中获取的参数是 <code>\'1.0\'</code>,而在 <code>onChange</code> 中获取的参数是 <code>\'1.00\'</code></li>\n<li>整数模式下,当输入是 <code>2.00</code> 时,<code>onInput</code> 的参数是 <code>\'2.00\'</code>,但是 <code>onChange</code> 的参数是 <code>2</code>,注意不仅值不同,类型也是不一样的</li>\n</ul>\n</li>\n</ul>'}))}}},80964:(n,a,s)=>{"use strict";s.d(a,{Y:()=>_,Z:()=>O});var t=s(59312),p=s(24246),e=s(27378),o=s(60042),c=s.n(o),u=s(9828),l=s.n(u),i=s(27036),r=s(82285),k=s(77125),d=s(1348);function m(n,a,s){return n>=s?n:a<=s?a:s}function h(n){var a=function(n){return"number"!=typeof n||Number.isNaN(n)?Number.MAX_SAFE_INTEGER:m(Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,n)}(n.max),s=function(n){return"number"!=typeof n||Number.isNaN(n)?Number.MIN_SAFE_INTEGER:m(Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,n)}(n.min);return s>a?(function(n,a){for(var s=[],t=2;t<arguments.length;t++)s[t-2]=arguments[t]}(!1,"max is smaller than min"),{min:a,max:s}):{min:s,max:a}}function v(n,a,s){var t,p=null;return null==n?(t=null,p=""):"string"==typeof n?t=parseInt(n,10)||0:Number.isNaN(n)?(t=0,p=""):t=Math.floor(n),null!==t&&(t=Math.min(s,t),t=Math.max(a,t)),null===p&&(p=String(t)),{value:t,input:p}}function g(n,a,s){if(null===n)return{canDec:!1,canInc:!1};var t=!0,p=!0;return a>=n&&(t=!1),s<=n&&(p=!1),{canDec:t,canInc:p}}function b(n){return n.startsWith("+")?n.substring(1):n}var f=new(l())(0);function j(n){return""===n||"."===n||"-"===n||"+"===n}function x(n){return/^[-+]?\d*\.?\d*$/.test(n)}function w(n,a){return Number.isFinite(a)?new(l())(a):new(l())(1).div(Math.pow(10,n))}function y(n){return x(n=String(n))?new(l())(b(n)):null}function N(n){return{min:y(n.min),max:y(n.max)}}function I(n,a,s,t){if(null==n)return{input:"",value:f};if(j(n=String(n))||!x(n))return{input:"",value:f};if(""===n||j(n))return{input:n,value:f};var p=new(l())(b(n));return null!==a&&1===a.cmp(p)&&(p=a),null!==s&&-1===s.cmp(p)&&(p=s),{input:p.toFixed(t),value:p}}function C(n,a,s){var t=!0,p=!0;return null!==a&&(t=-1===a.cmp(n)),null!==s&&(p=1===s.cmp(n)),{canDec:t,canInc:p}}var E=s(72551),S=Object.is;function z(n,a){if(!0===n.integer){var s=h(n),p=s.min,e=s.max;return(0,t.pi)({prevProps:n,min:p,max:e,delta:(o=n.step,Number.isFinite(o)?Math.round(o):1)},a?v(n.value,p,e):{})}var o,c=N(n);return p=c.min,e=c.max,(0,t.pi)({prevProps:n,min:p,max:e,delta:w(n.decimal,n.step)},a?I(n.value,p,e,n.decimal):{})}var _=function(n){function a(a){var s=n.call(this,a)||this;return s.focused=!1,s.inputRef=(0,e.createRef)(),s.inputContext={renderInner:function(n){return s.renderChild(n)}},s.onUserInput=function(n){var a=n.target.value;if(!1===s.props.integer){var t=s.props.onInput;j(a)?s.setState({input:a,value:f}):x(a)&&(s.setState({input:a,value:new(l())(b(a))}),t&&t(a))}else if(t=s.props.onInput,function(n){return""===n||"-"===n||"+"===n}(a))s.setState({input:a,value:null}),t&&t(a);else if(function(n){return/^[-+]?\d*$/.test(n.toString())}(a)){var p=parseInt(a,10)||0;s.setState({input:a,value:p}),t&&t(a)}},s.onFocus=function(n){s.focused=!0;var a=s.props.onFocus;a&&a(n)},s.onBlur=function(n){if(s.focused=!1,!0===s.props.integer){var a=s.props.onChange,t=s.state,p=v(t.value,t.min,t.max);null==a||a(p.value),s.setState(p),null==(e=s.props.onBlur)||e(n)}else{var e,o=s.props,c=(a=o.onChange,o.decimal),u=s.state;p=I(u.input,u.min,u.max,c),null==a||a(p.input),s.setState(p),(e=s.props.onBlur)&&e(n)}},s.inc=function(){s.step("inc")},s.dec=function(){s.step("dec")},s.state=z(a,!0),s}return(0,t.ZT)(a,n),a.prototype.step=function(n){if(!this.props.disabled)if(!0===this.props.integer){var a=this.state,s=a.value,t=a.min,p=a.max,e=a.delta,o=g(s,t,p),c=o.canInc,u=o.canDec;if(null===s||"inc"===n&&!c||"dec"===n&&!u)return;var l=void 0;l="inc"===n?s+e:s-e,null==(r=this.props.onChange)||r(l),this.setState({value:l,input:String(l)})}else{var i=this.props,r=i.onChange,k=i.decimal,d=this.state,m=(s=d.value,t=d.min,p=d.max,e=d.delta,C(s,t,p));if(c=m.canInc,u=m.canDec,"inc"===n&&!c||"dec"===n&&!u)return;l=void 0;var h=(l="inc"===n?s.plus(e):s.minus(e)).toFixed(k);null==r||r(h),this.setState({value:l,input:h})}},a.getDerivedStateFromProps=function(n,a){var s=a.prevProps;if(n===s)return null;var p=function(n){return(0,E.n)(n,"value")&&(0,E.n)(n,"onChange")}(n);if(n.integer!==s.integer)return z(n,p);if(!0===n.integer){var e=(0,t.pi)((0,t.pi)({},a),{prevProps:n}),o=!1;if(!S(n.min,s.min)||!S(n.max,s.max)){var c=h(n),u=c.min,l=c.max;e.min=u,e.max=l,o=!0}if(p&&(o||!S(n.value,s.value))){var i=v(n.value,e.min,e.max),r=i.value,k=i.input;e.value=r,e.input=k}return e}var d=(0,t.pi)((0,t.pi)({},a),{prevProps:n}),m=!1;if(!S(n.min,s.min)||!S(n.max,s.max)){var g=N(n);u=g.min,l=g.max,d.min=u,d.max=l,m=!0}if(p&&(m||!S(n.value,s.value)||!S(n.decimal,s.decimal))){var b=I(n.value,d.min,d.max,n.decimal);r=b.value,k=b.input,d.value=r,d.input=k}return S(n.step,s.step)&&S(n.decimal,s.decimal)||(d.delta=w(n.decimal,n.step)),d},a.prototype.checkPropsValue=function(){if(!0===this.props.integer)this.props.value!==this.state.value&&(a=this.props.onChange)&&a(this.state.value);else{var n=this.props,a=n.onChange,s=n.decimal,t=n.value,p=this.state.value.toFixed(s),e="number"==typeof t?t.toFixed(s):t;a&&""!==this.props.value&&""!==this.state.input&&e!==p&&a(p)}},a.prototype.componentDidMount=function(){"value"in this.props&&!this.focused&&this.checkPropsValue()},a.prototype.componentDidUpdate=function(n){n!==this.props&&"value"in this.props&&!this.focused&&this.checkPropsValue()},a.prototype.renderChild=function(n){var a,s=this.props,e=s.disabled,o=void 0===e?this.context.value:e,u=s.readOnly,l=s.showCounter,r=s.showStepper;if(!0===this.props.integer){var k=this.state,d=k.min,m=k.max;a=g(k.value,d,m)}else{var h=this.state;a=C(h.value,d=h.min,m=h.max)}var v=a.canDec,b=a.canInc,f=o||u||!b,j=o||u||!v,x=c()({"zent-number-input-arrow":!0,"zent-number-input-arrowup":!0,"zent-number-input-arrow-disable":f}),w=c()({"zent-number-input-arrow":!0,"zent-number-input-arrowdown":!0,"zent-number-input-arrow-disable":j}),y=c()({"zent-number-input-count":!0,"zent-number-input-countreduce":!0,"zent-number-input-count-disable":j}),N=c()({"zent-number-input-count":!0,"zent-number-input-countadd":!0,"zent-number-input-count-disable":f});return(0,p.jsxs)(p.Fragment,{children:[l&&(0,p.jsx)("div",(0,t.pi)({className:y,onClick:this.dec,"data-zv":"9.12.16"},{children:"–"}),void 0),n,l&&(0,p.jsx)("div",(0,t.pi)({className:N,onClick:this.inc,"data-zv":"9.12.16"},{children:"+"}),void 0),r&&(0,p.jsxs)("div",(0,t.pi)({className:"zent-number-input-arrows","data-zv":"9.12.16"},{children:[(0,p.jsx)("div",(0,t.pi)({className:x,onClick:this.inc,"data-zv":"9.12.16"},{children:(0,p.jsx)(i.Z,{type:"up"},void 0)}),void 0),(0,p.jsx)("div",(0,t.pi)({className:w,onClick:this.dec,"data-zv":"9.12.16"},{children:(0,p.jsx)(i.Z,{type:"down"},void 0)}),void 0)]}),void 0)]},void 0)},a.prototype.render=function(){var n=this.props,a=(n.integer,n.className),s=n.disabled,e=n.readOnly,o=(n.type,n.onChange,n.showStepper),u=n.showCounter,l=(n.min,n.max,n.decimal,n.onInput,(0,t._T)(n,["integer","className","disabled","readOnly","type","onChange","showStepper","showCounter","min","max","decimal","onInput"])),i=this.state.input;if(o&&u)throw new Error("NumberInput: showStepper、 showCounter cannot exist at the same time");return(0,p.jsx)(k.r.Provider,(0,t.pi)({value:this.inputContext},{children:(0,p.jsx)(r.I,(0,t.pi)({ref:this.inputRef,autoComplete:"off"},l,{readOnly:e,disabled:s,className:c()("zent-number-input",a),value:i,onChange:this.onUserInput,onFocus:this.onFocus,onBlur:this.onBlur}),void 0)}),void 0)},a.defaultProps={integer:!1,type:"number",decimal:0,size:"normal"},a.contextType=d.d,a}(e.Component),O=_}}]);