From 72f81106a0c03b8482933bb06e05420293837018 Mon Sep 17 00:00:00 2001
From: Cahllagerfeld <43843195+Cahllagerfeld@users.noreply.github.com>
Date: Thu, 11 Apr 2024 10:05:29 +0000
Subject: [PATCH 1/4] feature: add option to keep sidebar open
---
.storybook/assets/Appshell.tsx | 2 +-
src/components/Sidebar/Sidebar.stories.tsx | 32 ++++++++++++--
src/components/Sidebar/Sidebar.tsx | 44 ++++++++++++-------
src/components/Sidebar/SidebarContext.tsx | 32 ++++++++++++++
.../Sidebar/SidebarHeader.stories.tsx | 9 ++--
.../Sidebar/SidebarItem.stories.tsx | 5 ++-
src/components/Sidebar/index.tsx | 1 +
7 files changed, 101 insertions(+), 24 deletions(-)
create mode 100644 src/components/Sidebar/SidebarContext.tsx
diff --git a/.storybook/assets/Appshell.tsx b/.storybook/assets/Appshell.tsx
index 37ff9cf..97b39d5 100644
--- a/.storybook/assets/Appshell.tsx
+++ b/.storybook/assets/Appshell.tsx
@@ -2,7 +2,7 @@ import React, { ReactNode } from "react";
export function AppShell({ children }: { children: ReactNode }) {
return (
-
+
diff --git a/src/components/Sidebar/Sidebar.stories.tsx b/src/components/Sidebar/Sidebar.stories.tsx
index 938e505..40071e8 100644
--- a/src/components/Sidebar/Sidebar.stories.tsx
+++ b/src/components/Sidebar/Sidebar.stories.tsx
@@ -10,9 +10,11 @@ import {
SidebarHeaderTitle,
SidebarList
} from "./index";
+import { Button } from "../Button";
import { CPU, CloseButton } from "../../../.storybook/assets/icons";
import { StoryObj } from "@storybook/react";
import { AppShell } from "../../../.storybook/assets/Appshell";
+import { SidebarProvider, useSidebarContext } from "./SidebarContext";
const meta = {
title: "UI/Sidebar",
@@ -22,9 +24,11 @@ const meta = {
},
decorators: [
(Story) => (
-
-
-
+
+
+
+
+
)
],
tags: ["autodocs"]
@@ -39,7 +43,14 @@ export const defaultStory: Story = {
args: {
children: (
<>
-
} title="ZenML Tenant">
+
+
+
+ }
+ title="ZenML Tenant"
+ >
@@ -81,3 +92,16 @@ export const defaultStory: Story = {
)
}
};
+
+function SidebarButton() {
+ const { setIsOpen, isOpen } = useSidebarContext();
+ return (
+
+ );
+}
diff --git a/src/components/Sidebar/Sidebar.tsx b/src/components/Sidebar/Sidebar.tsx
index 158e7d5..b7de5db 100644
--- a/src/components/Sidebar/Sidebar.tsx
+++ b/src/components/Sidebar/Sidebar.tsx
@@ -10,14 +10,17 @@ import React, {
} from "react";
import { Slot } from "@radix-ui/react-slot";
import { cn } from "../../utilities/index";
+import { useSidebarContext } from "./SidebarContext";
export const Sidebar = forwardRef
>(
({ className, children, ...rest }, ref) => {
+ const { isOpen } = useSidebarContext();
+
return (