diff options
author | Fabio Berger <me@fabioberger.com> | 2018-03-03 13:07:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-03 13:07:00 +0800 |
commit | 4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3 (patch) | |
tree | 93f15ba9ad448d9390db38b76c601ac41e4f4eeb /packages/website/ts/pages/shared/markdown_link_block.tsx | |
parent | 4a57f2a762619932a882d08e62006e83a584a684 (diff) | |
parent | 212d680a477917817138790560d88d06cea5ec6f (diff) | |
download | dexon-sol-tools-4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3.tar dexon-sol-tools-4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3.tar.gz dexon-sol-tools-4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3.tar.bz2 dexon-sol-tools-4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3.tar.lz dexon-sol-tools-4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3.tar.xz dexon-sol-tools-4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3.tar.zst dexon-sol-tools-4dbb2ed167ff93cc5e5bb0daea5a272eef01baf3.zip |
Merge pull request #427 from 0xProject/fix/doc_bugs
Miscellaneous Doc Fixes
Diffstat (limited to 'packages/website/ts/pages/shared/markdown_link_block.tsx')
-rw-r--r-- | packages/website/ts/pages/shared/markdown_link_block.tsx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/website/ts/pages/shared/markdown_link_block.tsx b/packages/website/ts/pages/shared/markdown_link_block.tsx new file mode 100644 index 000000000..e4553c87f --- /dev/null +++ b/packages/website/ts/pages/shared/markdown_link_block.tsx @@ -0,0 +1,46 @@ +import * as _ from 'lodash'; +import * as React from 'react'; +import { configs } from 'ts/utils/configs'; +import { utils } from 'ts/utils/utils'; + +interface MarkdownLinkBlockProps { + href: string; +} + +interface MarkdownLinkBlockState {} + +export class MarkdownLinkBlock extends React.Component<MarkdownLinkBlockProps, MarkdownLinkBlockState> { + // Re-rendering a linkBlock causes it to remain unclickable. + // We therefore noop re-renders on this component if it's props haven't changed. + public shouldComponentUpdate(nextProps: MarkdownLinkBlockProps, nextState: MarkdownLinkBlockState) { + return nextProps.href !== this.props.href; + } + public render() { + const href = this.props.href; + const isLinkToSection = _.startsWith(href, '#'); + // If protocol is http or https, we can open in a new tab, otherwise don't for security reasons + if (_.startsWith(href, 'http') || _.startsWith(href, 'https')) { + return ( + <a href={href} target="_blank" rel="nofollow noreferrer noopener"> + {this.props.children} + </a> + ); + } else if (isLinkToSection) { + return ( + <a + style={{ cursor: 'pointer', textDecoration: 'underline' }} + onClick={this._onHashUrlClick.bind(this, href)} + > + {this.props.children} + </a> + ); + } else { + return <a href={href}>{this.props.children}</a>; + } + } + private _onHashUrlClick(href: string) { + const hash = href.split('#')[1]; + utils.scrollToHash(hash, configs.SCROLL_CONTAINER_ID); + utils.setUrlHash(hash); + } +} |