Skip to content

Make a amazing Office Website

Posted on:August 15, 2024 at 01:31 PM
Share on

Table of contents

Open Table of contents

Setup Project

  1. If you don’t install bun, please install it firstly.
curl -fsSL https://bun.sh/install | bash
  1. use bun create nextjs project
mkdir office-website
cd office-website
bun create next-app .
  1. install dependencies and start the project
bun i
bun run dev
  1. visit http://localhost:3000 to check the project is working or not.

  2. remove the unused code from the project and check the tailwindcss is working or not.

<div>
  <h1 className="text-2xl text-red-600">office website</h1>
</div>
  1. Change the Font to Poppins
import { Poppins } from "next/font/google";
const poppins = Poppins({
  subsets: ["latin"],
  display: "swap",
  variable: "--font-poppins",
  weight: ["100", "200", "300", "400", "500", "600", "700", "800", "900"],
});

Make the Navbar component

  1. make components/Navbar.tsx file and use it in the app/page.tsx
export const Navbar = () => {
  return (
    <div>
      <h1>Navbar</h1>
    </div>
  );
};
  1. add the assets image to public directory

  2. add navitems array

  3. Adapt to mobile phone display

bun add react-icons
  1. add css merge util function cn to lib/utils.ts
bun add clsx tailwind-merge
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

Make the Hero Component

  1. install react-typed package
bun add  react-typed
  1. after add image div modify the navbar style

  2. add typed component

  3. change the font Dancing Script of typed and add a mask to the type area

/* app/global.css */
@import url("https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&display=swap");
.typed {
  font-family: "Dancing Script", cursive;
}
  1. add the dancer ball
bun add framer-motion

Make the Services Component

  1. install lucide icons package
bun add lucide-react
  1. add service items array
  2. make ServiceItem component

Make the Work Component

  1. add work items array

  2. add tags color to app/global.css

Make the Contact Component

  1. add form
  2. deal with show form input error message and create Alert Component
  3. install emailjs package
bun add @emailjs/browser
  1. config emailjs variable
export const Footer = () => {
  return (
    <footer className="mt-[44px] w-full bg-[#333]">
      <div className="text-white flex flex-wrap items-center justify-center">
        <div className="my-8">
          <p className="m-1">
            Copyright © 2024 Zerotone ltd. All rights reserved
          </p>
        </div>
      </div>
    </footer>
  );
};

Fix the navbar scroll bugs

const [isSticky, setIsSticky] = useState(false);

useEffect(() => {
  const handleScroll = () => {
    setIsSticky(window.scrollY > 100);
  };
  window.addEventListener("scroll", handleScroll);
  return () => {
    window.removeEventListener("scroll", handleScroll);
  };
}, []);

Deal with the scrollbar and make scroll smooth

  1. add scroll content area

change the app/page.tsx

  1. add the css in app/global.css
.hidden-scroll-bar {
  overflow: hidden;
}

/* keep content scroll */
.scrollable-content {
  height: 100vh; /* the view hight */
  overflow: auto; /* make the content  scroll */
  -ms-overflow-style: none; /* hidden scrollbar (Internet Explorer and Edge) */
  scrollbar-width: none; /* hidden scrollbar (Firefox) */
  scroll-behavior: smooth;
}

.scrollable-content::-webkit-scrollbar {
  display: none; /* hidden scrollbar (WebKit) */
}

html {
  scroll-behavior: smooth;
}
  1. fix the navbar sticky bugs
useEffect(() => {
    const scrollableContent = document.getElementById("scrollable-content")!;

    const handleScroll = () => {
      setIsSticky(window.scrollY > 100 || scrollableContent.scrollTop > 100);
    };

    window.addEventListener("scroll", handleScroll);
    scrollableContent.addEventListener("scroll", handleScroll);

    return () => {
      window.removeEventListener("scroll", handleScroll);
      scrollableContent.removeEventListener("scroll", handleScroll);
    };
  }, []);

Congratulations!!! you have completed a amazing office website.

Share on