reacttypingcalendar
Version:
Light Weight React Typing Calendar
1 lines • 6.85 kB
JavaScript
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=2)}([function(t,e){t.exports=require("prop-types")},function(t,e){t.exports=require("react")},function(t,e,n){"use strict";n.r(e),n.d(e,"BharatDesktopInputCalendar",(function(){return Y}));var r=n(1),o=n.n(r),a=n(0),u=n.n(a);function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function s(t){return function(t){if(Array.isArray(t))return c(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return c(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return c(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function p(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function l(t,e){return(l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=m(t);if(e){var o=m(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return y(this,n)}}function y(t,e){return!e||"object"!==i(e)&&"function"!=typeof e?d(t):e}function d(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function m(t){return(m=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function b(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var h=0,Y=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&l(t,e)}(u,t);var e,n,r,a=f(u);function u(t){var e;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u),b(d(e=a.call(this,t)),"VisibilityChange",(function(){0===h?e.setState({IndexPosition:0,InputValue:""},(function(){e.AccessInput.current.blur()})):e.setState({IndexPosition:h},(function(){e.SetPosition()}))})),b(d(e),"SetPosition",(function(){h=e.state.IndexPosition,e.AccessInput.current.setSelectionRange(e.state.IndexPosition,e.state.IndexPosition)})),b(d(e),"KeyDownEvent",(function(t){8===t.keyCode?e.setState({BackSpace:!0}):((!(t.keyCode>=48&&t.keyCode<=57&&32!==t.keyCode)||46===t.keyCode)&&t.preventDefault(),e.setState({BackSpace:!1}))})),b(d(e),"FocusOut",(function(){0===e.state.IndexPosition?e.setState({InputValue:""},(function(){e.props.OnFocusOut({Date:e.state.InputValue})})):e.props.OnFocusOut({Date:e.state.InputValue})})),b(d(e),"StartChange",(function(t){var n="Left"===e.props.FormatType,r=e.state.IndexPosition,o=e.state.FormatArray;e.state.BackSpace?(o[n?3===r||6===r?r-2:r-1:5===r||8===r?r-2:r-1]="",r<10&&(o[r]=e.state.StoreFormatArray[r])):(o[r]=t.target.value[r],9!==r&&(o[n?1===r||4===r?r+2:r+1:3===r||6===r?r+2:r+1]="")),e.setState({InputValue:o.join(""),IndexPosition:n?e.state.BackSpace?3===r||6===r?r-2:r-1:1===r||4===r?r+2:r+1:e.state.BackSpace?5===r||8===r?r-2:r-1:3===r||6===r?r+2:r+1},(function(){e.SetPosition(),e.props.OnChange(e.state.InputValue)}))})),e.AccessInput=o.a.createRef(),e.state={InputValue:e.props.InputValue,FormatArray:e.props.Format.split(""),StoreFormatArray:e.props.Format.split(""),IndexPosition:""!==e.props.InputValue?10:0,BackSpace:!1},e}return e=u,(n=[{key:"componentDidMount",value:function(){var t=this;this.setState({IndexPosition:""!==this.props.InputValue?10:0,FormatArray:""!==this.props.InputValue?this.props.InputValue.split(""):[""].concat(s(this.state.FormatArray)),StoreFormatArray:[""].concat(s(this.state.StoreFormatArray))},(function(){t.props.AutoFocus&&t.AccessInput.current.focus()})),window.onfocus=function(){t.VisibilityChange()}}},{key:"render",value:function(){var t=this;return o.a.createElement("input",{className:this.props.ParentClassName,id:this.props.ParentId,ref:this.AccessInput,placeholder:this.props.Placeholder,value:this.state.InputValue,onClick:this.SetPosition,onFocus:function(){t.setState({InputValue:t.state.FormatArray.join("")},(function(){t.SetPosition()}))},onBlur:this.FocusOut,onChange:this.StartChange,onKeyDown:function(e){return t.KeyDownEvent(e)},maxLength:10,disabled:this.props.Disabled})}}])&&p(e.prototype,n),r&&p(e,r),u}(r.Component);Y.defaultProps={Format:"YYY-MM-DD",FormatType:"Right",Disabled:!1,InputValue:"",AutoFocus:!0,ParentClassName:"",ParentId:"",OnChange:void 0,OnFocusOut:void 0,Placeholder:""},Y.propTypes={Format:u.a.oneOf(["D-MM-YYYY","D:MM:YYYY","D/MM/YYYY","d/mm/yyyy","d:mm/yyyy","d-mm-yyyy","M-DD-YYYY","M:DD:YYYY","M/DD/YYYY","m/dd/yyyy","m:dd:yyyy","m-dd-yyyy","YYY-DD-MM","YYY:DD:MM","YYY/DD/MM","yyy/dd/mm","yyy:dd:mm","yyy-dd-mm","YYY-MM-DD","YYY:MM:DD","YYY/MM/DD","yyy/mm/dd","yyy:mm/dd","yyy-mm-dd"]),FormatType:u.a.oneOf(["Left","Right"]),Disabled:u.a.bool,InputValue:u.a.string,AutoFocus:u.a.bool,ParentClassName:u.a.string,ParentId:u.a.string,OnFocusOut:u.a.func.isRequired,OnChange:u.a.func.isRequired,Placeholder:u.a.string}}]);