ui(resources): tweak styling of resource list

This commit is contained in:
Jean-Philippe Sirois
2020-05-26 03:49:17 -04:00
parent bf3df759af
commit c83701ec58
3 changed files with 25 additions and 30 deletions
+7 -3
View File
@@ -5,13 +5,17 @@ interface ILinkProps {
to: string to: string
} }
export const Link: FC<ILinkProps> = ({ children, to }) => { export const Link: FC<ILinkProps> = ({ children, to, ...props }) => {
if (!to.match(/^(https?:\/\/)/)) { if (!to.match(/^(https?:\/\/)/)) {
return <SC.LinkInternal to={to}>{children}</SC.LinkInternal> return (
<SC.LinkInternal {...props} to={to}>
{children}
</SC.LinkInternal>
)
} }
return ( return (
<SC.LinkExternal rel="noreferrer" href={to} target="_blank"> <SC.LinkExternal {...props} rel="noreferrer" href={to} target="_blank">
{children} {children}
</SC.LinkExternal> </SC.LinkExternal>
) )
+5 -5
View File
@@ -1,3 +1,4 @@
import cx from "classnames"
import { graphql, useStaticQuery } from "gatsby" import { graphql, useStaticQuery } from "gatsby"
import sort from "ramda/es/sort" import sort from "ramda/es/sort"
import React, { FC, HTMLAttributes, memo, useMemo } from "react" import React, { FC, HTMLAttributes, memo, useMemo } from "react"
@@ -34,10 +35,7 @@ function plantTree(item: IFileOrFolder, single?: boolean) {
return ( return (
<SC.PageLink key={item.title} to={path}> <SC.PageLink key={item.title} to={path}>
{cleanedUpPath.map((node) => ( {cleanedUpPath.map((node) => humanize(node)).join(" / ")}
// TODO: use helper to format path
<SC.NodePart key={node}>{humanize(node)}</SC.NodePart>
))}
</SC.PageLink> </SC.PageLink>
) )
} }
@@ -61,7 +59,9 @@ const Language = memo(
return ( return (
<SC.TreeWrapper> <SC.TreeWrapper>
{!single && <SC.LanguageLabel>{humanize(item.title)}</SC.LanguageLabel>} {!single && <SC.LanguageLabel>{humanize(item.title)}</SC.LanguageLabel>}
<SC.Children>{children.map((node) => plantTree(node))}</SC.Children> <SC.Children className={cx({ "is-single": single })}>
{children.map((node) => plantTree(node))}
</SC.Children>
</SC.TreeWrapper> </SC.TreeWrapper>
) )
} }
+13 -22
View File
@@ -1,6 +1,6 @@
import { Link } from "gatsby"
import { transparentize } from "polished" import { transparentize } from "polished"
import styled from "styled-components" import styled from "styled-components"
import { Link } from "../Link"
export const ResourcesListWrapper = styled.div` export const ResourcesListWrapper = styled.div`
box-sizing: border-box; box-sizing: border-box;
@@ -14,6 +14,10 @@ export const Children = styled.div`
flex-direction: column; flex-direction: column;
align-items: flex-start; align-items: flex-start;
overflow: hidden; overflow: hidden;
&.is-single {
padding-left: 0;
}
` `
export const Label = styled.div` export const Label = styled.div`
@@ -65,7 +69,10 @@ export const TreeWrapper = styled.div`
flex-direction: column; flex-direction: column;
width: 100%; width: 100%;
font-size: 16px; font-size: 16px;
margin: 32px 0;
& + & {
margin-top: 32px;
}
${Children} { ${Children} {
display: flex; display: flex;
@@ -77,27 +84,11 @@ export const TreeWrapper = styled.div`
` `
export const PageLink = styled(Link)` export const PageLink = styled(Link)`
display: block; font-weight: 400;
padding: 2px 0; display: inline-block;
color: ${(props) => props.theme.sidebar.foreground}; font-size: 18px;
align-self: flex-start;
text-decoration: none;
border-bottom: 1px solid transparent;
&:hover {
border-color: ${(props) =>
transparentize(0.7, props.theme.sidebar.foreground)};
}
& + & { & + & {
margin-top: 4px; margin-top: 8px;
}
`
export const NodePart = styled.span`
& + &::before {
content: "/";
opacity: 0.3;
margin: 0 4px;
} }
` `