@fluidattacks/design 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -4,6 +4,18 @@
4
4
  "url": "https://gitlab.com/fluidattacks/universe/issues"
5
5
  },
6
6
  "description": "Fluidattacks core components library",
7
+ "dependencies": {
8
+ "@cloudinary/react": "1.13.0",
9
+ "@cloudinary/url-gen": "1.21.0",
10
+ "react": "18.2.0",
11
+ "react-dom": "18.2.0",
12
+ "styled-components": "6.1.13"
13
+ },
14
+ "devDependencies": {
15
+ "@types/react": "18.2.0",
16
+ "@types/react-dom": "18.2.0",
17
+ "typescript": "5.6.2"
18
+ },
7
19
  "homepage": "https://gitlab.com/fluidattacks/universe#readme",
8
20
  "keywords": [
9
21
  "components",
@@ -19,5 +31,5 @@
19
31
  "scripts": {
20
32
  "test": "echo \"Error: no test specified\" && exit 1"
21
33
  },
22
- "version": "1.0.0"
34
+ "version": "1.1.0"
23
35
  }
@@ -0,0 +1,38 @@
1
+ import type { Plugins } from "@cloudinary/html";
2
+ import { AdvancedImage, lazyload, placeholder } from "@cloudinary/react";
3
+ import React from "react";
4
+
5
+ import { useCloudinaryImage } from "hooks";
6
+
7
+ interface IImageProps {
8
+ alt?: string;
9
+ height?: number | string;
10
+ publicId: string;
11
+ width?: number | string;
12
+ plugins?: Plugins;
13
+ }
14
+
15
+ const CloudImage = ({
16
+ alt,
17
+ height,
18
+ publicId,
19
+ width,
20
+ plugins = [lazyload(), placeholder()],
21
+ }: Readonly<IImageProps>): JSX.Element => {
22
+ const image = useCloudinaryImage({ publicId });
23
+
24
+ return (
25
+ <AdvancedImage
26
+ alt={alt ?? "img"}
27
+ cldImg={image}
28
+ height={height ?? ""}
29
+ plugins={plugins}
30
+ width={width ?? ""}
31
+ />
32
+ );
33
+ };
34
+
35
+ const MemoizedImage = React.memo(CloudImage);
36
+
37
+ export type { IImageProps };
38
+ export { MemoizedImage as CloudImage };
@@ -0,0 +1,3 @@
1
+ import { useCloudinaryImage } from "./use-cloudinary-image";
2
+
3
+ export {useCloudinaryImage}
@@ -0,0 +1,27 @@
1
+ import type { CloudinaryImage } from "@cloudinary/url-gen";
2
+ import { Cloudinary } from "@cloudinary/url-gen";
3
+ import { useMemo } from "react";
4
+
5
+ interface IUseCloudinaryImageProps {
6
+ publicId: string;
7
+ format?: string;
8
+ }
9
+
10
+ export const useCloudinaryImage = ({
11
+ publicId,
12
+ format = "webp",
13
+ }: IUseCloudinaryImageProps): CloudinaryImage => {
14
+ const cloudinaryInstance = useMemo((): Cloudinary => {
15
+ return new Cloudinary({
16
+ cloud: {
17
+ cloudName: "fluid-attacks",
18
+ },
19
+ });
20
+ }, []);
21
+
22
+ const image = useMemo((): CloudinaryImage => {
23
+ return cloudinaryInstance.image(publicId).format(format);
24
+ }, [cloudinaryInstance, publicId, format]);
25
+
26
+ return image;
27
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": "src",
4
+ "esModuleInterop": true,
5
+ "jsx": "react",
6
+ "lib": ["dom", "es2023"],
7
+ "paths": {
8
+ "components/*": [ "components/*" ],
9
+ "hooks/*": [ "hooks/*" ],
10
+ }
11
+ }
12
+ }