-
Notifications
You must be signed in to change notification settings - Fork 0
Fix types and add animated background #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ac70065
fix types and add animated background
bprosen c1bab1d
fix build
bprosen 7bca12a
Merge branch 'main' into dev
bprosen bf75477
fix build
bprosen edc835c
remove duplicate
bprosen 6a1d7b7
fix default
bprosen c8d56cc
pr changes
bprosen 128d62f
remove strategy
bprosen d908eca
need strategy bacl
bprosen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,21 +1,21 @@ | ||
| { | ||
| "$schema": "https://ui.shadcn.com/schema.json", | ||
| "style": "new-york", | ||
| "rsc": false, | ||
| "tsx": true, | ||
| "tailwind": { | ||
| "config": "", | ||
| "css": "~/app/globals.css", | ||
| "baseColor": "neutral", | ||
| "cssVariables": true, | ||
| "prefix": "" | ||
| }, | ||
| "aliases": { | ||
| "components": "~/components", | ||
| "utils": "~/lib/utils", | ||
| "ui": "~/ui", | ||
| "lib": "~/lib", | ||
| "hooks": "~/hooks" | ||
| }, | ||
| "iconLibrary": "lucide" | ||
| } | ||
| "$schema": "https://ui.shadcn.com/schema.json", | ||
| "style": "new-york", | ||
| "rsc": false, | ||
| "tsx": true, | ||
| "tailwind": { | ||
| "config": "", | ||
| "css": "~/app/globals.css", | ||
| "baseColor": "neutral", | ||
| "cssVariables": true, | ||
| "prefix": "" | ||
| }, | ||
| "iconLibrary": "lucide", | ||
| "aliases": { | ||
| "components": "~/components", | ||
| "utils": "~/lib/utils", | ||
| "ui": "~/ui", | ||
| "lib": "~/lib", | ||
| "hooks": "~/hooks" | ||
| } | ||
| } |
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,9 +1,15 @@ | ||
| import { UnderConstruction } from '~/components'; | ||
| import { VantaNet } from '~/ui'; | ||
|
|
||
| export const Home = () => { | ||
| return ( | ||
| <div className='flex flex-col items-center justify-center h-screen'> | ||
| <VantaNet | ||
| backgroundColor='var(--primary)' | ||
| className='flex flex-col items-center justify-center h-screen' | ||
| maxDistance={20.0} | ||
| spacing={15.0} | ||
| > | ||
| <UnderConstruction /> | ||
| </div> | ||
| </VantaNet> | ||
| ); | ||
| }; |
This file contains hidden or 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,29 @@ | ||
| export interface VantaEffect { | ||
| destroy?: () => void; | ||
| } | ||
|
|
||
| interface VantaNetConfig { | ||
| el: HTMLElement; | ||
| gyroControls: boolean; | ||
| maxDistance: number; | ||
| minHeight: number; | ||
| minWidth: number; | ||
| mouseControls: boolean; | ||
| scale: number; | ||
| scaleMobile: number; | ||
| showDots: boolean; | ||
| spacing: number; | ||
| touchControls: boolean; | ||
| backgroundColor?: number | string; | ||
| color?: number | string; | ||
| } | ||
|
|
||
| interface VantaLibrary { | ||
| NET: (config: VantaNetConfig) => VantaEffect; | ||
| } | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| VANTA?: VantaLibrary; | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| export * from './Vanta'; |
This file contains hidden or 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,140 @@ | ||
| 'use client'; | ||
|
|
||
| import { formatHex, parse } from 'culori'; | ||
| import { useEffect, useRef } from 'react'; | ||
| import type { VantaEffect } from '~/types'; | ||
|
|
||
| type VantaNetProps = { | ||
| children?: React.ReactNode; | ||
| className?: string; | ||
| containerClassName?: string; | ||
| backgroundColor?: number | string; | ||
| color?: number | string; | ||
| mouseControls?: boolean; | ||
| touchControls?: boolean; | ||
| gyroControls?: boolean; | ||
| minHeight?: number; | ||
| minWidth?: number; | ||
| scale?: number; | ||
| scaleMobile?: number; | ||
| showDots?: boolean; | ||
| maxDistance?: number; | ||
| spacing?: number; | ||
| }; | ||
|
|
||
| export const VantaNet = ({ | ||
| children, | ||
| className, | ||
| containerClassName, | ||
| backgroundColor = 'var(--primary)', | ||
| color = '#FFFFFF', | ||
| mouseControls = true, | ||
| touchControls = true, | ||
| gyroControls = false, | ||
| minHeight = 200.0, | ||
| minWidth = 200.0, | ||
| scale = 1.0, | ||
| scaleMobile = 1.0, | ||
| showDots = false, | ||
| maxDistance = 25.0, | ||
| spacing = 18.0, | ||
| }: VantaNetProps) => { | ||
| const vantaRef = useRef<HTMLDivElement>(null); | ||
| const vantaInstance = useRef<VantaEffect | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!vantaRef.current || vantaInstance.current) { | ||
| return; | ||
| } | ||
|
|
||
| const initVanta = () => { | ||
| const VANTA = window?.VANTA; | ||
|
|
||
| if (!vantaRef.current || !VANTA?.NET) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const resolveColor = (colorValue: number | string): number | string => { | ||
| if (typeof colorValue === 'number') { | ||
| return colorValue; | ||
| } | ||
|
|
||
| if (colorValue.includes('var(')) { | ||
| const computedColor = getComputedStyle(vantaRef.current) | ||
| .getPropertyValue(colorValue.replace(/var\((--[\w-]+)\)/, '$1')) | ||
| .trim(); | ||
|
|
||
| return computedColor ? formatHex(parse(computedColor)) : colorValue; | ||
| } | ||
| return formatHex(parse(colorValue)); | ||
| }; | ||
| const bgColor = resolveColor(backgroundColor); | ||
|
|
||
| vantaInstance.current = VANTA.NET({ | ||
| el: vantaRef.current, | ||
| gyroControls, | ||
| maxDistance, | ||
| minHeight, | ||
| minWidth, | ||
| mouseControls, | ||
| scale, | ||
| scaleMobile, | ||
| showDots, | ||
| spacing, | ||
| touchControls, | ||
| ...(bgColor && { backgroundColor: bgColor }), | ||
| ...(color && { color }), | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error initializing Vanta.NET:', error); | ||
| } | ||
| }; | ||
|
|
||
| if (typeof window !== 'undefined' && window.VANTA) { | ||
| initVanta(); | ||
| } else { | ||
| const checkInterval = setInterval(() => { | ||
| if (window.VANTA && vantaRef.current) { | ||
| clearInterval(checkInterval); | ||
| initVanta(); | ||
| } | ||
| }, 50); | ||
|
|
||
| return () => { | ||
| clearInterval(checkInterval); | ||
| if (vantaInstance.current) { | ||
| vantaInstance.current.destroy?.(); | ||
| vantaInstance.current = null; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| return () => { | ||
| if (vantaInstance.current) { | ||
| vantaInstance.current.destroy?.(); | ||
| vantaInstance.current = null; | ||
| } | ||
| }; | ||
| }, [ | ||
| mouseControls, | ||
| touchControls, | ||
| gyroControls, | ||
| minHeight, | ||
| minWidth, | ||
| scale, | ||
| scaleMobile, | ||
| showDots, | ||
| backgroundColor, | ||
| color, | ||
| spacing, | ||
| maxDistance, | ||
| ]); | ||
|
|
||
| return ( | ||
| <div className={`relative h-full w-full ${containerClassName ?? ''}`}> | ||
| <div className='absolute inset-0 z-0 h-full w-full' ref={vantaRef} /> | ||
| <div className={`relative z-10 ${className ?? ''}`}>{children}</div> | ||
| </div> | ||
| ); | ||
|
bprosen marked this conversation as resolved.
|
||
| }; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './Button'; | ||
| export * from './Card'; | ||
| export * from './VantaNet'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.