@@ -4,58 +4,87 @@ import {
4
4
spacing ,
5
5
css ,
6
6
ItemActionControls ,
7
+ cx ,
7
8
} from '@mongodb-js/compass-components' ;
8
9
import { 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' ;
16
11
import { type NavigationItemActions } from './item-actions' ;
17
12
18
13
type NavigationBaseItemProps = {
19
- isActive : boolean ;
20
- style : React . CSSProperties ;
21
-
22
14
name : string ;
23
- icon : React . ReactNode ;
24
-
25
- dataAttributes ?: Record < string , string | undefined > ;
26
-
15
+ isActive : boolean ;
27
16
canExpand : boolean ;
28
17
isExpanded : boolean ;
29
18
isFocused : boolean ;
30
- onExpand : ( toggle : boolean ) => void ;
19
+ icon : React . ReactNode ;
20
+ style : React . CSSProperties ;
31
21
22
+ dataAttributes ?: Record < string , string | undefined > ;
32
23
actionProps : {
33
24
collapseAfter ?: number ;
34
25
collapseToMenuThreshold ?: number ;
35
26
actions : NavigationItemActions ;
36
27
onAction : ( action : Actions ) => void ;
37
28
} ;
29
+ onExpand : ( toggle : boolean ) => void ;
38
30
} ;
39
31
40
- const baseItemContainerStyles = css ( {
41
- height : ROW_HEIGHT ,
32
+ const menuStyles = css ( {
33
+ width : '240px' ,
34
+ maxHeight : 'unset' ,
35
+ marginLeft : 'auto' ,
42
36
} ) ;
43
37
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' ,
45
59
height : ROW_HEIGHT ,
60
+ alignItems : 'center' ,
61
+ paddingLeft : spacing [ 100 ] ,
46
62
paddingRight : spacing [ 100 ] ,
63
+ gap : spacing [ 50 ] ,
64
+ borderRadius : spacing [ 100 ] ,
47
65
} ) ;
48
66
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
+ } ,
51
78
} ) ;
52
79
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 ] ,
56
85
} ) ;
57
86
58
- export const NavigationBaseItem = ( {
87
+ export const NavigationBaseItem : React . FC < NavigationBaseItemProps > = ( {
59
88
isActive,
60
89
actionProps,
61
90
name,
@@ -66,43 +95,41 @@ export const NavigationBaseItem = ({
66
95
isExpanded,
67
96
isFocused,
68
97
onExpand,
69
- } : NavigationBaseItemProps ) => {
98
+ children,
99
+ } ) => {
70
100
const [ hoverProps , isHovered ] = useHoverState ( ) ;
71
101
return (
72
- < ItemContainer
102
+ < div
73
103
data-testid = "base-navigation-item"
74
- isActive = { isActive }
75
- className = { baseItemContainerStyles }
104
+ className = { itemContainerStyles }
76
105
{ ...hoverProps }
77
106
{ ...dataAttributes }
78
107
>
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 } >
93
119
{ 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 >
107
134
) ;
108
135
} ;
0 commit comments