-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from maiHydrogen/main
fix: fixed errors occuring in npm run build
- Loading branch information
Showing
4 changed files
with
211 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"use client"; | ||
|
||
import { useEffect, useMemo, useState } from "react"; | ||
import { useTheme } from "next-themes"; | ||
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: "88%", | ||
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, | ||
// dragControl: false, | ||
}, | ||
}; | ||
|
||
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-expect-error this may throw some errors but we're handling it somewhere else | ||
<Cloud {...cloudProps}> | ||
<>{renderedIcons}</> | ||
</Cloud> | ||
); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters