telegram-login-button
Version:
React Telegram login button
111 lines (93 loc) • 4.54 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('prop-types'), require('react')) :
typeof define === 'function' && define.amd ? define(['prop-types', 'react'], factory) :
(global = global || self, global.telegramLoginButton = factory(global.PropTypes, global.React));
}(this, function (PropTypes, React) { 'use strict';
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;
var React__default = 'default' in React ? React['default'] : React;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var TelegramLoginButton = function TelegramLoginButton(_a) {
var wrapperProps = _a.wrapperProps,
dataAuthUrl = _a.dataAuthUrl,
_b = _a.usePic,
usePic = _b === void 0 ? false : _b,
botName = _a.botName,
className = _a.className,
_c = _a.buttonSize,
buttonSize = _c === void 0 ? 'large' : _c,
_dataOnauth = _a.dataOnauth,
cornerRadius = _a.cornerRadius,
_d = _a.requestAccess,
requestAccess = _d === void 0 ? true : _d;
var ref = React.useRef(null);
React.useEffect(function () {
if (ref.current === null) return;
if (typeof _dataOnauth === 'undefined' && typeof dataAuthUrl === 'undefined') {
throw new Error('One of this props should be defined: dataAuthUrl (redirect URL), dataOnauth (callback fn) should be defined.');
}
if (typeof _dataOnauth === 'function') {
window.TelegramLoginWidget = {
dataOnauth: function dataOnauth(user) {
return _dataOnauth(user);
}
};
}
var script = document.createElement('script');
script.src = 'https://telegram.org/js/telegram-widget.js?22';
script.setAttribute('data-telegram-login', botName);
script.setAttribute('data-size', buttonSize);
if (cornerRadius !== undefined) {
script.setAttribute('data-radius', cornerRadius.toString());
}
if (requestAccess) {
script.setAttribute('data-request-access', 'write');
}
script.setAttribute('data-userpic', usePic.toString());
if (typeof dataAuthUrl === 'string') {
script.setAttribute('data-auth-url', dataAuthUrl);
} else {
script.setAttribute('data-onauth', 'TelegramLoginWidget.dataOnauth(user)');
}
script.async = true;
ref.current.appendChild(script);
}, [botName, buttonSize, cornerRadius, _dataOnauth, requestAccess, usePic, ref, dataAuthUrl]);
return React__default.createElement("div", __assign({
ref: ref,
className: className
}, wrapperProps));
};
TelegramLoginButton.propTypes = {
botName: PropTypes.string.isRequired,
usePic: PropTypes.bool,
className: PropTypes.string,
cornerRadius: PropTypes.number,
requestAccess: PropTypes.bool,
wrapperProps: PropTypes.object,
dataOnauth: PropTypes.func,
dataAuthUrl: PropTypes.string,
buttonSize: PropTypes.oneOf(['large', 'medium', 'small'])
};
return TelegramLoginButton;
}));
//# sourceMappingURL=telegram-login-button.umd.development.js.map