diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-13 18:46:31 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-13 18:53:15 +0100 |
| commit | e331106e56d59a8b987230860b66214139c12ef6 (patch) | |
| tree | 18b595ddd86089b405e9517cd3efc72e2f17a1ab /src/components/organisms/widgets/image-widget/image-widget.tsx | |
| parent | 56878f647ea0f1066fa3e222d7aa0d83057f496d (diff) | |
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
Diffstat (limited to 'src/components/organisms/widgets/image-widget/image-widget.tsx')
| -rw-r--r-- | src/components/organisms/widgets/image-widget/image-widget.tsx | 47 |
1 files changed, 47 insertions, 0 deletions
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<CollapsibleProps, 'children'> & { + /** + * 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) => ( + <Collapsible {...props} ref={ref}> + <Figure caption={description} hasBorders> + {url ? ( + <Link className={styles.link} href={url}> + {img} + </Link> + ) : ( + img + )} + </Figure> + </Collapsible> +); + +/** + * ImageWidget component + * + * Renders a widget that print an image and an optional text. + */ +export const ImageWidget = forwardRef(ImageWidgetWithRef); |
