Skip to content
This repository was archived by the owner on Apr 9, 2023. It is now read-only.

Commit 2575cec

Browse files
authored
refactor: move user description highlights to github user organism (#68)
This removes all references of GitHub from the user molecule.
1 parent 41d746c commit 2575cec

File tree

8 files changed

+87
-27
lines changed

8 files changed

+87
-27
lines changed

src/molecules/user/elements.js

-9
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,3 @@ export const UserDescription = styled.div`
6161
text-align: center;
6262
line-height: 1.5;
6363
`;
64-
65-
/**
66-
* The user's description highlights styles keywords within this description.
67-
*/
68-
export const UserDescriptionHighlight = styled.a`
69-
text-decoration: none;
70-
color: #24292e;
71-
font-weight: 600;
72-
`;

src/molecules/user/prop-type.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ export const propTypes = {
99
avatarUrl: PropTypes.string.isRequired,
1010
/** An optional description of this person. */
1111
description: PropTypes.string,
12+
/** An optional object with all decorators for user's description highlights. */
13+
highlights: PropTypes.object,
1214
};
1315

1416
export const defaultProps = {
1517
description: '',
18+
highlights: {},
1619
};

src/molecules/user/user.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,8 @@ import {
1010
UserAvatar,
1111
UserName,
1212
UserDescription,
13-
UserDescriptionHighlight,
1413
} from './elements';
1514

16-
const decorators = {
17-
'@': (segment, match, key) => (
18-
<UserDescriptionHighlight
19-
key={key}
20-
href={`https://github.com/${match}`}
21-
target='_blank'
22-
rel='noopener noreferrer'
23-
>
24-
{segment}
25-
</UserDescriptionHighlight>
26-
),
27-
'#': (segment, match, key) => (
28-
<UserDescriptionHighlight key={key}>{match}</UserDescriptionHighlight>
29-
)
30-
};
31-
3215
export default function UserMolecule(props) {
3316
const identifier = `${props.name} (${props.username})`;
3417

@@ -49,7 +32,7 @@ export default function UserMolecule(props) {
4932
</UserContainerMeta>
5033
<UserContainerInfo>
5134
<UserDescription>
52-
<Highlight decorators={decorators}>
35+
<Highlight decorators={props.highlights}>
5336
{props.description}
5437
</Highlight>
5538
</UserDescription>

src/organisms/github-user/elements.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import styled from 'styled-components/macro';
2+
3+
/**
4+
* This element styles a mention in the user description, which links to this organization or user.
5+
*/
6+
export const GithubUserMentionHighlight = styled.a`
7+
text-decoration: none;
8+
color: #24292e;
9+
font-weight: 600;
10+
11+
&:hover {
12+
text-decoration: underline;
13+
}
14+
`;
15+
16+
/**
17+
* This element styles a particular keyword, starting with a character, in the user description.
18+
*/
19+
export const GithubUserKeywordHighlight = styled.strong`
20+
color: #24292e;
21+
font-weight: 600;
22+
`;

src/organisms/github-user/github-user.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { AsyncUser } from 'src/providers/github';
33
import User from 'src/molecules/user';
4+
import highlights from './highlights';
45

56
export default function GithubUserOrganism() {
67
return (
@@ -12,6 +13,7 @@ export default function GithubUserOrganism() {
1213
username={data.login}
1314
avatarUrl={data.avatar_url}
1415
description={data.bio}
16+
highlights={highlights}
1517
/>
1618
)}
1719
</AsyncUser.Resolved>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import KeywordHighlight from './keyword';
2+
import MentionHighlight from './mention';
3+
4+
export default {
5+
...KeywordHighlight.decorator,
6+
...MentionHighlight.decorator,
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { GithubUserKeywordHighlight } from '../elements';
4+
5+
export default function GithubUserOrganismKeyword(props) {
6+
return (
7+
<GithubUserKeywordHighlight>
8+
{props.children}
9+
</GithubUserKeywordHighlight>
10+
);
11+
}
12+
13+
GithubUserOrganismKeyword.decorator = {
14+
'#': (match, text, key) => <GithubUserOrganismKeyword key={key} label={text} />,
15+
}
16+
17+
GithubUserOrganismKeyword.propTypes = {
18+
/** The text to show for this keyword. */
19+
label: PropTypes.string.isRequired,
20+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { GithubUserMentionHighlight } from '../elements';
4+
5+
export default function GithubUserOrganismMention(props) {
6+
return (
7+
<GithubUserMentionHighlight
8+
href={`https://github.com/${props.username}`}
9+
target='_blank'
10+
rel='noopener noreferrer'
11+
>
12+
{props.label}
13+
</GithubUserMentionHighlight>
14+
);
15+
}
16+
17+
GithubUserOrganismMention.decorator = {
18+
'@': (match, text, key) => (
19+
<GithubUserOrganismMention
20+
key={key}
21+
label={match}
22+
username={text}
23+
/>
24+
),
25+
};
26+
27+
GithubUserOrganismMention.propTypes = {
28+
/** The text to show for this link or mention. */
29+
label: PropTypes.string.isRequired,
30+
/** The GitHub username to use in the external link. */
31+
username: PropTypes.string.isRequired,
32+
};

0 commit comments

Comments
 (0)