From 00f147a7a687d5772bcc538bc606cfff972178cd Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 12 Oct 2023 17:24:13 +0200 Subject: feat(components): add a Time component Instead of using helpers functions to format the date each time we need to use a time element, it makes more sense to create a new component dedicated to this task. --- src/components/atoms/layout/copyright.tsx | 39 +++--- src/components/atoms/layout/index.ts | 1 + src/components/atoms/layout/time/index.ts | 1 + src/components/atoms/layout/time/time.stories.tsx | 32 +++++ src/components/atoms/layout/time/time.test.tsx | 39 ++++++ src/components/atoms/layout/time/time.tsx | 136 +++++++++++++++++++++ src/components/organisms/layout/comment.fixture.ts | 4 - src/components/organisms/layout/comment.test.tsx | 10 +- src/components/organisms/layout/comment.tsx | 20 +-- src/components/organisms/layout/summary.tsx | 18 +-- src/i18n/en.json | 8 +- src/i18n/fr.json | 8 +- src/pages/article/[slug].tsx | 18 +-- src/pages/cv.tsx | 18 +-- src/pages/index.tsx | 15 +-- src/pages/mentions-legales.tsx | 18 +-- src/pages/projets/[slug].tsx | 22 +--- src/pages/sujet/[slug].tsx | 18 +-- src/pages/thematique/[slug].tsx | 18 +-- src/utils/helpers/dates.ts | 40 ------ src/utils/helpers/index.ts | 1 - 21 files changed, 263 insertions(+), 221 deletions(-) create mode 100644 src/components/atoms/layout/time/index.ts create mode 100644 src/components/atoms/layout/time/time.stories.tsx create mode 100644 src/components/atoms/layout/time/time.test.tsx create mode 100644 src/components/atoms/layout/time/time.tsx delete mode 100644 src/utils/helpers/dates.ts (limited to 'src') diff --git a/src/components/atoms/layout/copyright.tsx b/src/components/atoms/layout/copyright.tsx index c60ff8b..3d56059 100644 --- a/src/components/atoms/layout/copyright.tsx +++ b/src/components/atoms/layout/copyright.tsx @@ -1,5 +1,6 @@ import type { FC, ReactNode } from 'react'; import styles from './copyright.module.scss'; +import { Time } from './time'; export type CopyrightDates = { /** @@ -32,26 +33,18 @@ export type CopyrightProps = { * * Renders a copyright information (owner, dates, license icon). */ -export const Copyright: FC = ({ owner, dates, icon }) => { - const getFormattedDate = (date: string) => { - const datetime = new Date(date).toISOString(); - - return ; - }; - - return ( -
- {owner} - {icon} - {getFormattedDate(dates.start)} - {dates.end ? ( - <> - - - {getFormattedDate(dates.end)} - - ) : ( - '' - )} -
- ); -}; +export const Copyright: FC = ({ owner, dates, icon }) => ( +
+ {owner} + {icon} +
+); diff --git a/src/components/atoms/layout/index.ts b/src/components/atoms/layout/index.ts index 3f2f8dc..c37ff02 100644 --- a/src/components/atoms/layout/index.ts +++ b/src/components/atoms/layout/index.ts @@ -6,3 +6,4 @@ export * from './header'; export * from './main'; export * from './nav'; export * from './section'; +export * from './time'; diff --git a/src/components/atoms/layout/time/index.ts b/src/components/atoms/layout/time/index.ts new file mode 100644 index 0000000..47e4e1f --- /dev/null +++ b/src/components/atoms/layout/time/index.ts @@ -0,0 +1 @@ +export * from './time'; diff --git a/src/components/atoms/layout/time/time.stories.tsx b/src/components/atoms/layout/time/time.stories.tsx new file mode 100644 index 0000000..d534f14 --- /dev/null +++ b/src/components/atoms/layout/time/time.stories.tsx @@ -0,0 +1,32 @@ +import type { ComponentMeta, ComponentStory } from '@storybook/react'; +import { Time } from './time'; + +/** + * Time - Storybook Meta + */ +export default { + title: 'Atoms/Layout/Time', + component: Time, + argTypes: { + date: { + control: { + type: 'text', + }, + description: 'A valid date string.', + type: { + name: 'string', + required: true, + }, + }, + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) =>