@@ -10,14 +10,17 @@ import React, {
1010} from "react" ;
1111import { Slot } from "@radix-ui/react-slot" ;
1212import { cn } from "../../utilities/index" ;
13+ import { useSidebarContext } from "./SidebarContext" ;
1314
1415export const Sidebar = forwardRef < HTMLDivElement , HTMLProps < HTMLDivElement > > (
1516 ( { className, children, ...rest } , ref ) => {
17+ const { isOpen } = useSidebarContext ( ) ;
18+
1619 return (
1720 < nav
1821 ref = { ref }
1922 className = { cn (
20- " group flex-1 h-full flex w-9 hover:w-[220px] bg-neutral-100 transition-all overflow-x-hidden duration-300 flex-col items-center border-r border-theme-border-moderate" ,
23+ ` group flex-1 h-full flex w-9 ${ isOpen ? "w-[220px]" : " hover:w-[220px]" } bg-neutral-100 transition-all overflow-x-hidden duration-300 flex-col items-center border-r border-theme-border-moderate` ,
2124 className
2225 ) }
2326 { ...rest }
@@ -37,18 +40,22 @@ export function SidebarHeaderImage({ children }: PropsWithChildren) {
3740export const SidebarHeaderTitle = forwardRef <
3841 HTMLParagraphElement ,
3942 HTMLAttributes < HTMLParagraphElement >
40- > ( ( { children, className, ...rest } , ref ) => (
41- < p
42- ref = { ref }
43- { ...rest }
44- className = { cn (
45- "opacity-0 group-hover:opacity-100 ml-1 truncate duration-300 transition-all" ,
46- className
47- ) }
48- >
49- { children }
50- </ p >
51- ) ) ;
43+ > ( ( { children, className, ...rest } , ref ) => {
44+ const { isOpen } = useSidebarContext ( ) ;
45+
46+ return (
47+ < p
48+ ref = { ref }
49+ { ...rest }
50+ className = { cn (
51+ `${ ! isOpen && "opacity-0 group-hover:opacity-100" } ml-1 truncate duration-300 transition-all` ,
52+ className
53+ ) }
54+ >
55+ { children }
56+ </ p >
57+ ) ;
58+ } ) ;
5259
5360SidebarHeaderTitle . displayName = "SidebarHeaderTitle" ;
5461
@@ -58,11 +65,13 @@ export type SidebarHeaderProps = HTMLAttributes<HTMLDivElement> & {
5865
5966export const SidebarHeader = forwardRef < HTMLDivElement , SidebarHeaderProps > (
6067 ( { icon, children, className, ...rest } , ref ) => {
68+ const { isOpen } = useSidebarContext ( ) ;
69+
6170 const existingIconClasses = isValidElement ( icon ) ? icon . props . className || "" : "" ;
6271
6372 const iconClasses = cn (
6473 existingIconClasses ,
65- "ml-auto shrink-0 opacity-0 group-hover:opacity-100 duration-300 transition-all"
74+ ` ${ ! isOpen && " opacity-0 group-hover:opacity-100" } ml-auto shrink-0 duration-300 transition-all`
6675 ) ;
6776
6877 return (
@@ -139,6 +148,7 @@ export function SidebarItemContent({
139148 isActive,
140149 svgStroke = false
141150} : SidebarItemContentProps ) {
151+ const { isOpen } = useSidebarContext ( ) ;
142152 const existingIconClasses = isValidElement ( icon ) ? icon . props . className || "" : "" ;
143153
144154 const iconClasses = cn (
@@ -156,7 +166,11 @@ export function SidebarItemContent({
156166 return (
157167 < >
158168 { cloneElement ( icon as ReactElement , { className : iconClasses } ) }
159- < div className = "opacity-0 group-hover:opacity-100 duration-300 transition-all" > { label } </ div >
169+ < div
170+ className = { `${ ! isOpen && "opacity-0 group-hover:opacity-100" } duration-300 transition-all` }
171+ >
172+ { label }
173+ </ div >
160174 </ >
161175 ) ;
162176}
0 commit comments