Skip to content

Commit f820d68

Browse files
authored
refactor(components): reorganised the structure of the components keeping things cleaner (nodejs#2921)
1 parent cfad20c commit f820d68

File tree

210 files changed

+443
-376
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+443
-376
lines changed

gatsby-browser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import ReactIntlProvider from './src/containers/ReactIntl';
2+
import ReactIntlProvider from './src/providers/ReactIntl';
33
import { defaultLanguage, defaultMessages } from './locales';
44
import type { WrapPageElementBrowser } from './src/types';
55

gatsby-ssr.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import ReactIntlProvider from './src/containers/ReactIntl';
2+
import ReactIntlProvider from './src/providers/ReactIntl';
33
import { defaultLanguage, defaultMessages } from './locales';
44
import type { WrapPageElementSSR } from './src/types';
55

src/components/Author/__tests__/__snapshots__/index.test.tsx.snap renamed to src/components/ArticleComponents/AuthorList/Author/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Author component does not render without a username 1`] = `<div />`;
3+
exports[`Author component does not render without a username 1`] = `
4+
<div>
5+
<li>
6+
<a
7+
aria-label=" Github - opens in new tab"
8+
class="link"
9+
href="https://github.com/"
10+
rel="noopener noreferrer"
11+
style="margin-left: 0px;"
12+
target="_blank"
13+
>
14+
<img
15+
alt=""
16+
src="https://github.com/.png?size="
17+
/>
18+
</a>
19+
</li>
20+
</div>
21+
`;
422

523
exports[`Author component renders correctly 1`] = `
624
<div>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import { injectIntl, WrappedComponentProps } from 'react-intl';
3+
import styles from './index.module.scss';
4+
5+
interface Props {
6+
index: number;
7+
username: string;
8+
size: string;
9+
}
10+
11+
const Author = ({
12+
index,
13+
username,
14+
size = '64',
15+
intl,
16+
}: Props & WrappedComponentProps) => {
17+
// Clean up username and build links.
18+
const githubUserName = username.trim();
19+
const githubLink = `https://github.com/${githubUserName}`;
20+
const githubImgLink = `https://github.com/${githubUserName}.png?size=${size}`;
21+
22+
// If it's the first author then no margin left.
23+
const mleft = index === 0 ? { marginLeft: 0 } : {};
24+
25+
const translation = intl.formatMessage(
26+
{ id: 'components.author.githubLinkLabel' },
27+
{ username }
28+
);
29+
30+
return (
31+
<li>
32+
<a
33+
className={styles.link}
34+
href={githubLink}
35+
aria-label={translation}
36+
key={username}
37+
target="_blank"
38+
rel="noopener noreferrer"
39+
style={mleft}
40+
>
41+
<img src={githubImgLink} alt="" />
42+
</a>
43+
</li>
44+
);
45+
};
46+
47+
export default injectIntl(Author);

0 commit comments

Comments
 (0)