-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dennis Vash
committed
Mar 14, 2020
1 parent
1610b71
commit ffe34af
Showing
2 changed files
with
66 additions
and
4 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,61 @@ | ||
import { IntroParallax, LogoParallax, SocialBar } from "@components"; | ||
import { mixins, styled } from "@styles"; | ||
import React, { useCallback } from "react"; | ||
import { config, useSpring } from "react-spring"; | ||
import tw from "twin.macro"; | ||
|
||
const Logo = styled(LogoParallax)` | ||
${tw`z-0 absolute right-0 | ||
w-1/2 sm:w-2/5 md:w-1/3 lg:w-1/3 xl:w-1/4 | ||
mr-3 sm:mr-10 md:mr-24 lg:mr-40 xl:mr-64`} | ||
`; | ||
|
||
const Intro = styled(IntroParallax)` | ||
${tw`z-10`} | ||
`; | ||
|
||
const Wrapper = styled.div` | ||
${mixins.flexCenter} | ||
${tw`w-full`} | ||
`; | ||
|
||
const Container = styled.div` | ||
${mixins.flexCenter} | ||
${mixins.fillContainer} | ||
${tw`flex-col`} | ||
${SocialBar.SC} { | ||
${tw`mt-24 sm:mt-16`} | ||
} | ||
`; | ||
|
||
const spring = () => ({ | ||
xy: [-100, -100], | ||
config: config.gentle | ||
}); | ||
|
||
const calc = (x, y) => [x - window.innerWidth / 2, y - window.innerHeight / 2]; | ||
const trans = delta => (x, y) => `translate3d(${x / delta}px,${y / delta}px,0)`; | ||
|
||
const Hero = () => { | ||
const [{ xy }, set] = useSpring(spring); | ||
|
||
const onMouseMove = useCallback( | ||
({ clientX: x, clientY: y }) => set({ xy: calc(x, y) }), | ||
[set] | ||
); | ||
const transform = useCallback(delta => ({ transform: xy.to(trans(delta)) }), [ | ||
xy | ||
]); | ||
|
||
return ( | ||
<Container onMouseMove={onMouseMove}> | ||
<Wrapper> | ||
<Intro transform={transform} /> | ||
<Logo transform={transform} /> | ||
</Wrapper> | ||
<SocialBar /> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Hero; |