aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/templates/page
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-09 18:19:38 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-09 19:41:02 +0200
commit0d59a6d2995b4119865271ed1908ede0bb96497c (patch)
tree67688e41b7aa253aa58cc08aa360431b07382f9d /src/components/templates/page
parent339c6957fe92c4ec1809159f09c55201d3794c18 (diff)
refactor: rewrite DescriptionList and Meta components
The meta can have different layout. The previous implementation was not enough to easily change the layout. Also, I prefer to restrict the meta types and it prevents me to repeat myself for the labels.
Diffstat (limited to 'src/components/templates/page')
-rw-r--r--src/components/templates/page/page-layout.stories.tsx107
-rw-r--r--src/components/templates/page/page-layout.tsx14
2 files changed, 50 insertions, 71 deletions
diff --git a/src/components/templates/page/page-layout.stories.tsx b/src/components/templates/page/page-layout.stories.tsx
index 1f72cb0..b4b0d68 100644
--- a/src/components/templates/page/page-layout.stories.tsx
+++ b/src/components/templates/page/page-layout.stories.tsx
@@ -6,7 +6,6 @@ import PostsList from '@components/organisms/layout/posts-list';
import LinksListWidget from '@components/organisms/widgets/links-list-widget';
import Sharing from '@components/organisms/widgets/sharing';
import { ComponentMeta, ComponentStory } from '@storybook/react';
-import { IntlProvider } from 'react-intl';
import PageLayoutComponent from './page-layout';
/**
@@ -157,15 +156,6 @@ export default {
},
},
},
- decorators: [
- (Story) => (
- <IntlProvider locale="en">
- <div id="__next">
- <Story />
- </div>
- </IntlProvider>
- ),
- ],
parameters: {
layout: 'fullscreen',
},
@@ -231,7 +221,6 @@ SinglePage.args = {
'linkedin',
'twitter',
]}
- title="Share"
level={2}
expanded={true}
/>,
@@ -320,22 +309,19 @@ Post.args = {
title: pageTitle,
intro: pageIntro,
headerMeta: {
- publication: { name: 'Published on:', value: 'March 14th 2020' },
- categories: {
- name: 'Categories:',
- value: [
- <Link key="cat1" href="#">
- Cat 1
- </Link>,
- <Link key="cat2" href="#">
- Cat 2
- </Link>,
- ],
- },
+ publication: { date: '2020-03-14' },
+ thematics: [
+ <Link key="cat1" href="#">
+ Cat 1
+ </Link>,
+ <Link key="cat2" href="#">
+ Cat 2
+ </Link>,
+ ],
},
footerMeta: {
- tags: {
- name: 'Read more about:',
+ custom: {
+ label: 'Read more about:',
value: <ButtonLink target="#">Topic 1</ButtonLink>,
},
},
@@ -379,7 +365,6 @@ Post.args = {
'linkedin',
'twitter',
]}
- title="Share"
level={2}
expanded={true}
/>,
@@ -400,23 +385,17 @@ const posts = [
'Esse et voluptas sapiente modi impedit unde et. Ducimus nulla ea impedit sit placeat nihil assumenda. Rem est fugiat amet quo hic. Corrupti fuga quod animi autem dolorem ullam corrupti vel aut.',
id: 'post-1',
meta: {
- publication: {
- name: 'Published on:',
- value: '2022-02-26T00:42:02',
- },
- readingTime: { name: 'Reading time:', value: '5 minutes' },
- categories: {
- name: 'Categories:',
- value: [
- <a key="cat-1" href="#">
- Cat 1
- </a>,
- <a key="cat-2" href="#">
- Cat 2
- </a>,
- ],
- },
- comments: { name: 'Comments:', value: '1 comment' },
+ publication: { date: '2022-02-26' },
+ readingTime: '5 minutes',
+ categories: [
+ <a key="cat-1" href="#">
+ Cat 1
+ </a>,
+ <a key="cat-2" href="#">
+ Cat 2
+ </a>,
+ ],
+ commentsCount: '1 comment',
},
title: 'Ratione velit fuga',
url: '#',
@@ -435,19 +414,15 @@ const posts = [
id: 'post-2',
meta: {
publication: {
- name: 'Published on:',
- value: '2022-02-20T10:40:00',
+ date: '2022-02-20',
},
- readingTime: { name: 'Reading time:', value: '8 minutes' },
- categories: {
- name: 'Categories:',
- value: [
- <a key="cat-2" href="#">
- Cat 2
- </a>,
- ],
- },
- comments: { name: 'Comments:', value: '0 comments' },
+ readingTime: '8 minutes',
+ categories: [
+ <a key="cat-2" href="#">
+ Cat 2
+ </a>,
+ ],
+ comments: '0 comments',
},
title: 'Debitis laudantium laudantium',
url: '#',
@@ -458,19 +433,15 @@ const posts = [
id: 'post-3',
meta: {
publication: {
- name: 'Published on:',
- value: '2021-12-20T15:12:02',
- },
- readingTime: { name: 'Reading time:', value: '3 minutes' },
- categories: {
- name: 'Categories:',
- value: [
- <a key="cat-1" href="#">
- Cat 1
- </a>,
- ],
+ date: '2021-12-20',
},
- comments: { name: 'Comments:', value: '3 comments' },
+ readingTime: '3 minutes',
+ categories: [
+ <a key="cat-1" href="#">
+ Cat 1
+ </a>,
+ ],
+ comments: '3 comments',
},
title: 'Quaerat ut corporis',
url: '#',
@@ -502,7 +473,7 @@ export const Blog = Template.bind({});
Blog.args = {
breadcrumb: postsListBreadcrumb,
title: 'Blog',
- headerMeta: { total: { name: 'Total:', value: `${posts.length} posts` } },
+ headerMeta: { total: `${posts.length} posts` },
children: (
<>
<PostsList posts={posts} byYear={true} />
diff --git a/src/components/templates/page/page-layout.tsx b/src/components/templates/page/page-layout.tsx
index 24c4e50..ac021ba 100644
--- a/src/components/templates/page/page-layout.tsx
+++ b/src/components/templates/page/page-layout.tsx
@@ -133,9 +133,17 @@ const PageLayout: FC<PageLayoutProps> = ({
)}
</Sidebar>
)}
- <div ref={bodyRef} className={styles.body}>
- {children}
- </div>
+ {typeof children === 'string' ? (
+ <div
+ ref={bodyRef}
+ className={styles.body}
+ dangerouslySetInnerHTML={{ __html: children }}
+ />
+ ) : (
+ <div ref={bodyRef} className={styles.body}>
+ {children}
+ </div>
+ )}
<PageFooter meta={footerMeta} className={styles.footer} />
<Sidebar className={`${styles.sidebar} ${styles['sidebar--last']}`}>
{widgets}