@comicrelief/component-library 5.3.0 → 5.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +1 -1
- package/dist/components/Atoms/Button/Button.js +3 -1
- package/dist/components/Atoms/Checkbox/Checkbox.js +5 -3
- package/dist/components/Atoms/ErrorText/ErrorText.js +3 -1
- package/dist/components/Atoms/Icons/Arrow.js +3 -1
- package/dist/components/Atoms/Icons/AtSign.js +2 -1
- package/dist/components/Atoms/Icons/Chevron.js +3 -1
- package/dist/components/Atoms/Icons/Download.js +3 -1
- package/dist/components/Atoms/Icons/External.js +3 -1
- package/dist/components/Atoms/Icons/Favourite.js +3 -1
- package/dist/components/Atoms/Icons/Internal.js +3 -1
- package/dist/components/Atoms/Input/Input.js +6 -4
- package/dist/components/Atoms/Label/Label.js +5 -2
- package/dist/components/Atoms/Link/Link.js +19 -5
- package/dist/components/Atoms/Link/Link.style.js +3 -3
- package/dist/components/Atoms/Pagination/Item/Item.js +3 -1
- package/dist/components/Atoms/Pagination/List/List.js +5 -3
- package/dist/components/Atoms/Pagination/Pagination.js +3 -1
- package/dist/components/Atoms/Picture/Picture.js +3 -1
- package/dist/components/Atoms/RadioButton/RadioButton.js +3 -1
- package/dist/components/Atoms/RichText/RichText.js +4 -2
- package/dist/components/Atoms/Select/Select.js +3 -1
- package/dist/components/Atoms/SocialIcons/Icon/Icon.js +6 -4
- package/dist/components/Atoms/SocialIcons/SocialIcons.js +5 -3
- package/dist/components/Atoms/Text/Text.js +3 -1
- package/dist/components/Atoms/TextArea/TextArea.js +3 -1
- package/dist/components/Atoms/TextInputWithDropdown/TextInputWithDropdown.js +5 -2
- package/dist/components/Molecules/Accordion/Accordion.js +3 -1
- package/dist/components/Molecules/Box/Box.js +3 -1
- package/dist/components/Molecules/Card/Card.js +3 -1
- package/dist/components/Molecules/CardDs/CardDs.js +8 -6
- package/dist/components/Molecules/Countdown/Countdown.style.js +2 -2
- package/dist/components/Molecules/HeroBanner/HeroBanner.js +3 -3
- package/dist/components/Molecules/PartnerLink/PartnerLink.js +3 -1
- package/dist/components/Molecules/Promo/Promo.style.js +4 -4
- package/dist/components/Molecules/SchoolLookup/SchoolLookup.js +3 -1
- package/dist/components/Molecules/SearchInput/SearchInput.js +3 -1
- package/dist/components/Molecules/SearchResult/SearchResult.js +5 -5
- package/dist/components/Molecules/ShareButton/ShareButton.js +3 -1
- package/dist/components/Molecules/SingleMessage/SingleMessage.js +1 -1
- package/dist/components/Molecules/SingleMessageDS/SingleMessageDs.js +16 -4
- package/dist/components/Molecules/SingleMessageDS/SingleMessageDs.md +28 -1
- package/dist/components/Molecules/SingleMessageDS/SingleMessageDs.style.js +9 -9
- package/dist/components/Molecules/SingleMessageDS/__snapshots__/SingleMessageDs.test.js.snap +0 -1
- package/dist/components/Molecules/Typeahead/Typeahead.js +3 -1
- package/dist/components/Molecules/VideoBanner/VideoBanner.js +1 -1
- package/dist/components/Organisms/CookieBanner/CookieBanner.style.js +4 -4
- package/dist/components/Organisms/Donate/Form/Form.js +3 -1
- package/dist/components/Organisms/Donate/GivingSelector/GivingSelector.js +4 -4
- package/dist/components/Organisms/Donate/MoneyBox/MoneyBox.js +3 -1
- package/dist/components/Organisms/EmailSignUp/EmailSignUp.js +3 -1
- package/dist/components/Organisms/EmailSignUp/EmailSignUp.style.js +7 -7
- package/dist/components/Organisms/Footer/Footer.js +7 -4
- package/dist/components/Organisms/Footer/Footer.md +8 -1
- package/dist/components/Organisms/Footer/Nav/Nav.js +12 -7
- package/dist/components/Organisms/Footer/Nav/Nav.style.js +8 -8
- package/dist/components/Organisms/Footer/__snapshots__/Footer.test.js.snap +31 -6
- package/dist/components/Organisms/Header/Burger/BurgerMenu.style.js +3 -3
- package/dist/components/Organisms/Header/Header.js +3 -1
- package/dist/components/Organisms/Header/Nav/Nav.js +3 -3
- package/dist/components/Organisms/MarketingPreferencesDS/_TextInput.js +3 -1
- package/dist/components/Organisms/Membership/Form/Form.js +3 -1
- package/dist/components/Organisms/Membership/MoneyBox/MoneyBox.js +3 -1
- package/dist/utils/internalLinkHelper.js +27 -5
- package/package.json +13 -13
- package/src/components/Atoms/Link/Link.js +17 -7
- package/src/components/Molecules/SingleMessage/SingleMessage.js +1 -1
- package/src/components/Molecules/SingleMessageDS/SingleMessageDs.js +19 -7
- package/src/components/Molecules/SingleMessageDS/SingleMessageDs.md +28 -1
- package/src/components/Molecules/SingleMessageDS/__snapshots__/SingleMessageDs.test.js.snap +0 -1
- package/src/components/Organisms/Footer/Footer.js +5 -3
- package/src/components/Organisms/Footer/Footer.md +8 -1
- package/src/components/Organisms/Footer/Nav/Nav.js +4 -3
- package/src/components/Organisms/Footer/__snapshots__/Footer.test.js.snap +31 -6
- package/src/components/Organisms/Header/Nav/Nav.js +1 -1
- package/src/utils/internalLinkHelper.js +23 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comicrelief/component-library",
|
|
3
3
|
"author": "Comic Relief Engineering Team",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.6.1",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"jest": {
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"url": "https://github.com/comicrelief/component-library.git"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/cli": "^7.
|
|
24
|
+
"@babel/cli": "^7.14.8",
|
|
25
25
|
"@hookform/resolvers": "^1.3.4",
|
|
26
26
|
"axios": "^0.21.1",
|
|
27
|
-
"jest-styled-components": "^7.0.
|
|
27
|
+
"jest-styled-components": "^7.0.5",
|
|
28
28
|
"lazysizes": "^5.3.2",
|
|
29
29
|
"lodash": "^4.17.11",
|
|
30
30
|
"moment": "^2.29.1",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"react-currency-format": "^1.0.0",
|
|
34
34
|
"react-dom": "^17.0.2",
|
|
35
35
|
"react-hook-form": "^6.3.0",
|
|
36
|
-
"react-modal": "^3.14.
|
|
36
|
+
"react-modal": "^3.14.3",
|
|
37
37
|
"react-scripts": "4.0.3",
|
|
38
|
-
"react-styleguidist": "^11.1.
|
|
38
|
+
"react-styleguidist": "^11.1.7",
|
|
39
39
|
"react-test-renderer": "^17.0.2",
|
|
40
40
|
"react-uid": "^2.2.0",
|
|
41
|
-
"styled-components": "^5.
|
|
41
|
+
"styled-components": "^5.3.1",
|
|
42
42
|
"youtube-player": "^5.5.2",
|
|
43
43
|
"yup": "^0.32.9",
|
|
44
44
|
"yup-phone": "^1.2.19"
|
|
@@ -73,17 +73,17 @@
|
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"babel-eslint": "^10.0.2",
|
|
75
75
|
"cross-env": "^7.0.3",
|
|
76
|
-
"cypress": "^
|
|
77
|
-
"eslint": "^7.
|
|
76
|
+
"cypress": "^8.3.0",
|
|
77
|
+
"eslint": "^7.32.0",
|
|
78
78
|
"eslint-config-airbnb": "^18.2.0",
|
|
79
|
-
"eslint-plugin-import": "^2.
|
|
79
|
+
"eslint-plugin-import": "^2.24.2",
|
|
80
80
|
"eslint-plugin-jsx-a11y": "^6.3.1",
|
|
81
|
-
"eslint-plugin-react": "^7.
|
|
81
|
+
"eslint-plugin-react": "^7.24.0",
|
|
82
82
|
"eslint-plugin-react-hooks": "^4.0.5",
|
|
83
|
-
"husky": "^
|
|
83
|
+
"husky": "^7.0.2",
|
|
84
84
|
"jest": "^26.1.0",
|
|
85
85
|
"npm-run-all": "^4.1.5",
|
|
86
|
-
"prettier": "^2.
|
|
87
|
-
"semantic-release": "^17.4.
|
|
86
|
+
"prettier": "^2.3.2",
|
|
87
|
+
"semantic-release": "^17.4.6"
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -3,10 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
|
|
4
4
|
import StyledLink, { HelperText, IconWrapper } from './Link.style';
|
|
5
5
|
import whiteListed from '../../../utils/whiteListed';
|
|
6
|
-
|
|
7
|
-
const domainRegEx = new RegExp(
|
|
8
|
-
'(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]'
|
|
9
|
-
);
|
|
6
|
+
import { getDomain } from '../../../utils/internalLinkHelper';
|
|
10
7
|
|
|
11
8
|
let window = '';
|
|
12
9
|
|
|
@@ -27,9 +24,22 @@ const Link = ({
|
|
|
27
24
|
* this is an internal link OR on our whitelist before making it a '_self' link
|
|
28
25
|
*/
|
|
29
26
|
if (target === null) {
|
|
30
|
-
|
|
27
|
+
// Use our helper function to determine the raw domains to compare
|
|
28
|
+
const currentDomain = getDomain(document.location.host);
|
|
29
|
+
const linkDomain = getDomain(href);
|
|
30
|
+
|
|
31
|
+
// Additional check for applications that need more control
|
|
32
|
+
const isWhiteListOverridden = rest.overrideWhiteList === true;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* If the link has no domain supplied (likely '/' or '#')
|
|
36
|
+
* OR has the same domain as the current page, don't open
|
|
37
|
+
* in a new tab
|
|
38
|
+
*/
|
|
39
|
+
const isExternalLink = linkDomain !== '' && (currentDomain !== linkDomain);
|
|
31
40
|
const isWhiteListed = whiteListed(href);
|
|
32
|
-
|
|
41
|
+
|
|
42
|
+
window = isExternalLink && (isWhiteListOverridden || !isWhiteListed) ? '_blank' : '_self';
|
|
33
43
|
} else {
|
|
34
44
|
window = target === 'blank' ? '_blank' : '_self';
|
|
35
45
|
}
|
|
@@ -46,7 +56,7 @@ const Link = ({
|
|
|
46
56
|
underline={underline}
|
|
47
57
|
>
|
|
48
58
|
{children}
|
|
49
|
-
{
|
|
59
|
+
{window === '_blank' && <HelperText>(opens in new window)</HelperText>}
|
|
50
60
|
{hasIcon && <IconWrapper type={type}>{icon}</IconWrapper>}
|
|
51
61
|
</StyledLink>
|
|
52
62
|
);
|
|
@@ -55,17 +55,29 @@ const SingleMessageDs = ({
|
|
|
55
55
|
imageLeft={imageLeft}
|
|
56
56
|
aria-hidden="true"
|
|
57
57
|
tabIndex="-1"
|
|
58
|
-
href={
|
|
58
|
+
href={link}
|
|
59
|
+
target={target}
|
|
60
|
+
{...rest}
|
|
61
|
+
>
|
|
62
|
+
{Media}
|
|
63
|
+
</MediaLink>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (imageLow && youTubeId) {
|
|
67
|
+
return (
|
|
68
|
+
<MediaLink
|
|
69
|
+
imageLeft={imageLeft}
|
|
70
|
+
aria-hidden="true"
|
|
71
|
+
tabIndex="-1"
|
|
72
|
+
href={youTubeId}
|
|
59
73
|
target={target}
|
|
60
74
|
{...rest}
|
|
61
75
|
onClick={e => { setIsOpen(true); e.preventDefault(); }}
|
|
62
76
|
>
|
|
63
|
-
|
|
64
|
-
<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
</PlayHolder>
|
|
68
|
-
) : Media}
|
|
77
|
+
<PlayHolder>
|
|
78
|
+
<PlayImage src={playImage} alt="" />
|
|
79
|
+
{Media}
|
|
80
|
+
</PlayHolder>
|
|
69
81
|
</MediaLink>
|
|
70
82
|
);
|
|
71
83
|
}
|
|
@@ -156,11 +156,38 @@ import Download from '../../Atoms/Icons/Download';
|
|
|
156
156
|
linkLabel='Download this'
|
|
157
157
|
linkIcon={<Download />}
|
|
158
158
|
imageLow={data.image}
|
|
159
|
+
imageLeft={true}
|
|
159
160
|
images={data.images}
|
|
160
161
|
>
|
|
161
162
|
<Text tag='p'>
|
|
162
|
-
|
|
163
|
+
Whatever you’ve got planned, the Sport Relief shop has everything you need
|
|
164
|
+
to get you looking your best while you’re raising some cash. Also
|
|
165
|
+
available in Sainsbury’s stores and online and in selected Argos stores.
|
|
163
166
|
</Text>
|
|
164
167
|
</SingleMessageDs>
|
|
165
168
|
</div>;
|
|
166
169
|
```
|
|
170
|
+
|
|
171
|
+
## Video with no CTA
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
const data = require('../../../styleguide/data/data').default;
|
|
175
|
+
import Text from '../../Atoms/Text/Text';
|
|
176
|
+
import Link from '../../Atoms/Link/Link';
|
|
177
|
+
import styled from 'styled-components';
|
|
178
|
+
import spacing from '../../../theme/shared/spacing';
|
|
179
|
+
import Download from '../../Atoms/Icons/Download';
|
|
180
|
+
|
|
181
|
+
<div>
|
|
182
|
+
<SingleMessageDs
|
|
183
|
+
imageLow={data.image}
|
|
184
|
+
images={data.images}
|
|
185
|
+
youTubeId="faz0JeBB41M"
|
|
186
|
+
imageLeft={true}
|
|
187
|
+
>
|
|
188
|
+
<Text tag='p'>
|
|
189
|
+
Some text and stuff.
|
|
190
|
+
</Text>
|
|
191
|
+
</SingleMessageDs>
|
|
192
|
+
</div>;
|
|
193
|
+
```
|
|
@@ -31,7 +31,7 @@ const Footer = ({
|
|
|
31
31
|
<Logo sizeSm="48px" sizeMd="72px" rotate={false} campaign={campaign} />
|
|
32
32
|
</Brand>
|
|
33
33
|
</FooterBranding>
|
|
34
|
-
<FooterNav navItems={navItems} />
|
|
34
|
+
<FooterNav navItems={navItems} {...rest} />
|
|
35
35
|
<FooterCopyright>
|
|
36
36
|
<Text tag="p" color="grey">
|
|
37
37
|
{footerCopy}
|
|
@@ -46,13 +46,15 @@ const Footer = ({
|
|
|
46
46
|
Footer.propTypes = {
|
|
47
47
|
navItems: PropTypes.objectOf(PropTypes.shape),
|
|
48
48
|
footerCopy: PropTypes.string,
|
|
49
|
-
campaign: PropTypes.string
|
|
49
|
+
campaign: PropTypes.string,
|
|
50
|
+
overrideWhiteList: PropTypes.bool
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
Footer.defaultProps = {
|
|
53
54
|
navItems: {},
|
|
54
55
|
footerCopy: '',
|
|
55
|
-
campaign: 'Comic Relief'
|
|
56
|
+
campaign: 'Comic Relief',
|
|
57
|
+
overrideWhiteList: false
|
|
56
58
|
};
|
|
57
59
|
|
|
58
60
|
export default Footer;
|
|
@@ -4,5 +4,12 @@
|
|
|
4
4
|
import data from './data/data';
|
|
5
5
|
import footerCopy from './data/footerCopy';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<>
|
|
8
|
+
<p>Standard footer</p>
|
|
9
|
+
<Footer navItems={data} footerCopy={footerCopy.copy} campaign="Comic Relief" />
|
|
10
|
+
|
|
11
|
+
<p>Overrides whitelist functionality for external usage</p>
|
|
12
|
+
<Footer navItems={data} footerCopy={footerCopy.copy} campaign="Comic Relief" overrideWhiteList />
|
|
13
|
+
</>
|
|
14
|
+
|
|
8
15
|
```
|
|
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
import Text from '../../../Atoms/Text/Text';
|
|
5
5
|
import { sizes } from '../../../../theme/shared/breakpoint';
|
|
6
6
|
import NavHelper from '../../../../utils/navHelper';
|
|
7
|
-
import InternalLinkHelper from '../../../../utils/internalLinkHelper';
|
|
7
|
+
import { InternalLinkHelper } from '../../../../utils/internalLinkHelper';
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
10
|
Nav,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
SubNavLink
|
|
17
17
|
} from './Nav.style';
|
|
18
18
|
|
|
19
|
-
const FooterNav = ({ navItems }) => {
|
|
19
|
+
const FooterNav = ({ navItems, ...rest }) => {
|
|
20
20
|
const { menuGroups } = navItems;
|
|
21
21
|
const [isExpandable] = useState(false);
|
|
22
22
|
const [isSubMenuOpen, setIsSubMenuOpen] = useState({});
|
|
@@ -78,6 +78,7 @@ const FooterNav = ({ navItems }) => {
|
|
|
78
78
|
aria-haspopup="true"
|
|
79
79
|
role="button"
|
|
80
80
|
onClick={toggleSubMenu(group.id)}
|
|
81
|
+
{...rest}
|
|
81
82
|
>
|
|
82
83
|
<Text color="white">{group.title}</Text>
|
|
83
84
|
</NavLink>
|
|
@@ -103,7 +104,7 @@ const FooterNav = ({ navItems }) => {
|
|
|
103
104
|
group.links.length % 2 === 0 && group.links.length > 2
|
|
104
105
|
}
|
|
105
106
|
>
|
|
106
|
-
<SubNavLink href={thisUrl} inline role="menuitem">
|
|
107
|
+
<SubNavLink href={thisUrl} inline role="menuitem" {...rest}>
|
|
107
108
|
<Text color="white">{child.title}</Text>
|
|
108
109
|
</SubNavLink>
|
|
109
110
|
</SubNavItem>
|
|
@@ -27,7 +27,7 @@ exports[`renders correctly 1`] = `
|
|
|
27
27
|
font-family: 'Montserrat',Helvetica,Arial,sans-serif;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
.
|
|
30
|
+
.c26 {
|
|
31
31
|
color: #969598;
|
|
32
32
|
font-size: 1rem;
|
|
33
33
|
line-height: 1rem;
|
|
@@ -69,6 +69,21 @@ exports[`renders correctly 1`] = `
|
|
|
69
69
|
border-bottom: 2px solid #000000;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
.c24 {
|
|
73
|
+
border: 0;
|
|
74
|
+
-webkit-clip: rect(0 0 0 0);
|
|
75
|
+
clip: rect(0 0 0 0);
|
|
76
|
+
-webkit-clip-path: inset(50%);
|
|
77
|
+
clip-path: inset(50%);
|
|
78
|
+
height: 1px;
|
|
79
|
+
margin: -1px;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
padding: 0;
|
|
82
|
+
position: absolute;
|
|
83
|
+
white-space: nowrap;
|
|
84
|
+
width: 1px;
|
|
85
|
+
}
|
|
86
|
+
|
|
72
87
|
.c5 {
|
|
73
88
|
-webkit-text-decoration: none;
|
|
74
89
|
text-decoration: none;
|
|
@@ -313,7 +328,7 @@ exports[`renders correctly 1`] = `
|
|
|
313
328
|
align-items: center;
|
|
314
329
|
}
|
|
315
330
|
|
|
316
|
-
.
|
|
331
|
+
.c25 {
|
|
317
332
|
display: block;
|
|
318
333
|
width: 100%;
|
|
319
334
|
height: 100%;
|
|
@@ -321,7 +336,7 @@ exports[`renders correctly 1`] = `
|
|
|
321
336
|
margin-top: 3rem;
|
|
322
337
|
}
|
|
323
338
|
|
|
324
|
-
.
|
|
339
|
+
.c25 p {
|
|
325
340
|
font-size: 15px;
|
|
326
341
|
line-height: 24px;
|
|
327
342
|
margin-bottom: 5px;
|
|
@@ -528,7 +543,7 @@ exports[`renders correctly 1`] = `
|
|
|
528
543
|
}
|
|
529
544
|
|
|
530
545
|
@media (min-width:1024px) {
|
|
531
|
-
.
|
|
546
|
+
.c25 p {
|
|
532
547
|
font-size: 16px;
|
|
533
548
|
line-height: 27px;
|
|
534
549
|
}
|
|
@@ -1166,6 +1181,11 @@ exports[`renders correctly 1`] = `
|
|
|
1166
1181
|
>
|
|
1167
1182
|
Link comp with only URL
|
|
1168
1183
|
</span>
|
|
1184
|
+
<span
|
|
1185
|
+
className="c24"
|
|
1186
|
+
>
|
|
1187
|
+
(opens in new window)
|
|
1188
|
+
</span>
|
|
1169
1189
|
</a>
|
|
1170
1190
|
</li>
|
|
1171
1191
|
<li
|
|
@@ -1206,6 +1226,11 @@ exports[`renders correctly 1`] = `
|
|
|
1206
1226
|
>
|
|
1207
1227
|
Test non-whitelisted external link
|
|
1208
1228
|
</span>
|
|
1229
|
+
<span
|
|
1230
|
+
className="c24"
|
|
1231
|
+
>
|
|
1232
|
+
(opens in new window)
|
|
1233
|
+
</span>
|
|
1209
1234
|
</a>
|
|
1210
1235
|
</li>
|
|
1211
1236
|
</ul>
|
|
@@ -1213,10 +1238,10 @@ exports[`renders correctly 1`] = `
|
|
|
1213
1238
|
</ul>
|
|
1214
1239
|
</nav>
|
|
1215
1240
|
<div
|
|
1216
|
-
className="
|
|
1241
|
+
className="c25"
|
|
1217
1242
|
>
|
|
1218
1243
|
<p
|
|
1219
|
-
className="
|
|
1244
|
+
className="c26"
|
|
1220
1245
|
color="grey"
|
|
1221
1246
|
size="s"
|
|
1222
1247
|
>
|
|
@@ -5,7 +5,7 @@ import Text from '../../../Atoms/Text/Text';
|
|
|
5
5
|
import BurgerMenu from '../Burger/BurgerMenu';
|
|
6
6
|
import { sizes } from '../../../../theme/shared/breakpoint';
|
|
7
7
|
import NavHelper from '../../../../utils/navHelper';
|
|
8
|
-
import InternalLinkHelper from '../../../../utils/internalLinkHelper';
|
|
8
|
+
import { InternalLinkHelper } from '../../../../utils/internalLinkHelper';
|
|
9
9
|
import whiteListed from '../../../../utils/whiteListed';
|
|
10
10
|
|
|
11
11
|
import {
|
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
);
|
|
1
|
+
const domainRegEx = new RegExp(
|
|
2
|
+
'(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]'
|
|
3
|
+
);
|
|
5
4
|
|
|
5
|
+
const InternalLinkHelper = link => {
|
|
6
6
|
// Check our URL for a domain pattern, if so return it
|
|
7
7
|
if (domainRegEx.test(link)) {
|
|
8
8
|
return link;
|
|
9
9
|
}
|
|
10
|
+
|
|
10
11
|
// If domain-free and internal, prefix it with slash if it doesn't already have one
|
|
11
12
|
return link.substring(0, 1) === '/' ? link : `/${link}`;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
const getDomain = url => {
|
|
16
|
+
let thisURL = url;
|
|
17
|
+
|
|
18
|
+
// Strip out protocol
|
|
19
|
+
thisURL = url.replace(/(https?:\/\/)?(www.)?/i, '');
|
|
20
|
+
|
|
21
|
+
// Strip out subdirectory/path
|
|
22
|
+
if (thisURL.indexOf('/') !== -1) {
|
|
23
|
+
const [splitURL] = thisURL.split('/');
|
|
24
|
+
thisURL = splitURL;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return thisURL;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
InternalLinkHelper, getDomain
|
|
32
|
+
};
|