Skip to content

Commit c4b8824

Browse files
committed
fix: rightbar ui
1 parent df45c29 commit c4b8824

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import classNames from 'classnames'
2+
import { memo, useMemo, useState } from 'react'
3+
import { Container as SideBarContainer, SideBarHeader } from './styles'
4+
import { RIGHTBARITEMKEYS } from '@/constants'
5+
import { Tooltip } from 'zens'
6+
import { TableOfContent } from '@/extensions/table-of-content'
7+
8+
function RightBar() {
9+
const [activeRightBarItemKey, setActiveRightBarItemKey] = useState<RIGHTBARITEMKEYS>(
10+
RIGHTBARITEMKEYS.TableOfContent,
11+
)
12+
13+
const rightBarDataSource: RightBarItem[] = useMemo(() => {
14+
return [
15+
TableOfContent,
16+
]
17+
}, [])
18+
19+
const activeRightBarItem = useMemo(() => {
20+
const activeItem = rightBarDataSource.find((item) => item.key === activeRightBarItemKey)
21+
return activeItem
22+
}, [activeRightBarItemKey, rightBarDataSource])
23+
24+
const noActiveItem = !activeRightBarItemKey
25+
26+
return (
27+
<SideBarContainer noActiveItem={noActiveItem}>
28+
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', width: '100%' }}>
29+
<SideBarHeader>
30+
{rightBarDataSource.map((item) => {
31+
const cls = classNames('icon', {
32+
'app-sidebar-active': activeRightBarItemKey === item.key,
33+
})
34+
35+
const handleRightBarItemClick = () => {
36+
setActiveRightBarItemKey(item.key)
37+
}
38+
39+
return (
40+
<Tooltip key={item.key} title={item.title}>
41+
<div className={cls} onClick={handleRightBarItemClick}>
42+
{item.icon}
43+
</div>
44+
</Tooltip>
45+
)
46+
})}
47+
</SideBarHeader>
48+
{activeRightBarItem?.components ?? null}
49+
</div>
50+
</SideBarContainer>
51+
)
52+
}
53+
54+
export interface RightBarItem {
55+
title: RIGHTBARITEMKEYS
56+
key: RIGHTBARITEMKEYS
57+
icon: React.ReactNode
58+
components: any
59+
}
60+
61+
export default memo(RightBar)

apps/desktop/src/extensions/table-of-content/styles.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const RightBarHeader = styled.div`
66
align-items: center;
77
flex-shrink: 0;
88
height: 32px;
9+
padding: 0 8px;
910
background-color: ${(props) => props.theme.rightBarHeaderBgColor};
1011
`
1112

apps/desktop/src/router/Root/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { appInfoStoreSetup } from '@/services/app-info'
1111
import StatusBar from '@/components/StatusBar'
1212
import { useTitleBarEffect } from '@/hooks/useTitleBarEffect'
1313
import { PanelGroup, Panel, PanelResizeHandle, ImperativePanelHandle } from 'react-resizable-panels'
14-
import { TableOfContent } from '@/extensions/table-of-content'
1514
import { useCommandStore } from '@/stores'
1615
import useLayoutStore from '@/stores/useLayoutStore'
16+
import RightBar from '@/components/SideBar/RightBar'
1717

1818
export const RESIZE_PANEL_STORAGE_KEY = 'resize-panel'
1919

@@ -105,7 +105,7 @@ function Root() {
105105
minSize={10}
106106
ref={rightPanelRef}
107107
>
108-
{TableOfContent.components}
108+
<RightBar />
109109
</Panel>
110110
</PanelGroup>
111111
<StatusBar />

0 commit comments

Comments
 (0)