diff options
Diffstat (limited to 'src/components/ui/Link.js')
-rw-r--r-- | src/components/ui/Link.js | 86 |
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 @@ | |||
1 | import { Component } from 'react'; | ||
2 | import PropTypes from 'prop-types'; | ||
3 | import { inject, observer } from 'mobx-react'; | ||
4 | import { RouterStore } from '@superwf/mobx-react-router'; | ||
5 | import classnames from 'classnames'; | ||
6 | |||
7 | import { oneOrManyChildElements } from '../../prop-types'; | ||
8 | import matchRoute from '../../helpers/routing-helpers'; | ||
9 | import { 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 | ||
13 | class 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 | |||
62 | Link.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 | |||
77 | Link.defaultProps = { | ||
78 | className: '', | ||
79 | activeClassName: '', | ||
80 | strictFilter: false, | ||
81 | disabled: false, | ||
82 | target: '', | ||
83 | style: {}, | ||
84 | }; | ||
85 | |||
86 | export default inject('stores')(observer(Link)); | ||