UNPKG

telegram-login-button

Version:
108 lines (90 loc) 3.89 kB
'use strict'; function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var PropTypes = _interopDefault(require('prop-types')); var React = require('react'); var React__default = _interopDefault(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']) }; module.exports = TelegramLoginButton; //# sourceMappingURL=telegram-login-button.cjs.development.js.map