Skip to content

Commit

Permalink
Merge pull request #105 from ruedap/refactor-styles
Browse files Browse the repository at this point in the history
Refactor nested selector in styled-components
  • Loading branch information
ruedap authored May 24, 2020
2 parents e46cbd7 + fce1911 commit 6843fbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
11 changes: 6 additions & 5 deletions components/organisms/article_list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const Time = ({ dateString, className }: { dateString: string, className?: strin
<time dateTime={d.toISOString()} className={className}>
<Styled.Year>{year}</Styled.Year>
<Styled.Dot>.</Styled.Dot>
<Styled.Month className="sc-month">{month}</Styled.Month>
<Styled.Month>{month}</Styled.Month>
<Styled.Dot>.</Styled.Dot>
<Styled.Date className="sc-date">{date}</Styled.Date>
<Styled.Date>{date}</Styled.Date>
</time>
)
}
Expand All @@ -34,6 +34,7 @@ const ArticleList = ({
}

const StyledTime = Styled.Time(Time)
const StyledItemLink = Styled.ItemLink(Styled.Month, Styled.Date, Styled.Title)

return (
<Styled.Root>
Expand All @@ -47,10 +48,10 @@ const ArticleList = ({
)}
<Styled.Item>
<Link href="[year]/[month]/[date]/[title]" passHref as={url}>
<Styled.ItemLink>
<StyledItemLink>
<StyledTime dateString={date} />
<Styled.Title className="sc-title">{title}</Styled.Title>
</Styled.ItemLink>
<Styled.Title>{title}</Styled.Title>
</StyledItemLink>
</Link>
</Styled.Item>
</React.Fragment>
Expand Down
16 changes: 5 additions & 11 deletions components/organisms/article_list/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Year = styled.span`
export const Dot = Year

// FIXME: `Warning: Prop `className` did not match. Server: "styled__Time-sc-5t8qkb-4 ennoTY" Client: "styled-sc-5t8qkb-4 gbbMlh"`
export const Time = (rc) => styled(rc)`
export const Time = (Time) => styled(Time)`
background-color: #fff;
display: block;
float: left;
Expand Down Expand Up @@ -87,7 +87,7 @@ export const Date = styled(_ItemLineMonthAndDate)`
background-color: rgba(var(--b-rgb-base), 0.38);
`

export const ItemLink = styled.a`
export const ItemLink = (Month, Date, Title) => styled.a`
${Styles.mixins.linkColors(
'#fff',
`rgba(var(--b-rgb-base), ${Styles.funcs.fibo('sm', 'alpha')})`,
Expand All @@ -102,21 +102,15 @@ export const ItemLink = styled.a`
width: 100%;
&:hover {
/* FIXME: nested selector */
/* ${Month} { */
.sc-month {
${Month} {
background-color: rgba(var(--b-rgb-base), 0.26);
}
/* FIXME: nested selector */
/* ${Date} { */
.sc-date {
${Date} {
background-color: rgba(var(--b-rgb-base), 0.3);
}
/* FIXME: nested selector */
/* ${Title} { */
.sc-title {
${Title} {
background-color: rgba(var(--b-rgb-base), 0.34);
}
}
Expand Down

1 comment on commit 6843fbc

@vercel
Copy link

@vercel vercel bot commented on 6843fbc May 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.