Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

feat:Interactive-Icon-Cloud (#43)

Satyaprakash Sahu680ece5efeda
diff --git a/config/docs.ts b/config/docs.ts
index 10c9be34..3c30c242 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -89,6 +89,12 @@ export const docsConfig: DocsConfig = {
items: [],
label: "New",
},
+ {
+ title: "Interactive Icon Cloud",
+ href: `/docs/components/icon-cloud`,
+ items: [],
+ label: "New",
+ },
],
},
{
diff --git a/content/docs/components/icon-cloud.mdx b/content/docs/components/icon-cloud.mdx
new file mode 100644
index 00000000..0b180e82
--- /dev/null
+++ b/content/docs/components/icon-cloud.mdx
@@ -0,0 +1,58 @@
+---
+title: Interactive Icon Cloud
+date: 2024-05-24
+description: An interactive 3D tag cloud component
+author: dillionverma
+published: true
+---
+
+<ComponentPreview name="icon-cloud-demo" />
+
+<Steps>
+
+### Installation
+
+Copy and paste the following code into your project.
+
+```bash
+npm i react-icon-cloud
+```
+
+```text
+components/magicui/icon-cloud.tsx
+```
+
+<ComponentSource name="icon-cloud" />
+
+</Steps>
+
+## Props
+
+## Cloud
+| Prop | type | default | description |
+|:--------------:|:-------------------------------------------------:|:-------:|:---------------------------------------------------------------:|
+| canvasProps | HTMLAttributes < HTMLCanvasElement > \| undefined | {} | Attributes that will be passed to the underlying canvas element |
+| children | Tag[] | [] | Tags rendered using the provided renderers |
+| containerProps | HTMLAttributes < HTMLDivElement > \| undefined | {} | Attributes passed to the root div element |
+| id | string \| number \| undefined | uuid | Should be provided when using SSR |
+| options | IOptions \| undefined | {} | https://www.goat1000.com/tagcanvas-options.php |
+| maxSpeed | int | 0.04 | To adjust the rotation speed in idle state |
+| minSpeed | int | 0.02 | To adjust the rotation speed when hovering |
+
+## renderSimpleIcon
+Used to create a tag for the Cloud component
+| Prop | type | default | description |
+|:----------------:|:-----------------------------------------------:|:---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------:|
+| aProps | HTMLAttributes < HTMLAnchorElement > \| undefined | {} | Attributes passed to the underlying anchor element |
+| bgHex | string \| undefined | '#fff' | The string hex of the background the icon will be rendered on. Ex: '#fff'. Used to determine if the min contrast ratio for the icons default color will be met |
+| fallbackHex | string \| undefined | '#000' | The color of the icon if the minContrastRatio is not met Ex: '#000' |
+| icon | any | undefined | The simple icon object you would like to render. Ex: import icon from "simple-icons/icons/javascript";
+| imgProps | HTMLAttributes < HTMLImageElement > \| undefined | {} | Attributes passed to the underlying img element | |
+| minContrastRatio | number \| undefined | 1 | 0 - 21 The min contrast ratio between icon and bgHex before the fallbackHex will be used for the icon color |
+| size | number \| undefined | 42 | The size in px of the icon |
+
+## fetchSimpleIcons
+Used when you cant statically import simple icons during built time. Calling this will use `fetch` to get icons for each provided slug.
+| Prop | type | default | description |
+|:----------------:|:-----------------------------------------------:|:---------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------:|
+| slugs | string[] | | Slugs to fetch svgs and colors for. The return icons may be passed to renderSimpleIcon |
diff --git a/package.json b/package.json
index 20aeb221..706aa8ab 100644
--- a/package.json
+++ b/package.json
@@ -93,6 +93,7 @@
"react-dom": "18.2.0",
"react-email": "1.9.4",
"react-hook-form": "^7.45.0",
+ "react-icon-cloud": "^4.1.4",
"react-spring": "^9.7.3",
"react-tweet": "^3.1.1",
"react-wrap-balancer": "^1.0.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e6c416e3..778770be 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -221,6 +221,9 @@ importers:
react-hook-form:
specifier: ^7.45.0
version: 7.50.1([email protected])
+ react-icon-cloud:
+ specifier: ^4.1.4
+ version: 4.1.4([email protected])
react-spring:
specifier: ^9.7.3
@@ -1097,6 +1100,10 @@ packages:
'@effect-ts/otel-node':
optional: true
+ '@csstools/[email protected]':
+ resolution: {integrity: sha512-P7BVvddsP2Wl5v3drJ3ArzpdfXMqoZ/oHOV/yFiGFb3JQr9Z9UXZ9tnHAKJsO89lfprR1F9ExW3Yij21EjEBIA==}
+ engines: {node: '>=6.0.0'}
+
'@effect-ts/[email protected]':
resolution: {integrity: sha512-qi1WrtJA90XLMnj2hnUszW9Sx4dXP03ZJtCc5DiUBIOhF4Vw7plfb65/bdBySPoC9s7zy995TdUX1XBSxUkl5w==}
@@ -3285,7 +3292,7 @@ packages:
engines: {node: '>=10.16.0'}
- resolution: {integrity: sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=}
+ resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==}
engines: {node: '>= 0.8'}
@@ -3787,7 +3794,7 @@ packages:
hasBin: true
- resolution: {integrity: sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=}
+ resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==}
resolution: {integrity: sha512-3avY1B+vUzNxEgkBDpKOP8WarvUAEwpRaiCL0He5OKWEFxzaOFiq4WoZEZe7qh0ReS7DiWoHMnYoQCKxNZNzSg==}
@@ -4166,7 +4173,7 @@ packages:
optional: true
- resolution: {integrity: sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=}
+ resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==}
engines: {node: '>= 0.6'}
@@ -6118,6 +6125,12 @@ packages:
peerDependencies:
react: ^16.8.0 || ^17 || ^18
+ resolution: {integrity: sha512-hc8yGNU98V6ObPdeNIt75M016xGMxbTWqB4l6exo1uwE5bvFU095unMbX2K3YBKYhGKEV3c7fSmq3jD3cRWX+A==}
+ engines: {node: '>=10'}
+ peerDependencies:
+ react: '>=16'
+
resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==}
@@ -7065,7 +7078,7 @@ packages:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
- resolution: {integrity: sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=}
+ resolution: {integrity: sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==}
engines: {node: '>= 0.4.0'}
@@ -8238,6 +8251,8 @@ snapshots:
ts-pattern: 4.3.0
type-fest: 3.13.1
+ '@csstools/[email protected]': {}
+
'@effect-ts/[email protected]':
dependencies:
'@effect-ts/system': 0.57.5
@@ -14170,6 +14185,11 @@ snapshots:
dependencies:
react: 18.2.0
+ dependencies:
+ '@csstools/convert-colors': 2.0.0
+ react: 18.2.0
+
diff --git a/registry/components/example/icon-cloud-demo.tsx b/registry/components/example/icon-cloud-demo.tsx
new file mode 100644
index 00000000..f8cc2001
--- /dev/null
+++ b/registry/components/example/icon-cloud-demo.tsx
@@ -0,0 +1,42 @@
+import IconCloud from "@/registry/components/magicui/icon-cloud";
+
+const slugs = [
+ "typescript",
+ "javascript",
+ "dart",
+ "java",
+ "react",
+ "flutter",
+ "android",
+ "html5",
+ "css3",
+ "nodedotjs",
+ "express",
+ "nextdotjs",
+ "prisma",
+ "amazonaws",
+ "postgresql",
+ "firebase",
+ "nginx",
+ "vercel",
+ "testinglibrary",
+ "jest",
+ "cypress",
+ "docker",
+ "git",
+ "jira",
+ "github",
+ "gitlab",
+ "visualstudiocode",
+ "androidstudio",
+ "sonarqube",
+ "figma",
+];
+
+export default function IconCloudDemo() {
+ return (
+ <div className="relative flex h-full w-full max-w-[32rem] items-center justify-center overflow-hidden rounded-lg border bg-background px-20 pb-20 pt-8 ">
+ <IconCloud iconSlugs={slugs} />
+ </div>
+ );
+}
diff --git a/registry/components/magicui/icon-cloud.tsx b/registry/components/magicui/icon-cloud.tsx
new file mode 100644
index 00000000..72b0b33f
--- /dev/null
+++ b/registry/components/magicui/icon-cloud.tsx
@@ -0,0 +1,87 @@
+"use client";
+
+import { useTheme } from "next-themes";
+import { useEffect, useMemo, useState } from "react";
+import {
+ Cloud,
+ fetchSimpleIcons,
+ ICloud,
+ renderSimpleIcon,
+ SimpleIcon,
+} from "react-icon-cloud";
+
+export const cloudProps: Omit<ICloud, "children"> = {
+ containerProps: {
+ style: {
+ display: "flex",
+ justifyContent: "center",
+ alignItems: "center",
+ width: "100%",
+ paddingTop: 40,
+ },
+ },
+ options: {
+ reverse: true,
+ depth: 1,
+ wheelZoom: false,
+ imageScale: 2,
+ activeCursor: "default",
+ tooltip: "native",
+ initial: [0.1, -0.1],
+ clickToFront: 500,
+ tooltipDelay: 0,
+ outlineColour: "#0000",
+ maxSpeed: 0.04,
+ minSpeed: 0.02,
+ },
+};
+
+export const renderCustomIcon = (icon: SimpleIcon, theme: string) => {
+ const bgHex = theme === "light" ? "#f3f2ef" : "#080510";
+ const fallbackHex = theme === "light" ? "#6e6e73" : "#ffffff";
+ const minContrastRatio = theme === "dark" ? 2 : 1.2;
+
+ return renderSimpleIcon({
+ icon,
+ bgHex,
+ fallbackHex,
+ minContrastRatio,
+ size: 42,
+ aProps: {
+ href: undefined,
+ target: undefined,
+ rel: undefined,
+ onClick: (e: any) => e.preventDefault(),
+ },
+ });
+};
+
+export type DynamicCloudProps = {
+ iconSlugs: string[];
+};
+
+type IconData = Awaited<ReturnType<typeof fetchSimpleIcons>>;
+
+export default function IconCloud({ iconSlugs }: DynamicCloudProps) {
+ const [data, setData] = useState<IconData | null>(null);
+ const { theme } = useTheme();
+
+ useEffect(() => {
+ fetchSimpleIcons({ slugs: iconSlugs }).then(setData);
+ }, [iconSlugs]);
+
+ const renderedIcons = useMemo(() => {
+ if (!data) return null;
+
+ return Object.values(data.simpleIcons).map((icon) =>
+ renderCustomIcon(icon, theme || "light"),
+ );
+ }, [data, theme]);
+
+ return (
+ // @ts-ignore
+ <Cloud {...cloudProps}>
+ <>{renderedIcons}</>
+ </Cloud>
+ );
+}
diff --git a/registry/index.tsx b/registry/index.tsx
index 4c424170..0642afc9 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -182,6 +182,11 @@ const ui: Registry = {
type: "components:ui",
files: ["registry/components/magicui/flip-text.tsx"],
},
+ "icon-cloud": {
+ name: "icon-cloud",
+ type: "components:ui",
+ files: ["registry/components/magicui/icon-cloud.tsx"],
+ },
};
const example: Registry = {
@@ -677,8 +682,15 @@ const example: Registry = {
() => import("@/registry/components/example/flip-text-demo"),
),
},
+ "icon-cloud-demo": {
+ name: "icon-cloud-demo",
+ type: "components:example",
+ files: ["registry/components/example/icon-cloud-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/icon-cloud-demo"),
+ ),
+ },
};
-
export const registry: Registry = {
...ui,
...example,