aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/layout
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-04-16 16:08:49 +0200
committerArmand Philippot <git@armandphilippot.com>2022-04-16 16:41:30 +0200
commit5a6e4eea16047083e2de0e91a1b3ed9be8d6eb68 (patch)
treeea0c5390aca73907aade5321f30cb7bf8d3ab1cb /src/components/organisms/layout
parentdaffe6e8b9e2021ffb9d006482143bc4db985f02 (diff)
refactor: support React 18
I replaced the deprecated VFC type with FC type and made all children explicits. Formatjs is still not compatible with React 18 so I need to skip type checking when comitting. There are some type errors because of IntlProvider in Storybook stories.
Diffstat (limited to 'src/components/organisms/layout')
-rw-r--r--src/components/organisms/layout/cards-list.tsx4
-rw-r--r--src/components/organisms/layout/footer.tsx13
-rw-r--r--src/components/organisms/layout/overview.tsx4
-rw-r--r--src/components/organisms/layout/summary.stories.tsx2
-rw-r--r--src/components/organisms/layout/summary.test.tsx2
-rw-r--r--src/components/organisms/layout/summary.tsx77
6 files changed, 56 insertions, 46 deletions
diff --git a/src/components/organisms/layout/cards-list.tsx b/src/components/organisms/layout/cards-list.tsx
index a53df0d..33ffe23 100644
--- a/src/components/organisms/layout/cards-list.tsx
+++ b/src/components/organisms/layout/cards-list.tsx
@@ -3,7 +3,7 @@ import List, {
type ListProps,
} from '@components/atoms/lists/list';
import Card, { type CardProps } from '@components/molecules/layout/card';
-import { VFC } from 'react';
+import { FC } from 'react';
import styles from './cards-list.module.scss';
export type CardsListItem = Omit<
@@ -37,7 +37,7 @@ export type CardsListProps = {
*
* Return a list of Card components.
*/
-const CardsList: VFC<CardsListProps> = ({
+const CardsList: FC<CardsListProps> = ({
coverFit,
items,
kind = 'unordered',
diff --git a/src/components/organisms/layout/footer.tsx b/src/components/organisms/layout/footer.tsx
index c9cb067..15bfa24 100644
--- a/src/components/organisms/layout/footer.tsx
+++ b/src/components/organisms/layout/footer.tsx
@@ -1,7 +1,9 @@
-import Copyright, { CopyrightProps } from '@components/atoms/layout/copyright';
+import Copyright, {
+ type CopyrightProps,
+} from '@components/atoms/layout/copyright';
import BackToTop from '@components/molecules/buttons/back-to-top';
import Nav, { type NavItem } from '@components/molecules/nav/nav';
-import { VFC } from 'react';
+import { FC } from 'react';
import styles from './footer.module.scss';
export type FooterProps = {
@@ -28,12 +30,7 @@ export type FooterProps = {
*
* Renders a footer with copyright and nav;
*/
-const Footer: VFC<FooterProps> = ({
- className,
- copyright,
- navItems,
- topId,
-}) => {
+const Footer: FC<FooterProps> = ({ className, copyright, navItems, topId }) => {
return (
<footer className={`${styles.wrapper} ${className}`}>
<Copyright
diff --git a/src/components/organisms/layout/overview.tsx b/src/components/organisms/layout/overview.tsx
index 3f83342..42d0431 100644
--- a/src/components/organisms/layout/overview.tsx
+++ b/src/components/organisms/layout/overview.tsx
@@ -2,7 +2,7 @@ import ResponsiveImage, {
type ResponsiveImageProps,
} from '@components/molecules/images/responsive-image';
import Meta, { type MetaMap } from '@components/molecules/layout/meta';
-import { VFC } from 'react';
+import { FC } from 'react';
import styles from './overview.module.scss';
export type OverviewProps = {
@@ -15,7 +15,7 @@ export type OverviewProps = {
*
* Render an overview.
*/
-const Overview: VFC<OverviewProps> = ({ cover, meta }) => {
+const Overview: FC<OverviewProps> = ({ cover, meta }) => {
return (
<div className={styles.wrapper}>
{cover && (
diff --git a/src/components/organisms/layout/summary.stories.tsx b/src/components/organisms/layout/summary.stories.tsx
index 5214d70..b33acde 100644
--- a/src/components/organisms/layout/summary.stories.tsx
+++ b/src/components/organisms/layout/summary.stories.tsx
@@ -103,7 +103,7 @@ Summary.args = {
cover: {
alt: 'A cover',
height: 480,
- url: 'http://placeimg.com/640/480',
+ src: 'http://placeimg.com/640/480',
width: 640,
},
excerpt:
diff --git a/src/components/organisms/layout/summary.test.tsx b/src/components/organisms/layout/summary.test.tsx
index ce87c0c..4944805 100644
--- a/src/components/organisms/layout/summary.test.tsx
+++ b/src/components/organisms/layout/summary.test.tsx
@@ -4,7 +4,7 @@ import Summary from './summary';
const cover = {
alt: 'A cover',
height: 480,
- url: 'http://placeimg.com/640/480',
+ src: 'http://placeimg.com/640/480',
width: 640,
};
diff --git a/src/components/organisms/layout/summary.tsx b/src/components/organisms/layout/summary.tsx
index 3624e5d..733a660 100644
--- a/src/components/organisms/layout/summary.tsx
+++ b/src/components/organisms/layout/summary.tsx
@@ -2,18 +2,18 @@ import ButtonLink from '@components/atoms/buttons/button-link';
import Heading, { type HeadingLevel } from '@components/atoms/headings/heading';
import Arrow from '@components/atoms/icons/arrow';
import Link from '@components/atoms/links/link';
-import ResponsiveImage from '@components/molecules/images/responsive-image';
+import ResponsiveImage, {
+ type ResponsiveImageProps,
+} from '@components/molecules/images/responsive-image';
import Meta, { type MetaItem } from '@components/molecules/layout/meta';
-import { VFC } from 'react';
+import { FC } from 'react';
import { useIntl } from 'react-intl';
import styles from './summary.module.scss';
-export type Cover = {
- alt: string;
- height: number;
- url: string;
- width: number;
-};
+export type Cover = Pick<
+ ResponsiveImageProps,
+ 'alt' | 'src' | 'width' | 'height'
+>;
export type RequiredMetaKey = 'publication';
@@ -35,11 +35,29 @@ export type OptionalMeta = {
export type Meta = RequiredMeta & OptionalMeta;
export type SummaryProps = {
+ /**
+ * The post cover.
+ */
cover?: Cover;
+ /**
+ * The post excerpt.
+ */
excerpt: string;
+ /**
+ * The post meta.
+ */
meta: Meta;
+ /**
+ * The post title.
+ */
title: string;
+ /**
+ * The heading level (hn).
+ */
titleLevel?: HeadingLevel;
+ /**
+ * The post url.
+ */
url: string;
};
@@ -48,7 +66,7 @@ export type SummaryProps = {
*
* Render a page summary.
*/
-const Summary: VFC<SummaryProps> = ({
+const Summary: FC<SummaryProps> = ({
cover,
excerpt,
meta,
@@ -57,18 +75,23 @@ const Summary: VFC<SummaryProps> = ({
url,
}) => {
const intl = useIntl();
+ const readMore = intl.formatMessage(
+ {
+ defaultMessage: 'Read more<a11y> about {title}</a11y>',
+ description: 'Summary: read more link',
+ id: 'Zpgv+f',
+ },
+ {
+ title,
+ a11y: (chunks: string) => (
+ <span className="screen-reader-text">{chunks}</span>
+ ),
+ }
+ );
return (
<article className={styles.wrapper}>
- {cover && (
- <ResponsiveImage
- alt={cover.alt}
- src={cover.url}
- width={cover.width}
- height={cover.height}
- className={styles.cover}
- />
- )}
+ {cover && <ResponsiveImage className={styles.cover} {...cover} />}
<header className={styles.header}>
<Link href={url}>
<Heading level={titleLevel} className={styles.title}>
@@ -79,20 +102,10 @@ const Summary: VFC<SummaryProps> = ({
<div className={styles.body}>
{excerpt}
<ButtonLink target={url} className={styles['read-more']}>
- {intl.formatMessage(
- {
- defaultMessage: 'Read more<a11y> about {title}</a11y>',
- description: 'Summary: read more link',
- id: 'Zpgv+f',
- },
- {
- title,
- a11y: (chunks: string) => (
- <span className="screen-reader-text">{chunks}</span>
- ),
- }
- )}
- <Arrow direction="right" />
+ <>
+ {readMore}
+ <Arrow direction="right" />
+ </>
</ButtonLink>
</div>
<footer className={styles.footer}>