Skip to content

Commit 08552a8

Browse files
committed
Completely change header, pin header after user scrolls 300px
1 parent cfe6670 commit 08552a8

File tree

3 files changed

+53
-128
lines changed

3 files changed

+53
-128
lines changed

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"dependencies": {
1212
"@emotion/react": "^11.11.3",
1313
"@icons-pack/react-simple-icons": "^9.3.0",
14-
"@integreat-app/react-sticky-headroom": "^2.2.0",
1514
"@mantine/carousel": "^7.5.3",
1615
"@mantine/core": "^7.5.0",
1716
"@mantine/form": "^7.5.0",
@@ -30,7 +29,6 @@
3029
"react-dom": "^18.2.0",
3130
"react-simple-typewriter": "^5.0.1",
3231
"react-spinners": "^0.13.8",
33-
"styled-components": "^6.1.8",
3432
"tabler-icons-react": "^1.56.0",
3533
"typescript": "5.3.3"
3634
},

src/app/components/HeaderMenu.tsx

+53-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from "react";
1+
import React, { useEffect } from "react";
22
import {
33
Group,
44
Burger,
@@ -10,19 +10,13 @@ import {
1010
Anchor,
1111
} from "@mantine/core";
1212
import { useDisclosure, useWindowScroll } from "@mantine/hooks";
13+
import { useState } from "react";
1314
import { IconChevronDown } from "@tabler/icons-react";
1415
import classes from "./HeaderMenu.module.css";
1516
import Image from "next/image";
1617
import Link from "next/link";
17-
import dynamic from "next/dynamic";
1818
import { IconBrandFacebook, IconBrandLinkedin } from "@tabler/icons-react";
1919

20-
// next/dynamic is used to import the StickyHeadroom component dynamically
21-
// This is done to prevent the component from being rendered on the server, which would cause an error.
22-
const StickyHeadroom = dynamic(
23-
() => import("@integreat-app/react-sticky-headroom")
24-
);
25-
2620
const links = [
2721
{ link: "/#about", label: "About" },
2822
{ link: "/#services", label: "Our Services" },
@@ -45,14 +39,16 @@ export function HeaderMenu() {
4539
const [opened, { toggle }] = useDisclosure(false);
4640
const [active, setActive] = useState(-1);
4741
const [scroll] = useWindowScroll(); // Get the current scroll position
48-
const [showHeader, setShowHeader] = useState(false); // State to control the visibility of the header.
42+
const [showHeader, setShowHeader] = useState(false);
4943

5044
useEffect(() => {
51-
// Check if the page has been scrolled (i.e., scroll.y > 300), and update showHeader accordingly.
52-
setShowHeader(scroll.y > 300);
53-
}, [scroll.y]);
45+
// Check if the user has scrolled down 200px and update showHeader accordingly
46+
const handleScroll = () => setShowHeader(scroll.y > 300);
47+
handleScroll(); // Call it on component mount
5448

55-
if (!showHeader) return null; // Do not render the header if showHeader is false.
49+
// Since useWindowScroll hook provides scroll position reactively,
50+
// there's no need to add a separate event listener for scroll events.
51+
}, [scroll.y]);
5652

5753
const items = links.map((link, index) => {
5854
// This is the code for the DROPDOWN menu
@@ -101,41 +97,53 @@ export function HeaderMenu() {
10197
);
10298
});
10399

100+
if (!showHeader) return null; // Do not render the header if the user hasn't scrolled down 200px yet
101+
104102
return (
105103
<>
106-
<StickyHeadroom scrollHeight={56} zIndex={2} pinStart={300}>
107-
<header className={classes.header}>
108-
<Container size="lg">
109-
<div className={classes.inner}>
110-
<Link
111-
href="/"
112-
onClick={() => {
113-
setActive(-1);
114-
}}
115-
>
116-
<Image
117-
src={`${process.env.NEXT_PUBLIC_BASE_PATH}/cc-main-logo-green.svg`}
118-
alt="Colchuck Consulting Logo"
119-
width={120}
120-
height={30}
121-
priority={true} // Load this image before others
122-
className={classes.logo}
123-
style={{ marginTop: "7px" }}
124-
/>
125-
</Link>
126-
<Group gap={0} justify="flex-end" visibleFrom="sm">
127-
{items}
128-
</Group>
129-
<Burger
130-
opened={opened}
131-
onClick={toggle}
132-
size="sm"
133-
hiddenFrom="sm"
104+
<header
105+
className={classes.header}
106+
style={{
107+
position: "fixed",
108+
top: 0,
109+
left: 0,
110+
right: 0,
111+
height: rem(56),
112+
zIndex: 2,
113+
transition: "transform 400ms ease",
114+
backgroundColor: "var(--mantine-color-body)",
115+
}}
116+
>
117+
<Container size="lg">
118+
<div className={classes.inner}>
119+
<Link
120+
href="/"
121+
onClick={() => {
122+
setActive(-1);
123+
}}
124+
>
125+
<Image
126+
src={`${process.env.NEXT_PUBLIC_BASE_PATH}/cc-main-logo-green.svg`}
127+
alt="Colchuck Consulting Logo"
128+
width={120}
129+
height={30}
130+
priority={true} // Load this image before others
131+
className={classes.logo}
132+
style={{ marginTop: "7px" }}
134133
/>
135-
</div>
136-
</Container>
137-
</header>
138-
</StickyHeadroom>
134+
</Link>
135+
<Group gap={0} justify="flex-end" visibleFrom="sm">
136+
{items}
137+
</Group>
138+
<Burger
139+
opened={opened}
140+
onClick={toggle}
141+
size="sm"
142+
hiddenFrom="sm"
143+
/>
144+
</div>
145+
</Container>
146+
</header>
139147
<Drawer
140148
opened={opened}
141149
onClose={toggle}

yarn.lock

-81
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@
9090
resolved "https://registry.yarnpkg.com/@emotion/hash/-/hash-0.9.1.tgz#4ffb0055f7ef676ebc3a5a91fb621393294e2f43"
9191
integrity sha512-gJB6HLm5rYwSLI6PQa+X1t5CFGrv1J1TWG+sOyMCeKz2ojaj6Fnl/rZEspogG+cvqbt4AE/2eIyD2QfLKTBNlQ==
9292

93-
"@emotion/[email protected]":
94-
version "1.2.1"
95-
resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-1.2.1.tgz#23116cf1ed18bfeac910ec6436561ecb1a3885cc"
96-
integrity sha512-61Mf7Ufx4aDxx1xlDeOm8aFFigGHE4z+0sKCa+IHCeZKiyP9RLD0Mmx7m8b9/Cf37f7NAvQOOJAbQQGVr5uERw==
97-
dependencies:
98-
"@emotion/memoize" "^0.8.1"
99-
10093
"@emotion/memoize@^0.8.1":
10194
version "0.8.1"
10295
resolved "https://registry.yarnpkg.com/@emotion/memoize/-/memoize-0.8.1.tgz#c1ddb040429c6d21d38cc945fe75c818cfb68e17"
@@ -132,11 +125,6 @@
132125
resolved "https://registry.yarnpkg.com/@emotion/sheet/-/sheet-1.2.2.tgz#d58e788ee27267a14342303e1abb3d508b6d0fec"
133126
integrity sha512-0QBtGvaqtWi+nx6doRwDdBIzhNdZrXUppvTM4dtZZWEGTXL/XE/yJxLMGlDT1Gt+UHH5IX1n+jkXyytE/av7OA==
134127

135-
"@emotion/[email protected]":
136-
version "0.8.0"
137-
resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.8.0.tgz#a4a36e9cbdc6903737cd20d38033241e1b8833db"
138-
integrity sha512-VINS5vEYAscRl2ZUDiT3uMPlrFQupiKgHz5AA4bCH1miKBg4qtwkim1qPmJj/4WG6TreYMY111rEFsjupcOKHw==
139-
140128
"@emotion/unitless@^0.8.1":
141129
version "0.8.1"
142130
resolved "https://registry.yarnpkg.com/@emotion/unitless/-/unitless-0.8.1.tgz#182b5a4704ef8ad91bde93f7a860a88fd92c79a3"
@@ -249,11 +237,6 @@
249237
resolved "https://registry.yarnpkg.com/@icons-pack/react-simple-icons/-/react-simple-icons-9.3.0.tgz#a3901d7eb0f2f4109d8f2c584f537cea056aa238"
250238
integrity sha512-e2VRDFrhI9rCkEdkuAUhf/Ool0cwusWnwKqMACbIRMLHXxnHp1SdnGlRaEEjDeF4R0pQaEkmVNs2x2vn1sl+7A==
251239

252-
"@integreat-app/react-sticky-headroom@^2.2.0":
253-
version "2.2.0"
254-
resolved "https://registry.yarnpkg.com/@integreat-app/react-sticky-headroom/-/react-sticky-headroom-2.2.0.tgz#2b16b06f632f785c2a882983143dd3274c89c67a"
255-
integrity sha512-PqeQ8dm51f3rSZIT+XpnAHl7t2kI3bp/X3gnb6OGW6bQy8loFa5uUcSgiTZ8yRN/XoQv5mtUBStz3DaHfS9vmQ==
256-
257240
"@isaacs/cliui@^8.0.2":
258241
version "8.0.2"
259242
resolved "https://registry.yarnpkg.com/@isaacs/cliui/-/cliui-8.0.2.tgz#b37667b7bc181c168782259bab42474fbf52b550"
@@ -447,11 +430,6 @@
447430
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.8.tgz#ce5ace04cfeabe7ef87c0091e50752e36707deff"
448431
integrity sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==
449432

450-
451-
version "4.2.0"
452-
resolved "https://registry.yarnpkg.com/@types/stylis/-/stylis-4.2.0.tgz#199a3f473f0c3a6f6e4e1b17cdbc967f274bdc6b"
453-
integrity sha512-n4sx2bqL0mW1tvDf/loQ+aMX7GQD3lc3fkCMC55VFNDu/vBOabO+LTIeXKM14xK0ppk5TUGcWRjiSpIlUpghKw==
454-
455433
"@typescript-eslint/parser@^5.4.2 || ^6.0.0":
456434
version "6.20.0"
457435
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.20.0.tgz#17e314177304bdf498527e3c4b112e41287b7416"
@@ -758,11 +736,6 @@ camelcase-css@^2.0.1:
758736
resolved "https://registry.yarnpkg.com/camelcase-css/-/camelcase-css-2.0.1.tgz#ee978f6947914cc30c6b44741b6ed1df7f043fd5"
759737
integrity sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA==
760738

761-
camelize@^1.0.0:
762-
version "1.0.1"
763-
resolved "https://registry.yarnpkg.com/camelize/-/camelize-1.0.1.tgz#89b7e16884056331a35d6b5ad064332c91daa6c3"
764-
integrity sha512-dU+Tx2fsypxTgtLoE36npi3UqcjSSMNYfkqgmoEhtZrraP5VWq0K7FkWVTYa8eMPtnU/G2txVsfdCJTn9uzpuQ==
765-
766739
caniuse-lite@^1.0.30001579:
767740
version "1.0.30001581"
768741
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001581.tgz#0dfd4db9e94edbdca67d57348ebc070dece279f4"
@@ -859,30 +832,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2:
859832
shebang-command "^2.0.0"
860833
which "^2.0.1"
861834

862-
css-color-keywords@^1.0.0:
863-
version "1.0.0"
864-
resolved "https://registry.yarnpkg.com/css-color-keywords/-/css-color-keywords-1.0.0.tgz#fea2616dc676b2962686b3af8dbdbe180b244e05"
865-
integrity sha512-FyyrDHZKEjXDpNJYvVsV960FiqQyXc/LlYmsxl2BcdMb2WPx0OGRVgTg55rPSyLSNMqP52R9r8geSp7apN3Ofg==
866-
867-
868-
version "3.2.0"
869-
resolved "https://registry.yarnpkg.com/css-to-react-native/-/css-to-react-native-3.2.0.tgz#cdd8099f71024e149e4f6fe17a7d46ecd55f1e32"
870-
integrity sha512-e8RKaLXMOFii+02mOlqwjbD00KSEKqblnpO9e++1aXS1fPQOpS1YoqdVHBqPjHNoxeF2mimzVqawm2KCbEdtHQ==
871-
dependencies:
872-
camelize "^1.0.0"
873-
css-color-keywords "^1.0.0"
874-
postcss-value-parser "^4.0.2"
875-
876835
cssesc@^3.0.0:
877836
version "3.0.0"
878837
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
879838
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==
880839

881-
882-
version "3.1.2"
883-
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
884-
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==
885-
886840
csstype@^3.0.2:
887841
version "3.1.3"
888842
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81"
@@ -2382,11 +2336,6 @@ postcss-simple-vars@^7.0.0:
23822336
resolved "https://registry.yarnpkg.com/postcss-simple-vars/-/postcss-simple-vars-7.0.1.tgz#836b3097a54dcd13dbd3c36a5dbdd512fad2954c"
23832337
integrity sha512-5GLLXaS8qmzHMOjVxqkk1TZPf1jMqesiI7qLhnlyERalG0sMbHIbJqrcnrpmZdKCLglHnRHoEBB61RtGTsj++A==
23842338

2385-
postcss-value-parser@^4.0.2:
2386-
version "4.2.0"
2387-
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
2388-
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==
2389-
23902339
23912340
version "8.4.31"
23922341
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
@@ -2643,11 +2592,6 @@ set-function-name@^2.0.0, set-function-name@^2.0.1:
26432592
functions-have-names "^1.2.3"
26442593
has-property-descriptors "^1.0.0"
26452594

2646-
2647-
version "1.1.0"
2648-
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
2649-
integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==
2650-
26512595
shebang-command@^2.0.0:
26522596
version "2.0.0"
26532597
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea"
@@ -2786,21 +2730,6 @@ strip-outer@^1.0.1:
27862730
dependencies:
27872731
escape-string-regexp "^1.0.2"
27882732

2789-
styled-components@^6.1.8:
2790-
version "6.1.8"
2791-
resolved "https://registry.yarnpkg.com/styled-components/-/styled-components-6.1.8.tgz#c109d36aeea52d8f049e12de2f3be39a6fc86201"
2792-
integrity sha512-PQ6Dn+QxlWyEGCKDS71NGsXoVLKfE1c3vApkvDYS5KAK+V8fNWGhbSUEo9Gg2iaID2tjLXegEW3bZDUGpofRWw==
2793-
dependencies:
2794-
"@emotion/is-prop-valid" "1.2.1"
2795-
"@emotion/unitless" "0.8.0"
2796-
"@types/stylis" "4.2.0"
2797-
css-to-react-native "3.2.0"
2798-
csstype "3.1.2"
2799-
postcss "8.4.31"
2800-
shallowequal "1.1.0"
2801-
stylis "4.3.1"
2802-
tslib "2.5.0"
2803-
28042733
28052734
version "5.1.1"
28062735
resolved "https://registry.yarnpkg.com/styled-jsx/-/styled-jsx-5.1.1.tgz#839a1c3aaacc4e735fed0781b8619ea5d0009d1f"
@@ -2813,11 +2742,6 @@ [email protected]:
28132742
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.2.0.tgz#79daee0208964c8fe695a42fcffcac633a211a51"
28142743
integrity sha512-Orov6g6BB1sDfYgzWfTHDOxamtX1bE/zo104Dh9e6fqJ3PooipYyfJ0pUmrZO2wAvO8YbEyeFrkV91XTsGMSrw==
28152744

2816-
2817-
version "4.3.1"
2818-
resolved "https://registry.yarnpkg.com/stylis/-/stylis-4.3.1.tgz#ed8a9ebf9f76fe1e12d462f5cc3c4c980b23a7eb"
2819-
integrity sha512-EQepAV+wMsIaGVGX1RECzgrcqRRU/0sYOHkeLsZ3fzHaHXZy4DaOOX0vOlGQdlsjkh3mFHAIlVimpwAs4dslyQ==
2820-
28212745
sugarss@^4.0.1:
28222746
version "4.0.1"
28232747
resolved "https://registry.yarnpkg.com/sugarss/-/sugarss-4.0.1.tgz#128a783ed71ee0fc3b489ce1f7d5a89bc1e24383"
@@ -2896,11 +2820,6 @@ tsconfig-paths@^3.15.0:
28962820
minimist "^1.2.6"
28972821
strip-bom "^3.0.0"
28982822

2899-
2900-
version "2.5.0"
2901-
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.5.0.tgz#42bfed86f5787aeb41d031866c8f402429e0fddf"
2902-
integrity sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==
2903-
29042823
tslib@^2.0.0, tslib@^2.1.0, tslib@^2.4.0:
29052824
version "2.6.2"
29062825
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"

0 commit comments

Comments
 (0)