diff --git a/.eslintrc b/.eslintrc index e509776..4263973 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,8 @@ }, "env": { "browser": true, - "es6": true + "es6": true, + "jest": true }, "plugins": [ "react" diff --git a/README.md b/README.md index d15f857..3f9d110 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ The component takes the following props. | `classNames` | string | Additional classnames for the component | | `searchText` | string | Initial search value of the input | | `placeholder` | string | placeholder for the search input | +| `disabled` | boolean | Disabling the search input | | `onChange` | _function_ | Callback function to invoke when the user press any key. The function should contain two parameters(value, event). | | `onEnter` | _function_ | Callback function to invoke when the user press enter after pressing few keys. The function should contain two parameters(value, event). | | `onSearchClick` | _function_ | Callback function to invoke when the user click the search button. The function should contain one parameter(value). | @@ -54,4 +55,4 @@ npm start ## License -MIT Licensed. Copyright (c) Farhad Yasir 2018. +MIT Licensed. Copyright (c) Farhad Yasir 2021. diff --git a/dist/index.min.js b/dist/index.min.js index 8e11805..9241546 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.ReactSearch=t(require("react")):e.ReactSearch=t(e.react)}(this,(function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(t,n){t.exports=e},function(e,t,n){e.exports=n(4)()},function(e,t,n){"use strict";const r=e=>Object.prototype.toString.call(e).slice(8,-1),o=e=>"Array"===r(e),a=e=>"Object"===r(e),i=e=>"String"===r(e),c=e=>"Number"===r(e)&&!Number.isNaN(e),u=e=>"Null"===r(e)||"Undefined"===r(e),s=e=>i(e)?""===e.trim():o(e)?0===e.length:a(e)?0===Object.keys(e).length:u(e);e.exports={isArray:o,isObject:a,isString:i,isDate:e=>"Date"===r(e),isRegExp:e=>"RegExp"===r(e),isFunction:e=>"Function"===r(e),isBoolean:e=>"Boolean"===r(e)||i(e)&&("true"===e||"false"===e),isNumber:c,isNull:u,isEmpty:s,isEmptyOrZero:e=>s(e)||c(e)&&0===e}},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),a=n(1),i=n.n(a),c=n(2),u=n.n(c);function s(e){return(s="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 l(e,t){for(var n=0;nObject.prototype.toString.call(e).slice(8,-1),o=e=>"Array"===r(e),a=e=>"Object"===r(e),c=e=>"String"===r(e),i=e=>"Number"===r(e)&&!Number.isNaN(e),l=e=>"Null"===r(e)||"Undefined"===r(e),u=e=>c(e)?""===e.trim():o(e)?0===e.length:a(e)?0===Object.keys(e).length:l(e);e.exports={isArray:o,isObject:a,isString:c,isDate:e=>"Date"===r(e),isRegExp:e=>"RegExp"===r(e),isFunction:e=>"Function"===r(e),isBoolean:e=>"Boolean"===r(e)||c(e)&&("true"===e||"false"===e),isNumber:i,isNull:l,isEmpty:u,isEmptyOrZero:e=>u(e)||i(e)&&0===e}},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),a=n(1),c=n.n(a),i=n(2),l=n.n(i);var u={border:"1px #ddd solid",display:"inline-flex",justifyContent:"space-between",height:35},s=function(e){return{height:33,width:33,outline:"none",backgroundColor:"white",cursor:e?"auto":"pointer",padding:5,boxSizing:"border-box",appearance:"none",border:"none",borderLeft:"1px #ddd solid"}},f={outline:"none",border:"none",fontSize:14,padding:10,flex:1,color:"#5a5a5a",fontWeight:100,height:33},p=function(){var e=Math.ceil(21);return o.a.createElement("svg",{version:"1.1",x:"0px",y:"0px",width:e,height:e,viewBox:"0 0 635 635",style:{fill:"#727272"}},o.a.createElement("g",null,o.a.createElement("path",{d:"M255.108,0C119.863,0,10.204,109.66,10.204,244.904c0,135.245,109.659,244.905,244.904,244.905 c52.006,0,100.238-16.223,139.883-43.854l185.205,185.176c1.671,1.672,4.379,1.672,5.964,0.115l34.892-34.891 c1.613-1.613,1.47-4.379-0.115-5.965L438.151,407.605c38.493-43.246,61.86-100.237,61.86-162.702 C500.012,109.66,390.353,0,255.108,0z M255.108,460.996c-119.34,0-216.092-96.752-216.092-216.092 c0-119.34,96.751-216.091,216.092-216.091s216.091,96.751,216.091,216.091C471.199,364.244,374.448,460.996,255.108,460.996z"})))},d=function(e){var t=e.classNames,n=e.searchText,a=e.placeholder,c=e.disabled,i=e.onChange,d=e.onEnter,b=e.onSearchClick,y=e.onBlur,h=function(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,o=!1,a=void 0;try{for(var c,i=e[Symbol.iterator]();!(r=(c=i.next()).done)&&(n.push(c.value),!t||n.length!==t);r=!0);}catch(e){o=!0,a=e}finally{try{r||null==i.return||i.return()}finally{if(o)throw a}}return n}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}(Object(r.useState)(n),2),g=h[0],m=h[1];Object(r.useEffect)((function(){m(n)}),[n,m]);var v=Object(r.useCallback)((function(e){m(e.target.value),l.a.isFunction(i)&&i(e.target.value,e)}),[i,m]),x=Object(r.useCallback)((function(e){(13===e.which||13===e.keyCode)&&l.a.isFunction(d)&&d(e.target.value,e)}),[d]),O=Object(r.useCallback)((function(){l.a.isFunction(b)&&b(g)}),[b]),j=Object(r.useCallback)((function(e){l.a.isFunction(y)&&y(e.target.value,e)}),[y]),S="react-search-field ".concat(t);return o.a.createElement("div",{className:S,style:u},o.a.createElement("input",{className:"react-search-field-input",style:f,onChange:v,onKeyPress:x,onBlur:j,placeholder:a,type:"text",value:g,disabled:c}),o.a.createElement("button",{className:"react-search-field-button",type:"button","aria-label":"search button",style:s(c),onClick:O,disabled:c},o.a.createElement(p,null)))};d.propTypes={classNames:c.a.string,searchText:c.a.string,placeholder:c.a.string,disabled:c.a.bool,onChange:c.a.func,onEnter:c.a.func,onSearchClick:c.a.func,onBlur:c.a.func},d.defaultProps={classNames:"",searchText:"",placeholder:"Search",disabled:!1,onChange:null,onEnter:null,onSearchClick:null,onBlur:null},t.default=d},function(e,t,n){"use strict";var r=n(5);function o(){}function a(){}a.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,a,c){if(c!==r){var i=new Error("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");throw i.name="Invariant Violation",i}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:a,resetWarningCache:o};return n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}])})); \ No newline at end of file diff --git a/docs/bundle.min.js b/docs/bundle.min.js index 85ae007..38b6fd6 100644 --- a/docs/bundle.min.js +++ b/docs/bundle.min.js @@ -1,2 +1,2 @@ /*! For license information please see bundle.min.js.LICENSE.txt */ -!function(e){var t={};function n(r){if(t[r])return t[r].exports;var a=t[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(r,a,function(t){return e[t]}.bind(null,a));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=312)}([function(e,t,n){"use strict";e.exports=n(10)},function(e,t,n){e.exports=n(16)()},function(e,t,n){"use strict";const r=e=>Object.prototype.toString.call(e).slice(8,-1),a=e=>"Array"===r(e),o=e=>"Object"===r(e),i=e=>"String"===r(e),l=e=>"Number"===r(e)&&!Number.isNaN(e),s=e=>"Null"===r(e)||"Undefined"===r(e),c=e=>i(e)?""===e.trim():a(e)?0===e.length:o(e)?0===Object.keys(e).length:s(e);e.exports={isArray:a,isObject:o,isString:i,isDate:e=>"Date"===r(e),isRegExp:e=>"RegExp"===r(e),isFunction:e=>"Function"===r(e),isBoolean:e=>"Boolean"===r(e)||i(e)&&("true"===e||"false"===e),isNumber:l,isNull:s,isEmpty:c,isEmptyOrZero:e=>c(e)||l(e)&&0===e}},function(e,t,n){var r=n(216);e.exports=function(e){for(var t=1;t=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}},function(e,t){function n(){return e.exports=n=Object.assign||function(e){for(var t=1;tx.length&&x.push(e)}function L(e,t,n){return null==e?0:function e(t,n,r,a){var l=typeof t;"undefined"!==l&&"boolean"!==l||(t=null);var s=!1;if(null===t)s=!0;else switch(l){case"string":case"number":s=!0;break;case"object":switch(t.$$typeof){case o:case i:s=!0}}if(s)return r(a,t,""===n?"."+P(t,0):n),1;if(s=0,n=""===n?".":n+":",Array.isArray(t))for(var c=0;cthis.eventPool.length&&this.eventPool.push(e)}function ue(e){e.eventPool=[],e.getPooled=de,e.release=_e}a(ce.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():"unknown"!=typeof e.returnValue&&(e.returnValue=!1),this.isDefaultPrevented=le)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():"unknown"!=typeof e.cancelBubble&&(e.cancelBubble=!0),this.isPropagationStopped=le)},persist:function(){this.isPersistent=le},isPersistent:se,destructor:function(){var e,t=this.constructor.Interface;for(e in t)this[e]=null;this.nativeEvent=this._targetInst=this.dispatchConfig=null,this.isPropagationStopped=this.isDefaultPrevented=se,this._dispatchInstances=this._dispatchListeners=null}}),ce.Interface={type:null,target:null,currentTarget:function(){return null},eventPhase:null,bubbles:null,cancelable:null,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:null,isTrusted:null},ce.extend=function(e){function t(){}function n(){return r.apply(this,arguments)}var r=this;t.prototype=r.prototype;var o=new t;return a(o,n.prototype),n.prototype=o,n.prototype.constructor=n,n.Interface=a({},r.Interface,e),n.extend=r.extend,ue(n),n},ue(ce);var pe=ce.extend({data:null}),me=ce.extend({data:null}),ge=[9,13,27,32],Ee=W&&"CompositionEvent"in window,fe=null;W&&"documentMode"in document&&(fe=document.documentMode);var be=W&&"TextEvent"in window&&!fe,Se=W&&(!Ee||fe&&8=fe),he=String.fromCharCode(32),Te={beforeInput:{phasedRegistrationNames:{bubbled:"onBeforeInput",captured:"onBeforeInputCapture"},dependencies:["compositionend","keypress","textInput","paste"]},compositionEnd:{phasedRegistrationNames:{bubbled:"onCompositionEnd",captured:"onCompositionEndCapture"},dependencies:"blur compositionend keydown keypress keyup mousedown".split(" ")},compositionStart:{phasedRegistrationNames:{bubbled:"onCompositionStart",captured:"onCompositionStartCapture"},dependencies:"blur compositionstart keydown keypress keyup mousedown".split(" ")},compositionUpdate:{phasedRegistrationNames:{bubbled:"onCompositionUpdate",captured:"onCompositionUpdateCapture"},dependencies:"blur compositionupdate keydown keypress keyup mousedown".split(" ")}},Ce=!1;function ve(e,t){switch(e){case"keyup":return-1!==ge.indexOf(t.keyCode);case"keydown":return 229!==t.keyCode;case"keypress":case"mousedown":case"blur":return!0;default:return!1}}function ye(e){return"object"==typeof(e=e.detail)&&"data"in e?e.data:null}var Ne=!1,Oe={eventTypes:Te,extractEvents:function(e,t,n,r){var a=void 0,o=void 0;if(Ee)e:{switch(e){case"compositionstart":a=Te.compositionStart;break e;case"compositionend":a=Te.compositionEnd;break e;case"compositionupdate":a=Te.compositionUpdate;break e}a=void 0}else Ne?ve(e,n)&&(a=Te.compositionEnd):"keydown"===e&&229===n.keyCode&&(a=Te.compositionStart);return a?(Se&&"ko"!==n.locale&&(Ne||a!==Te.compositionStart?a===Te.compositionEnd&&Ne&&(o=ie()):(ae="value"in(re=r)?re.value:re.textContent,Ne=!0)),a=pe.getPooled(a,t,n,r),o?a.data=o:null!==(o=ye(n))&&(a.data=o),q(a),o=a):o=null,(e=be?function(e,t){switch(e){case"compositionend":return ye(t);case"keypress":return 32!==t.which?null:(Ce=!0,he);case"textInput":return(e=t.data)===he&&Ce?null:e;default:return null}}(e,n):function(e,t){if(Ne)return"compositionend"===e||!Ee&&ve(e,t)?(e=ie(),oe=ae=re=null,Ne=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1