-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(blog) Migrate BlogCard component #5323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ovflowd
merged 9 commits into
nodejs:major/website-redesign
from
Harkunwar:feat/migrate-blog-card-component
Apr 25, 2023
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8de1cc4
feat(blog) Migrate BlogCard component
Harkunwar 4152117
Merge branch 'major/website-redesign' into feat/migrate-blog-card-com…
mikeesto f3319e0
feat(blog): Fix prettier
Harkunwar 0d0cf55
feat(blog): Format Date
Harkunwar 600a5be
feat(blog): making requested review changes
Harkunwar 8624673
feat(blog): update snapshot
Harkunwar d239278
feat(blog): Mock useLocale and make readingTime optional
Harkunwar 02e556b
feat(blog): added todo
Harkunwar 6039b99
Merge branch 'major/website-redesign' into feat/migrate-blog-card-com…
Harkunwar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
components/Blog/BlogCard/__tests__/__snapshots__/index.test.tsx.snap
This file contains hidden or 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,43 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`BlogCard component renders correctly 1`] = ` | ||
| <div> | ||
| <div | ||
| class="blogCard" | ||
| > | ||
| <div | ||
| class="title" | ||
| > | ||
| <a | ||
| href="/en/blog/category-mock/sample-blog" | ||
| > | ||
| Sample Test Blog | ||
| </a> | ||
| <div | ||
| class="metadata" | ||
| > | ||
| <a | ||
| class="category" | ||
| href="/en/blog/category-mock" | ||
| > | ||
| category-mock | ||
| </a> | ||
| </div> | ||
| </div> | ||
| <div | ||
| class="content" | ||
| > | ||
| <h4> | ||
| 4/21/2023 | ||
| </h4> | ||
| <p> | ||
| by | ||
|
|
||
| <span> | ||
| Bat Man | ||
| </span> | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| `; |
This file contains hidden or 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,38 @@ | ||
| import { render } from '@testing-library/react'; | ||
| import { LocaleProvider } from '../../../../providers/localeProvider'; | ||
| import englishMessages from '../../../../i18n/locales/en.json'; | ||
| import BlogCard from '..'; | ||
|
|
||
| jest.mock('next/router', () => ({ | ||
| useRouter: jest.fn().mockReturnValue({}), | ||
| })); | ||
|
|
||
| describe('BlogCard component', () => { | ||
| it('renders correctly', () => { | ||
| const { container } = render( | ||
| <LocaleProvider | ||
| i18nData={{ | ||
| currentLocale: { | ||
| code: 'en', | ||
| localName: 'English', | ||
| name: 'English', | ||
| langDir: 'ltr', | ||
| dateFormat: 'MM.DD.YYYY', | ||
| hrefLang: 'en-US', | ||
| enabled: true, | ||
| }, | ||
| localeMessages: englishMessages, | ||
| }} | ||
| > | ||
| <BlogCard | ||
| author="Bat Man" | ||
| category="category-mock" | ||
| date="2023-04-21 23:40:56.77" | ||
| slug="/blog/category-mock/sample-blog" | ||
| title="Sample Test Blog" | ||
| /> | ||
| </LocaleProvider> | ||
| ); | ||
| expect(container).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,71 @@ | ||
| .blogCard { | ||
| display: flex; | ||
| flex-direction: column; | ||
| padding: var(--space-32) var(--space-24) var(--space-32) 0; | ||
|
|
||
| @media (max-width: 900px) { | ||
| padding: var(--space-12) var(--space-24); | ||
| } | ||
|
|
||
| .title { | ||
| background-color: var(--color-blog-card-background); | ||
| border-radius: 5px; | ||
| display: flex; | ||
| flex: 1 1 0px; | ||
| flex-direction: column; | ||
| padding: 1rem 1.5rem; | ||
|
|
||
| a { | ||
| font-size: 2em; | ||
| margin-bottom: 10px; | ||
| text-decoration: none; | ||
|
|
||
| &:hover { | ||
| text-decoration: underline; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .metadata { | ||
| align-self: flex-start; | ||
| background-color: var(--color-dropdown-hover); | ||
| border-radius: 1rem; | ||
| display: flex; | ||
| margin-top: auto; | ||
| padding: 0.25rem; | ||
|
|
||
| span, | ||
| a { | ||
| color: var(--color-text-high-contrast); | ||
| font-size: var(--font-size-body3); | ||
| padding: 0.125rem 0.5rem; | ||
|
|
||
| &.category { | ||
| background-color: var(--color-dropdown-background); | ||
| border-radius: 1rem; | ||
| margin: 0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .content { | ||
| justify-self: flex-end; | ||
|
|
||
| h4 { | ||
| margin: 0; | ||
| margin-top: 7px; | ||
| opacity: 0.7; | ||
| } | ||
|
|
||
| p { | ||
| margin: 7px 0; | ||
| opacity: 0.8; | ||
|
|
||
| li { | ||
| display: inline; | ||
| list-style: none; | ||
| margin: 0 3px; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,17 @@ | ||
| import BlockQuote from './index'; | ||
| import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
|
||
| type Story = StoryObj<typeof BlockQuote>; | ||
| type Meta = MetaObj<typeof BlockQuote>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| author: 'Bat Man', | ||
| category: 'category-mock', | ||
| date: '2023-04-21 23:40:56.77', | ||
| slug: '/blog/category-mock/sample-blog', | ||
| title: 'Sample Test Blog', | ||
| }, | ||
| }; | ||
|
|
||
| export default { component: BlockQuote } as Meta; |
This file contains hidden or 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,46 @@ | ||
| import { FormattedDate, FormattedMessage } from 'react-intl'; | ||
| import styles from './index.module.scss'; | ||
| import LocalizedLink from '../../LocalizedLink'; | ||
| import navigation from '../../../navigation.json'; | ||
| import type { BlogPost } from '../../../types'; | ||
| import type { FC } from 'react'; | ||
|
|
||
| const getBlogCategoryUrl = (category: string): string => | ||
| `${navigation.blog.link}/${category}/`; | ||
|
|
||
| const getBlogPostUrl = (slug: string) => | ||
| slug.endsWith('/') ? slug : `${slug}/`; | ||
|
ovflowd marked this conversation as resolved.
Outdated
|
||
|
|
||
| type Props = {} & Omit<BlogPost, 'file'>; | ||
|
ovflowd marked this conversation as resolved.
Outdated
|
||
|
|
||
| const BlogCard: FC<Props> = ({ title, author, date, category, slug }) => { | ||
| const blogCategoryUrl = getBlogCategoryUrl(category); | ||
|
|
||
| return ( | ||
| <div className={styles.blogCard}> | ||
| <div className={styles.title}> | ||
| <LocalizedLink href={getBlogPostUrl(slug)}>{title}</LocalizedLink> | ||
| <div className={styles.metadata}> | ||
| {category && ( | ||
| <LocalizedLink className={styles.category} href={blogCategoryUrl}> | ||
|
ovflowd marked this conversation as resolved.
Outdated
|
||
| {category} | ||
| </LocalizedLink> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <div className={styles.content}> | ||
| <h4> | ||
| <FormattedDate value={date} /> | ||
| </h4> | ||
| {author && ( | ||
| <p> | ||
| <FormattedMessage id="components.blog.blogCard.author.by" />{' '} | ||
| <span>{author}</span> | ||
| </p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default BlogCard; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.