Skip to content

Commit

Permalink
#6 Allow minimizing sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
tina-e committed Aug 18, 2022
1 parent fafaf93 commit dd4c9a3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
19 changes: 16 additions & 3 deletions src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from "react";
import { SidebarHeader } from "./SidebarHeader";
import { SidebarNotes } from "./SidebarNotes";
import cx from "classnames";

const sidebars = [
{
Expand All @@ -22,10 +23,22 @@ export const Sidebar = () => {
const [sidebarOpen, setSidebarOpen] = useState<boolean>(true);

return (
<aside className="w-[400px] h-full overflow-y-clip shadow-lg p-4 divide-y-[1px] divide-lightGrey">
<SidebarHeader setActiveSidebar={setActiveSidebar} />
<aside
className={cx(
"h-full overflow-y-clip shadow-lg divide-y-[1px] divide-lightGrey transition-width duration-300",
{
"w-[40px] pt-4 px-1 overflow-hidden": !sidebarOpen,
"w-[400px] p-4": sidebarOpen,
}
)}
>
<SidebarHeader
setActiveSidebar={setActiveSidebar}
setSidebarOpenForContent={setSidebarOpen}
/>
{sidebars.map(
(sidebar) => sidebar.name === activeSidebar && sidebar.jsxElem
(sidebar) =>
sidebar.name === activeSidebar && sidebarOpen && sidebar.jsxElem
)}
</aside>
);
Expand Down
13 changes: 10 additions & 3 deletions src/components/sidebar/SidebarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from "../Button";

interface SidebarProps {
setActiveSidebar: any;
setSidebarOpenForContent: any;
}

const buttons = [
Expand All @@ -22,7 +23,10 @@ const buttons = [
},
];

export const SidebarHeader: React.FC<SidebarProps> = ({ setActiveSidebar }) => {
export const SidebarHeader: React.FC<SidebarProps> = ({
setActiveSidebar,
setSidebarOpenForContent,
}) => {
const [activeButton, setActiveButton] = useState<string>(buttons[0].name);
const [sidebarOpen, setSidebarOpen] = useState<boolean>(true);

Expand All @@ -38,15 +42,18 @@ export const SidebarHeader: React.FC<SidebarProps> = ({ setActiveSidebar }) => {
"rotate-90": sidebarOpen,
"rotate-0": !sidebarOpen,
})}
onClick={() => setSidebarOpen(!sidebarOpen)}
onClick={() => {
setSidebarOpen(!sidebarOpen);
setSidebarOpenForContent(!sidebarOpen);
}}
>
<Button
key={"sidebarActive"}
bgColor="transparent"
size="sm"
textColor="font-bold text-darkGrey"
hasText={false}
alternativePadding="p-2"
alternativePadding="py-1.5 px-1.5"
icon={<List size={18} />}
/>
</div>
Expand Down
6 changes: 5 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {},
extend: {
transitionProperty: {
'width': 'width'
}
},
colors: {
white: "#fff",
offWhite: "#F5F5F5",
Expand Down

0 comments on commit dd4c9a3

Please sign in to comment.