@@ -4,12 +4,15 @@ import {
4
4
List ,
5
5
ListItem ,
6
6
ListItemText ,
7
+ ListItemSecondaryAction ,
8
+ IconButton ,
7
9
Theme ,
8
- useTheme
10
+ useTheme ,
9
11
} from '@committed/components'
10
12
import React from 'react'
11
13
import { Info , Item } from '../types'
12
14
import { firstUrl } from '../util/tree'
15
+ import { useLayout } from '@committed/layout'
13
16
14
17
export interface TreeNodeProps extends Item {
15
18
isActive : ( id : string ) => boolean
@@ -35,38 +38,50 @@ export const TreeNode = React.memo(
35
38
...rest
36
39
} : TreeNodeProps ) => {
37
40
const theme = useTheme < Theme > ( )
41
+ const { navVariant, setOpen } = useLayout ( )
38
42
const url = firstUrl ( { id, label, items, info } )
39
43
const isCollapsed = collapsed [ id ] || false
40
44
const hasChildren = items . length !== 0
41
45
const title = info ? info . title : label
42
46
const active = isActive ( id )
47
+
48
+ const handleClick = ( ) => {
49
+ if ( navVariant === 'temporary' ) {
50
+ setOpen ( false )
51
+ }
52
+ navigate ( url )
53
+ }
54
+
43
55
return (
44
56
< >
45
57
< ListItem
46
58
style = { {
47
- paddingLeft : theme . spacing ( 2 ) * ( level + 1 )
59
+ paddingLeft : theme . spacing ( 2 ) * ( level + 1 ) ,
48
60
} }
49
61
selected = { active }
50
62
button
51
- onClick = { ( ) => {
52
- setCollapsed ( id )
53
- navigate ( url )
54
- } }
63
+ onClick = { handleClick }
55
64
>
56
65
< ListItemText
57
66
primary = { title }
58
67
primaryTypographyProps = { {
59
- variant : level === 0 ? 'body1' : 'caption'
68
+ variant : level === 0 ? 'body1' : 'caption' ,
60
69
} }
61
70
/>
62
71
{ title && hasChildren ? (
63
- < >
64
- { ! isCollapsed ? (
65
- < Icons . KeyboardArrowDown />
66
- ) : (
67
- < Icons . KeyboardArrowRight />
68
- ) }
69
- </ >
72
+ < ListItemSecondaryAction >
73
+ < IconButton
74
+ onClick = { ( ) => setCollapsed ( id ) }
75
+ edge = "end"
76
+ aria-label = { isCollapsed ? 'expand' : 'collapse' }
77
+ >
78
+ { ! isCollapsed ? (
79
+ < Icons . KeyboardArrowDown />
80
+ ) : (
81
+ < Icons . KeyboardArrowRight />
82
+ ) }
83
+ </ IconButton >
84
+ </ ListItemSecondaryAction >
70
85
) : null }
71
86
</ ListItem >
72
87
0 commit comments