From 5a6e4eea16047083e2de0e91a1b3ed9be8d6eb68 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 16 Apr 2022 16:08:49 +0200 Subject: 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. --- src/components/organisms/widgets/image-widget.tsx | 34 +++++++--------------- .../organisms/widgets/links-list-widget.tsx | 9 ++++-- src/components/organisms/widgets/sharing.tsx | 6 ++-- 3 files changed, 20 insertions(+), 29 deletions(-) (limited to 'src/components/organisms/widgets') diff --git a/src/components/organisms/widgets/image-widget.tsx b/src/components/organisms/widgets/image-widget.tsx index 928d5ea..ba04c6a 100644 --- a/src/components/organisms/widgets/image-widget.tsx +++ b/src/components/organisms/widgets/image-widget.tsx @@ -1,28 +1,16 @@ -import ResponsiveImage from '@components/molecules/images/responsive-image'; +import ResponsiveImage, { + type ResponsiveImageProps, +} from '@components/molecules/images/responsive-image'; import Widget, { type WidgetProps } from '@components/molecules/layout/widget'; -import { VFC } from 'react'; +import { FC } from 'react'; import styles from './image-widget.module.scss'; export type Alignment = 'left' | 'center' | 'right'; -export type Image = { - /** - * An alternative text for the image. - */ - alt: string; - /** - * The image height. - */ - height: number; - /** - * The image source. - */ - src: string; - /** - * The image width. - */ - width: number; -}; +export type Image = Pick< + ResponsiveImageProps, + 'alt' | 'height' | 'src' | 'width' +>; export type ImageWidgetProps = Pick< WidgetProps, @@ -35,7 +23,7 @@ export type ImageWidgetProps = Pick< /** * Add a caption to the image. */ - description?: string; + description?: ResponsiveImageProps['caption']; /** * An object describing the image. */ @@ -43,7 +31,7 @@ export type ImageWidgetProps = Pick< /** * Add a link to the image. */ - url?: string; + url?: ResponsiveImageProps['target']; }; /** @@ -51,7 +39,7 @@ export type ImageWidgetProps = Pick< * * Renders a widget that print an image and an optional text. */ -const ImageWidget: VFC = ({ +const ImageWidget: FC = ({ alignment = 'left', description, img, diff --git a/src/components/organisms/widgets/links-list-widget.tsx b/src/components/organisms/widgets/links-list-widget.tsx index 155354e..559d0b6 100644 --- a/src/components/organisms/widgets/links-list-widget.tsx +++ b/src/components/organisms/widgets/links-list-widget.tsx @@ -1,8 +1,11 @@ import Link from '@components/atoms/links/link'; -import List, { ListProps, type ListItem } from '@components/atoms/lists/list'; +import List, { + type ListProps, + type ListItem, +} from '@components/atoms/lists/list'; import Widget, { type WidgetProps } from '@components/molecules/layout/widget'; import { slugify } from '@utils/helpers/slugify'; -import { VFC } from 'react'; +import { FC } from 'react'; import styles from './links-list-widget.module.scss'; export type LinksListItems = { @@ -33,7 +36,7 @@ export type LinksListWidgetProps = Pick & * * Render a list of links inside a widget. */ -const LinksListWidget: VFC = ({ +const LinksListWidget: FC = ({ items, kind = 'unordered', ...props diff --git a/src/components/organisms/widgets/sharing.tsx b/src/components/organisms/widgets/sharing.tsx index ccd3a21..571c1a4 100644 --- a/src/components/organisms/widgets/sharing.tsx +++ b/src/components/organisms/widgets/sharing.tsx @@ -2,7 +2,7 @@ import SharingLink, { type SharingMedium, } from '@components/atoms/links/sharing-link'; import Widget, { type WidgetProps } from '@components/molecules/layout/widget'; -import { VFC } from 'react'; +import { FC } from 'react'; import { useIntl } from 'react-intl'; import styles from './sharing.module.scss'; @@ -21,7 +21,7 @@ export type SharingData = { url: string; }; -export type SharingProps = WidgetProps & { +export type SharingProps = Omit & { /** * The page data to share. */ @@ -37,7 +37,7 @@ export type SharingProps = WidgetProps & { * * Render a list of sharing links inside a widget. */ -const Sharing: VFC = ({ data, media, ...props }) => { +const Sharing: FC = ({ data, media, ...props }) => { const intl = useIntl(); /** -- cgit v1.2.3