Skip to content

Commit 59fa4e3

Browse files
author
Kubit
committed
Include genericComponent for images
1 parent b5b56f0 commit 59fa4e3

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/provider/genericComponents/defaultGenericComponents.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { IGenericLink } from './genericComponents.type';
3+
import { IGenericImage, IGenericLink } from './genericComponents.type';
44

55
const Link = React.forwardRef(function Link(props: IGenericLink, ref: unknown) {
66
return (
@@ -25,6 +25,17 @@ const Link = React.forwardRef(function Link(props: IGenericLink, ref: unknown) {
2525
);
2626
});
2727

28+
const Image = React.forwardRef(function Image(props: IGenericImage, ref: unknown) {
29+
return (
30+
<img
31+
ref={ref as React.LegacyRef<HTMLImageElement> | undefined}
32+
{...props}
33+
alt={props.alt || ''}
34+
/>
35+
);
36+
});
37+
2838
export const defaultGenericComponents = {
2939
LINK: Link,
40+
IMAGE: Image,
3041
};

src/provider/genericComponents/genericComponents.type.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
import React from 'react';
2+
13
import { ROLES } from '@/types/role';
24

5+
/**
6+
* Defines the properties for a generic link component.
7+
* @property {string} url - The URL the link points to.
8+
* @property {string | JSX.Element} children - The content inside the link.
9+
* @property {string} [className] - Optional CSS class for styling.
10+
* @property {string} [target] - Specifies where to open the linked document.
11+
* @property {boolean} [aria-disabled] - Indicates that the element is perceivable but disabled.
12+
* @property {string} [aria-label] - Defines a string value that labels the current element.
13+
* @property {() => void} [onClick] - Function to call when the link is clicked.
14+
* @property {() => void} [onFocus] - Function to call when the link is focused.
15+
* @property {() => void} [onMouseEnter] - Function to call when the mouse enters the link area.
16+
* @property {() => void} [onMouseLeave] - Function to call when the mouse leaves the link area.
17+
* @property {ROLES} [role] - ARIA role to describe the link's type.
18+
* @property {string} [dataTestId] - Test ID for testing purposes.
19+
* @property {boolean} [draggable] - Indicates whether the element can be dragged.
20+
*/
321
export type IGenericLink = {
422
url: string;
523
children: string | JSX.Element;
@@ -16,14 +34,37 @@ export type IGenericLink = {
1634
draggable?: boolean;
1735
};
1836

37+
/**
38+
* Defines the type for a generic link component, which can be either a functional component or a forward ref component.
39+
*/
1940
export type GenericLinkType =
2041
| ((props: IGenericLink) => JSX.Element)
2142
| React.ForwardRefExoticComponent<IGenericLink & React.RefAttributes<unknown>>;
2243

44+
/**
45+
* Defines the properties for a generic image component.
46+
*/
47+
export interface IGenericImage extends React.ImgHTMLAttributes<HTMLImageElement> {}
48+
49+
/**
50+
* Defines the type for a generic image component, which can be either a functional component or a forward ref component.
51+
*/
52+
export type GenericImageType =
53+
| ((props: IGenericImage) => JSX.Element)
54+
| React.ForwardRefExoticComponent<IGenericImage & React.RefAttributes<unknown>>;
55+
56+
/**
57+
* Defines the types for generic components, including links and images.
58+
*/
2359
export type GenericComponentsType = {
2460
LINK: GenericLinkType;
61+
IMAGE?: GenericImageType;
2562
};
2663

64+
/**
65+
* Provides the interface for the generic components provider.
66+
* @property {GenericComponentsType} value - The actual components to be provided.
67+
*/
2768
export interface IGenericComponentsProvider {
2869
value: GenericComponentsType;
2970
}

src/provider/genericComponents/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ export type {
77
GenericComponentsType,
88
IGenericLink,
99
GenericLinkType,
10+
GenericImageType,
11+
IGenericImage,
12+
IGenericComponentsProvider,
1013
} from './genericComponents.type';
1114
export * from './defaultGenericComponents';

0 commit comments

Comments
 (0)