@@ -4,58 +4,87 @@ import {
44 spacing ,
55 css ,
66 ItemActionControls ,
7+ cx ,
78} from '@mongodb-js/compass-components' ;
89import { ROW_HEIGHT , type Actions } from './constants' ;
9- import {
10- ItemContainer ,
11- ItemLabel ,
12- ItemWrapper ,
13- ItemButtonWrapper ,
14- ExpandButton ,
15- } from './tree-item' ;
10+ import { ExpandButton } from './tree-item' ;
1611import { type NavigationItemActions } from './item-actions' ;
1712
1813type NavigationBaseItemProps = {
19- isActive : boolean ;
20- style : React . CSSProperties ;
21-
2214 name : string ;
23- icon : React . ReactNode ;
24-
25- dataAttributes ?: Record < string , string | undefined > ;
26-
15+ isActive : boolean ;
2716 canExpand : boolean ;
2817 isExpanded : boolean ;
2918 isFocused : boolean ;
30- onExpand : ( toggle : boolean ) => void ;
19+ icon : React . ReactNode ;
20+ style : React . CSSProperties ;
3121
22+ dataAttributes ?: Record < string , string | undefined > ;
3223 actionProps : {
3324 collapseAfter ?: number ;
3425 collapseToMenuThreshold ?: number ;
3526 actions : NavigationItemActions ;
3627 onAction : ( action : Actions ) => void ;
3728 } ;
29+ onExpand : ( toggle : boolean ) => void ;
3830} ;
3931
40- const baseItemContainerStyles = css ( {
41- height : ROW_HEIGHT ,
32+ const menuStyles = css ( {
33+ width : '240px' ,
34+ maxHeight : 'unset' ,
35+ marginLeft : 'auto' ,
4236} ) ;
4337
44- const baseItemButtonWrapperStyles = css ( {
38+ const itemContainerStyles = css ( {
39+ paddingLeft : spacing [ 300 ] ,
40+ paddingRight : spacing [ 300 ] ,
41+ cursor : 'pointer' ,
42+ color : 'var(--item-color)' ,
43+ backgroundColor : 'var(--item-bg-color)' ,
44+ '&[data-is-active="true"] .item-wrapper' : {
45+ fontWeight : 600 ,
46+ color : 'var(--item-color-active)' ,
47+ backgroundColor : 'var(--item-bg-color-active)' ,
48+ } ,
49+ '&:hover:not([data-is-active="true"]) .item-wrapper' : {
50+ backgroundColor : 'var(--item-bg-color-hover)' ,
51+ } ,
52+ svg : {
53+ flexShrink : 0 ,
54+ } ,
55+ } ) ;
56+
57+ const itemWrapperStyles = css ( {
58+ display : 'flex' ,
4559 height : ROW_HEIGHT ,
60+ alignItems : 'center' ,
61+ paddingLeft : spacing [ 100 ] ,
4662 paddingRight : spacing [ 100 ] ,
63+ gap : spacing [ 50 ] ,
64+ borderRadius : spacing [ 100 ] ,
4765} ) ;
4866
49- const baseItemLabelStyles = css ( {
50- marginLeft : spacing [ 200 ] ,
67+ const labelAndIconWrapperStyles = css ( {
68+ width : '100%' ,
69+ display : 'flex' ,
70+ gap : spacing [ 150 ] ,
71+ overflow : 'hidden' ,
72+ alignItems : 'center' ,
73+ '& span' : {
74+ overflow : 'hidden' ,
75+ whiteSpace : 'nowrap' ,
76+ textOverflow : 'ellipsis' ,
77+ } ,
5178} ) ;
5279
53- const menuStyles = css ( {
54- width : '240px' ,
55- maxHeight : 'unset' ,
80+ const actionControlsWrapperStyles = css ( {
81+ display : 'flex' ,
82+ marginLeft : 'auto' ,
83+ alignItems : 'center' ,
84+ gap : spacing [ 100 ] ,
5685} ) ;
5786
58- export const NavigationBaseItem = ( {
87+ export const NavigationBaseItem : React . FC < NavigationBaseItemProps > = ( {
5988 isActive,
6089 actionProps,
6190 name,
@@ -66,43 +95,41 @@ export const NavigationBaseItem = ({
6695 isExpanded,
6796 isFocused,
6897 onExpand,
69- } : NavigationBaseItemProps ) => {
98+ children,
99+ } ) => {
70100 const [ hoverProps , isHovered ] = useHoverState ( ) ;
71101 return (
72- < ItemContainer
102+ < div
73103 data-testid = "base-navigation-item"
74- isActive = { isActive }
75- className = { baseItemContainerStyles }
104+ className = { itemContainerStyles }
76105 { ...hoverProps }
77106 { ...dataAttributes }
78107 >
79- < ItemWrapper >
80- < ItemButtonWrapper
81- style = { style }
82- className = { baseItemButtonWrapperStyles }
83- >
84- { canExpand && (
85- < ExpandButton
86- onClick = { ( evt ) => {
87- evt . stopPropagation ( ) ;
88- onExpand ( ! isExpanded ) ;
89- } }
90- isExpanded = { isExpanded }
91- > </ ExpandButton >
92- ) }
108+ < div className = { cx ( 'item-wrapper' , itemWrapperStyles ) } style = { style } >
109+ { canExpand && (
110+ < ExpandButton
111+ onClick = { ( evt ) => {
112+ evt . stopPropagation ( ) ;
113+ onExpand ( ! isExpanded ) ;
114+ } }
115+ isExpanded = { isExpanded }
116+ > </ ExpandButton >
117+ ) }
118+ < div className = { labelAndIconWrapperStyles } >
93119 { icon }
94- < ItemLabel className = { baseItemLabelStyles } title = { name } >
95- { name }
96- </ ItemLabel >
97- </ ItemButtonWrapper >
98- < ItemActionControls < Actions >
99- menuClassName = { menuStyles }
100- isVisible = { isActive || isHovered || isFocused }
101- data-testid = "sidebar-navigation-item-actions"
102- iconSize = "small"
103- { ...actionProps }
104- > </ ItemActionControls >
105- </ ItemWrapper >
106- </ ItemContainer >
120+ < span title = { name } > { name } </ span >
121+ </ div >
122+ < div className = { actionControlsWrapperStyles } >
123+ < ItemActionControls < Actions >
124+ menuClassName = { menuStyles }
125+ isVisible = { isActive || isHovered || isFocused }
126+ data-testid = "sidebar-navigation-item-actions"
127+ iconSize = "xsmall"
128+ { ...actionProps }
129+ > </ ItemActionControls >
130+ { children }
131+ </ div >
132+ </ div >
133+ </ div >
107134 ) ;
108135} ;
0 commit comments