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

Commit

Permalink
refactor: move user description highlights to github user organism (#68)
Browse files Browse the repository at this point in the history
This removes all references of GitHub from the user molecule.
  • Loading branch information
byCedric committed Oct 19, 2018
1 parent 41d746c commit 2575cec
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 27 deletions.
9 changes: 0 additions & 9 deletions src/molecules/user/elements.js
Expand Up @@ -61,12 +61,3 @@ export const UserDescription = styled.div`
text-align: center;
line-height: 1.5;
`;

/**
* The user's description highlights styles keywords within this description.
*/
export const UserDescriptionHighlight = styled.a`
text-decoration: none;
color: #24292e;
font-weight: 600;
`;
3 changes: 3 additions & 0 deletions src/molecules/user/prop-type.js
Expand Up @@ -9,8 +9,11 @@ export const propTypes = {
avatarUrl: PropTypes.string.isRequired,
/** An optional description of this person. */
description: PropTypes.string,
/** An optional object with all decorators for user's description highlights. */
highlights: PropTypes.object,
};

export const defaultProps = {
description: '',
highlights: {},
};
19 changes: 1 addition & 18 deletions src/molecules/user/user.js
Expand Up @@ -10,25 +10,8 @@ import {
UserAvatar,
UserName,
UserDescription,
UserDescriptionHighlight,
} from './elements';

const decorators = {
'@': (segment, match, key) => (
<UserDescriptionHighlight
key={key}
href={`https://github.com/${match}`}
target='_blank'
rel='noopener noreferrer'
>
{segment}
</UserDescriptionHighlight>
),
'#': (segment, match, key) => (
<UserDescriptionHighlight key={key}>{match}</UserDescriptionHighlight>
)
};

export default function UserMolecule(props) {
const identifier = `${props.name} (${props.username})`;

Expand All @@ -49,7 +32,7 @@ export default function UserMolecule(props) {
</UserContainerMeta>
<UserContainerInfo>
<UserDescription>
<Highlight decorators={decorators}>
<Highlight decorators={props.highlights}>
{props.description}
</Highlight>
</UserDescription>
Expand Down
22 changes: 22 additions & 0 deletions src/organisms/github-user/elements.js
@@ -0,0 +1,22 @@
import styled from 'styled-components/macro';

/**
* This element styles a mention in the user description, which links to this organization or user.
*/
export const GithubUserMentionHighlight = styled.a`
text-decoration: none;
color: #24292e;
font-weight: 600;
&:hover {
text-decoration: underline;
}
`;

/**
* This element styles a particular keyword, starting with a character, in the user description.
*/
export const GithubUserKeywordHighlight = styled.strong`
color: #24292e;
font-weight: 600;
`;
2 changes: 2 additions & 0 deletions src/organisms/github-user/github-user.js
@@ -1,6 +1,7 @@
import React from 'react';
import { AsyncUser } from 'src/providers/github';
import User from 'src/molecules/user';
import highlights from './highlights';

export default function GithubUserOrganism() {
return (
Expand All @@ -12,6 +13,7 @@ export default function GithubUserOrganism() {
username={data.login}
avatarUrl={data.avatar_url}
description={data.bio}
highlights={highlights}
/>
)}
</AsyncUser.Resolved>
Expand Down
7 changes: 7 additions & 0 deletions src/organisms/github-user/highlights/index.js
@@ -0,0 +1,7 @@
import KeywordHighlight from './keyword';
import MentionHighlight from './mention';

export default {
...KeywordHighlight.decorator,
...MentionHighlight.decorator,
};
20 changes: 20 additions & 0 deletions src/organisms/github-user/highlights/keyword.js
@@ -0,0 +1,20 @@
import React from 'react';
import PropTypes from 'prop-types';
import { GithubUserKeywordHighlight } from '../elements';

export default function GithubUserOrganismKeyword(props) {
return (
<GithubUserKeywordHighlight>
{props.children}
</GithubUserKeywordHighlight>
);
}

GithubUserOrganismKeyword.decorator = {
'#': (match, text, key) => <GithubUserOrganismKeyword key={key} label={text} />,
}

GithubUserOrganismKeyword.propTypes = {
/** The text to show for this keyword. */
label: PropTypes.string.isRequired,
};
32 changes: 32 additions & 0 deletions src/organisms/github-user/highlights/mention.js
@@ -0,0 +1,32 @@
import React from 'react';
import PropTypes from 'prop-types';
import { GithubUserMentionHighlight } from '../elements';

export default function GithubUserOrganismMention(props) {
return (
<GithubUserMentionHighlight
href={`https://github.com/${props.username}`}
target='_blank'
rel='noopener noreferrer'
>
{props.label}
</GithubUserMentionHighlight>
);
}

GithubUserOrganismMention.decorator = {
'@': (match, text, key) => (
<GithubUserOrganismMention
key={key}
label={match}
username={text}
/>
),
};

GithubUserOrganismMention.propTypes = {
/** The text to show for this link or mention. */
label: PropTypes.string.isRequired,
/** The GitHub username to use in the external link. */
username: PropTypes.string.isRequired,
};

0 comments on commit 2575cec

Please sign in to comment.