Skip to content

Commit

Permalink
made sidebar responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunsoftprodigy committed Oct 21, 2024
1 parent a04e2e1 commit e559e2b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions mirror-2/app/home/components/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use client'
import { cn } from '@/lib/utils'
import { useEffect, useState } from 'react'

import { Playlist } from '../data/playlists'
import { Button } from '@/components/ui/button'
import Link from 'next/link'
import { Axis3D, Gamepad2, PlusCircleIcon } from 'lucide-react'
import {
Dialog,
DialogClose,
DialogContent,
DialogOverlay,
DialogPortal,
Expand Down Expand Up @@ -69,7 +70,23 @@ const SidebarMenuForSmallScreen = () => {
)
}

export function Sidebar({ className, playlists, style }: SidebarProps) {
export function Sidebar({ className, style }: SidebarProps) {
const [windowWidth, setWindowWidth] = useState(window.innerWidth)
const [showSmallSideBar, setShowSmallSidebar] = useState(false)

const handleResize = () => setWindowWidth(window.innerWidth)

useEffect(() => {
window.addEventListener('resize', handleResize)
return () => window.removeEventListener('resize', handleResize)
}, [])

useEffect(() => {
if (windowWidth > 1024) {
setShowSmallSidebar(false)
}
}, [windowWidth])

return (
<>
<div
Expand Down Expand Up @@ -149,9 +166,12 @@ export function Sidebar({ className, playlists, style }: SidebarProps) {
</div>
</div>
{/* =========Sidebar button for smaller screens less than 1024px======= */}
<div className="space-y-4 py-4 mt-2 block sm:block md:block lg:hidden">
<Dialog>
<DialogTrigger>
<div className="space-y-4 py-4 mt-2 sm:block md:block lg:hidden sidebarMenuMobile">
<Dialog open={showSmallSideBar} onOpenChange={setShowSmallSidebar}>
<DialogTrigger
onClick={() => setShowSmallSidebar(true)}
className="p-2"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
Expand Down

0 comments on commit e559e2b

Please sign in to comment.