Skip to content

Commit

Permalink
[C] refactor sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff committed Jul 18, 2024
1 parent c60cf8d commit a34a03c
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 188 deletions.
35 changes: 0 additions & 35 deletions components/layout/MediaAside/Tags.js

This file was deleted.

87 changes: 0 additions & 87 deletions components/layout/MediaAside/styles.js

This file was deleted.

21 changes: 21 additions & 0 deletions components/page/Aside/Section/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import PropTypes from "prop-types";
import * as Styled from "./styles";

const AsideSection = ({ title, children, className }) => {
return (
<Styled.Section {...{ className }}>
{title && <Styled.Title>{title}</Styled.Title>}
{children}
</Styled.Section>
);
};

AsideSection.displayName = "Page.Aside.Section";

AsideSection.propTypes = {
children: PropTypes.node,
title: PropTypes.string,
className: PropTypes.string,
};

export default AsideSection;
25 changes: 25 additions & 0 deletions components/page/Aside/Section/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import styled from "styled-components";

export const Section = styled.section``;

export const Title = styled.h3`
position: relative;
padding-right: 1em;
padding-bottom: 0.5em;
margin-bottom: 0.5em;
border-bottom: 8px solid var(--color-background-accent-aside);
& svg {
position: absolute;
top: 4px;
right: 0;
display: block;
width: 32px;
height: 32px;
padding: 8px;
overflow: visible;
background-color: var(--turquoise60);
border-radius: 50%;
fill: var(--white);
}
`;
40 changes: 40 additions & 0 deletions components/page/Aside/Tags/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import PropTypes from "prop-types";
import Link from "next/link";
import { useTranslation } from "react-i18next";
import AsideSection from "../Section";
import * as Styled from "./styles";

export default function Tags({ tags, rootHomeLink }) {
const { t } = useTranslation();

if (!tags) return null;
if (tags.length <= 0) return null;

return (
<AsideSection title={t(`tags`)}>
<Styled.TagList>
{tags.map((tag, i) => {
if (rootHomeLink?.uri && tag.slug) {
return (
<Styled.Tag key={i}>
<Link
prefetch={false}
href={`/${rootHomeLink?.uri}?search=${tag.slug}`}
>
{`#${tag.title}`}
</Link>
</Styled.Tag>
);
}
})}
</Styled.TagList>
</AsideSection>
);
}

Tags.displayName = "Page.Aside.Tags";

Tags.propTypes = {
tags: PropTypes.array,
rootHomeLink: PropTypes.object,
};
8 changes: 8 additions & 0 deletions components/page/Aside/Tags/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import styled from "styled-components";

export const TagList = styled.ul``;

export const Tag = styled.li`
display: inline-block;
margin-inline-end: 1ch;
`;
22 changes: 22 additions & 0 deletions components/page/Aside/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import PropTypes from "prop-types";
import Tags from "./Tags";
import * as Styled from "./styles";

const Aside = ({ children, tags = [], rootHomeLink }) => {
return (
<Styled.Aside>
{children}
{tags.length > 0 && rootHomeLink && <Tags {...{ tags, rootHomeLink }} />}
</Styled.Aside>
);
};

Aside.displayName = "Page.Aside";

Aside.propTypes = {
children: PropTypes.node,
tags: PropTypes.array,
rootHomeLink: PropTypes.object,
};

export default Aside;
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { ResponsiveImage, Figure } from "@rubin-epo/epo-react-lib";
import ReleaseAssets from "./ReleaseAssets";
import * as Styled from "./styles";

export default function MediaAssets({
contentBlockAssets,
releaseImages,
releaseVideos,
export default function MediaSection({
contentBlockAssets = [],
releaseImages = [],
releaseVideos = [],
}) {
const { t } = useTranslation();

Expand All @@ -22,8 +22,7 @@ export default function MediaAssets({
return null;

return (
<Styled.AsideSecondary>
<h3>{t(`media`)}</h3>
<Styled.MediaSection title={t(`media`)}>
{contentBlockAssets.map((asset, i) => {
if (asset.image?.[0].url) {
return (
Expand All @@ -35,13 +34,12 @@ export default function MediaAssets({
);
}
})}
<ReleaseAssets assets={releaseImages} />
<ReleaseAssets assets={releaseVideos} />
</Styled.AsideSecondary>
<ReleaseAssets assets={[...releaseImages, ...releaseVideos]} />
</Styled.MediaSection>
);
}

MediaAssets.propTypes = {
MediaSection.propTypes = {
contentBlockAssets: PropTypes.array,
releaseImages: PropTypes.array,
releaseVideos: PropTypes.array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
IconComposer,
Figure,
} from "@rubin-epo/epo-react-lib";
import Tags from "./Tags";
import MediaAssets from "./MediaAssets";
import * as Styled from "./styles";
import MediaAssets from "./MediaSection";
import Aside from "../../index";
import AsideSection from "../../Section";

export default function MediaAside({
manualAssets,
Expand All @@ -23,9 +23,9 @@ export default function MediaAside({
);

return (
<Styled.Aside>
<Aside {...{ tags, rootHomeLink }}>
{manualAssets?.length > 0 && (
<Styled.AsidePrimary>
<AsideSection>
{manualAssets.map((a, i) => {
if (a.assetHeader) {
return (
Expand Down Expand Up @@ -78,15 +78,14 @@ export default function MediaAside({
}
}
})}
</Styled.AsidePrimary>
</AsideSection>
)}
<MediaAssets
contentBlockAssets={contentBlockAssets}
releaseImages={releaseImages}
releaseVideos={releaseVideos}
/>
<Tags tags={tags} rootHomeLink={rootHomeLink} />
</Styled.Aside>
</Aside>
);
}

Expand Down
31 changes: 31 additions & 0 deletions components/page/Aside/patterns/Media/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import styled from "styled-components";
import AsideSection from "../../Section";

export const AsidePrimary = styled.div`
h3 {
&:first-of-type {
border-bottom: 8px solid var(--turquoise60);
svg {
position: absolute;
top: 4px;
right: 0;
display: block;
width: 32px;
height: 32px;
padding: 8px;
overflow: visible;
background-color: var(--turquoise60);
border-radius: 50%;
fill: var(--white);
}
}
}
`;

export const MediaSection = styled(AsideSection)`
& > a {
display: block;
margin-block-start: 1em;
}
`;
Loading

0 comments on commit a34a03c

Please sign in to comment.