From e331106e56d59a8b987230860b66214139c12ef6 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 13 Nov 2023 18:46:31 +0100 Subject: refactor(components): rewrite ImageWidget component * remove `imageClassName` prop * replace `image` prop with `img` and expect an image instead of an object * remove `alignment prop` * remove useless CSS --- .../widgets/image-widget/image-widget.tsx | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/components/organisms/widgets/image-widget/image-widget.tsx (limited to 'src/components/organisms/widgets/image-widget/image-widget.tsx') diff --git a/src/components/organisms/widgets/image-widget/image-widget.tsx b/src/components/organisms/widgets/image-widget/image-widget.tsx new file mode 100644 index 0000000..23e6775 --- /dev/null +++ b/src/components/organisms/widgets/image-widget/image-widget.tsx @@ -0,0 +1,47 @@ +import { + forwardRef, + type ForwardRefRenderFunction, + type ReactNode, +} from 'react'; +import { Figure, Link, type FigureProps } from '../../../atoms'; +import { Collapsible, type CollapsibleProps } from '../../../molecules'; +import styles from './image-widget.module.scss'; + +export type ImageWidgetProps = Omit & { + /** + * Add a caption to the image. + */ + description?: FigureProps['caption']; + /** + * The image. + */ + img: ReactNode; + /** + * Add a link to the image. + */ + url?: string; +}; + +const ImageWidgetWithRef: ForwardRefRenderFunction< + HTMLDivElement, + ImageWidgetProps +> = ({ description, img, isCollapsed, url, ...props }, ref) => ( + +
+ {url ? ( + + {img} + + ) : ( + img + )} +
+
+); + +/** + * ImageWidget component + * + * Renders a widget that print an image and an optional text. + */ +export const ImageWidget = forwardRef(ImageWidgetWithRef); -- cgit v1.2.3