-

+ {children}
{title}
diff --git a/src/components/Sidebar/SidebarHeader.stories.tsx b/src/components/Sidebar/SidebarHeader.stories.tsx
index 059b4e9..0e5df48 100644
--- a/src/components/Sidebar/SidebarHeader.stories.tsx
+++ b/src/components/Sidebar/SidebarHeader.stories.tsx
@@ -1,6 +1,6 @@
import { Meta } from "@storybook/react";
import React from "react";
-import { SidebarHeader } from "./Sidebar";
+import { SidebarHeader, SidebarHeaderImage } from "./Sidebar";
import { CloseButton } from "../../../.storybook/assets/icons";
import { StoryObj } from "@storybook/react";
@@ -25,6 +25,11 @@ export const sidebarHeader: Story = {
name: "Sidebar Header",
args: {
title: "ZenML Tenant",
- icon:
+ icon:
,
+ children: (
+
+
+
+ )
}
};
From b71c20d2d7a940ba261748543aef7607a563de86 Mon Sep 17 00:00:00 2001
From: Cahllagerfeld <43843195+Cahllagerfeld@users.noreply.github.com>
Date: Thu, 19 Oct 2023 14:57:44 +0200
Subject: [PATCH 08/10] refactor: use forwardRef
---
src/components/Sidebar/Sidebar.tsx | 149 +++++++++++++++++------------
1 file changed, 88 insertions(+), 61 deletions(-)
diff --git a/src/components/Sidebar/Sidebar.tsx b/src/components/Sidebar/Sidebar.tsx
index 7a3c9d9..208da30 100644
--- a/src/components/Sidebar/Sidebar.tsx
+++ b/src/components/Sidebar/Sidebar.tsx
@@ -1,86 +1,113 @@
import React, {
HTMLAttributes,
+ HTMLProps,
PropsWithChildren,
ReactNode,
cloneElement,
+ forwardRef,
isValidElement
} from "react";
-import { Slot, Slottable } from "@radix-ui/react-slot";
+import { Slot } from "@radix-ui/react-slot";
import { cn } from "../../utilities/index";
-export function Sidebar({ className, children, ...rest }: HTMLAttributes
) {
- return (
-
- );
+export const Sidebar = forwardRef>(
+ ({ className, children, ...rest }, ref) => {
+ return (
+
+ );
+ }
+);
+
+Sidebar.displayName = "Sidebar";
+
+export function SidebarHeaderImage({ children }: PropsWithChildren) {
+ return {children};
}
-type SidebarHeaderProps = {
+export type SidebarHeaderProps = HTMLAttributes & {
title: string;
icon?: React.ReactNode;
};
-export function SidebarHeaderImage({ children }: PropsWithChildren) {
- return {children};
-}
+export const SidebarHeader = forwardRef(
+ ({ title, icon, children, className, ...rest }, ref) => {
+ const existingIconClasses = isValidElement(icon) ? icon.props.className || "" : "";
-export function SidebarHeader({ title, icon, children }: PropsWithChildren) {
- const existingIconClasses = isValidElement(icon) ? icon.props.className || "" : "";
+ const iconClasses = cn(
+ existingIconClasses,
+ "w-6 ml-auto shrink-0 h-6 opacity-0 group-hover:opacity-100 duration-300 transition-all"
+ );
- const iconClasses = cn(
- existingIconClasses,
- "w-6 ml-auto shrink-0 h-6 opacity-0 group-hover:opacity-100 duration-300 transition-all"
- );
+ return (
+
+ {children}
+
+ {title}
+
+ {icon && cloneElement(icon as React.ReactElement, { className: iconClasses })}
+
+ );
+ }
+);
- return (
-
- {children}
-
- {title}
-
- {icon && cloneElement(icon as React.ReactElement, { className: iconClasses })}
-
- );
-}
+SidebarHeader.displayName = "SidebarHeader";
-export function SidebarBody({ className, ...rest }: HTMLAttributes) {
- return ;
-}
+export const SidebarBody = forwardRef>(
+ ({ className, ...rest }, ref) => {
+ return ;
+ }
+);
-export function SidebarList({ className, ...rest }: HTMLAttributes) {
- return (
-
- );
-}
+export const SidebarList = forwardRef>(
+ ({ className, ...rest }, ref) => {
+ return (
+
+ );
+ }
+);
+
+SidebarList.displayName = "SidebarList";
-export function SidebarItem({
- isActive = false,
- ...rest
-}: {
- children: ReactNode;
+export type SidebarItemProps = HTMLAttributes & {
isActive?: boolean;
-}) {
- return (
-
-
-
- );
-}
+};
+
+export const SidebarItem = forwardRef(
+ ({ isActive, className, ...rest }, ref) => {
+ return (
+
+
+
+ );
+ }
+);
+
+SidebarItem.displayName = "SidebarItem";
type SidebarItemContentProps = {
icon: React.ReactNode;
From f7e39be08e073a82b69e9e9909feafaef7963093 Mon Sep 17 00:00:00 2001
From: Cahllagerfeld <43843195+Cahllagerfeld@users.noreply.github.com>
Date: Sat, 21 Oct 2023 13:53:42 +0000
Subject: [PATCH 09/10] refactor: add another component
---
src/components/Sidebar/Sidebar.stories.tsx | 50 ++++++++++--------
src/components/Sidebar/Sidebar.tsx | 61 +++++++++++++---------
2 files changed, 65 insertions(+), 46 deletions(-)
diff --git a/src/components/Sidebar/Sidebar.stories.tsx b/src/components/Sidebar/Sidebar.stories.tsx
index e6c9212..15af51f 100644
--- a/src/components/Sidebar/Sidebar.stories.tsx
+++ b/src/components/Sidebar/Sidebar.stories.tsx
@@ -2,12 +2,13 @@ import { Meta } from "@storybook/react";
import React from "react";
import {
Sidebar,
- SidebarList,
SidebarHeader,
SidebarItem,
SidebarItemContent,
SidebarBody,
- SidebarHeaderImage
+ SidebarHeaderImage,
+ SidebarHeaderTitle,
+ SidebarList
} from "./index";
import { CPU, CloseButton } from "../../../.storybook/assets/icons";
import { StoryObj } from "@storybook/react";
@@ -42,33 +43,38 @@ export const defaultStory: Story = {
+ My Tenant
-
-
- } label="Models" />
-
-
-
-
- } label="Models" />
-
-
-
-
- } label="Models" />
-
-
-
-
-
-
+
+
+
+ } label="Models" />
+
+
+
+
+
+
+ } label="Models" />
+
+
+
+
+
} label="Models" />
-
+
+
+
+
+
+ } label="Models" />
+
+
>
diff --git a/src/components/Sidebar/Sidebar.tsx b/src/components/Sidebar/Sidebar.tsx
index 208da30..dd37c7e 100644
--- a/src/components/Sidebar/Sidebar.tsx
+++ b/src/components/Sidebar/Sidebar.tsx
@@ -2,6 +2,7 @@ import React, {
HTMLAttributes,
HTMLProps,
PropsWithChildren,
+ ReactElement,
ReactNode,
cloneElement,
forwardRef,
@@ -35,9 +36,27 @@ export function SidebarHeaderImage({ children }: PropsWithChildren) {
export type SidebarHeaderProps = HTMLAttributes
& {
title: string;
- icon?: React.ReactNode;
+ icon?: ReactNode;
};
+export const SidebarHeaderTitle = forwardRef<
+ HTMLParagraphElement,
+ HTMLAttributes
+>(({ children, className, ...rest }, ref) => (
+
+ {children}
+
+));
+
+SidebarHeaderTitle.displayName = "SidebarHeaderTitle";
+
export const SidebarHeader = forwardRef(
({ title, icon, children, className, ...rest }, ref) => {
const existingIconClasses = isValidElement(icon) ? icon.props.className || "" : "";
@@ -57,10 +76,8 @@ export const SidebarHeader = forwardRef(
)}
>
{children}
-
- {title}
-
- {icon && cloneElement(icon as React.ReactElement, { className: iconClasses })}
+
+ {icon && cloneElement(icon as ReactElement, { className: iconClasses })}
);
}
@@ -73,7 +90,6 @@ export const SidebarBody = forwardRef;
}
);
-
export const SidebarList = forwardRef>(
({ className, ...rest }, ref) => {
return (
@@ -92,25 +108,22 @@ export type SidebarItemProps = HTMLAttributes & {
isActive?: boolean;
};
-export const SidebarItem = forwardRef(
- ({ isActive, className, ...rest }, ref) => {
- return (
-
-
-
- );
- }
-);
-
-SidebarItem.displayName = "SidebarItem";
+export function SidebarItem({
+ isActive = false,
+ ...rest
+}: PropsWithChildren<{ isActive?: boolean }>) {
+ return (
+
+ );
+}
type SidebarItemContentProps = {
- icon: React.ReactNode;
+ icon: ReactNode;
label: string;
isActive?: boolean;
};
@@ -124,7 +137,7 @@ export function SidebarItemContent({ icon, label, isActive }: SidebarItemContent
);
return (
<>
- {cloneElement(icon as React.ReactElement, { className: iconClasses })}
+ {cloneElement(icon as ReactElement, { className: iconClasses })}
{label}
>
);
From 8c5e7e07421ec0f06e5f77e8adc07a599843ef83 Mon Sep 17 00:00:00 2001
From: Cahllagerfeld <43843195+Cahllagerfeld@users.noreply.github.com>
Date: Sat, 21 Oct 2023 16:04:38 +0200
Subject: [PATCH 10/10] chore: adjust file structure & styles
---
src/components/Sidebar/Sidebar.stories.tsx | 2 +-
src/components/Sidebar/Sidebar.tsx | 16 +++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/components/Sidebar/Sidebar.stories.tsx b/src/components/Sidebar/Sidebar.stories.tsx
index 15af51f..28481ab 100644
--- a/src/components/Sidebar/Sidebar.stories.tsx
+++ b/src/components/Sidebar/Sidebar.stories.tsx
@@ -69,7 +69,7 @@ export const defaultStory: Story = {
-
+
} label="Models" />
diff --git a/src/components/Sidebar/Sidebar.tsx b/src/components/Sidebar/Sidebar.tsx
index dd37c7e..de1141c 100644
--- a/src/components/Sidebar/Sidebar.tsx
+++ b/src/components/Sidebar/Sidebar.tsx
@@ -34,11 +34,6 @@ export function SidebarHeaderImage({ children }: PropsWithChildren) {
return
{children};
}
-export type SidebarHeaderProps = HTMLAttributes
& {
- title: string;
- icon?: ReactNode;
-};
-
export const SidebarHeaderTitle = forwardRef<
HTMLParagraphElement,
HTMLAttributes
@@ -57,6 +52,11 @@ export const SidebarHeaderTitle = forwardRef<
SidebarHeaderTitle.displayName = "SidebarHeaderTitle";
+export type SidebarHeaderProps = HTMLAttributes & {
+ title: string;
+ icon?: ReactNode;
+};
+
export const SidebarHeader = forwardRef(
({ title, icon, children, className, ...rest }, ref) => {
const existingIconClasses = isValidElement(icon) ? icon.props.className || "" : "";
@@ -87,7 +87,9 @@ SidebarHeader.displayName = "SidebarHeader";
export const SidebarBody = forwardRef>(
({ className, ...rest }, ref) => {
- return ;
+ return (
+
+ );
}
);
export const SidebarList = forwardRef>(
@@ -95,7 +97,7 @@ export const SidebarList = forwardRef
);