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

Commit d1ad708

Browse files
authored
refactor: user molecule layout to allow other content (#63)
This is to prepare for the GitHub event cards.
1 parent a6b7897 commit d1ad708

File tree

4 files changed

+53
-50
lines changed

4 files changed

+53
-50
lines changed

src/molecules/user/elements.js

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
11
import styled from 'styled-components/macro';
22

33
/**
4-
* The user container creates a vertical-directed flexbox.
5-
* It also centers the content to connect the otherwise unrelated content visually.
4+
* The user container creates a block that should fully contain the necessary user information.
5+
* It will push other content, like event cards, below this content.
66
*/
77
export const UserContainer = styled.div`
8+
/*width: 100%;*/
9+
`;
10+
11+
/**
12+
* The user container meta element splits the screen in half and put the avatar and user in this half.
13+
* It creates some emphasis on the user's name and also allows extra information without affecting this positioning.
14+
*/
15+
export const UserContainerMeta = styled.div`
816
display: flex;
917
flex-direction: column;
1018
align-items: center;
11-
color: #6a737d;
19+
justify-content: flex-end;
20+
height: 50vh;
1221
`;
1322

1423
/**
15-
* The user avatar aligns the user's avatar with the name, using flexbox.
16-
* This technique is also applied for the description to center the user's name correctly.
24+
* The user container info element centers the user's description horizontally.
25+
* The length of this content does not affect the avatar and name positioning.
1726
*/
18-
export const UserAvatar = styled.div`
27+
export const UserContainerInfo = styled.div`
1928
display: flex;
20-
flex: 1;
21-
align-items: flex-end;
29+
justify-content: center;
30+
`;
31+
32+
/**
33+
* The user avatar creates a slightly bigger avatar for the user.
34+
* It's because this is the primary visual symbol of the user itself.
35+
*/
36+
export const UserAvatar = styled.div`
2237
padding: 0.5rem;
2338
font-size: 1.5em;
2439
`;
2540

2641
/**
27-
* The user's name is also the title of the app and is therefore vertically centered.
28-
* It's positioned with flexbox to achieve this without knowing the sizes of both the avatar and description.
42+
* The user's name is increased in size and styled to style the title of the page.
43+
* It's because this is the actual human-identifiable information about the user.
2944
*/
3045
export const UserName = styled.h1`
31-
flex: 0;
3246
margin: 0;
3347
padding: 0.5rem;
3448
text-align: center;
@@ -38,25 +52,20 @@ export const UserName = styled.h1`
3852
`;
3953

4054
/**
41-
* The user description aligns the user's description with the name, using flexbox.
42-
* Because of this flexbox positioning, the size of the text has no impact on the alignment.
43-
* This technique is also applied for the avatar to center the name correctly.
55+
* The user's description is styled to make it a bit more readable and to have a max width.
56+
* This styling will create more visual coherence between the name and description.
4457
*/
4558
export const UserDescription = styled.div`
46-
display: flex;
47-
flex: 1;
48-
align-items: flex-start;
49-
justify-content: center;
5059
margin: 0;
5160
padding: 0.5rem;
52-
width: 100%;
5361
max-width: 24em;
5462
text-align: center;
5563
line-height: 1.5;
64+
color: #6a737d;
5665
`;
5766

5867
/**
59-
* The user description highlight styles a single word within this description.
68+
* The user's description highlights styles keywords within this description.
6069
*/
6170
export const UserDescriptionHighlight = styled.strong`
6271
color: #24292e;

src/molecules/user/user.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { propTypes, defaultProps } from './prop-type';
55
import UserMeta from './user-meta';
66
import {
77
UserContainer,
8+
UserContainerMeta,
9+
UserContainerInfo,
810
UserAvatar,
911
UserName,
1012
UserDescription,
@@ -21,22 +23,26 @@ export default function UserMolecule(props) {
2123

2224
return (
2325
<UserContainer>
24-
<UserMeta {...props} />
25-
<UserAvatar>
26-
<Avatar
27-
url={props.avatarUrl}
28-
name={identifier}
29-
title={identifier}
30-
/>
31-
</UserAvatar>
32-
<UserName title={identifier}>
33-
{props.name}
34-
</UserName>
35-
<UserDescription>
36-
<Highlight decorators={decorators}>
37-
{props.description}
38-
</Highlight>
39-
</UserDescription>
26+
<UserContainerMeta>
27+
<UserMeta {...props} />
28+
<UserAvatar>
29+
<Avatar
30+
url={props.avatarUrl}
31+
name={identifier}
32+
title={identifier}
33+
/>
34+
</UserAvatar>
35+
<UserName title={identifier}>
36+
{props.name}
37+
</UserName>
38+
</UserContainerMeta>
39+
<UserContainerInfo>
40+
<UserDescription>
41+
<Highlight decorators={decorators}>
42+
{props.description}
43+
</Highlight>
44+
</UserDescription>
45+
</UserContainerInfo>
4046
</UserContainer>
4147
);
4248
}

src/pages/app/app.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from 'react';
22
import GithubUser from 'src/organisms/github-user';
3-
import { AppContainer } from './elements';
43

54
export default function AppPage() {
65
return (
7-
<AppContainer>
6+
<main role="main">
87
<GithubUser />
9-
</AppContainer>
8+
</main>
109
);
1110
}

src/pages/app/elements.js

-11
This file was deleted.

0 commit comments

Comments
 (0)