Skip to content

Commit 5535912

Browse files
committed
[B-000] Fix bug: CategoryLines
1 parent 47ddb8c commit 5535912

3 files changed

Lines changed: 86 additions & 24 deletions

File tree

src/templates/archive/main-category.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@ import * as React from "react"
55
import { CategoryArticle } from "."
66
import SubCategoryArticles from "./sub-category"
77

8-
export const CategoryLine = styled(`div`)<{ size: 'main' | 'sub' | 'nested' ,top: number, left: number, plusHeight: number }>(
9-
({ size, top, left, plusHeight: minusHeight }) => ({
10-
content: '""',
11-
position: 'absolute',
12-
top: `${top}px`,
13-
left: `${left}px`,
14-
height: `calc(100% + ${minusHeight}px)`,
15-
width: '2px',
16-
backgroundColor: 'var(--text-link)',
17-
'@media only screen and (max-width: 700px)': {
18-
top: `${top + (size === 'nested' ? 2 : (size === 'sub' ? 5 : 2))}px`,
19-
height: `calc(100% + ${minusHeight - (size === 'nested' ? 2 : (size === 'sub' ? 36 : 6))}px)`,
20-
},
21-
'@media only screen and (max-width: 600px)': {
22-
top: `${top + (size === 'nested' ? 4 : (size === 'sub' ? 7 : 3))}px`,
23-
height: `calc(100% + ${minusHeight - (size === 'nested' ? 4 : (size === 'sub' ? 77 : 6))}px)`,
24-
},
25-
})
26-
)
8+
export const CategoryLine = styled(`div`)({
9+
content: '""',
10+
position: 'absolute',
11+
width: '2px',
12+
backgroundColor: 'var(--text-link)',
13+
})
14+
15+
const CategoryMainLine = styled(CategoryLine)({
16+
left: `14px`,
17+
top: `-0.2rem`,
18+
height: `calc(100% + 1.5rem + 0.3rem)`,
19+
'@media only screen and (max-width: 700px)': {
20+
top: `0px`,
21+
height: `calc(100% + 1.5rem)`,
22+
},
23+
'@media only screen and (max-width: 600px)': {
24+
top: `0px`,
25+
height: `calc(100% + 1.5rem)`,
26+
},
27+
})
2728

2829
export const sliceStringWithMax = (str: string, max: number) =>
2930
(str.length >= max)
@@ -39,7 +40,7 @@ const MainCategoryArticles: React.FunctionComponent<{ maxTitleLength: number, ca
3940
<MainCategoryBox key={mainCategory}>
4041
<MainCategoryTitle category={mainCategory} articleCount={each.count} />
4142
<ul css={styles.articles} key={mainCategory}>
42-
{hasSubCategory && <CategoryLine size="main" top={-4} left={14} plusHeight={30} />}
43+
{hasSubCategory && <CategoryMainLine />}
4344
{each.articles.map(article => (
4445
<li css={styles.article} key={article.title}>
4546
<Link css={styles.articleTitle} to={article.link}>
@@ -133,7 +134,7 @@ export const styles = {
133134
`,
134135
articles: css`
135136
position: relative;
136-
top: -12px;
137+
top: -0.8rem;
137138
margin-bottom: -6px;
138139
`,
139140
nestedArticles: css`

src/templates/archive/nested-category.tsx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
11
import { css } from "@emotion/react"
2+
import styled from "@emotion/styled"
23
import { Link } from "gatsby"
34
import * as React from "react"
45
import { CategoryArticle } from "."
56
import { CategoryLine, sliceStringWithMax, styles } from "./main-category"
67

8+
const CategoryMainConnectedNestedLine = styled(CategoryLine)({
9+
left: `-20px`,
10+
top: `-1.1rem`,
11+
height: `calc(100% + 1.5rem + 1.5rem)`,
12+
// | -1.0rem + 1.3rem | = 2.6rem -> CategoryMainLine
13+
'@media only screen and (max-width: 700px)': {
14+
top: `-1.0rem`,
15+
height: `calc(100% + 1.5rem + 1.3rem)`,
16+
},
17+
'@media only screen and (max-width: 600px)': {
18+
top: `-1.0rem`,
19+
height: `calc(100% + 1.5rem + 1.3rem)`,
20+
},
21+
})
22+
23+
const CategorySubConnectedNestedLine = styled(CategoryLine)({
24+
left: `21px`,
25+
top: `-1.1rem`,
26+
height: `calc(100% + 1.5rem + 1.1rem)`,
27+
'@media only screen and (max-width: 700px)': {
28+
top: `-1.0rem`,
29+
height: `calc(100% + 1.5rem + 1.0rem)`,
30+
},
31+
'@media only screen and (max-width: 600px)': {
32+
top: `-1.0rem`,
33+
height: `calc(100% + 1.5rem + 1.2rem)`,
34+
},
35+
})
36+
737
const NestedCategoryArticles: React.FunctionComponent<{ maxTitleLength: number, categories: Array<CategoryArticle> }> = ({ maxTitleLength, categories }) => (
838
<React.Fragment>
939
{categories.map((each, index) => {
@@ -13,7 +43,8 @@ const NestedCategoryArticles: React.FunctionComponent<{ maxTitleLength: number,
1343
<NestedCategoryBox key={subCategory}>
1444
<NestedCategoryTitle category={subCategory} articleCount={each.count} />
1545
<ul css={styles.nestedArticles} key={subCategory}>
16-
{notLastNestedCategory && <CategoryLine size="nested" top={-21} left={21} plusHeight={44} />}
46+
<CategoryMainConnectedNestedLine />
47+
{notLastNestedCategory && <CategorySubConnectedNestedLine />}
1748
{each.articles.map(article => (
1849
<li css={[styles.article, css`position: relative; left: 24px;`]} key={article.title}>
1950
<Link css={styles.articleTitle} to={article.link}>

src/templates/archive/sub-category.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
import { css } from "@emotion/react"
2+
import styled from "@emotion/styled"
23
import { Link } from "gatsby"
34
import * as React from "react"
45
import { CategoryArticle } from "."
56
import { CategoryLine, sliceStringWithMax, styles } from "./main-category"
67
import NestedCategoryArticles from "./nested-category"
78

9+
const CategoryMainConnectedSubLine = styled(CategoryLine)({
10+
left: `14px`,
11+
top: `-1.5rem`,
12+
height: `calc(100% + 1.5rem + 1.5rem)`,
13+
// | -1.1rem + 1.2rem | = 2.6rem -> CategoryMainLine
14+
'@media only screen and (max-width: 700px)': {
15+
top: `-1.1rem`,
16+
height: `calc(100% + 1.5rem + 1.2rem)`,
17+
},
18+
'@media only screen and (max-width: 600px)': {
19+
top: `-1.1rem`,
20+
height: `calc(100% + 1.5rem + 1.2rem)`,
21+
},
22+
})
23+
24+
const CategorySubLine = styled(CategoryLine)({
25+
left: `55px`,
26+
top: `-0.2rem`,
27+
height: `calc(100% + 1.5rem + 0.0rem)`,
28+
'@media only screen and (max-width: 700px)': {
29+
top: `-0.1rem`,
30+
height: `calc(100% + 1.5rem - 0.1rem)`,
31+
},
32+
'@media only screen and (max-width: 600px)': {
33+
top: `-0.1rem`,
34+
height: `calc(100% + 1.5rem + 0.0rem)`,
35+
},
36+
})
37+
838
const SubCategoryArticles: React.FunctionComponent<{ maxTitleLength: number, categories: Array<CategoryArticle> }> = ({ maxTitleLength, categories }) => (
939
<React.Fragment>
1040
{categories.map((each, index) => {
@@ -24,8 +54,8 @@ const SubCategoryArticles: React.FunctionComponent<{ maxTitleLength: number, cat
2454
<SubCategoryBox key={subCategory}>
2555
<SubCategoryTitle category={subCategory} articleCount={each.count} />
2656
<ul css={styles.articles} key={subCategory}>
27-
{hasNestedCategory && <CategoryLine size="nested" top={-4} left={55} plusHeight={25} />}
28-
{notLastSubCategory && <CategoryLine size="sub" top={-23} left={14} plusHeight={(66 + nestedHeightCorrection)} />}
57+
{hasNestedCategory && <CategorySubLine />}
58+
{notLastSubCategory && <CategoryMainConnectedSubLine />}
2959
{each.articles.map(article => (
3060
<li css={[styles.article, css`position: relative; left: 40px;`]} key={article.title}>
3161
<Link css={styles.articleTitle} to={article.link}>

0 commit comments

Comments
 (0)