fe-pilot
Version:
scanner in web, phonebook in web, autofill otp in web, share web, TextToSpeech in web, Voice Recognition in web, live location tracking in web, detect my location web, wakelock in web, color picker, WhatsappShare, SnapScanner, NetworkMonitor, View360
1 lines • 3.9 kB
JavaScript
var _excluded=["children","successCb","failureCb","loadingCb","successMsg","failureMsg"];function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import React from"react";import{handleSuccess,handleError,handleLoading}from"../services/handlerService";import Wrapper from"../Wrapper/Wrapper";var failureMsgDefault={unSupported:"WhatsappShare is not supporting in your device",error:""},isBrowserSupport=function(){return globalThis},whatsAppShare=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{},b=a.successCb,c=void 0===b?function(){}:b,d=a.failureCb,e=void 0===d?function(){}:d,f=a.loadingCb,g=void 0===f?function(){}:f,h=a.successMsg,i=void 0===h?"WhatsappShare details fetch Successfully!!":h,j=a.failureMsg,k=void 0===j?_objectSpread({},failureMsgDefault):j,l=a.mobile,m=a.msg,n=void 0===m?"":m,o=_objectSpread(_objectSpread({},failureMsgDefault),k);(function(){if(!isBrowserSupport())return handleError({msgType:"UN_SUPPORTED_FEATURE",msg:o.unSupported,failureCb:e});if(handleLoading({loadingCb:g}),!navigator.userAgent.match(/iPhone|Android/i))window.location.href="https://web.whatsapp.com/send?text=".concat(n,"&phone=").concat(l);else if(l)window.location.href="https://wa.me/".concat(l,"/?text=").concat(n),handleSuccess({msgType:"SUCCESSFUL",msg:i,successCb:c,data:n});else if(n)window.location.href="https://wa.me/?text=".concat(n),handleSuccess({msgType:"SUCCESSFUL",msg:i,successCb:c,data:n});else return handleError({msgType:"ERROR",msg:o.error||"Mandatory props are missing",failureCb:e});return!0})()};function WhatsAppShare(a){var b=a.children,c=a.successCb,d=a.failureCb,e=a.loadingCb,f=a.successMsg,g=a.failureMsg,h=_objectWithoutProperties(a,_excluded);return React.Children.map(b||"WhatsAppShare",function(a){return React.cloneElement("string"==typeof a?React.createElement("span",null,a):a,{onClick:function(){return whatsAppShare(_objectSpread({successCb:c,failureCb:d,loadingCb:e,successMsg:f,failureMsg:g},h))}})})}var WWhatsAppShare=Wrapper(WhatsAppShare,isBrowserSupport);export{whatsAppShare,WWhatsAppShare as WhatsAppShare};export default WWhatsAppShare;