UNPKG

react-whatsapp-button

Version:

A simple react component to show a Whatsapp floating button.

15 lines (14 loc) 17.6 kB
"use strict";var e,t=require("react"),r={exports:{}},n={exports:{}},o={};var a,i,c,u,s,f,p,l,y,d,m,b,v,h,g={}; /** @license React v16.13.1 * react-is.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */function w(){return i||(i=1,function(t){"production"===process.env.NODE_ENV?t.exports=function(){if(e)return o;e=1;var t="function"==typeof Symbol&&Symbol.for,r=t?Symbol.for("react.element"):60103,n=t?Symbol.for("react.portal"):60106,a=t?Symbol.for("react.fragment"):60107,i=t?Symbol.for("react.strict_mode"):60108,c=t?Symbol.for("react.profiler"):60114,u=t?Symbol.for("react.provider"):60109,s=t?Symbol.for("react.context"):60110,f=t?Symbol.for("react.async_mode"):60111,p=t?Symbol.for("react.concurrent_mode"):60111,l=t?Symbol.for("react.forward_ref"):60112,y=t?Symbol.for("react.suspense"):60113,d=t?Symbol.for("react.suspense_list"):60120,m=t?Symbol.for("react.memo"):60115,b=t?Symbol.for("react.lazy"):60116,v=t?Symbol.for("react.block"):60121,h=t?Symbol.for("react.fundamental"):60117,g=t?Symbol.for("react.responder"):60118,w=t?Symbol.for("react.scope"):60119;function x(e){if("object"==typeof e&&null!==e){var t=e.$$typeof;switch(t){case r:switch(e=e.type){case f:case p:case a:case c:case i:case y:return e;default:switch(e=e&&e.$$typeof){case s:case l:case b:case m:case u:return e;default:return t}}case n:return t}}}function S(e){return x(e)===p}return o.AsyncMode=f,o.ConcurrentMode=p,o.ContextConsumer=s,o.ContextProvider=u,o.Element=r,o.ForwardRef=l,o.Fragment=a,o.Lazy=b,o.Memo=m,o.Portal=n,o.Profiler=c,o.StrictMode=i,o.Suspense=y,o.isAsyncMode=function(e){return S(e)||x(e)===f},o.isConcurrentMode=S,o.isContextConsumer=function(e){return x(e)===s},o.isContextProvider=function(e){return x(e)===u},o.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===r},o.isForwardRef=function(e){return x(e)===l},o.isFragment=function(e){return x(e)===a},o.isLazy=function(e){return x(e)===b},o.isMemo=function(e){return x(e)===m},o.isPortal=function(e){return x(e)===n},o.isProfiler=function(e){return x(e)===c},o.isStrictMode=function(e){return x(e)===i},o.isSuspense=function(e){return x(e)===y},o.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===a||e===p||e===c||e===i||e===y||e===d||"object"==typeof e&&null!==e&&(e.$$typeof===b||e.$$typeof===m||e.$$typeof===u||e.$$typeof===s||e.$$typeof===l||e.$$typeof===h||e.$$typeof===g||e.$$typeof===w||e.$$typeof===v)},o.typeOf=x,o}():t.exports=(a||(a=1,"production"!==process.env.NODE_ENV&&function(){var e="function"==typeof Symbol&&Symbol.for,t=e?Symbol.for("react.element"):60103,r=e?Symbol.for("react.portal"):60106,n=e?Symbol.for("react.fragment"):60107,o=e?Symbol.for("react.strict_mode"):60108,a=e?Symbol.for("react.profiler"):60114,i=e?Symbol.for("react.provider"):60109,c=e?Symbol.for("react.context"):60110,u=e?Symbol.for("react.async_mode"):60111,s=e?Symbol.for("react.concurrent_mode"):60111,f=e?Symbol.for("react.forward_ref"):60112,p=e?Symbol.for("react.suspense"):60113,l=e?Symbol.for("react.suspense_list"):60120,y=e?Symbol.for("react.memo"):60115,d=e?Symbol.for("react.lazy"):60116,m=e?Symbol.for("react.block"):60121,b=e?Symbol.for("react.fundamental"):60117,v=e?Symbol.for("react.responder"):60118,h=e?Symbol.for("react.scope"):60119;function w(e){if("object"==typeof e&&null!==e){var l=e.$$typeof;switch(l){case t:var m=e.type;switch(m){case u:case s:case n:case a:case o:case p:return m;default:var b=m&&m.$$typeof;switch(b){case c:case f:case d:case y:case i:return b;default:return l}}case r:return l}}}var x=u,S=s,O=c,E=i,$=t,j=f,T=n,_=d,P=y,C=r,N=a,k=o,I=p,R=!1;function A(e){return w(e)===s}g.AsyncMode=x,g.ConcurrentMode=S,g.ContextConsumer=O,g.ContextProvider=E,g.Element=$,g.ForwardRef=j,g.Fragment=T,g.Lazy=_,g.Memo=P,g.Portal=C,g.Profiler=N,g.StrictMode=k,g.Suspense=I,g.isAsyncMode=function(e){return R||(R=!0,console.warn("The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),A(e)||w(e)===u},g.isConcurrentMode=A,g.isContextConsumer=function(e){return w(e)===c},g.isContextProvider=function(e){return w(e)===i},g.isElement=function(e){return"object"==typeof e&&null!==e&&e.$$typeof===t},g.isForwardRef=function(e){return w(e)===f},g.isFragment=function(e){return w(e)===n},g.isLazy=function(e){return w(e)===d},g.isMemo=function(e){return w(e)===y},g.isPortal=function(e){return w(e)===r},g.isProfiler=function(e){return w(e)===a},g.isStrictMode=function(e){return w(e)===o},g.isSuspense=function(e){return w(e)===p},g.isValidElementType=function(e){return"string"==typeof e||"function"==typeof e||e===n||e===s||e===a||e===o||e===p||e===l||"object"==typeof e&&null!==e&&(e.$$typeof===d||e.$$typeof===y||e.$$typeof===i||e.$$typeof===c||e.$$typeof===f||e.$$typeof===b||e.$$typeof===v||e.$$typeof===h||e.$$typeof===m)},g.typeOf=w}()),g)}(n)),n.exports} /* object-assign (c) Sindre Sorhus @license MIT */function x(){if(f)return s;f=1;return s="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"}function S(){return l?p:(l=1,p=Function.call.bind(Object.prototype.hasOwnProperty))}if("production"!==process.env.NODE_ENV){var O=w();r.exports=function(){if(b)return m;b=1;var e=w(),t=function(){if(u)return c;u=1;var e=Object.getOwnPropertySymbols,t=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable;function n(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}return c=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach((function(e){n[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}()?Object.assign:function(o,a){for(var i,c,u=n(o),s=1;s<arguments.length;s++){for(var f in i=Object(arguments[s]))t.call(i,f)&&(u[f]=i[f]);if(e){c=e(i);for(var p=0;p<c.length;p++)r.call(i,c[p])&&(u[c[p]]=i[c[p]])}}return u},c}(),r=x(),n=S(),o=function(){if(d)return y;d=1;var e=function(){};if("production"!==process.env.NODE_ENV){var t=x(),r={},n=S();e=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}}function o(o,a,i,c,u){if("production"!==process.env.NODE_ENV)for(var s in o)if(n(o,s)){var f;try{if("function"!=typeof o[s]){var p=Error((c||"React class")+": "+i+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw p.name="Invariant Violation",p}f=o[s](a,s,c,i,null,t)}catch(e){f=e}if(!f||f instanceof Error||e((c||"React class")+": type specification of "+i+" `"+s+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof f+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),f instanceof Error&&!(f.message in r)){r[f.message]=!0;var l=u?u():"";e("Failed "+i+" type: "+f.message+(null!=l?l:""))}}}return o.resetWarningCache=function(){"production"!==process.env.NODE_ENV&&(r={})},y=o}(),a=function(){};function i(){return null}return"production"!==process.env.NODE_ENV&&(a=function(e){var t="Warning: "+e;"undefined"!=typeof console&&console.error(t);try{throw new Error(t)}catch(e){}}),m=function(c,u){var s="function"==typeof Symbol&&Symbol.iterator,f="<<anonymous>>",p={array:m("array"),bigint:m("bigint"),bool:m("boolean"),func:m("function"),number:m("number"),object:m("object"),string:m("string"),symbol:m("symbol"),any:d(i),arrayOf:function(e){return d((function(t,n,o,a,i){if("function"!=typeof e)return new y("Property `"+i+"` of component `"+o+"` has invalid PropType notation inside arrayOf.");var c=t[n];if(!Array.isArray(c))return new y("Invalid "+a+" `"+i+"` of type `"+h(c)+"` supplied to `"+o+"`, expected an array.");for(var u=0;u<c.length;u++){var s=e(c,u,o,a,i+"["+u+"]",r);if(s instanceof Error)return s}return null}))},element:d((function(e,t,r,n,o){var a=e[t];return c(a)?null:new y("Invalid "+n+" `"+o+"` of type `"+h(a)+"` supplied to `"+r+"`, expected a single ReactElement.")})),elementType:d((function(t,r,n,o,a){var i=t[r];return e.isValidElementType(i)?null:new y("Invalid "+o+" `"+a+"` of type `"+h(i)+"` supplied to `"+n+"`, expected a single ReactElement type.")})),instanceOf:function(e){return d((function(t,r,n,o,a){if(!(t[r]instanceof e)){var i=e.name||f;return new y("Invalid "+o+" `"+a+"` of type `"+((c=t[r]).constructor&&c.constructor.name?c.constructor.name:f)+"` supplied to `"+n+"`, expected instance of `"+i+"`.")}var c;return null}))},node:d((function(e,t,r,n,o){return v(e[t])?null:new y("Invalid "+n+" `"+o+"` supplied to `"+r+"`, expected a ReactNode.")})),objectOf:function(e){return d((function(t,o,a,i,c){if("function"!=typeof e)return new y("Property `"+c+"` of component `"+a+"` has invalid PropType notation inside objectOf.");var u=t[o],s=h(u);if("object"!==s)return new y("Invalid "+i+" `"+c+"` of type `"+s+"` supplied to `"+a+"`, expected an object.");for(var f in u)if(n(u,f)){var p=e(u,f,a,i,c+"."+f,r);if(p instanceof Error)return p}return null}))},oneOf:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&a(arguments.length>1?"Invalid arguments supplied to oneOf, expected an array, got "+arguments.length+" arguments. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).":"Invalid argument supplied to oneOf, expected an array."),i;function t(t,r,n,o,a){for(var i=t[r],c=0;c<e.length;c++)if(l(i,e[c]))return null;var u=JSON.stringify(e,(function(e,t){return"symbol"===g(t)?String(t):t}));return new y("Invalid "+o+" `"+a+"` of value `"+String(i)+"` supplied to `"+n+"`, expected one of "+u+".")}return d(t)},oneOfType:function(e){if(!Array.isArray(e))return"production"!==process.env.NODE_ENV&&a("Invalid argument supplied to oneOfType, expected an instance of array."),i;for(var t=0;t<e.length;t++){var o=e[t];if("function"!=typeof o)return a("Invalid argument supplied to oneOfType. Expected an array of check functions, but received "+w(o)+" at index "+t+"."),i}return d((function(t,o,a,i,c){for(var u=[],s=0;s<e.length;s++){var f=(0,e[s])(t,o,a,i,c,r);if(null==f)return null;f.data&&n(f.data,"expectedType")&&u.push(f.data.expectedType)}return new y("Invalid "+i+" `"+c+"` supplied to `"+a+"`"+(u.length>0?", expected one of type ["+u.join(", ")+"]":"")+".")}))},shape:function(e){return d((function(t,n,o,a,i){var c=t[n],u=h(c);if("object"!==u)return new y("Invalid "+a+" `"+i+"` of type `"+u+"` supplied to `"+o+"`, expected `object`.");for(var s in e){var f=e[s];if("function"!=typeof f)return b(o,a,i,s,g(f));var p=f(c,s,o,a,i+"."+s,r);if(p)return p}return null}))},exact:function(e){return d((function(o,a,i,c,u){var s=o[a],f=h(s);if("object"!==f)return new y("Invalid "+c+" `"+u+"` of type `"+f+"` supplied to `"+i+"`, expected `object`.");var p=t({},o[a],e);for(var l in p){var d=e[l];if(n(e,l)&&"function"!=typeof d)return b(i,c,u,l,g(d));if(!d)return new y("Invalid "+c+" `"+u+"` key `"+l+"` supplied to `"+i+"`.\nBad object: "+JSON.stringify(o[a],null," ")+"\nValid keys: "+JSON.stringify(Object.keys(e),null," "));var m=d(s,l,i,c,u+"."+l,r);if(m)return m}return null}))}};function l(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function y(e,t){this.message=e,this.data=t&&"object"==typeof t?t:{},this.stack=""}function d(e){if("production"!==process.env.NODE_ENV)var t={},n=0;function o(o,i,c,s,p,l,d){if(s=s||f,l=l||c,d!==r){if(u){var m=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 m.name="Invariant Violation",m}if("production"!==process.env.NODE_ENV&&"undefined"!=typeof console){var b=s+":"+c;!t[b]&&n<3&&(a("You are manually calling a React.PropTypes validation function for the `"+l+"` prop on `"+s+"`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details."),t[b]=!0,n++)}}return null==i[c]?o?null===i[c]?new y("The "+p+" `"+l+"` is marked as required in `"+s+"`, but its value is `null`."):new y("The "+p+" `"+l+"` is marked as required in `"+s+"`, but its value is `undefined`."):null:e(i,c,s,p,l)}var i=o.bind(null,!1);return i.isRequired=o.bind(null,!0),i}function m(e){return d((function(t,r,n,o,a,i){var c=t[r];return h(c)!==e?new y("Invalid "+o+" `"+a+"` of type `"+g(c)+"` supplied to `"+n+"`, expected `"+e+"`.",{expectedType:e}):null}))}function b(e,t,r,n,o){return new y((e||"React class")+": "+t+" type `"+r+"."+n+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+o+"`.")}function v(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(v);if(null===e||c(e))return!0;var t=function(e){var t=e&&(s&&e[s]||e["@@iterator"]);if("function"==typeof t)return t}(e);if(!t)return!1;var r,n=t.call(e);if(t!==e.entries){for(;!(r=n.next()).done;)if(!v(r.value))return!1}else for(;!(r=n.next()).done;){var o=r.value;if(o&&!v(o[1]))return!1}return!0;default:return!1}}function h(e){var t=typeof e;return Array.isArray(e)?"array":e instanceof RegExp?"object":function(e,t){return"symbol"===e||!!t&&("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}(t,e)?"symbol":t}function g(e){if(null==e)return""+e;var t=h(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function w(e){var t=g(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}return y.prototype=Error.prototype,p.checkPropTypes=o,p.resetWarningCache=o.resetWarningCache,p.PropTypes=p,p},m}()(O.isElement,!0)}else r.exports=function(){if(h)return v;h=1;var e=x();function t(){}function r(){}return r.resetWarningCache=t,v=function(){function n(t,r,n,o,a,i){if(i!==e){var c=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 c.name="Invariant Violation",c}}function o(){return n}n.isRequired=n;var a={array:n,bigint:n,bool:n,func:n,number:n,object:n,string:n,symbol:n,any:n,arrayOf:o,element:n,elementType:n,instanceOf:o,node:n,objectOf:o,oneOf:o,oneOfType:o,shape:o,exact:o,checkPropTypes:r,resetWarningCache:t};return a.PropTypes=a,a}}()();!function(e,t){void 0===t&&(t={});var r=t.insertAt;if(e&&"undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===r&&n.firstChild?n.insertBefore(o,n.firstChild):n.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}('.btn-floating-whatsapp{align-items:center;background-color:#25d366;border-radius:50%;bottom:2rem;box-shadow:0 4px 10px 0 rgba(0,0,0,.15);cursor:pointer;display:flex;height:60px;justify-content:center;position:fixed;right:2rem;user-select:none;width:60px;z-index:9998}.btn-floating-whatsapp svg{height:70%;width:70%}.btn-floating-whatsapp__animated:before{animation:_pulse 1.2s infinite;border-color:inherit;border-radius:50%;box-shadow:0 0 0 0 rgba(37,211,101,0);content:"";height:60px;position:absolute;width:60px}@keyframes _pulse{0%{box-shadow:0 0 0 0 rgba(37,211,101,.75)}to{box-shadow:0 0 0 15px rgba(37,211,101,0)}}');const E=({phoneNumber:e,countryCode:r,message:n,callback:o,style:a,animated:i})=>{if(!e||!r)return null;let c=`https://api.whatsapp.com/send/?phone=${r}${e}&text=`;return n&&(c+=`&text=${encodeURI(n)}`),t.createElement("a",{onClick:()=>{"function"==typeof o&&o()},className:`btn-floating-whatsapp ${i&&"btn-floating-whatsapp__animated"}`,href:c,target:"_blank",style:a},t.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",fill:"none",viewBox:"0 0 24 24"},t.createElement("path",{fill:"#fff",d:"M19.05 4.91A9.816 9.816 0 0012.04 2c-5.46 0-9.91 4.45-9.91 9.91 0 1.75.46 3.45 1.32 4.95L2.05 22l5.25-1.38c1.45.79 3.08 1.21 4.74 1.21 5.46 0 9.91-4.45 9.91-9.91 0-2.65-1.03-5.14-2.9-7.01zm-7.01 15.24c-1.48 0-2.93-.4-4.2-1.15l-.3-.18-3.12.82.83-3.04-.2-.31a8.264 8.264 0 01-1.26-4.38c0-4.54 3.7-8.24 8.24-8.24 2.2 0 4.27.86 5.82 2.42a8.183 8.183 0 012.41 5.83c.02 4.54-3.68 8.23-8.22 8.23zm4.52-6.16c-.25-.12-1.47-.72-1.69-.81-.23-.08-.39-.12-.56.12-.17.25-.64.81-.78.97-.14.17-.29.19-.54.06-.25-.12-1.05-.39-1.99-1.23-.74-.66-1.23-1.47-1.38-1.72-.14-.25-.02-.38.11-.51.11-.11.25-.29.37-.43s.17-.25.25-.41c.08-.17.04-.31-.02-.43s-.56-1.34-.76-1.84c-.2-.48-.41-.42-.56-.43h-.48c-.17 0-.43.06-.66.31-.22.25-.86.85-.86 2.07 0 1.22.89 2.4 1.01 2.56.12.17 1.75 2.67 4.23 3.74.59.26 1.05.41 1.41.52.59.19 1.13.16 1.56.1.48-.07 1.47-.6 1.67-1.18.21-.58.21-1.07.14-1.18-.07-.11-.22-.16-.47-.28z"})))};E.propTypes={phoneNumber:r.exports.string.isRequired,countryCode:r.exports.string.isRequired,message:r.exports.string,callback:r.exports.func,style:r.exports.object,animated:r.exports.bool},module.exports=E;