|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import React, { PropsWithChildren } from 'react'; |
| 17 | +import React, { PropsWithChildren, useState } from 'react'; |
18 | 18 | import { makeStyles } from '@material-ui/core'; |
19 | 19 | import HomeIcon from '@material-ui/icons/Home'; |
20 | 20 | import ExtensionIcon from '@material-ui/icons/Extension'; |
@@ -76,6 +76,49 @@ const Logo = (props: { isOpen?: boolean }) => { |
76 | 76 | return logo; |
77 | 77 | }; |
78 | 78 |
|
| 79 | +const CollapsibleSubmenu = ({ |
| 80 | + icon, |
| 81 | + text, |
| 82 | + children, |
| 83 | +}: { |
| 84 | + icon: React.ReactElement; |
| 85 | + text: string; |
| 86 | + children: React.ReactNode; |
| 87 | +}) => { |
| 88 | + const [isOpen, setIsOpen] = useState(false); |
| 89 | + const { isOpen: sidebarOpen } = useSidebarOpenState(); |
| 90 | + |
| 91 | + return ( |
| 92 | + <> |
| 93 | + <div |
| 94 | + onClick={() => setIsOpen(!isOpen)} |
| 95 | + onKeyDown={e => { |
| 96 | + if (e.key === 'Enter' || e.key === ' ') { |
| 97 | + e.preventDefault(); |
| 98 | + setIsOpen(!isOpen); |
| 99 | + } |
| 100 | + }} |
| 101 | + role="button" |
| 102 | + tabIndex={0} |
| 103 | + style={{ |
| 104 | + display: 'flex', |
| 105 | + alignItems: 'center', |
| 106 | + cursor: 'pointer', |
| 107 | + padding: '16px 16px', |
| 108 | + userSelect: 'none', |
| 109 | + }} |
| 110 | + > |
| 111 | + {icon} |
| 112 | + {sidebarOpen && <span style={{ marginLeft: 12, flex: 1 }}>{text}</span>} |
| 113 | + {sidebarOpen && ( |
| 114 | + <span style={{ fontSize: '12px' }}>{isOpen ? '▼' : '▶'}</span> |
| 115 | + )} |
| 116 | + </div> |
| 117 | + {isOpen && <div style={{ marginLeft: 40 }}>{children}</div>} |
| 118 | + </> |
| 119 | + ); |
| 120 | +}; |
| 121 | + |
79 | 122 | const SidebarLogo = () => { |
80 | 123 | const classes = useSidebarLogoStyles(); |
81 | 124 | const { isOpen } = useSidebarOpenState(); |
@@ -105,11 +148,16 @@ export const Root = ({ children }: PropsWithChildren<{}>) => ( |
105 | 148 | <SidebarItem icon={CreateComponentIcon} to="create" text="Create..." /> |
106 | 149 | {/* End global nav */} |
107 | 150 | <SidebarDivider /> |
108 | | - <SidebarItem |
109 | | - icon={ResourceOptimizationIconOutlined} |
110 | | - to="/redhat-resource-optimization" |
111 | | - text="Optimizations" |
112 | | - /> |
| 151 | + <CollapsibleSubmenu |
| 152 | + icon={<ResourceOptimizationIconOutlined />} |
| 153 | + text="Cost management" |
| 154 | + > |
| 155 | + <SidebarItem |
| 156 | + icon={ResourceOptimizationIconOutlined} |
| 157 | + to="/redhat-resource-optimization" |
| 158 | + text="Optimizations" |
| 159 | + /> |
| 160 | + </CollapsibleSubmenu> |
113 | 161 | <SidebarItem |
114 | 162 | icon={OrchestratorIcon} |
115 | 163 | to="orchestrator" |
|
0 commit comments