Skip to content

Commit

Permalink
feat(plugins/mpa): support remove tab
Browse files Browse the repository at this point in the history
  • Loading branch information
NWYLZW committed Nov 14, 2023
1 parent 32973f7 commit a0abcd7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions core/src/plugins/mpa/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export const useTabs = () => {
...tabs.slice(index)
]
})
}, [setTabs]),
removeTabs: useCallback((...ids: string[]) => {
setTabs(tabs => tabs.filter(tab => !ids.includes(tab.id)))
}, [setTabs])
}
}
6 changes: 4 additions & 2 deletions core/src/plugins/mpa/topbar/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useTabs } from '../atoms'
const prefix = 'mpa__topbar__files'

export const Files: React.ComponentType<BarItemProps> = () => {
const { tabs, addTab } = useTabs()
const { tabs, addTab, removeTabs } = useTabs()
const addOnlyOnce = useRef(false)
useEffect(() => {
if (addOnlyOnce.current) return
Expand All @@ -28,7 +28,9 @@ export const Files: React.ComponentType<BarItemProps> = () => {
>
{tab.icon && <span className={`cldr codicon codicon-${tab.icon}`} />}
{tab.title}
<span className='cldr codicon codicon-close' />
<span className='cldr codicon codicon-close'
onClick={() => removeTabs(tab.id)}
/>
</div>)}
<div className={`${prefix}-full`} />
</div>
Expand Down

0 comments on commit a0abcd7

Please sign in to comment.