summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-core/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-core/src/components')
-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;