aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui/Link.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ui/Link.js')
-rw-r--r--src/components/ui/Link.js86
1 files changed, 0 insertions, 86 deletions
diff --git a/src/components/ui/Link.js b/src/components/ui/Link.js
deleted file mode 100644
index 714fc5a68..000000000
--- a/src/components/ui/Link.js
+++ /dev/null
@@ -1,86 +0,0 @@
1import { Component } from 'react';
2import PropTypes from 'prop-types';
3import { inject, observer } from 'mobx-react';
4import { RouterStore } from '@superwf/mobx-react-router';
5import classnames from 'classnames';
6
7import { oneOrManyChildElements } from '../../prop-types';
8import matchRoute from '../../helpers/routing-helpers';
9import { openExternalUrl } from '../../helpers/url-helpers';
10
11// Should this file be converted into the coding style similar to './toggle/index.tsx'?
12// TODO: create container component for this component
13class Link extends Component {
14 onClick(e) {
15 if (this.props.disabled) {
16 e.preventDefault();
17 } else if (this.props.target === '_blank') {
18 e.preventDefault();
19 openExternalUrl(this.props.to, true);
20 }
21 // Note: if neither of the above, then let the other onClick handlers process it
22 }
23
24 render() {
25 const {
26 children,
27 stores,
28 to,
29 className,
30 activeClassName,
31 strictFilter,
32 style,
33 } = this.props;
34 const { router } = stores;
35
36 let filter = `${to}(*action)`;
37 if (strictFilter) {
38 filter = `${to}`;
39 }
40
41 const match = matchRoute(filter, router.location.pathname);
42
43 const linkClasses = classnames({
44 [`${className}`]: true,
45 [`${activeClassName}`]: match,
46 'is-disabled': this.props.disabled,
47 });
48
49 return (
50 <a
51 href={router.history.createHref(to)}
52 className={linkClasses}
53 style={style}
54 onClick={e => this.onClick(e)}
55 >
56 {children}
57 </a>
58 );
59 }
60}
61
62Link.propTypes = {
63 stores: PropTypes.shape({
64 router: PropTypes.instanceOf(RouterStore).isRequired,
65 }).isRequired,
66 children: PropTypes.oneOfType([oneOrManyChildElements, PropTypes.string])
67 .isRequired,
68 to: PropTypes.string.isRequired,
69 className: PropTypes.string,
70 activeClassName: PropTypes.string,
71 strictFilter: PropTypes.bool,
72 target: PropTypes.string,
73 style: PropTypes.object,
74 disabled: PropTypes.bool,
75};
76
77Link.defaultProps = {
78 className: '',
79 activeClassName: '',
80 strictFilter: false,
81 disabled: false,
82 target: '',
83 style: {},
84};
85
86export default inject('stores')(observer(Link));