-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
289 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/components/ArticleDigest/AuthorSidebar/AuthorSidebar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { TEST_ID } from '~/common/enums' | ||
import { render, screen } from '~/common/utils/test' | ||
import { ArticleDigestAuthorSidebar } from '~/components' | ||
import { MOCK_ARTILCE } from '~/stories/mocks' | ||
|
||
describe('<ArticleDigest.Sidebar>', () => { | ||
it('should render an ArticleDigest.Sidebar', () => { | ||
render(<ArticleDigestAuthorSidebar article={MOCK_ARTILCE} />) | ||
|
||
const $digest = screen.getByTestId(TEST_ID.DIGEST_ARTICLE_AUTHOR_SIDEBAR) | ||
expect($digest).toBeInTheDocument() | ||
|
||
const $title = screen.getByRole('heading', { name: MOCK_ARTILCE.title }) | ||
expect($title).toBeInTheDocument() | ||
}) | ||
}) |
15 changes: 15 additions & 0 deletions
15
src/components/ArticleDigest/AuthorSidebar/Placeholder/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import styles from './styles.module.css' | ||
|
||
const Placeholder = () => { | ||
return ( | ||
<section className={styles.container}> | ||
<section className={styles.title}> | ||
<section className={styles.text}></section> | ||
<section className={styles.text}></section> | ||
</section> | ||
<section className={styles.image}></section> | ||
</section> | ||
) | ||
} | ||
|
||
export default Placeholder |
24 changes: 24 additions & 0 deletions
24
src/components/ArticleDigest/AuthorSidebar/Placeholder/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.container { | ||
@mixin flex-start-space-between; | ||
|
||
margin: var(--spacing-tight) 0; | ||
|
||
& .title { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--spacing-base-tight); | ||
|
||
& .text { | ||
width: 9.375rem; | ||
height: 1rem; | ||
background-color: var(--color-grey-lighter); | ||
} | ||
} | ||
|
||
& .image { | ||
width: 2.75rem; | ||
height: 2.75rem; | ||
background-color: var(--color-grey-lighter); | ||
border-radius: 0.25rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import classNames from 'classnames' | ||
import gql from 'graphql-tag' | ||
|
||
import { TEST_ID } from '~/common/enums' | ||
import { capitalizeFirstLetter, toPath } from '~/common/utils' | ||
import { LinkWrapper, ResponsiveImage } from '~/components' | ||
import { ArticleDigestAuthorSidebarArticleFragment } from '~/gql/graphql' | ||
|
||
import { ArticleDigestTitle, ArticleDigestTitleTextSize } from '../Title' | ||
import Placeholder from './Placeholder' | ||
import styles from './styles.module.css' | ||
|
||
export type ArticleDigestAuthorSidebarProps = { | ||
article: ArticleDigestAuthorSidebarArticleFragment | ||
collectionId?: string | ||
titleTextSize?: ArticleDigestTitleTextSize | ||
titleColor?: 'greyDarker' | 'black' | ||
} | ||
|
||
const fragments = { | ||
article: gql` | ||
fragment ArticleDigestAuthorSidebarArticle on Article { | ||
id | ||
articleState: state | ||
title | ||
slug | ||
mediaHash | ||
cover | ||
...ArticleDigestTitleArticle | ||
} | ||
${ArticleDigestTitle.fragments.article} | ||
`, | ||
} | ||
|
||
export const ArticleDigestAuthorSidebar = ({ | ||
article, | ||
collectionId, | ||
|
||
titleTextSize = 'mdS', | ||
titleColor = 'greyDarker', | ||
}: ArticleDigestAuthorSidebarProps) => { | ||
const { articleState: state } = article | ||
const isBanned = state === 'banned' | ||
const cover = !isBanned ? article.cover : null | ||
const containerClasses = classNames({ | ||
[styles.container]: true, | ||
[styles.hasCover]: !!cover, | ||
}) | ||
const path = toPath({ | ||
page: 'articleDetail', | ||
article, | ||
collectionId, | ||
}) | ||
|
||
const headerClasses = classNames({ | ||
[styles[`textColor${capitalizeFirstLetter(titleColor)}`]]: !!titleColor, | ||
}) | ||
|
||
return ( | ||
<section | ||
className={containerClasses} | ||
data-test-id={TEST_ID.DIGEST_ARTICLE_AUTHOR_SIDEBAR} | ||
> | ||
<header className={headerClasses}> | ||
<ArticleDigestTitle | ||
article={article} | ||
textSize={titleTextSize} | ||
collectionId={collectionId} | ||
textWeight="normal" | ||
is="h3" | ||
/> | ||
</header> | ||
|
||
{cover && ( | ||
<LinkWrapper {...path} disabled={isBanned}> | ||
<aside className={styles.cover}> | ||
<ResponsiveImage | ||
url={cover} | ||
width={44} | ||
height={44} | ||
disableAnimation={true} | ||
/> | ||
</aside> | ||
</LinkWrapper> | ||
)} | ||
</section> | ||
) | ||
} | ||
|
||
ArticleDigestAuthorSidebar.Placeholder = Placeholder | ||
ArticleDigestAuthorSidebar.fragments = fragments |
47 changes: 47 additions & 0 deletions
47
src/components/ArticleDigest/AuthorSidebar/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.container { | ||
margin-top: var(--spacing-tight); | ||
margin-bottom: var(--spacing-tight); | ||
|
||
@mixin flex-start-space-between; | ||
|
||
& header { | ||
flex-grow: 1; | ||
|
||
& h3 { | ||
line-height: 1.375rem; | ||
} | ||
|
||
&.textColorBlack { | ||
& a { | ||
color: var(--color-black); | ||
} | ||
} | ||
|
||
&.textColorGreyDarker { | ||
& a { | ||
color: var(--color-grey-darker); | ||
} | ||
} | ||
} | ||
|
||
&.hasCover { | ||
position: relative; | ||
min-height: 2.75rem; | ||
padding-right: calc(2.75rem + var(--spacing-loose)); | ||
|
||
& .cover { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
display: initial; | ||
width: 2.75rem; | ||
height: 2.75rem; | ||
|
||
& img { | ||
@mixin object-fit-cover; | ||
|
||
border-radius: var(--spacing-xx-tight); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
src/views/ArticleDetail/AuthorSidebar/Author/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.