UNPKG

@mornya/react-social-libs

Version:

The project of React.js Social Share and Widget modules.

92 lines (91 loc) 4.2 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import React from 'react'; import { CopyToClipboard } from 'react-copy-to-clipboard'; import { BaseShareComponent } from '../utils/BaseShareComponent'; var Clipboard = (function (_super) { __extends(Clipboard, _super); function Clipboard() { var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this; _this.onCopyClipboard = function (text, result) { if (result) { _this.onComplete(result, text); } else { _this.onError('SHARE_CLIPBOARD_ERROR'); } }; _this.renderShareButton = function (_a) { var _b, _c, _d; var id = _a.id, label = _a.label, className = _a.className, style = _a.style; if (!((_b = _this.state.extra) === null || _b === void 0 ? void 0 : _b.message) || !_this.state.OG) { return null; } var text = _this.state.extra.message(_this.state.OG); if ((_d = (_c = _this.state.extra).title) === null || _d === void 0 ? void 0 : _d.call(_c, _this.state.OG)) { text += _this.getHashtag(_this.state.extra.hashtags, '\n') + '\n\n' + _this.state.OG.url; } return (React.createElement(CopyToClipboard, { text: text, onCopy: _this.onCopyClipboard }, React.createElement("button", { id: id, type: "button", title: label, "aria-label": label, className: className, style: style }, React.createElement("span", { className: "share-default-button x128", style: { width: _this.props.defaultIconSize, height: _this.props.defaultIconSize, } }, React.createElement("span", { className: _this.shareId, style: { transform: _this.state.defaultIconScale >= 1.0 ? undefined : "scale(".concat(_this.state.defaultIconScale, ")"), top: _this.state.defaultIconPos, left: _this.state.defaultIconPos, } }))))); }; return _this; } Clipboard.prototype.onInit = function () { this.initialize('Clipboard', { title: function (OG) { return "[".concat(OG.title, "]"); }, message: function (OG) { return OG.description; }, }); }; Clipboard.prototype.onMount = function (_extra) { this.setApiStep(); }; return Clipboard; }(BaseShareComponent)); export default Clipboard;