import React, { useState } from 'react';
import { Box, Flex, Icon, Text, IconButton } from '@chakra-ui/react';
import { FiMenu, FiHome, FiSettings, FiUser } from 'react-icons/fi';
const Sidebar = () => {
const [isExpanded, setIsExpanded] = useState(false);
const toggleSidebar = () => {
setIsExpanded(!isExpanded);
};
const sidebarItems = [
{ icon: FiHome, text: 'Home' },
{ icon: FiUser, text: 'Profile' },
{ icon: FiSettings, text: 'Settings' },
];
return (
<Box
as="nav"
h="100vh"
bg="blue.700"
color="white"
w={isExpanded ? '15%' : '5%'}
transition="width 0.3s ease"
>
<Flex justify="flex-end" p={3}>
<IconButton
aria-label="Toggle Sidebar"
icon={<FiMenu />}
variant="ghost"
color="white"
onClick={toggleSidebar}
_hover={{ bg: 'blue.600' }}
/>
</Flex>
{sidebarItems.map((item, index) => (
<Flex
key={index}
align="center"
p={3}
cursor="pointer"
_hover={{ bg: 'blue.600' }}
role="group"
>
<Icon as={item.icon} boxSize={5} />
<Text
ml={3}
display={isExpanded ? 'block' : 'none'}
opacity={isExpanded ? 1 : 0}
transition="opacity 0.2s"
>
{item.text}
</Text>
</Flex>
))}
</Box>
);
};
export default Sidebar;