summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-plugin-sharing/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-plugin-sharing/src/components')
-rw-r--r--packages/gitbook-plugin-sharing/src/components/ShareButton.js47
-rw-r--r--packages/gitbook-plugin-sharing/src/components/SharingButtons.js63
-rw-r--r--packages/gitbook-plugin-sharing/src/components/SiteButton.js29
3 files changed, 139 insertions, 0 deletions
diff --git a/packages/gitbook-plugin-sharing/src/components/ShareButton.js b/packages/gitbook-plugin-sharing/src/components/ShareButton.js
new file mode 100644
index 0000000..8983423
--- /dev/null
+++ b/packages/gitbook-plugin-sharing/src/components/ShareButton.js
@@ -0,0 +1,47 @@
+const GitBook = require('gitbook-core');
+const { React, Dropdown, Backdrop } = GitBook;
+
+const SITES = require('../SITES');
+
+// Share button with dropdown list of sites
+const ShareButton = React.createClass({
+ propTypes: {
+ siteIds: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
+ onShare: React.PropTypes.func.isRequired
+ },
+
+ getInitialState() {
+ return { open: false };
+ },
+
+ onToggle() {
+ const { open } = this.state;
+ this.setState({ open: !open });
+ },
+
+ render() {
+ const { siteIds, onShare } = this.props;
+ const { open } = this.state;
+
+ return (
+ <Dropdown.Container>
+ {open ? <Backdrop onClose={this.onToggle} /> : null}
+
+ <GitBook.Button onClick={this.onToggle}>
+ <GitBook.Icon id="share-alt" />
+ </GitBook.Button>
+
+ {open ? (
+ <Dropdown.Menu>
+ {siteIds.map((id) => (
+ <Dropdown.ItemLink onClick={() => onShare(SITES[id])} key={id}>
+ {SITES[id].label}
+ </Dropdown.ItemLink>
+ ))}
+ </Dropdown.Menu>) : null}
+ </Dropdown.Container>
+ );
+ }
+});
+
+module.exports = ShareButton;
diff --git a/packages/gitbook-plugin-sharing/src/components/SharingButtons.js b/packages/gitbook-plugin-sharing/src/components/SharingButtons.js
new file mode 100644
index 0000000..4f5ada9
--- /dev/null
+++ b/packages/gitbook-plugin-sharing/src/components/SharingButtons.js
@@ -0,0 +1,63 @@
+const GitBook = require('gitbook-core');
+const { React } = GitBook;
+
+const SITES = require('../SITES');
+const optionsShape = require('../shapes/options');
+const SiteButton = require('./SiteButton');
+const ShareButton = require('./ShareButton');
+
+/**
+ * Displays the group of sharing buttons
+ */
+const SharingButtons = React.createClass({
+ propTypes: {
+ options: optionsShape.isRequired,
+ page: GitBook.PropTypes.Page.isRequired
+ },
+
+ onShare(site) {
+ site.onShare(location.href, this.props.page.title);
+ },
+
+ render() {
+ const { options } = this.props;
+
+ // Highlighted sites
+ const mainButtons = SITES
+ .ALL
+ .filter(id => options[id])
+ .map(id => <SiteButton key={id} onShare={this.onShare} site={SITES[id]} />);
+
+ // Other sites
+ let shareButton = undefined;
+ if (options.all.length > 0) {
+ shareButton = (
+ <ShareButton siteIds={options.all}
+ onShare={this.onShare} />
+ );
+ }
+
+ return (
+ <GitBook.ButtonGroup>
+ { mainButtons }
+ { shareButton }
+ </GitBook.ButtonGroup>
+ );
+ }
+});
+
+function mapStateToProps(state) {
+ let options = state.config.getIn(['pluginsConfig', 'sharing']);
+ if (options) {
+ options = options.toJS();
+ } else {
+ options = { all: [] };
+ }
+
+ return {
+ page: state.page,
+ options
+ };
+}
+
+module.exports = GitBook.connect(SharingButtons, mapStateToProps);
diff --git a/packages/gitbook-plugin-sharing/src/components/SiteButton.js b/packages/gitbook-plugin-sharing/src/components/SiteButton.js
new file mode 100644
index 0000000..e03720d
--- /dev/null
+++ b/packages/gitbook-plugin-sharing/src/components/SiteButton.js
@@ -0,0 +1,29 @@
+const GitBook = require('gitbook-core');
+const { React } = GitBook;
+
+const siteShape = require('../shapes/site');
+
+// An individual site sharing button
+const SiteButton = React.createClass({
+ propTypes: {
+ site: siteShape.isRequired,
+ onShare: React.PropTypes.func.isRequired
+ },
+
+ onClick(e) {
+ e.preventDefault();
+ this.props.onShare(this.props.site);
+ },
+
+ render() {
+ const { site } = this.props;
+
+ return (
+ <GitBook.Button onClick={this.onClick}>
+ <GitBook.Icon id={site.icon}/>
+ </GitBook.Button>
+ );
+ }
+});
+
+module.exports = SiteButton;