@hackoregon/component-library
Version:
Official repo for Hack Oregon React component library
150 lines (115 loc) • 6.39 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _templateObject3() {
var data = _taggedTemplateLiteral(["\n margin-right: 0;\n display: flex;\n"]);
_templateObject3 = function _templateObject3() {
return data;
};
return data;
}
function _templateObject2() {
var data = _taggedTemplateLiteral(["\n margin-left: 0;\n display: flex;\n"]);
_templateObject2 = function _templateObject2() {
return data;
};
return data;
}
function _templateObject() {
var data = _taggedTemplateLiteral(["\n background: #eee;\n display: flex;\n justify-content: space-between;\n margin: -3em;\n margin-top: 2em;\n padding: 0 3em;\n @media (max-width: 640px) {\n margin: -3em -2em;\n margin-top: 2em;\n padding: 0;\n }\n"]);
_templateObject = function _templateObject() {
return data;
};
return data;
}
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
import React, { Component } from "react";
import PropTypes from "prop-types";
import copy from "copy-to-clipboard";
import { css } from "emotion";
import { get } from "lodash";
import window from "global/window";
import CivicStoryLink from "./CivicStoryLink";
import { ICONS } from "../styleConstants";
var MS_TO_SWITCH_TEXT = 3000;
var actionsClass = css(_templateObject());
var alignRight = css(_templateObject2());
var alignLeft = css(_templateObject3());
var StoryFooter = function (_Component) {
_inherits(StoryFooter, _Component);
function StoryFooter(props) {
var _this;
_classCallCheck(this, StoryFooter);
_this = _possibleConstructorReturn(this, _getPrototypeOf(StoryFooter).call(this, props));
_defineProperty(_assertThisInitialized(_this), "setToFalse", function () {
return _this.setState({
copied: false
});
});
_defineProperty(_assertThisInitialized(_this), "handleCopy", function () {
var slug = _this.props.slug;
copy("".concat(get(window, "location.origin", ""), "/cards/").concat(slug));
_this.switchState(MS_TO_SWITCH_TEXT);
_this.setState({
copied: true
});
});
_defineProperty(_assertThisInitialized(_this), "switchState", function (ms) {
return setTimeout(_this.setToFalse, ms);
});
_this.state = {
copied: false
};
return _this;
}
_createClass(StoryFooter, [{
key: "render",
value: function render() {
var _this$props = this.props,
slug = _this$props.slug,
source = _this$props.source;
var copied = this.state.copied;
var shareTxt = copied ? "Copied!" : "Share";
var shareIcon = copied ? ICONS.check : ICONS.link;
var isEmbedded = "".concat(get(window, "location.origin", ""), "/cards/").concat(slug, "/embed/") === get(window, "location.href", "");
var issue = "https://github.com/hackoregon/civic/issues/new?labels=type%3Astory-card&template=story-card-improve.md&title=[FEEDBACK] ".concat(slug);
return React.createElement("div", {
className: actionsClass
}, React.createElement("div", {
className: alignLeft
}, React.createElement(CivicStoryLink, {
link: source,
embed: isEmbedded,
route: source ? undefined : "/cards/".concat(slug),
icon: ICONS.info
}, "Source")), React.createElement("div", {
className: alignRight
}, React.createElement(CivicStoryLink, {
additionalClassName: alignRight,
link: issue,
embed: isEmbedded,
icon: ICONS.improve
}, "Improve"), React.createElement(CivicStoryLink, {
additionalClassName: alignRight,
action: this.handleCopy,
icon: shareIcon
}, shareTxt)));
}
}]);
return StoryFooter;
}(Component);
_defineProperty(StoryFooter, "defaultProps", {
slug: "some-card-id"
});
_defineProperty(StoryFooter, "propTypes", {
slug: PropTypes.string,
source: PropTypes.string
});
export { StoryFooter as default };