Skip to content

Commit c795159

Browse files
author
Kubit
committed
Add image generic Component to Image component
1 parent 0ce4309 commit c795159

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

src/components/image/image.styled.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import styled from 'styled-components';
22

33
import { ImageObjectFitType, ImageStylesPropsType } from './types';
44

5+
export const ImageStyled = styled.img``;
6+
57
export const ImagePictureStyled = styled.picture<ImageStylesPropsType>`
68
position: relative;
79
display: inline-block;

src/components/image/image.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as React from 'react';
22

3+
import { useGenericComponents } from '@/provider/genericComponents';
4+
35
import { ImageStandAlone } from './imageStandAlone';
46
import type { IImage } from './types';
57

68
const ImageComponent = (
79
props: IImage,
810
ref: React.ForwardedRef<HTMLElement> | undefined | null
911
): JSX.Element => {
10-
return <ImageStandAlone {...props} ref={ref} />;
12+
const { IMAGE: GenericImageType } = useGenericComponents();
13+
return <ImageStandAlone {...props} ref={ref} component={GenericImageType} />;
1114
};
1215

1316
/**

src/components/image/imageStandAlone.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as React from 'react';
22

3+
import { ROLES } from '@/types';
34
import { DeviceBreakpointsType } from '@/types/breakpoints';
45

56
// internal components
67
import { PictureSourceStandAlone } from './components/pictureSourceStandAlone';
78
// styles
8-
import { ImagePictureStyled } from './image.styled';
9+
import { ImagePictureStyled, ImageStyled } from './image.styled';
910
import { IImageStandAlone, ImageLoadingType } from './types';
1011
import { getFallbackRatio } from './utils/getFallbackRatio';
1112

@@ -25,8 +26,9 @@ const ImageStandAloneComponent = (
2526
<PictureSourceStandAlone mediaSource={props.images[DeviceBreakpointsType.DESKTOP]} />
2627
<PictureSourceStandAlone mediaSource={props.images[DeviceBreakpointsType.TABLET]} />
2728
<PictureSourceStandAlone mediaSource={props.images[DeviceBreakpointsType.MOBILE]} />
28-
<img
29+
<ImageStyled
2930
alt={props.alt}
31+
as={props.component || ROLES.IMG}
3032
height={props.height}
3133
loading={loading}
3234
src={props.images.DEFAULT.src}

src/components/image/types/image.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GenericImageType } from '@/provider/genericComponents';
12
import { DeviceBreakpointsType } from '@/types/breakpoints';
23

34
import { ImageLoadingType } from './loading';
@@ -23,6 +24,7 @@ export interface IImageStandAlone {
2324
dataTestId?: string;
2425
borderRadius?: string;
2526
objectFit?: ImageObjectFitType;
27+
component?: GenericImageType;
2628
}
2729

2830
export type IImage = IImageStandAlone;

0 commit comments

Comments
 (0)