33 InstagramIcon ,
44 LinkedInIcon ,
55 MediumIcon ,
6+ MusicIcon ,
7+ MusicOffIcon ,
68 RobotIcon ,
79} from '@assets' ;
810import {
@@ -16,7 +18,7 @@ import {
1618 VStack ,
1719} from '@chakra-ui/react' ;
1820import { useCursor } from '@components' ;
19- import { RefObject , useRef } from 'react' ;
21+ import { RefObject , useEffect , useRef , useState } from 'react' ;
2022import { CharacterType } from '../scene' ;
2123import { CONTACT } from '@data' ;
2224
@@ -39,10 +41,22 @@ const SocialNavigation = ({
3941 handleCharacterClick : ( type : CharacterType ) => void ;
4042} ) => {
4143 const ref = useRef < HTMLDivElement > ( null ) ;
44+ const [ isPlaying , setIsPlaying ] = useState ( true ) ;
45+
46+ useEffect ( ( ) => {
47+ if ( isPlaying ) {
48+ document . querySelector ( 'audio' ) ?. play ( ) ;
49+ } else {
50+ document . querySelector ( 'audio' ) ?. pause ( ) ;
51+ }
52+ } , [ isPlaying ] ) ;
53+
4254 const menuButtonRef = useRef < HTMLDivElement > ( null ) ;
55+ const musicRef = useRef < HTMLButtonElement > ( null ) ;
4356 const { setCursorInsets } = useCursor ( ) ;
4457 const onMouseEnter =
45- ( ref : RefObject < HTMLDivElement > , radius : string ) => ( ) => {
58+ ( ref : RefObject < HTMLDivElement | HTMLButtonElement > , radius : string ) =>
59+ ( ) => {
4660 const { width, height, top, left } =
4761 ref . current ?. getBoundingClientRect ( ) || {
4862 width : 56 ,
@@ -60,7 +74,34 @@ const SocialNavigation = ({
6074 } ;
6175
6276 return (
63- < VStack position = { 'fixed' } bottom = { 20 } right = { 14 } rowGap = { 10 } zIndex = { 1 } >
77+ < VStack position = { 'fixed' } bottom = { 20 } right = { 14 } rowGap = { 6 } zIndex = { 1 } >
78+ < IconButton
79+ ref = { musicRef }
80+ aria-label = { 'music' }
81+ borderColor = { 'gray' }
82+ boxShadow = { '0px 0px 10px 3px gray' }
83+ bg = { 'rgba(255, 255, 255, 0.1)' }
84+ backdropFilter = { 'blur(20px)' }
85+ transition = { 'background-color 0.3s' }
86+ padding = { 2 }
87+ borderRadius = { '10px' }
88+ icon = {
89+ isPlaying ? (
90+ < MusicIcon width = { '1.5em' } height = { '1.5em' } color = "white" />
91+ ) : (
92+ < MusicOffIcon width = { '1.5em' } height = { '1.5em' } color = "white" />
93+ )
94+ }
95+ onClick = { ( ) => setIsPlaying ( ! isPlaying ) }
96+ onMouseEnter = { onMouseEnter ( musicRef , '10px' ) }
97+ onMouseLeave = { onMouseLeave }
98+ />
99+ < audio src = "bg.mp3" loop hidden autoPlay >
100+ < p >
101+ If you are reading this, it is because your browser does not support
102+ the audio element.
103+ </ p >
104+ </ audio >
64105 < Box
65106 ref = { menuButtonRef }
66107 zIndex = { 1 }
0 commit comments