summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/components/Link.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-09-25 19:05:35 +0200
committerSamy Pesse <samypesse@gmail.com>2016-09-25 19:05:35 +0200
commit7fa3e34f9fe433ee99f797c745ef0f54b5efd89a (patch)
tree4bbc39a59c853347cd5b68ec52544347cc11a408 /packages/gitbook-core/src/components/Link.js
parente46cd78f803891dfc8c304ea8ec4bc813ad16b5b (diff)
downloadgitbook-7fa3e34f9fe433ee99f797c745ef0f54b5efd89a.zip
gitbook-7fa3e34f9fe433ee99f797c745ef0f54b5efd89a.tar.gz
gitbook-7fa3e34f9fe433ee99f797c745ef0f54b5efd89a.tar.bz2
Mark article as active in summary
Diffstat (limited to 'packages/gitbook-core/src/components/Link.js')
-rw-r--r--packages/gitbook-core/src/components/Link.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/gitbook-core/src/components/Link.js b/packages/gitbook-core/src/components/Link.js
new file mode 100644
index 0000000..2f909de
--- /dev/null
+++ b/packages/gitbook-core/src/components/Link.js
@@ -0,0 +1,38 @@
+const React = require('react');
+const SummaryArticleShape = require('../shapes/SummaryArticle');
+
+const Link = React.createClass({
+ propTypes: {
+ children: React.PropTypes.node,
+ href: React.PropTypes.string,
+ to: React.PropTypes.oneOfType([
+ React.PropTypes.string,
+ SummaryArticleShape
+ ])
+ },
+
+ getHref() {
+ const { to, href } = this.props;
+
+ if (href) {
+ return href;
+ }
+
+ if (typeof to === 'string') {
+ return to;
+ }
+
+ if (typeof to.ref === 'string') {
+ // TODO: normalize url
+ return to.ref;
+ }
+ },
+
+ render() {
+ const { children, ...props } = this.props;
+ const href = this.getHref();
+ return <a href={href} {...props}>{children}</a>;
+ }
+});
+
+module.exports = Link;