Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import theme from "./theme";
import { ThemeProvider } from "@emotion/react";
import { useState } from "react";
import { useState, useRef, useEffect } from "react";
import Hero from "./views/Hero";
import Navbar from "./components/Navbar";
import WeAreSprout from "./views/WeAreSprout";
Expand All @@ -9,23 +9,38 @@ import OurVision from "./views/OurVision";
import OurCases from "./views/OurCases";
import Contact from "./views/Contact";
import { useCurrentView } from "./hooks";

import styled from "@emotion/styled";
function App() {
useCurrentView();

const [introVisited, setIntroVisited] = useState(false);
const scrollContainer = useRef(null);

return (
<ThemeProvider theme={theme}>
{!introVisited && <Wave setIntroVisited={setIntroVisited}></Wave>}
<Navbar showMenu={true}></Navbar>
<Hero></Hero>
<WeAreSprout></WeAreSprout>
<OurVision></OurVision>
<OurCases></OurCases>
<Contact></Contact>
<ScrollSnapContainer ref={scrollContainer} >
{!introVisited && <Wave setIntroVisited={setIntroVisited}></Wave>}
<Navbar introVisited={introVisited} scrollContainer={scrollContainer}></Navbar>
<Hero></Hero>
<WeAreSprout></WeAreSprout>
<OurVision></OurVision>
<OurCases></OurCases>
<Contact></Contact>
</ScrollSnapContainer>
</ThemeProvider>
);
}

const ScrollSnapContainer = styled.div`
position : relative;
scroll-snap-type: y mandatory;
height : 100%;
scroll-behavior: smooth;
overflow : auto;
> * {
scroll-snap-align: start;
}
`;


export default App;
102 changes: 62 additions & 40 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useState, useEffect, Ref } from "react";
import styled from "@emotion/styled";
import { css } from "@emotion/react";

Expand All @@ -7,11 +7,14 @@ import HamburgerMenu from "./HamburgerMenu";
import { mq } from "../theme";
import NavLink from "./NavLink";


interface Props {
showMenu: boolean;
introVisited: boolean;
scrollContainer : React.MutableRefObject<HTMLDivElement | null>
}

function Navbar({ showMenu }: Props) {
function Navbar({ scrollContainer, introVisited }: Props) {

function handleOpen(open: boolean) {
if (open) {
document.documentElement.classList.add("fullscreen-modal");
Expand All @@ -20,64 +23,77 @@ function Navbar({ showMenu }: Props) {
}
setOpen(open);
}

const [fixed, setFixed] = useState(false);
const [open, setOpen] = useState(false);
const [visible, setVisible] = useState(true);
const [visible, setVisible] = useState(false);

useEffect(() => {
if(scrollContainer.current) {

setVisible(scrollContainer.current?.scrollTop > 0 || scrollContainer.current?.scrollTop === 0 && introVisited)

type ScrollDirection = "up" | "down";

const scrollOffset = 50;
const visibleOffset = -100;
const fixedOffset = 0;

let prevScrollPos = window.scrollY;
let prevScrollPos = scrollContainer.current?.scrollTop;
let totalScrollDiff = 0;
let prevScrollDirection: ScrollDirection = "down";

const handleScroll = () => {
const currentScrollPos = window.scrollY;
const scrollDirection = prevScrollPos > currentScrollPos ? "up" : "down";
let alwaysVisible = false;

// Handle fixed/static menu
const homeRect = document.getElementById("Home")?.getBoundingClientRect();
if (homeRect) {
if (homeRect.top > visibleOffset) {
alwaysVisible = true;
}

if (homeRect.top < fixedOffset && scrollDirection == "up") {
setFixed(true);
} else {
setFixed(false);
if(scrollContainer.current) {
setVisible(scrollContainer.current?.scrollTop > 0 || scrollContainer.current?.scrollTop === 0 && introVisited)
const currentScrollPos = scrollContainer.current?.scrollTop;
if(currentScrollPos) {
const scrollDirection = prevScrollPos > currentScrollPos ? "up" : "down";
let alwaysVisible = false;

// Handle fixed/static menu
const homeRect = document.getElementById("Home")?.getBoundingClientRect();
if (homeRect) {
if (homeRect.top > visibleOffset) {
alwaysVisible = true;
}

if (homeRect.top < fixedOffset && scrollDirection == "up") {
setFixed(scrollContainer.current?.scrollTop > 10 && introVisited || scrollContainer.current?.scrollTop !== 0 && !introVisited );

} else {
setFixed(false);
}
}

if (scrollDirection === prevScrollDirection) {
totalScrollDiff += currentScrollPos - prevScrollPos;
} else {
totalScrollDiff = 0;
prevScrollDirection = scrollDirection;
}

if (Math.abs(totalScrollDiff) > scrollOffset || alwaysVisible) {
setVisible(scrollDirection === "up" ? true : alwaysVisible);
}

prevScrollPos = currentScrollPos;
}
}

if (scrollDirection === prevScrollDirection) {
totalScrollDiff += currentScrollPos - prevScrollPos;
} else {
totalScrollDiff = 0;
prevScrollDirection = scrollDirection;
}

if (Math.abs(totalScrollDiff) > scrollOffset || alwaysVisible) {
setVisible(scrollDirection === "up" ? true : alwaysVisible);
}

prevScrollPos = currentScrollPos;


};

window.addEventListener("scroll", handleScroll, { passive: true });
scrollContainer.current.addEventListener("scroll", handleScroll, { passive: true });
return () => {
window.removeEventListener("scroll", handleScroll);
scrollContainer.current?.removeEventListener("scroll", handleScroll);
};
}, []);
}
}, [scrollContainer, introVisited]);

return (
<Nav fixed={fixed} open={open} visible={visible}>
{showMenu && (
{(
<>
<NavHeader>
<NavLink id={"#Contact"} title="Contact" subtitle="We are sprout" text="Lorum ipsum"></NavLink>
Expand Down Expand Up @@ -118,8 +134,9 @@ const NavHeader = styled.header`
`;

const Nav = styled.nav<{ fixed: boolean; open: boolean; visible: boolean }>`
position: absolute;
top: auto;
position: fixed;

top: 0;
z-index: 10;
background: ${(props) => (props.open ? "black" : "transparent")};
display: flex;
Expand All @@ -131,12 +148,17 @@ const Nav = styled.nav<{ fixed: boolean; open: boolean; visible: boolean }>`
transition: opacity 0.2s linear;
opacity: ${(props) => (props.visible ? "1" : "0")};

${mq["sm"]} {
right : 1rem;
}

${(props) =>
props.fixed &&
css`
position: fixed;
top: 0;
background: black;

`}

${(props) =>
Expand Down
11 changes: 9 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ body {
-webkit-overflow-scrolling: touch;
}

#root {
overflow: hidden;
height : 100%;

}

html,
body {
padding: 0;
margin: 0;
overflow-y: auto;
overflow-y: hidden;
background-color: rgba(255 255 255 / 100%);

height : 100%;
.circle {
width: 20px;
height: 20px;
Expand All @@ -66,6 +72,7 @@ body * {
-webkit-tap-highlight-color: transparent;
user-select: none;
-webkit-user-drag: none;

}

:root {
Expand Down