UNPKG

@iqmo/browser

Version:
3 lines (2 loc) 6.59 kB
import{c2 as h,c3 as T,cx as H,r as c,cV as z,cW as A,ao as B}from"./index-0xtYjrTa.js";import{g as C,a as _,b as D,B as I}from"./base-input-Dx4BUhOB.js";function w(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),r.push.apply(r,n)}return r}function l(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?w(Object(r),!0).forEach(function(n){N(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):w(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function N(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var m=h("div",function(e){return l(l({},C(l(l({$positive:!1},e),{},{$hasIconTrailing:!1}))),{},{width:e.$resize?"fit-content":"100%"})});m.displayName="StyledTextAreaRoot",m.displayName="StyledTextAreaRoot";var g=h("div",function(e){return _(l({$positive:!1},e))});g.displayName="StyledTextareaContainer",g.displayName="StyledTextareaContainer";var v=h("textarea",function(e){return l(l({},D(e)),{},{resize:e.$resize||"none"})});v.displayName="StyledTextarea",v.displayName="StyledTextarea";function O(e){"@babel/helpers - typeof";return O=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},O(e)}function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},f.apply(this,arguments)}function k(e,t){return M(e)||L(e,t)||K(e,t)||q()}function q(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function K(e,t){if(e){if(typeof e=="string")return S(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if(r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set")return Array.from(e);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return S(e,t)}}function S(e,t){(t==null||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function L(e,t){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var n=[],o=!0,a=!1,i,u;try{for(r=r.call(e);!(o=(i=r.next()).done)&&(n.push(i.value),!(t&&n.length===t));o=!0);}catch(s){a=!0,u=s}finally{try{!o&&r.return!=null&&r.return()}finally{if(a)throw u}}return n}}function M(e){if(Array.isArray(e))return e}function U(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function V(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function W(e,t,r){return t&&V(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function G(e,t){if(typeof t!="function"&&t!==null)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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&j(e,t)}function j(e,t){return j=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,n){return r.__proto__=n,r},j(e,t)}function J(e){var t=X();return function(){var r=y(e),n;if(t){var o=y(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Q(this,n)}}function Q(e,t){if(t&&(O(t)==="object"||typeof t=="function"))return t;if(t!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}function p(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function X(){if(typeof Reflect>"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function y(e){return y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},y(e)}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var x=function(e){G(r,e);var t=J(r);function r(){var n;U(this,r);for(var o=arguments.length,a=new Array(o),i=0;i<o;i++)a[i]=arguments[i];return n=t.call.apply(t,[this].concat(a)),b(p(n),"state",{isFocused:n.props.autoFocus||!1}),b(p(n),"onFocus",function(u){n.setState({isFocused:!0}),n.props.onFocus(u)}),b(p(n),"onBlur",function(u){n.setState({isFocused:!1}),n.props.onBlur(u)}),n}return W(r,[{key:"render",value:function(){var n=this.props.overrides,o=n===void 0?{}:n,a=T(o.Root,m),i=k(a,2),u=i[0],s=i[1],d=H({Input:{component:v},InputContainer:{component:g}},o);return c.createElement(u,f({"data-baseweb":"textarea",$isFocused:this.state.isFocused,$isReadOnly:this.props.readOnly,$disabled:this.props.disabled,$error:this.props.error,$positive:this.props.positive,$required:this.props.required,$resize:this.props.resize},s),c.createElement(I,f({},this.props,{type:A.textarea,overrides:d,onFocus:this.onFocus,onBlur:this.onBlur,resize:this.props.resize})))}}]),r}(c.Component);b(x,"defaultProps",{autoFocus:!1,disabled:!1,readOnly:!1,error:!1,name:"",onBlur:function(){},onChange:function(){},onKeyDown:function(){},onKeyPress:function(){},onKeyUp:function(){},onFocus:function(){},overrides:{},placeholder:"",required:!1,rows:3,size:z.default});const Y=6.5,P=1,Z=e=>{let t=0;const{current:r}=e;return r&&(r.style.height="auto",t=r.scrollHeight,r.style.height=""),t},ee=(e,t,r)=>e>0&&r.current?Math.abs(e-t)>P:!1,te=(e,t)=>{if(e.current&&t.current){const{offsetHeight:r}=e.current;t.current.minHeight=r,t.current.maxHeight=r*Y}},re=(e,t,r)=>e?`${t+P}px`:r?String(r):"",ne=e=>e?`${e}px`:"",oe=({textareaRef:e,dependencies:t=[]})=>{const r=B(),n=c.useRef({minHeight:0,maxHeight:0}),[o,a]=c.useState(0),[i,u]=c.useState(!1),s=c.useCallback(()=>{a(Z(e))},[e,a]);c.useLayoutEffect(()=>{e.current&&te(e,n)},[e]),c.useLayoutEffect(()=>{const{minHeight:R}=n.current;u(ee(o,R,e))},[o,e]),c.useLayoutEffect(()=>{s()},[e,s,...t]);const{maxHeight:d}=n.current,$=r.sizes.minElementHeight,E=re(i,o,$),F=ne(d);return{isExtended:i,height:E,maxHeight:F,updateScrollHeight:s}};export{x as T,oe as u};