@livelybone/react-mobile-code-input
Version:
A module for code input, each char corresponds to one input box
10 lines (8 loc) • 3.23 kB
JavaScript
/**
* Bundle of @livelybone/react-mobile-code-input
* Generated: 2021-09-25
* Version: 1.0.1
* License: MIT
* Author: 2631541504@qq.com
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e=e||self).IndexReactMobileCodeInput=t(e.React)}(this,function(r){"use strict";var i="default"in r?r.default:r;function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function f(n){return function(){var e,t=o(n);return e=function(){if("undefined"!=typeof Reflect&&Reflect.construct&&!Reflect.construct.sham){if("function"==typeof Proxy)return 1;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),1}catch(e){return}}}()?(e=o(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments),t=this,!(e=e)||"object"!==u(e)&&"function"!=typeof e?a(t):e}}function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var e=function(){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}(u,r.PureComponent);var e,t,n,o=f(u);function u(){var e;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return s(a(e=o.call.apply(o,[this].concat(n))),"id",e.props.id||String(Math.random())),e}return e=u,(t=[{key:"length",get:function(){return this.props.length||4}},{key:"genArr",value:function(){for(var e=this.length,t=this.props.value||"",n=[],r=0;r<e;r++)n.push({value:t[r]});return n}},{key:"render",value:function(){var r=this;return i.createElement("label",{htmlFor:this.id,className:[u.cls(),this.props.className].filter(Boolean).join(" "),style:this.props.style},this.genArr().map(function(e,t){return i.createElement("div",{className:u.cls("char"),key:t},e.value)}),i.createElement("input",{id:this.id,className:u.cls("input"),type:this.props.inputType||"number",value:this.props.value||"",onChange:function(e){var t,n=r.length;e.target.value.length>n&&(e.target.value=e.target.value.slice(n)),e.target.value.length===n&&e.target.blur(),null!==(n=(t=r.props).onChange)&&void 0!==n&&n.call(t,e.target.value)}}))}}])&&c(e.prototype,t),n&&c(e,n),u}();return s(e,"cls",function(e){return["react-mobile-code-input",e].filter(Boolean).join("__")}),e});