Skip to content

Commit 3072b4c

Browse files
committed
feat(desktop): animate editor tabs
1 parent 086a1ec commit 3072b4c

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed
Binary file not shown.

apps/desktop/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@emotion/css": "^11.11.0",
1515
"@emotion/react": "^11.11.1",
1616
"@emotion/styled": "^11.11.0",
17+
"@formkit/auto-animate": "^0.7.0",
1718
"@linebyline/editor": "workspace:*",
1819
"@mui/material": "^5.14.6",
1920
"@tauri-apps/api": "^1.4.0",

apps/desktop/src/components/EditorArea/EditorAreaTabs.tsx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
import { getFileObject } from "@/helper/files"
2-
import type { IFile } from "@/helper/filesys"
3-
import { useGlobalTheme } from "@/hooks"
4-
import { useEditorStore, useEditorStateStore } from "@/stores"
5-
import { memo } from "react"
6-
import { TabItem, Dot } from "./styles"
1+
import { getFileObject } from '@/helper/files'
2+
import type { IFile } from '@/helper/filesys'
3+
import { useGlobalTheme } from '@/hooks'
4+
import { useEditorStore, useEditorStateStore } from '@/stores'
5+
import { memo, useEffect, useRef } from 'react'
6+
import autoAnimate from '@formkit/auto-animate'
7+
import { TabItem, Dot } from './styles'
8+
import styled, { css } from 'styled-components'
79

10+
type ContainerProps = {
11+
visible: boolean
12+
}
13+
const Container = styled.div<ContainerProps>`
14+
${(props) =>
15+
!props.visible &&
16+
css({
17+
display: 'none',
18+
})}
19+
`
820
const EditorAreaTabs = memo(() => {
921
const { opened, activeId, setActiveId, delOpenedFile } = useEditorStore()
1022
const { idStateMap } = useEditorStateStore()
1123
const { themeColors } = useGlobalTheme()
24+
const parent = useRef<HTMLDivElement>(null)
25+
26+
useEffect(() => {
27+
if (parent.current) {
28+
autoAnimate(parent.current)
29+
}
30+
}, [])
1231

1332
const onSelectItem = (id: string) => {
1433
setActiveId(id)
@@ -28,8 +47,8 @@ const EditorAreaTabs = memo(() => {
2847
delOpenedFile(id)
2948
}
3049

31-
return opened.length > 1 ? (
32-
<div className='tab-items'>
50+
return (
51+
<Container className='tab-items' visible={opened.length > 1} ref={parent}>
3352
{opened.map((id) => {
3453
const file = getFileObject(id) as IFile
3554
const active = activeId === id
@@ -56,8 +75,8 @@ const EditorAreaTabs = memo(() => {
5675
</TabItem>
5776
)
5877
})}
59-
</div>
60-
) : null
78+
</Container>
79+
)
6180
})
6281

6382
export default EditorAreaTabs

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,13 @@ __metadata:
27432743
languageName: node
27442744
linkType: hard
27452745

2746+
"@formkit/auto-animate@npm:^0.7.0":
2747+
version: 0.7.0
2748+
resolution: "@formkit/auto-animate@npm:0.7.0"
2749+
checksum: c714bf960946eddd3abbe339e43dcfc972a193fa2717d1c9c3d89a3acc6590dc68ee3e366ed473f5e9f359d4ef6daa46d75649d963c795ab06da8bbadb5d71a3
2750+
languageName: node
2751+
linkType: hard
2752+
27462753
"@halodong/eslint-config-basic@npm:0.38.24":
27472754
version: 0.38.24
27482755
resolution: "@halodong/eslint-config-basic@npm:0.38.24"
@@ -3143,6 +3150,7 @@ __metadata:
31433150
"@emotion/css": ^11.11.0
31443151
"@emotion/react": ^11.11.1
31453152
"@emotion/styled": ^11.11.0
3153+
"@formkit/auto-animate": ^0.7.0
31463154
"@linebyline/editor": "workspace:*"
31473155
"@mui/material": ^5.14.6
31483156
"@remirror/core": ^2.0.17

0 commit comments

Comments
 (0)