aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/organisms/widgets
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/widgets
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/widgets')
-rw-r--r--src/components/organisms/widgets/image-widget.tsx34
-rw-r--r--src/components/organisms/widgets/links-list-widget.tsx9
-rw-r--r--src/components/organisms/widgets/sharing.tsx6
3 files changed, 20 insertions, 29 deletions
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<ImageWidgetProps> = ({
+const ImageWidget: FC<ImageWidgetProps> = ({
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<WidgetProps, 'level' | 'title'> &
*
* Render a list of links inside a widget.
*/
-const LinksListWidget: VFC<LinksListWidgetProps> = ({
+const LinksListWidget: FC<LinksListWidgetProps> = ({
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<WidgetProps, 'children'> & {
/**
* 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<SharingProps> = ({ data, media, ...props }) => {
+const Sharing: FC<SharingProps> = ({ data, media, ...props }) => {
const intl = useIntl();
/**