Coder Social home page Coder Social logo

nextjs-chakra-navigation-example's Introduction

nextjs-chakra-navigation-example

I looked at how to implement navigation in next.js and chakra. Since this small project was so complex, I decided to publish it.

Here's a quick rundown of all the commands I've used. I will document this as soon as possible and comment on it as soon as I find time for it.

Create Project

  npx create-next-app knasan-nextjs-chakra-backend --with-typescript

Install chakra and chakra icons (MenuBurger in this project)

  npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^5 @chakra-ui/icons

Configure Typescript

touch tsconfig.json

Starting dev server, this fills the tsconfig.json file with simple configuration.

npm run dev

Add custom configuration into tsconfig.json

"baseUrl": ".",
    "paths" :{
      "@components/*": ["components/*"],
      "@styles/*": ["styles/*"],
    },

These lines set up aliases. This means you can always access the components with "@components" and don't have to think about the levels.

import Layout from '@components/Layout'

Build Navigation

I saved all related components in a subfolder of components.

  1. Build Logo.tsx (return a text, but could also return a logo or whatever.)
  2. Build MenuItem.tsx (return a link)
  3. Build MenuToogle.tsx (HamburgerMenu for Mobile, Desktop and Tablet)
  4. Build ToggleLayout (switching from light to dark mode)
  5. NavBarContainer.tsx (Basically, it's the component that encloses everything else.)
  6. NavBar.tsx (Is the only component that should actually be used by other sites! In this example, I've packed them into a layout page.)

Layout

Layout of the pages so that each page always has the same layout and it doesn't have to be rewritten over and over for each page. This got placed in the first level. Everything that I put in the first level, I also use in other pages. I only use everything in subfolders (e.g. navigation) within the components. I came up with this to keep track. If you know a better and easier way, please feel free to share it with me.

Index

Only uses layout and the layout component takes care of everything. Everything in between is passed on and processed as children.

nextjs-chakra-navigation-example's People

Contributors

knasan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.