{"id":26218103,"url":"https://github.com/arnobt78/navbar--react-fundamental-project-11","last_synced_at":"2025-03-12T13:15:31.404Z","repository":{"id":276601807,"uuid":"929748943","full_name":"arnobt78/Navbar--React-Fundamental-Project-11","owner":"arnobt78","description":"This project demonstrates how to create a responsive navigation bar using React and Vite. The navigation bar includes links and social icons, which are dynamically rendered based on the component's state.","archived":false,"fork":false,"pushed_at":"2025-02-09T10:04:32.000Z","size":61,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-09T11:19:17.385Z","etag":null,"topics":["getboundingclientrect","html-css-javascript","navbar","navbar-css","netlify-deployment","react","react-fundamentals","reactjs","useref","useref-hook"],"latest_commit_sha":null,"homepage":"https://navbar-arnob.netlify.app/","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arnobt78.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-09T09:58:26.000Z","updated_at":"2025-02-09T10:48:56.000Z","dependencies_parsed_at":"2025-02-09T11:19:19.198Z","dependency_job_id":"3d9bd161-2e00-4a22-ac45-42ff2561b393","html_url":"https://github.com/arnobt78/Navbar--React-Fundamental-Project-11","commit_stats":null,"previous_names":["arnobt78/navbar--react-fundamental-project-11"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnobt78%2FNavbar--React-Fundamental-Project-11","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnobt78%2FNavbar--React-Fundamental-Project-11/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnobt78%2FNavbar--React-Fundamental-Project-11/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnobt78%2FNavbar--React-Fundamental-Project-11/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnobt78","download_url":"https://codeload.github.com/arnobt78/Navbar--React-Fundamental-Project-11/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243222183,"owners_count":20256229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["getboundingclientrect","html-css-javascript","navbar","navbar-css","netlify-deployment","react","react-fundamentals","reactjs","useref","useref-hook"],"created_at":"2025-03-12T13:15:30.565Z","updated_at":"2025-03-12T13:15:31.397Z","avatar_url":"https://github.com/arnobt78.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cimg width=\"1195\" alt=\"Screenshot 2025-02-09 at 15 57 33\" src=\"https://github.com/user-attachments/assets/28095bdf-6ad6-4cda-a168-1c5faa605474\" /\u003e\n\n## Navbar Project - React Fundamental Project 11\n\nThis project demonstrates how to create a responsive navigation bar using React and Vite. The navigation bar includes links and social icons, which are dynamically rendered based on the component's state.\n\n**Online Live:** https://navbar-arnob.netlify.app/\n\n## Project Details and Steps\n\n### Data\n\nCheck the data.jsx file and find two arrays: one for links and one for social icons. Notice how icons from react-icons can be used directly in the data structures. Just make sure in Vite to use .jsx file extension\n\n### Initial Approach\n\nSet up a Navbar component with a showLinks state value (boolean). Import the links from data and render them conditionally in the Navbar based on the showLinks state value. Set up a button that toggles the value and as a result, toggles the links. Set up CSS for the Navbar.\n\n### Fixed Approach\n\nHide links by default in the CSS. Create a class that displays links with a fixed height. Refactor the JSX in the Navbar to toggle the class, which in turn toggles the Navbar.\n\n### Dynamic Approach\n\nUse the useRef and getBoundingClientRect() function, to get exact height of links\n\n[Javascript Nuggets - Width/Height](https://www.youtube.com/watch?v=v8YENdbDv1w\u0026list=PLnHJACx3NwAfRUcuKaYhZ6T5NRIpzgNGJ\u0026index=20)\n\n### Complete App\n\nFinally, add social links and CSS to render the Navbar on the big screen.\n\n### Application Flow\n\nThe flow of the application should look something like this:\n\n- Check the data.js file and find two arrays: one for links and one for social icons.\n\n- Set up a Navbar component with a showLinks state value (boolean). Import the links from data and render them conditionally in the Navbar based on the showLinks state value. Set up a button that toggles the value and as a result, toggles the links. Set up CSS for the Navbar.\n\n- Hide links by default in the CSS. Create a class that displays links with a fixed height. Refactor the JSX in the Navbar to toggle the class, which in turn toggles the Navbar.\n\n- Use the useRef and getBoundingClientRect() function, to get exact height of links\n\n- Add social links and CSS to render the Navbar on the big screen.\n\n### Initial Approach\n\nNavbar.jsx\n\n```js\nimport { useState } from \"react\";\nimport { FaBars } from \"react-icons/fa\";\nimport { links, social } from \"./data\";\nimport logo from \"./logo.svg\";\n\nconst Navbar = () =\u003e {\n  const [showLinks, setShowLinks] = useState(false);\n\n  const toggleLinks = () =\u003e {\n    setShowLinks(!showLinks);\n  };\n\n  return (\n    \u003cnav\u003e\n      \u003cdiv className=\"nav-center\"\u003e\n        \u003cdiv className=\"nav-header\"\u003e\n          \u003cimg src={logo} className=\"logo\" alt=\"logo\" /\u003e\n          \u003cbutton className=\"nav-toggle\" onClick={toggleLinks}\u003e\n            \u003cFaBars /\u003e\n          \u003c/button\u003e\n        \u003c/div\u003e\n        {showLinks \u0026\u0026 (\n          \u003cdiv className=\"links-container\"\u003e\n            \u003cul className=\"links\"\u003e\n              {links.map((link) =\u003e {\n                const { id, url, text } = link;\n                return (\n                  \u003cli key={id}\u003e\n                    \u003ca href={url}\u003e{text}\u003c/a\u003e\n                  \u003c/li\u003e\n                );\n              })}\n            \u003c/ul\u003e\n          \u003c/div\u003e\n        )}\n      \u003c/div\u003e\n    \u003c/nav\u003e\n  );\n};\n\nexport default Navbar;\n```\n\n```css\nnav {\n  background: var(--white);\n  box-shadow: var(--shadow-1);\n}\n.nav-header {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  padding: 1rem;\n}\n.nav-toggle {\n  font-size: 1.5rem;\n  color: var(--primary-500);\n  background: transparent;\n  border-color: transparent;\n  transition: var(--transition);\n  cursor: pointer;\n}\n.nav-toggle:hover {\n  color: var(--primary-700);\n  transform: rotate(90deg);\n}\n.logo {\n  height: 40px;\n}\n.links a {\n  color: var(--grey-700);\n  font-size: 1rem;\n  text-transform: capitalize;\n  letter-spacing: var(--letterSpacing);\n  display: block;\n  padding: 0.5rem 1rem;\n  transition: var(--transition);\n}\n.links a:hover {\n  background: var(--primary-100);\n  color: var(--primary-500);\n  padding-left: 1.5rem;\n}\n```\n\n### Fixed Approach\n\n```css\n.links-container {\n  height: 0;\n  overflow: hidden;\n  transition: var(--transition);\n}\n.show-container {\n  height: 10rem;\n}\n```\n\n```js\n\u003cdiv\n  className={showLinks ? \"links-container show-container\" : \"links-container\"}\n\u003e\n  \u003cul className=\"links\"\u003e....links\u003c/ul\u003e\n\u003c/div\u003e\n```\n\n### Dynamic Approach\n\n```css\n.links-container {\n  overflow: hidden;\n  transition: var(--transition);\n}\n```\n\n```js\nimport { useState, useRef } from \"react\";\nimport { FaBars } from \"react-icons/fa\";\nimport { links, social } from \"./data\";\nimport logo from \"./logo.svg\";\n\nconst Navbar = () =\u003e {\n  const [showLinks, setShowLinks] = useState(false);\n  const linksContainerRef = useRef(null);\n  const linksRef = useRef(null);\n\n  const toggleLinks = () =\u003e {\n    setShowLinks(!showLinks);\n  };\n  const linkStyles = {\n    height: showLinks\n      ? `${linksRef.current.getBoundingClientRect().height}px`\n      : \"0px\",\n  };\n  return (\n    \u003cnav\u003e\n      \u003cdiv className=\"nav-center\"\u003e\n        \u003cdiv className=\"nav-header\"\u003e\n          \u003cimg src={logo} className=\"logo\" alt=\"logo\" /\u003e\n          \u003cbutton className=\"nav-toggle\" onClick={toggleLinks}\u003e\n            \u003cFaBars /\u003e\n          \u003c/button\u003e\n        \u003c/div\u003e\n\n        \u003cdiv\n          className=\"links-container\"\n          ref={linksContainerRef}\n          style={linkStyles}\n        \u003e\n          \u003cul className=\"links\" ref={linksRef}\u003e\n            {links.map((link) =\u003e {\n              const { id, url, text } = link;\n              return (\n                \u003cli key={id}\u003e\n                  \u003ca href={url}\u003e{text}\u003c/a\u003e\n                \u003c/li\u003e\n              );\n            })}\n          \u003c/ul\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    \u003c/nav\u003e\n  );\n};\n\nexport default Navbar;\n```\n\n### Complete APP CSS\n\n```css\n.social-icons {\n  display: none;\n}\n@media screen and (min-width: 800px) {\n  .nav-center {\n    max-width: 1170px;\n    margin: 0 auto;\n    display: flex;\n    align-items: center;\n    justify-content: space-between;\n    padding: 1rem;\n  }\n  .nav-header {\n    padding: 0;\n  }\n  .nav-toggle {\n    display: none;\n  }\n  .links-container {\n    height: auto !important;\n  }\n  .links {\n    display: flex;\n    gap: 0.5rem;\n  }\n  .links a {\n    padding: 0;\n  }\n  .links a:hover {\n    padding: 0;\n    background: transparent;\n  }\n  .social-icons {\n    display: flex;\n    gap: 0.5rem;\n  }\n  .social-icons a {\n    color: var(--primary-500);\n    transition: var(--transition);\n  }\n  .social-icons a:hover {\n    color: var(--primary-300);\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnobt78%2Fnavbar--react-fundamental-project-11","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnobt78%2Fnavbar--react-fundamental-project-11","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnobt78%2Fnavbar--react-fundamental-project-11/lists"}