react-input-autosize
Advanced tools
Comparing version 1.2.0 to 2.0.0
module.exports = { | ||
extends: 'keystone-react', | ||
parser: 'babel-eslint', | ||
}; |
@@ -1,1 +0,1 @@ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.AutosizeInput=t()}}(function(){return function t(e,n,r){function i(s,a){if(!n[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var c=n[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(t,e,n){"use strict";function r(t){return t}function i(t,e,n){function i(t,e){var n=v.hasOwnProperty(e)?v[e]:null;j.hasOwnProperty(e)&&u("OVERRIDE_BASE"===n,"ReactClassInterface: You are attempting to override `%s` from your class specification. Ensure that your method names do not overlap with React methods.",e),t&&u("DEFINE_MANY"===n||"DEFINE_MANY_MERGED"===n,"ReactClassInterface: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",e)}function o(t,n){if(n){u("function"!=typeof n,"ReactClass: You're attempting to use a component class or function as a mixin. Instead, just use a regular object."),u(!e(n),"ReactClass: You're attempting to use a component as a mixin. Instead, just use a regular object.");var r=t.prototype,o=r.__reactAutoBindPairs;n.hasOwnProperty(p)&&g.mixins(t,n.mixins);for(var s in n)if(n.hasOwnProperty(s)&&s!==p){var a=n[s],c=r.hasOwnProperty(s);if(i(c,s),g.hasOwnProperty(s))g[s](t,a);else{var l=v.hasOwnProperty(s),y="function"==typeof a,h=y&&!l&&!c&&n.autobind!==!1;if(h)o.push(s,a),r[s]=a;else if(c){var m=v[s];u(l&&("DEFINE_MANY_MERGED"===m||"DEFINE_MANY"===m),"ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.",m,s),"DEFINE_MANY_MERGED"===m?r[s]=f(r[s],a):"DEFINE_MANY"===m&&(r[s]=d(r[s],a))}else r[s]=a}}}else;}function c(t,e){if(e)for(var n in e){var r=e[n];if(e.hasOwnProperty(n)){var i=n in g;u(!i,'ReactClass: You are attempting to define a reserved property, `%s`, that shouldn\'t be on the "statics" key. Define it as an instance property instead; it will still be accessible on the constructor.',n);var o=n in t;u(!o,"ReactClass: You are attempting to define `%s` on your component more than once. This conflict may be due to a mixin.",n),t[n]=r}}}function l(t,e){u(t&&e&&"object"==typeof t&&"object"==typeof e,"mergeIntoWithNoDuplicateKeys(): Cannot merge non-objects.");for(var n in e)e.hasOwnProperty(n)&&(u(void 0===t[n],"mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the same key: `%s`. This conflict may be due to a mixin; in particular, this may be caused by two getInitialState() or getDefaultProps() methods returning objects with clashing keys.",n),t[n]=e[n]);return t}function f(t,e){return function(){var n=t.apply(this,arguments),r=e.apply(this,arguments);if(null==n)return r;if(null==r)return n;var i={};return l(i,n),l(i,r),i}}function d(t,e){return function(){t.apply(this,arguments),e.apply(this,arguments)}}function y(t,e){var n=e.bind(t);return n}function h(t){for(var e=t.__reactAutoBindPairs,n=0;n<e.length;n+=2){var r=e[n],i=e[n+1];t[r]=y(t,i)}}function m(t){var e=r(function(t,r,i){this.__reactAutoBindPairs.length&&h(this),this.props=t,this.context=r,this.refs=a,this.updater=i||n,this.state=null;var o=this.getInitialState?this.getInitialState():null;u("object"==typeof o&&!Array.isArray(o),"%s.getInitialState(): must return an object or null",e.displayName||"ReactCompositeComponent"),this.state=o});e.prototype=new N,e.prototype.constructor=e,e.prototype.__reactAutoBindPairs=[],b.forEach(o.bind(null,e)),o(e,E),o(e,t),o(e,w),e.getDefaultProps&&(e.defaultProps=e.getDefaultProps()),u(e.prototype.render,"createClass(...): Class specification must implement a `render` method.");for(var i in v)e.prototype[i]||(e.prototype[i]=null);return e}var b=[],v={mixins:"DEFINE_MANY",statics:"DEFINE_MANY",propTypes:"DEFINE_MANY",contextTypes:"DEFINE_MANY",childContextTypes:"DEFINE_MANY",getDefaultProps:"DEFINE_MANY_MERGED",getInitialState:"DEFINE_MANY_MERGED",getChildContext:"DEFINE_MANY_MERGED",render:"DEFINE_ONCE",componentWillMount:"DEFINE_MANY",componentDidMount:"DEFINE_MANY",componentWillReceiveProps:"DEFINE_MANY",shouldComponentUpdate:"DEFINE_ONCE",componentWillUpdate:"DEFINE_MANY",componentDidUpdate:"DEFINE_MANY",componentWillUnmount:"DEFINE_MANY",updateComponent:"OVERRIDE_BASE"},g={displayName:function(t,e){t.displayName=e},mixins:function(t,e){if(e)for(var n=0;n<e.length;n++)o(t,e[n])},childContextTypes:function(t,e){t.childContextTypes=s({},t.childContextTypes,e)},contextTypes:function(t,e){t.contextTypes=s({},t.contextTypes,e)},getDefaultProps:function(t,e){t.getDefaultProps?t.getDefaultProps=f(t.getDefaultProps,e):t.getDefaultProps=e},propTypes:function(t,e){t.propTypes=s({},t.propTypes,e)},statics:function(t,e){c(t,e)},autobind:function(){}},E={componentDidMount:function(){this.__isMounted=!0}},w={componentWillUnmount:function(){this.__isMounted=!1}},j={replaceState:function(t,e){this.updater.enqueueReplaceState(this,t,e)},isMounted:function(){return!!this.__isMounted}},N=function(){};return s(N.prototype,t.prototype,j),m}var o,s=t("object-assign"),a=t("fbjs/lib/emptyObject"),u=t("fbjs/lib/invariant"),p="mixins";o={},e.exports=i},{"fbjs/lib/emptyObject":4,"fbjs/lib/invariant":5,"fbjs/lib/warning":6,"object-assign":7}],2:[function(t,e,n){"use strict";var r=t("react"),i=t("./factory");if("undefined"==typeof r)throw Error("create-react-class could not find the React object. If you are using script tags, make sure that React is being loaded before create-react-class.");var o=(new r.Component).updater;e.exports=i(r.Component,r.isValidElement,o)},{"./factory":1,react:void 0}],3:[function(t,e,n){"use strict";function r(t){return function(){return t}}var i=function(){};i.thatReturns=r,i.thatReturnsFalse=r(!1),i.thatReturnsTrue=r(!0),i.thatReturnsNull=r(null),i.thatReturnsThis=function(){return this},i.thatReturnsArgument=function(t){return t},e.exports=i},{}],4:[function(t,e,n){"use strict";var r={};e.exports=r},{}],5:[function(t,e,n){"use strict";function r(t,e,n,r,o,s,a,u){if(i(e),!t){var p;if(void 0===e)p=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,s,a,u],l=0;p=new Error(e.replace(/%s/g,function(){return c[l++]})),p.name="Invariant Violation"}throw p.framesToPop=1,p}}var i=function(t){};e.exports=r},{}],6:[function(t,e,n){"use strict";var r=t("./emptyFunction"),i=r;e.exports=i},{"./emptyFunction":3}],7:[function(t,e,n){"use strict";function r(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function i(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;var r=Object.getOwnPropertyNames(e).map(function(t){return e[t]});if("0123456789"!==r.join(""))return!1;var i={};return"abcdefghijklmnopqrst".split("").forEach(function(t){i[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},i)).join("")}catch(o){return!1}}var o=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;e.exports=i()?Object.assign:function(t,e){for(var n,i,u=r(t),p=1;p<arguments.length;p++){n=Object(arguments[p]);for(var c in n)s.call(n,c)&&(u[c]=n[c]);if(o){i=o(n);for(var l=0;l<i.length;l++)a.call(n,i[l])&&(u[i[l]]=n[i[l]])}}return u}},{}],8:[function(t,e,n){"use strict";function r(t,e,n,r,i){}e.exports=r},{"./lib/ReactPropTypesSecret":12,"fbjs/lib/invariant":5,"fbjs/lib/warning":6}],9:[function(t,e,n){"use strict";var r=t("fbjs/lib/emptyFunction"),i=t("fbjs/lib/invariant"),o=t("./lib/ReactPropTypesSecret");e.exports=function(){function t(t,e,n,r,s,a){a!==o&&i(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function e(){return t}t.isRequired=t;var n={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e};return n.checkPropTypes=r,n.PropTypes=n,n}},{"./lib/ReactPropTypesSecret":12,"fbjs/lib/emptyFunction":3,"fbjs/lib/invariant":5}],10:[function(t,e,n){"use strict";var r=t("fbjs/lib/emptyFunction"),i=t("fbjs/lib/invariant"),o=t("fbjs/lib/warning"),s=t("./lib/ReactPropTypesSecret"),a=t("./checkPropTypes");e.exports=function(t,e){function n(t){var e=t&&(S&&t[S]||t[T]);if("function"==typeof e)return e}function u(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e}function p(t){this.message=t,this.stack=""}function c(t){function n(n,r,o,a,u,c,l){if(a=a||_,c=c||o,l!==s)if(e)i(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use `PropTypes.checkPropTypes()` to call them. Read more at http://fb.me/use-check-prop-types");else;return null==r[o]?n?new p(null===r[o]?"The "+u+" `"+c+"` is marked as required "+("in `"+a+"`, but its value is `null`."):"The "+u+" `"+c+"` is marked as required in "+("`"+a+"`, but its value is `undefined`.")):null:t(r,o,a,u,c)}var r=n.bind(null,!1);return r.isRequired=n.bind(null,!0),r}function l(t){function e(e,n,r,i,o,s){var a=e[n],u=N(a);if(u!==t){var c=x(a);return new p("Invalid "+i+" `"+o+"` of type "+("`"+c+"` supplied to `"+r+"`, expected ")+("`"+t+"`."))}return null}return c(e)}function f(){return c(r.thatReturnsNull)}function d(t){function e(e,n,r,i,o){if("function"!=typeof t)return new p("Property `"+o+"` of component `"+r+"` has invalid PropType notation inside arrayOf.");var a=e[n];if(!Array.isArray(a)){var u=N(a);return new p("Invalid "+i+" `"+o+"` of type "+("`"+u+"` supplied to `"+r+"`, expected an array."))}for(var c=0;c<a.length;c++){var l=t(a,c,r,i,o+"["+c+"]",s);if(l instanceof Error)return l}return null}return c(e)}function y(){function e(e,n,r,i,o){var s=e[n];if(!t(s)){var a=N(s);return new p("Invalid "+i+" `"+o+"` of type "+("`"+a+"` supplied to `"+r+"`, expected a single ReactElement."))}return null}return c(e)}function h(t){function e(e,n,r,i,o){if(!(e[n]instanceof t)){var s=t.name||_,a=R(e[n]);return new p("Invalid "+i+" `"+o+"` of type "+("`"+a+"` supplied to `"+r+"`, expected ")+("instance of `"+s+"`."))}return null}return c(e)}function m(t){function e(e,n,r,i,o){for(var s=e[n],a=0;a<t.length;a++)if(u(s,t[a]))return null;var c=JSON.stringify(t);return new p("Invalid "+i+" `"+o+"` of value `"+s+"` "+("supplied to `"+r+"`, expected one of "+c+"."))}return Array.isArray(t)?c(e):r.thatReturnsNull}function b(t){function e(e,n,r,i,o){if("function"!=typeof t)return new p("Property `"+o+"` of component `"+r+"` has invalid PropType notation inside objectOf.");var a=e[n],u=N(a);if("object"!==u)return new p("Invalid "+i+" `"+o+"` of type "+("`"+u+"` supplied to `"+r+"`, expected an object."));for(var c in a)if(a.hasOwnProperty(c)){var l=t(a,c,r,i,o+"."+c,s);if(l instanceof Error)return l}return null}return c(e)}function v(t){function e(e,n,r,i,o){for(var a=0;a<t.length;a++){var u=t[a];if(null==u(e,n,r,i,o,s))return null}return new p("Invalid "+i+" `"+o+"` supplied to "+("`"+r+"`."))}if(!Array.isArray(t))return r.thatReturnsNull;for(var n=0;n<t.length;n++){var i=t[n];if("function"!=typeof i)return o(!1,"Invalid argument supplid to oneOfType. Expected an array of check functions, but received %s at index %s.",I(i),n),r.thatReturnsNull}return c(e)}function g(){function t(t,e,n,r,i){return w(t[e])?null:new p("Invalid "+r+" `"+i+"` supplied to "+("`"+n+"`, expected a ReactNode."))}return c(t)}function E(t){function e(e,n,r,i,o){var a=e[n],u=N(a);if("object"!==u)return new p("Invalid "+i+" `"+o+"` of type `"+u+"` "+("supplied to `"+r+"`, expected `object`."));for(var c in t){var l=t[c];if(l){var f=l(a,c,r,i,o+"."+c,s);if(f)return f}}return null}return c(e)}function w(e){switch(typeof e){case"number":case"string":case"undefined":return!0;case"boolean":return!e;case"object":if(Array.isArray(e))return e.every(w);if(null===e||t(e))return!0;var r=n(e);if(!r)return!1;var i,o=r.call(e);if(r!==e.entries){for(;!(i=o.next()).done;)if(!w(i.value))return!1}else for(;!(i=o.next()).done;){var s=i.value;if(s&&!w(s[1]))return!1}return!0;default:return!1}}function j(t,e){return"symbol"===t||("Symbol"===e["@@toStringTag"]||"function"==typeof Symbol&&e instanceof Symbol)}function N(t){var e=typeof t;return Array.isArray(t)?"array":t instanceof RegExp?"object":j(e,t)?"symbol":e}function x(t){if("undefined"==typeof t||null===t)return""+t;var e=N(t);if("object"===e){if(t instanceof Date)return"date";if(t instanceof RegExp)return"regexp"}return e}function I(t){var e=x(t);switch(e){case"array":case"object":return"an "+e;case"boolean":case"date":case"regexp":return"a "+e;default:return e}}function R(t){return t.constructor&&t.constructor.name?t.constructor.name:_}var S="function"==typeof Symbol&&Symbol.iterator,T="@@iterator",_="<<anonymous>>",O={array:l("array"),bool:l("boolean"),func:l("function"),number:l("number"),object:l("object"),string:l("string"),symbol:l("symbol"),any:f(),arrayOf:d,element:y(),instanceOf:h,node:g(),objectOf:b,oneOf:m,oneOfType:v,shape:E};return p.prototype=Error.prototype,O.checkPropTypes=a,O.PropTypes=O,O}},{"./checkPropTypes":8,"./lib/ReactPropTypesSecret":12,"fbjs/lib/emptyFunction":3,"fbjs/lib/invariant":5,"fbjs/lib/warning":6}],11:[function(t,e,n){e.exports=t("./factoryWithThrowingShims")()},{"./factoryWithThrowingShims":9,"./factoryWithTypeCheckers":10}],12:[function(t,e,n){"use strict";var r="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=r},{}],13:[function(t,e,n){(function(n){"use strict";var r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},i="undefined"!=typeof window?window.React:"undefined"!=typeof n?n.React:null,o=t("prop-types"),s=t("create-react-class"),a={position:"absolute",top:0,left:0,visibility:"hidden",height:0,overflow:"scroll",whiteSpace:"pre"},u=s({propTypes:{className:o.string,defaultValue:o.any,inputClassName:o.string,inputRef:o.func,inputStyle:o.object,minWidth:o.oneOfType([o.number,o.string]),onAutosize:o.func,onChange:o.func,placeholder:o.string,placeholderIsMinWidth:o.bool,style:o.object,value:o.any},getDefaultProps:function(){return{minWidth:1}},getInitialState:function(){return{inputWidth:this.props.minWidth,inputId:"_"+Math.random().toString(36).substr(2,12)}},componentDidMount:function(){this.mounted=!0,this.copyInputStyles(),this.updateInputWidth()},componentDidUpdate:function(t,e){e.inputWidth!==this.state.inputWidth&&"function"==typeof this.props.onAutosize&&this.props.onAutosize(this.state.inputWidth),this.updateInputWidth()},componentWillUnmount:function(){this.mounted=!1},inputRef:function(t){this.input=t,"function"==typeof this.props.inputRef&&this.props.inputRef(t)},placeHolderSizerRef:function(t){this.placeHolderSizer=t},sizerRef:function(t){this.sizer=t},copyInputStyles:function(){if(this.mounted&&window.getComputedStyle){var t=this.input&&window.getComputedStyle(this.input);if(t){var e=this.sizer;if(e.style.fontSize=t.fontSize,e.style.fontFamily=t.fontFamily,e.style.fontWeight=t.fontWeight,e.style.fontStyle=t.fontStyle,e.style.letterSpacing=t.letterSpacing,e.style.textTransform=t.textTransform,this.props.placeholder){var n=this.placeHolderSizer;n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.fontWeight=t.fontWeight,n.style.fontStyle=t.fontStyle,n.style.letterSpacing=t.letterSpacing,n.style.textTransform=t.textTransform}}}},updateInputWidth:function(){if(this.mounted&&this.sizer&&"undefined"!=typeof this.sizer.scrollWidth){var t=void 0;t=this.props.placeholder&&(!this.props.value||this.props.value&&this.props.placeholderIsMinWidth)?Math.max(this.sizer.scrollWidth,this.placeHolderSizer.scrollWidth)+2:this.sizer.scrollWidth+2,t<this.props.minWidth&&(t=this.props.minWidth),t!==this.state.inputWidth&&this.setState({inputWidth:t})}},getInput:function(){return this.input},focus:function(){this.input.focus()},blur:function(){this.input.blur()},select:function(){this.input.select()},render:function(){var t=[this.props.defaultValue,this.props.value,""].reduce(function(t,e){return null!==t&&void 0!==t?t:e}),e=this.props.style||{};e.display||(e.display="inline-block");var n=r({},this.props.inputStyle);n.width=this.state.inputWidth+"px",n.boxSizing="content-box";var o=r({},this.props);return o.className=this.props.inputClassName,o.style=n,delete o.inputClassName,delete o.inputStyle,delete o.minWidth,delete o.onAutosize,delete o.placeholderIsMinWidth,delete o.inputRef,i.createElement("div",{className:this.props.className,style:e},i.createElement("style",{dangerouslySetInnerHTML:{__html:["input#"+this.state.id+"::-ms-clear {display: none;}"].join("\n")}}),i.createElement("input",r({id:this.state.id},o,{ref:this.inputRef})),i.createElement("div",{ref:this.sizerRef,style:a},t),this.props.placeholder?i.createElement("div",{ref:this.placeHolderSizerRef,style:a},this.props.placeholder):null)}});e.exports=u}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"create-react-class":2,"prop-types":11}]},{},[13])(13)}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],e):t.AutosizeInput=e(t.React,t.PropTypes)}(this,function(t,e){"use strict";var n="default"in t?t.default:t;e=e&&e.hasOwnProperty("default")?e.default:e;!function(){function t(t){this.value=t}function e(e){function n(o,r){try{var s=e[o](r),u=s.value;u instanceof t?Promise.resolve(u.value).then(function(t){n("next",t)},function(t){n("throw",t)}):i(s.done?"return":"normal",s.value)}catch(t){i("throw",t)}}function i(t,e){switch(t){case"return":o.resolve({value:e,done:!0});break;case"throw":o.reject(e);break;default:o.resolve({value:e,done:!1})}(o=o.next)?n(o.key,o.arg):r=null}var o,r;this._invoke=function(t,e){return new Promise(function(i,s){var u={key:t,arg:e,resolve:i,reject:s,next:null};r?r=r.next=u:(o=r=u,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(t){return this._invoke("next",t)},e.prototype.throw=function(t){return this._invoke("throw",t)},e.prototype.return=function(t){return this._invoke("return",t)}}();var i=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},s=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},u=function(t,e){var n={};for(var i in t)e.indexOf(i)>=0||Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n},l=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},p={position:"absolute",top:0,left:0,visibility:"hidden",height:0,overflow:"scroll",whiteSpace:"pre"},a=function(t){function e(t){i(this,e);var n=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t));return n.inputRef=function(t){n.input=t,"function"==typeof n.props.inputRef&&n.props.inputRef(t)},n.placeHolderSizerRef=function(t){n.placeHolderSizer=t},n.sizerRef=function(t){n.sizer=t},n.state={inputWidth:t.minWidth,inputId:"_"+Math.random().toString(36).substr(2,12)},n}return s(e,t),o(e,[{key:"componentDidMount",value:function(){this.mounted=!0,this.copyInputStyles(),this.updateInputWidth()}},{key:"componentDidUpdate",value:function(t,e){e.inputWidth!==this.state.inputWidth&&"function"==typeof this.props.onAutosize&&this.props.onAutosize(this.state.inputWidth),this.updateInputWidth()}},{key:"componentWillUnmount",value:function(){this.mounted=!1}},{key:"copyInputStyles",value:function(){if(this.mounted&&window.getComputedStyle){var t=this.input&&window.getComputedStyle(this.input);if(t){var e=this.sizer;if(e.style.fontSize=t.fontSize,e.style.fontFamily=t.fontFamily,e.style.fontWeight=t.fontWeight,e.style.fontStyle=t.fontStyle,e.style.letterSpacing=t.letterSpacing,e.style.textTransform=t.textTransform,this.props.placeholder){var n=this.placeHolderSizer;n.style.fontSize=t.fontSize,n.style.fontFamily=t.fontFamily,n.style.fontWeight=t.fontWeight,n.style.fontStyle=t.fontStyle,n.style.letterSpacing=t.letterSpacing,n.style.textTransform=t.textTransform}}}}},{key:"updateInputWidth",value:function(){if(this.mounted&&this.sizer&&void 0!==this.sizer.scrollWidth){var t=void 0;(t=this.props.placeholder&&(!this.props.value||this.props.value&&this.props.placeholderIsMinWidth)?Math.max(this.sizer.scrollWidth,this.placeHolderSizer.scrollWidth)+2:this.sizer.scrollWidth+2)<this.props.minWidth&&(t=this.props.minWidth),t!==this.state.inputWidth&&this.setState({inputWidth:t})}}},{key:"getInput",value:function(){return this.input}},{key:"focus",value:function(){this.input.focus()}},{key:"blur",value:function(){this.input.blur()}},{key:"select",value:function(){this.input.select()}},{key:"render",value:function(){var t=[this.props.defaultValue,this.props.value,""].reduce(function(t,e){return null!==t&&void 0!==t?t:e}),e=r({},this.props.style);e.display||(e.display="inline-block");var i=r({},this.props.inputStyle);i.width=this.state.inputWidth+"px",i.boxSizing="content-box";var o=u(this.props,[]);return o.className=this.props.inputClassName,o.style=i,delete o.inputClassName,delete o.inputStyle,delete o.minWidth,delete o.onAutosize,delete o.placeholderIsMinWidth,delete o.inputRef,n.createElement("div",{className:this.props.className,style:e},n.createElement("style",{dangerouslySetInnerHTML:{__html:["input#"+this.state.id+"::-ms-clear {display: none;}"].join("\n")}}),n.createElement("input",r({id:this.state.id},o,{ref:this.inputRef})),n.createElement("div",{ref:this.sizerRef,style:p},t),this.props.placeholder?n.createElement("div",{ref:this.placeHolderSizerRef,style:p},this.props.placeholder):null)}}]),e}(t.Component);return a.propTypes={className:e.string,defaultValue:e.any,inputClassName:e.string,inputRef:e.func,inputStyle:e.object,minWidth:e.oneOfType([e.number,e.string]),onAutosize:e.func,onChange:e.func,placeholder:e.string,placeholderIsMinWidth:e.bool,style:e.object,value:e.any},a.defaultProps={minWidth:1},a}); |
# react-input-autosize | ||
## v2.0.0 / 2017-09-12 | ||
* fixed; converted to es6 Class and removed `create-react-class` | ||
* changed; default export is now an es6 module | ||
### Note: | ||
As of 2.0.0 this package exports an es6 module in the main entry | ||
(`/lib/AutoSizeInput.js`). If you are in an older environment, you'll need to | ||
refer to the `.default` export: | ||
```js | ||
var AutoSizeInput = require('react-input-autosize').default; | ||
``` | ||
Aside from this, the new version doesn't change any public API. | ||
## v1.2.0 / 2017-09-12 | ||
@@ -4,0 +21,0 @@ |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var React = require('react'); | ||
var PropTypes = require('prop-types'); | ||
var createClass = require('create-react-class'); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _propTypes = require('prop-types'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var sizerStyle = { | ||
@@ -19,157 +39,194 @@ position: 'absolute', | ||
var AutosizeInput = createClass({ | ||
propTypes: { | ||
className: PropTypes.string, // className for the outer element | ||
defaultValue: PropTypes.any, // default field value | ||
inputClassName: PropTypes.string, // className for the input element | ||
inputRef: PropTypes.func, // ref callback for the input element | ||
inputStyle: PropTypes.object, // css styles for the input element | ||
minWidth: PropTypes.oneOfType([// minimum width for input element | ||
PropTypes.number, PropTypes.string]), | ||
onAutosize: PropTypes.func, // onAutosize handler: function(newWidth) {} | ||
onChange: PropTypes.func, // onChange handler: function(newValue) {} | ||
placeholder: PropTypes.string, // placeholder text | ||
placeholderIsMinWidth: PropTypes.bool, // don't collapse size to less than the placeholder | ||
style: PropTypes.object, // css styles for the outer element | ||
value: PropTypes.any }, | ||
// field value | ||
getDefaultProps: function getDefaultProps() { | ||
return { | ||
minWidth: 1 | ||
var AutosizeInput = function (_Component) { | ||
_inherits(AutosizeInput, _Component); | ||
function AutosizeInput(props) { | ||
_classCallCheck(this, AutosizeInput); | ||
var _this = _possibleConstructorReturn(this, (AutosizeInput.__proto__ || Object.getPrototypeOf(AutosizeInput)).call(this, props)); | ||
_this.inputRef = function (el) { | ||
_this.input = el; | ||
if (typeof _this.props.inputRef === 'function') { | ||
_this.props.inputRef(el); | ||
} | ||
}; | ||
}, | ||
getInitialState: function getInitialState() { | ||
return { | ||
inputWidth: this.props.minWidth, | ||
_this.placeHolderSizerRef = function (el) { | ||
_this.placeHolderSizer = el; | ||
}; | ||
_this.sizerRef = function (el) { | ||
_this.sizer = el; | ||
}; | ||
_this.state = { | ||
inputWidth: props.minWidth, | ||
inputId: '_' + Math.random().toString(36).substr(2, 12) | ||
}; | ||
}, | ||
componentDidMount: function componentDidMount() { | ||
this.mounted = true; | ||
this.copyInputStyles(); | ||
this.updateInputWidth(); | ||
}, | ||
componentDidUpdate: function componentDidUpdate(prevProps, prevState) { | ||
if (prevState.inputWidth !== this.state.inputWidth) { | ||
if (typeof this.props.onAutosize === 'function') { | ||
this.props.onAutosize(this.state.inputWidth); | ||
return _this; | ||
} | ||
_createClass(AutosizeInput, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
this.mounted = true; | ||
this.copyInputStyles(); | ||
this.updateInputWidth(); | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate(prevProps, prevState) { | ||
if (prevState.inputWidth !== this.state.inputWidth) { | ||
if (typeof this.props.onAutosize === 'function') { | ||
this.props.onAutosize(this.state.inputWidth); | ||
} | ||
} | ||
this.updateInputWidth(); | ||
} | ||
this.updateInputWidth(); | ||
}, | ||
componentWillUnmount: function componentWillUnmount() { | ||
this.mounted = false; | ||
}, | ||
inputRef: function inputRef(el) { | ||
this.input = el; | ||
if (typeof this.props.inputRef === 'function') { | ||
this.props.inputRef(el); | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
this.mounted = false; | ||
} | ||
}, | ||
placeHolderSizerRef: function placeHolderSizerRef(el) { | ||
this.placeHolderSizer = el; | ||
}, | ||
sizerRef: function sizerRef(el) { | ||
this.sizer = el; | ||
}, | ||
copyInputStyles: function copyInputStyles() { | ||
if (!this.mounted || !window.getComputedStyle) { | ||
return; | ||
}, { | ||
key: 'copyInputStyles', | ||
value: function copyInputStyles() { | ||
if (!this.mounted || !window.getComputedStyle) { | ||
return; | ||
} | ||
var inputStyle = this.input && window.getComputedStyle(this.input); | ||
if (!inputStyle) { | ||
return; | ||
} | ||
var widthNode = this.sizer; | ||
widthNode.style.fontSize = inputStyle.fontSize; | ||
widthNode.style.fontFamily = inputStyle.fontFamily; | ||
widthNode.style.fontWeight = inputStyle.fontWeight; | ||
widthNode.style.fontStyle = inputStyle.fontStyle; | ||
widthNode.style.letterSpacing = inputStyle.letterSpacing; | ||
widthNode.style.textTransform = inputStyle.textTransform; | ||
if (this.props.placeholder) { | ||
var placeholderNode = this.placeHolderSizer; | ||
placeholderNode.style.fontSize = inputStyle.fontSize; | ||
placeholderNode.style.fontFamily = inputStyle.fontFamily; | ||
placeholderNode.style.fontWeight = inputStyle.fontWeight; | ||
placeholderNode.style.fontStyle = inputStyle.fontStyle; | ||
placeholderNode.style.letterSpacing = inputStyle.letterSpacing; | ||
placeholderNode.style.textTransform = inputStyle.textTransform; | ||
} | ||
} | ||
var inputStyle = this.input && window.getComputedStyle(this.input); | ||
if (!inputStyle) { | ||
return; | ||
}, { | ||
key: 'updateInputWidth', | ||
value: function updateInputWidth() { | ||
if (!this.mounted || !this.sizer || typeof this.sizer.scrollWidth === 'undefined') { | ||
return; | ||
} | ||
var newInputWidth = void 0; | ||
if (this.props.placeholder && (!this.props.value || this.props.value && this.props.placeholderIsMinWidth)) { | ||
newInputWidth = Math.max(this.sizer.scrollWidth, this.placeHolderSizer.scrollWidth) + 2; | ||
} else { | ||
newInputWidth = this.sizer.scrollWidth + 2; | ||
} | ||
if (newInputWidth < this.props.minWidth) { | ||
newInputWidth = this.props.minWidth; | ||
} | ||
if (newInputWidth !== this.state.inputWidth) { | ||
this.setState({ | ||
inputWidth: newInputWidth | ||
}); | ||
} | ||
} | ||
var widthNode = this.sizer; | ||
widthNode.style.fontSize = inputStyle.fontSize; | ||
widthNode.style.fontFamily = inputStyle.fontFamily; | ||
widthNode.style.fontWeight = inputStyle.fontWeight; | ||
widthNode.style.fontStyle = inputStyle.fontStyle; | ||
widthNode.style.letterSpacing = inputStyle.letterSpacing; | ||
widthNode.style.textTransform = inputStyle.textTransform; | ||
if (this.props.placeholder) { | ||
var placeholderNode = this.placeHolderSizer; | ||
placeholderNode.style.fontSize = inputStyle.fontSize; | ||
placeholderNode.style.fontFamily = inputStyle.fontFamily; | ||
placeholderNode.style.fontWeight = inputStyle.fontWeight; | ||
placeholderNode.style.fontStyle = inputStyle.fontStyle; | ||
placeholderNode.style.letterSpacing = inputStyle.letterSpacing; | ||
placeholderNode.style.textTransform = inputStyle.textTransform; | ||
}, { | ||
key: 'getInput', | ||
value: function getInput() { | ||
return this.input; | ||
} | ||
}, | ||
updateInputWidth: function updateInputWidth() { | ||
if (!this.mounted || !this.sizer || typeof this.sizer.scrollWidth === 'undefined') { | ||
return; | ||
}, { | ||
key: 'focus', | ||
value: function focus() { | ||
this.input.focus(); | ||
} | ||
var newInputWidth = undefined; | ||
if (this.props.placeholder && (!this.props.value || this.props.value && this.props.placeholderIsMinWidth)) { | ||
newInputWidth = Math.max(this.sizer.scrollWidth, this.placeHolderSizer.scrollWidth) + 2; | ||
} else { | ||
newInputWidth = this.sizer.scrollWidth + 2; | ||
}, { | ||
key: 'blur', | ||
value: function blur() { | ||
this.input.blur(); | ||
} | ||
if (newInputWidth < this.props.minWidth) { | ||
newInputWidth = this.props.minWidth; | ||
}, { | ||
key: 'select', | ||
value: function select() { | ||
this.input.select(); | ||
} | ||
if (newInputWidth !== this.state.inputWidth) { | ||
this.setState({ | ||
inputWidth: newInputWidth | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var sizerValue = [this.props.defaultValue, this.props.value, ''].reduce(function (previousValue, currentValue) { | ||
if (previousValue !== null && previousValue !== undefined) { | ||
return previousValue; | ||
} | ||
return currentValue; | ||
}); | ||
} | ||
}, | ||
getInput: function getInput() { | ||
return this.input; | ||
}, | ||
focus: function focus() { | ||
this.input.focus(); | ||
}, | ||
blur: function blur() { | ||
this.input.blur(); | ||
}, | ||
select: function select() { | ||
this.input.select(); | ||
}, | ||
render: function render() { | ||
var sizerValue = [this.props.defaultValue, this.props.value, ''].reduce(function (previousValue, currentValue) { | ||
if (previousValue !== null && previousValue !== undefined) { | ||
return previousValue; | ||
} | ||
return currentValue; | ||
}); | ||
var wrapperStyle = this.props.style || {}; | ||
if (!wrapperStyle.display) wrapperStyle.display = 'inline-block'; | ||
var inputStyle = _extends({}, this.props.inputStyle); | ||
inputStyle.width = this.state.inputWidth + 'px'; | ||
inputStyle.boxSizing = 'content-box'; | ||
var inputProps = _extends({}, this.props); | ||
inputProps.className = this.props.inputClassName; | ||
inputProps.style = inputStyle; | ||
// ensure props meant for `AutosizeInput` don't end up on the `input` | ||
delete inputProps.inputClassName; | ||
delete inputProps.inputStyle; | ||
delete inputProps.minWidth; | ||
delete inputProps.onAutosize; | ||
delete inputProps.placeholderIsMinWidth; | ||
delete inputProps.inputRef; | ||
return React.createElement( | ||
'div', | ||
{ className: this.props.className, style: wrapperStyle }, | ||
React.createElement('style', { dangerouslySetInnerHTML: { | ||
__html: ['input#' + this.state.id + '::-ms-clear {display: none;}'].join('\n') | ||
} }), | ||
React.createElement('input', _extends({ id: this.state.id }, inputProps, { ref: this.inputRef })), | ||
React.createElement( | ||
var wrapperStyle = _extends({}, this.props.style); | ||
if (!wrapperStyle.display) wrapperStyle.display = 'inline-block'; | ||
var inputStyle = _extends({}, this.props.inputStyle); | ||
inputStyle.width = this.state.inputWidth + 'px'; | ||
inputStyle.boxSizing = 'content-box'; | ||
var inputProps = _objectWithoutProperties(this.props, []); | ||
inputProps.className = this.props.inputClassName; | ||
inputProps.style = inputStyle; | ||
// ensure props meant for `AutosizeInput` don't end up on the `input` | ||
delete inputProps.inputClassName; | ||
delete inputProps.inputStyle; | ||
delete inputProps.minWidth; | ||
delete inputProps.onAutosize; | ||
delete inputProps.placeholderIsMinWidth; | ||
delete inputProps.inputRef; | ||
return _react2.default.createElement( | ||
'div', | ||
{ ref: this.sizerRef, style: sizerStyle }, | ||
sizerValue | ||
), | ||
this.props.placeholder ? React.createElement( | ||
'div', | ||
{ ref: this.placeHolderSizerRef, style: sizerStyle }, | ||
this.props.placeholder | ||
) : null | ||
); | ||
} | ||
}); | ||
{ className: this.props.className, style: wrapperStyle }, | ||
_react2.default.createElement('style', { dangerouslySetInnerHTML: { | ||
__html: ['input#' + this.state.id + '::-ms-clear {display: none;}'].join('\n') | ||
} }), | ||
_react2.default.createElement('input', _extends({ id: this.state.id }, inputProps, { ref: this.inputRef })), | ||
_react2.default.createElement( | ||
'div', | ||
{ ref: this.sizerRef, style: sizerStyle }, | ||
sizerValue | ||
), | ||
this.props.placeholder ? _react2.default.createElement( | ||
'div', | ||
{ ref: this.placeHolderSizerRef, style: sizerStyle }, | ||
this.props.placeholder | ||
) : null | ||
); | ||
} | ||
}]); | ||
module.exports = AutosizeInput; | ||
return AutosizeInput; | ||
}(_react.Component); | ||
; | ||
AutosizeInput.propTypes = { | ||
className: _propTypes2.default.string, // className for the outer element | ||
defaultValue: _propTypes2.default.any, // default field value | ||
inputClassName: _propTypes2.default.string, // className for the input element | ||
inputRef: _propTypes2.default.func, // ref callback for the input element | ||
inputStyle: _propTypes2.default.object, // css styles for the input element | ||
minWidth: _propTypes2.default.oneOfType([// minimum width for input element | ||
_propTypes2.default.number, _propTypes2.default.string]), | ||
onAutosize: _propTypes2.default.func, // onAutosize handler: function(newWidth) {} | ||
onChange: _propTypes2.default.func, // onChange handler: function(newValue) {} | ||
placeholder: _propTypes2.default.string, // placeholder text | ||
placeholderIsMinWidth: _propTypes2.default.bool, // don't collapse size to less than the placeholder | ||
style: _propTypes2.default.object, // css styles for the outer element | ||
value: _propTypes2.default.any // field value | ||
}; | ||
AutosizeInput.defaultProps = { | ||
minWidth: 1 | ||
}; | ||
exports.default = AutosizeInput; |
{ | ||
"name": "react-input-autosize", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Auto-resizing Input Component for React", | ||
"main": "lib/AutosizeInput.js", | ||
"js:next": "dist/react-input-autosize.es.js", | ||
"author": "Jed Watson", | ||
@@ -17,3 +18,12 @@ "license": "MIT", | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.0", | ||
"babel-eslint": "^7.2.3", | ||
"babel-jest": "^6.0.1", | ||
"babel-loader": "^7.1.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-2": "^6.24.1", | ||
"css-loader": "^0.28.7", | ||
"eslint": "^3.19.0", | ||
@@ -23,8 +33,21 @@ "eslint-config-keystone": "^3.0.0", | ||
"eslint-plugin-react": "^6.10.3", | ||
"gulp": "^3.9.0", | ||
"jest-cli": "^0.8.1", | ||
"extract-text-webpack-plugin": "^3.0.0", | ||
"html-loader": "^0.5.1", | ||
"html-webpack-plugin": "^2.30.1", | ||
"jest-cli": "^21.0.2", | ||
"less": "^2.3.1", | ||
"less-loader": "^4.0.5", | ||
"nps": "^5.7.1", | ||
"nps-utils": "^1.3.0", | ||
"react": "^15.0", | ||
"react-addons-test-utils": "^15.0", | ||
"react-component-gulp-tasks": "^0.7.6", | ||
"react-dom": "^15.0" | ||
"react-dom": "^15.0", | ||
"rollup": "^0.49.2", | ||
"rollup-plugin-babel": "^3.0.2", | ||
"rollup-plugin-commonjs": "^8.2.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-uglify": "^2.0.1", | ||
"style-loader": "^0.18.2", | ||
"uglify-es": "^3.0.28", | ||
"webpack": "^3.5.5", | ||
"webpack-dev-server": "^2.7.1" | ||
}, | ||
@@ -38,23 +61,15 @@ "peerDependencies": { | ||
"scripts": { | ||
"build": "gulp clean && NODE_ENV=production gulp build", | ||
"bump": "gulp bump", | ||
"bump:major": "gulp bump:major", | ||
"bump:minor": "gulp bump:minor", | ||
"examples": "gulp dev:server", | ||
"build": "nps build", | ||
"lint": "eslint ./; true", | ||
"publish:site": "NODE_ENV=production gulp publish:examples", | ||
"release": "NODE_ENV=production gulp release", | ||
"start": "gulp dev", | ||
"test": "jest; true", | ||
"watch": "gulp watch:lib" | ||
"publish:examples": "NODE_ENV=production nps publish", | ||
"start": "webpack-dev-server --progress", | ||
"test": "jest; true" | ||
}, | ||
"jest": { | ||
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest", | ||
"unmockedModulePathPatterns": [ | ||
"<rootDir>/node_modules/react", | ||
"<rootDir>/node_modules/fbjs", | ||
"<rootDir>/node_modules/react-dom", | ||
"<rootDir>/node_modules/react-addons-test-utils" | ||
"<rootDir>/node_modules/react-dom" | ||
], | ||
"testPathDirs": [ | ||
"roots": [ | ||
"<rootDir>/src" | ||
@@ -61,0 +76,0 @@ ] |
@@ -15,3 +15,3 @@ React-Input-Autosize | ||
npm install | ||
npm dev | ||
npm start | ||
``` | ||
@@ -39,3 +39,3 @@ | ||
```es6 | ||
var AutosizeInput = require('react-input-autosize'); | ||
import AutosizeInput from 'react-input-autosize'; | ||
@@ -42,0 +42,0 @@ <AutosizeInput |
@@ -1,4 +0,3 @@ | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const createClass = require('create-react-class'); | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
@@ -15,31 +14,10 @@ const sizerStyle = { | ||
const AutosizeInput = createClass({ | ||
propTypes: { | ||
className: PropTypes.string, // className for the outer element | ||
defaultValue: PropTypes.any, // default field value | ||
inputClassName: PropTypes.string, // className for the input element | ||
inputRef: PropTypes.func, // ref callback for the input element | ||
inputStyle: PropTypes.object, // css styles for the input element | ||
minWidth: PropTypes.oneOfType([ // minimum width for input element | ||
PropTypes.number, | ||
PropTypes.string, | ||
]), | ||
onAutosize: PropTypes.func, // onAutosize handler: function(newWidth) {} | ||
onChange: PropTypes.func, // onChange handler: function(newValue) {} | ||
placeholder: PropTypes.string, // placeholder text | ||
placeholderIsMinWidth: PropTypes.bool, // don't collapse size to less than the placeholder | ||
style: PropTypes.object, // css styles for the outer element | ||
value: PropTypes.any, // field value | ||
}, | ||
getDefaultProps () { | ||
return { | ||
minWidth: 1, | ||
}; | ||
}, | ||
getInitialState () { | ||
return { | ||
inputWidth: this.props.minWidth, | ||
class AutosizeInput extends Component { | ||
constructor (props) { | ||
super(props); | ||
this.state = { | ||
inputWidth: props.minWidth, | ||
inputId: '_' + Math.random().toString(36).substr(2, 12), | ||
}; | ||
}, | ||
} | ||
componentDidMount () { | ||
@@ -49,3 +27,3 @@ this.mounted = true; | ||
this.updateInputWidth(); | ||
}, | ||
} | ||
componentDidUpdate (prevProps, prevState) { | ||
@@ -58,7 +36,7 @@ if (prevState.inputWidth !== this.state.inputWidth) { | ||
this.updateInputWidth(); | ||
}, | ||
} | ||
componentWillUnmount () { | ||
this.mounted = false; | ||
}, | ||
inputRef (el) { | ||
} | ||
inputRef = (el) => { | ||
this.input = el; | ||
@@ -68,9 +46,9 @@ if (typeof this.props.inputRef === 'function') { | ||
} | ||
}, | ||
placeHolderSizerRef (el) { | ||
} | ||
placeHolderSizerRef = (el) => { | ||
this.placeHolderSizer = el; | ||
}, | ||
sizerRef (el) { | ||
} | ||
sizerRef = (el) => { | ||
this.sizer = el; | ||
}, | ||
} | ||
copyInputStyles () { | ||
@@ -100,3 +78,3 @@ if (!this.mounted || !window.getComputedStyle) { | ||
} | ||
}, | ||
} | ||
updateInputWidth () { | ||
@@ -120,17 +98,17 @@ if (!this.mounted || !this.sizer || typeof this.sizer.scrollWidth === 'undefined') { | ||
} | ||
}, | ||
} | ||
getInput () { | ||
return this.input; | ||
}, | ||
} | ||
focus () { | ||
this.input.focus(); | ||
}, | ||
} | ||
blur () { | ||
this.input.blur(); | ||
}, | ||
} | ||
select () { | ||
this.input.select(); | ||
}, | ||
} | ||
render () { | ||
const sizerValue = [this.props.defaultValue, this.props.value, ''].reduce(function (previousValue, currentValue) { | ||
const sizerValue = [this.props.defaultValue, this.props.value, ''].reduce((previousValue, currentValue) => { | ||
if (previousValue !== null && previousValue !== undefined) { | ||
@@ -142,8 +120,8 @@ return previousValue; | ||
const wrapperStyle = this.props.style || {}; | ||
const wrapperStyle = { ...this.props.style }; | ||
if (!wrapperStyle.display) wrapperStyle.display = 'inline-block'; | ||
const inputStyle = Object.assign({}, this.props.inputStyle); | ||
const inputStyle = { ...this.props.inputStyle }; | ||
inputStyle.width = this.state.inputWidth + 'px'; | ||
inputStyle.boxSizing = 'content-box'; | ||
const inputProps = Object.assign({}, this.props); | ||
const { ...inputProps } = this.props; | ||
inputProps.className = this.props.inputClassName; | ||
@@ -171,5 +149,26 @@ inputProps.style = inputStyle; | ||
); | ||
}, | ||
}); | ||
} | ||
}; | ||
module.exports = AutosizeInput; | ||
AutosizeInput.propTypes = { | ||
className: PropTypes.string, // className for the outer element | ||
defaultValue: PropTypes.any, // default field value | ||
inputClassName: PropTypes.string, // className for the input element | ||
inputRef: PropTypes.func, // ref callback for the input element | ||
inputStyle: PropTypes.object, // css styles for the input element | ||
minWidth: PropTypes.oneOfType([ // minimum width for input element | ||
PropTypes.number, | ||
PropTypes.string, | ||
]), | ||
onAutosize: PropTypes.func, // onAutosize handler: function(newWidth) {} | ||
onChange: PropTypes.func, // onChange handler: function(newValue) {} | ||
placeholder: PropTypes.string, // placeholder text | ||
placeholderIsMinWidth: PropTypes.bool, // don't collapse size to less than the placeholder | ||
style: PropTypes.object, // css styles for the outer element | ||
value: PropTypes.any, // field value | ||
}; | ||
AutosizeInput.defaultProps = { | ||
minWidth: 1, | ||
}; | ||
export default AutosizeInput; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1090038
30
23033
33
11
1