Skip to content

Commit

Permalink
feat: add collapse animation to a sidebar (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
r1skz3ro authored Jun 21, 2024
1 parent 67c4731 commit 6a02654
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 25 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"postinstall": "cd .. && husky frontend/.husky"
},
"dependencies": {
"@headlessui/react": "^1.7.18",
"@headlessui/react": "^2.0.4",
"clsx": "^2.1.0",
"next": "14.1.3",
"react": "^18",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function RootLayout({
<body className={`${inter.className} bg-navy-50 h-full`}>
<div className="flex">
<Sidebar />
<div className="w-full pl-72">
<div className="w-full">
<Topbar />
<main className="p-8">{children}</main>
</div>
Expand Down
41 changes: 30 additions & 11 deletions frontend/src/components/modules/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
'use client';
import Image from 'next/image';
import Link from 'next/link';
import { generateClassNames } from '@app/utils';
import { navigation } from './utils';
import { ChevronDoubleLeft } from '@app/static/icons/ChevronDoubleLeft';
import { Button } from '@headlessui/react';
import { useState } from 'react';

const duration = 'duration-300' as const;

export const Sidebar = () => {
const [open, setOpen] = useState(true);

const toggleSidebar = () => setOpen((prev) => !prev);

return (
<nav className="w-72 z-50 fixed h-full flex flex-col bg-white px-3 border-r border-navy-200">
<div className="flex h-16 shrink-0 items-center">
<Image
src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=600"
alt="Logo"
width={32}
height={32}
/>
<nav
className={`z-50 h-screen ${open ? 'w-72' : 'w-16'} ${duration} flex flex-col bg-white px-3 border-r border-navy-200`}
>
<div className="flex h-16 shrink-0 justify-between">
<div className={`${duration} flex ${open ? 'opacity-1' : 'opacity-0'}`}>
<Image
src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=600"
alt="Logo"
width={32}
height={32}
/>
</div>
<Button onClick={toggleSidebar}>
<ChevronDoubleLeft className={`flex ${duration} ${open ? '' : 'rotate-180 mr-2'}`} />
</Button>
</div>
<ul role="list" className="flex flex-1 flex-col gap-y-7">
<li>
Expand All @@ -22,12 +39,14 @@ export const Sidebar = () => {
<Link
href={item.href}
className={generateClassNames(
'flex items-center gap-x-3 rounded-md p-2 text-sm leading-6 font-medium text-navy-600 hover:bg-blue-100',
'flex items-center p-2 rounded-md font-medium text-navy-600 hover:bg-blue-100 whitespace-nowrap',
{ 'bg-blue-100 text-blue-900': item.current },
)}
>
<item.icon className={`w-5 h-5`} />
{item.name}
<div className="flex gap-x-3 items-center">
<item.icon className="w-5 h-5" />
<span className={`${duration} leading-6 ${open ? 'text-sm' : 'text-[0px]'}`}>{item.name}</span>
</div>
</Link>
</li>
))}
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/static/icons/ChevronDoubleLeft.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const ChevronDoubleLeft: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
<path
d="M10 16L6.53034 12.5303C6.23745 12.2374 6.23745 11.7626 6.53034 11.4697L10 8M17 16L13.5303 12.5303C13.2374 12.2374 13.2374 11.7626 13.5303 11.4697L17 8"
stroke="#A1A5AC"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
);
118 changes: 106 additions & 12 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
dependencies:
"@floating-ui/utils" "^0.2.1"

"@floating-ui/dom@^1.0.0":
version "1.6.5"
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.6.5.tgz#323f065c003f1d3ecf0ff16d2c2c4d38979f4cb9"
integrity sha512-Nsdud2X65Dz+1RHjAIP0t8z5e2ff/IRbei6BqFrl1urT8sDVzM1HMQ+R0XcU5ceRfyO3I6ayeqIfh+6Wb8LGTw==
dependencies:
"@floating-ui/core" "^1.0.0"
"@floating-ui/utils" "^0.2.0"

"@floating-ui/dom@^1.6.1":
version "1.6.3"
resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.6.3.tgz#954e46c1dd3ad48e49db9ada7218b0985cee75ef"
Expand All @@ -73,18 +81,36 @@
"@floating-ui/core" "^1.0.0"
"@floating-ui/utils" "^0.2.0"

"@floating-ui/react-dom@^2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@floating-ui/react-dom/-/react-dom-2.1.0.tgz#4f0e5e9920137874b2405f7d6c862873baf4beff"
integrity sha512-lNzj5EQmEKn5FFKc04+zasr09h/uX8RtJRNj5gUXsSQIXHVWTVh+hVAg1vOMCexkX8EgvemMvIFpQfkosnVNyA==
dependencies:
"@floating-ui/dom" "^1.0.0"

"@floating-ui/react@^0.26.13":
version "0.26.17"
resolved "https://registry.yarnpkg.com/@floating-ui/react/-/react-0.26.17.tgz#efa2e1a0dea3d9d308965c5ccd49756bb64a883d"
integrity sha512-ESD+jYWwqwVzaIgIhExrArdsCL1rOAzryG/Sjlu8yaD3Mtqi3uVyhbE2V7jD58Mo52qbzKz2eUY/Xgh5I86FCQ==
dependencies:
"@floating-ui/react-dom" "^2.1.0"
"@floating-ui/utils" "^0.2.0"
tabbable "^6.0.0"

"@floating-ui/utils@^0.2.0", "@floating-ui/utils@^0.2.1":
version "0.2.1"
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.1.tgz#16308cea045f0fc777b6ff20a9f25474dd8293d2"
integrity sha512-9TANp6GPoMtYzQdt54kfAyMmz1+osLlXdg2ENroU7zzrtflTLrrC/lgrIfaSe+Wu0b89GKccT7vxXA0MoAIO+Q==

"@headlessui/react@^1.7.18":
version "1.7.18"
resolved "https://registry.yarnpkg.com/@headlessui/react/-/react-1.7.18.tgz#30af4634d2215b2ca1aa29d07f33d02bea82d9d7"
integrity sha512-4i5DOrzwN4qSgNsL4Si61VMkUcWbcSKueUV7sFhpHzQcSShdlHENE5+QBntMSRvHt8NyoFO2AGG8si9lq+w4zQ==
"@headlessui/react@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@headlessui/react/-/react-2.0.4.tgz#46cb39ca9dde3c2d15f4706c81dad78405b608f0"
integrity sha512-16d/rOLeYsFsmPlRmXGu8DCBzrWD0zV1Ccx3n73wN87yFu8Y9+X04zflv8EJEt9TAYRyLKOmQXUnOnqQl6NgpA==
dependencies:
"@tanstack/react-virtual" "^3.0.0-beta.60"
client-only "^0.0.1"
"@floating-ui/react" "^0.26.13"
"@react-aria/focus" "^3.16.2"
"@react-aria/interactions" "^3.21.1"
"@tanstack/react-virtual" "3.5.0"

"@humanwhocodes/config-array@^0.11.14":
version "0.11.14"
Expand Down Expand Up @@ -237,6 +263,57 @@
resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31"
integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==

"@react-aria/focus@^3.16.2":
version "3.17.1"
resolved "https://registry.yarnpkg.com/@react-aria/focus/-/focus-3.17.1.tgz#c796a188120421e2fedf438cadacdf463c77ad29"
integrity sha512-FLTySoSNqX++u0nWZJPPN5etXY0WBxaIe/YuL/GTEeuqUIuC/2bJSaw5hlsM6T2yjy6Y/VAxBcKSdAFUlU6njQ==
dependencies:
"@react-aria/interactions" "^3.21.3"
"@react-aria/utils" "^3.24.1"
"@react-types/shared" "^3.23.1"
"@swc/helpers" "^0.5.0"
clsx "^2.0.0"

"@react-aria/interactions@^3.21.1", "@react-aria/interactions@^3.21.3":
version "3.21.3"
resolved "https://registry.yarnpkg.com/@react-aria/interactions/-/interactions-3.21.3.tgz#a2a3e354a8b894bed7a46e1143453f397f2538d7"
integrity sha512-BWIuf4qCs5FreDJ9AguawLVS0lV9UU+sK4CCnbCNNmYqOWY+1+gRXCsnOM32K+oMESBxilAjdHW5n1hsMqYMpA==
dependencies:
"@react-aria/ssr" "^3.9.4"
"@react-aria/utils" "^3.24.1"
"@react-types/shared" "^3.23.1"
"@swc/helpers" "^0.5.0"

"@react-aria/ssr@^3.9.4":
version "3.9.4"
resolved "https://registry.yarnpkg.com/@react-aria/ssr/-/ssr-3.9.4.tgz#9da8b10342c156e816dbfa4c9e713b21f274d7ab"
integrity sha512-4jmAigVq409qcJvQyuorsmBR4+9r3+JEC60wC+Y0MZV0HCtTmm8D9guYXlJMdx0SSkgj0hHAyFm/HvPNFofCoQ==
dependencies:
"@swc/helpers" "^0.5.0"

"@react-aria/utils@^3.24.1":
version "3.24.1"
resolved "https://registry.yarnpkg.com/@react-aria/utils/-/utils-3.24.1.tgz#9d16023f07c23c41793c9030a9bd203a9c8cf0a7"
integrity sha512-O3s9qhPMd6n42x9sKeJ3lhu5V1Tlnzhu6Yk8QOvDuXf7UGuUjXf9mzfHJt1dYzID4l9Fwm8toczBzPM9t0jc8Q==
dependencies:
"@react-aria/ssr" "^3.9.4"
"@react-stately/utils" "^3.10.1"
"@react-types/shared" "^3.23.1"
"@swc/helpers" "^0.5.0"
clsx "^2.0.0"

"@react-stately/utils@^3.10.1":
version "3.10.1"
resolved "https://registry.yarnpkg.com/@react-stately/utils/-/utils-3.10.1.tgz#dc8685b4994bef0dc10c37b024074be8afbfba62"
integrity sha512-VS/EHRyicef25zDZcM/ClpzYMC5i2YGN6uegOeQawmgfGjb02yaCX0F0zR69Pod9m2Hr3wunTbtpgVXvYbZItg==
dependencies:
"@swc/helpers" "^0.5.0"

"@react-types/shared@^3.23.1":
version "3.23.1"
resolved "https://registry.yarnpkg.com/@react-types/shared/-/shared-3.23.1.tgz#2f23c81d819d0ef376df3cd4c944be4d6bce84c3"
integrity sha512-5d+3HbFDxGZjhbMBeFHRQhexMFt4pUce3okyRtUVKbbedQFUrtXSBg9VszgF2RTeQDKDkMCIQDtz5ccP/Lk1gw==

"@rushstack/eslint-patch@^1.3.3":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@rushstack/eslint-patch/-/eslint-patch-1.7.2.tgz#2d4260033e199b3032a08b41348ac10de21c47e9"
Expand Down Expand Up @@ -264,12 +341,19 @@
resolved "https://registry.yarnpkg.com/@tanstack/react-virtual/-/react-virtual-3.2.0.tgz#fb70f9c6baee753a5a0f7618ac886205d5a02af9"
integrity sha512-OEdMByf2hEfDa6XDbGlZN8qO6bTjlNKqjM3im9JG+u3mCL8jALy0T/67oDI001raUUPh1Bdmfn4ZvPOV5knpcg==
dependencies:
"@tanstack/virtual-core" "3.2.0"
tslib "^2.4.0"

"@tanstack/[email protected]":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@tanstack/virtual-core/-/virtual-core-3.2.0.tgz#874d36135e4badce2719e7bdc556ce240cbaff14"
integrity sha512-P5XgYoAw/vfW65byBbJQCw+cagdXDT/qH6wmABiLt4v4YBT2q2vqCOhihe+D1Nt325F/S/0Tkv6C5z0Lv+VBQQ==
"@tanstack/[email protected]":
version "3.5.0"
resolved "https://registry.yarnpkg.com/@tanstack/react-virtual/-/react-virtual-3.5.0.tgz#873b5b77cf78af563a4a11e6251ed51ee8868132"
integrity sha512-rtvo7KwuIvqK9zb0VZ5IL7fiJAEnG+0EiFZz8FUOs+2mhGqdGmjKIaT1XU7Zq0eFqL0jonLlhbayJI/J2SA/Bw==
dependencies:
"@tanstack/virtual-core" "3.5.0"

"@tanstack/[email protected]":
version "3.5.0"
resolved "https://registry.yarnpkg.com/@tanstack/virtual-core/-/virtual-core-3.5.0.tgz#108208d0f1d75271300bc5560cf9a85a1fa01e89"
integrity sha512-KnPRCkQTyqhanNC0K63GBG3wA8I+D1fQuVnAvcBF8f13akOKeQp1gSbu6f77zCxhEk727iV5oQnbHLYzHrECLg==

"@types/debug@^4.0.0":
version "4.1.12"
Expand Down Expand Up @@ -750,11 +834,16 @@ classnames@^2.3.0:
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.5.1.tgz#ba774c614be0f016da105c858e7159eae8e7687b"
integrity sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==

[email protected], client-only@^0.0.1:
[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/client-only/-/client-only-0.0.1.tgz#38bba5d403c41ab150bff64a95c85013cf73bca1"
integrity sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==

clsx@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==

clsx@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.0.tgz#e851283bcb5c80ee7608db18487433f7b23f77cb"
Expand Down Expand Up @@ -3389,6 +3478,11 @@ synckit@^0.8.6:
"@pkgr/core" "^0.1.0"
tslib "^2.6.2"

tabbable@^6.0.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/tabbable/-/tabbable-6.2.0.tgz#732fb62bc0175cfcec257330be187dcfba1f3b97"
integrity sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==

tailwind-merge@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/tailwind-merge/-/tailwind-merge-2.2.2.tgz#87341e7604f0e20499939e152cd2841f41f7a3df"
Expand Down

0 comments on commit 6a02654

Please sign in to comment.