74 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-05-29 17:53:27 +08:00
import Icon from './Icon'
2022-04-16 21:14:03 +08:00
import { IpcChannels } from '@/shared/IpcChannels'
2022-05-12 02:45:43 +08:00
import useIpcRenderer from '@/web/hooks/useIpcRenderer'
2023-01-07 14:39:03 +08:00
import { useState } from 'react'
2022-10-28 20:29:04 +08:00
import { css, cx } from '@emotion/css'
2022-04-04 17:51:07 +08:00
const Controls = () => {
const [isMaximized, setIsMaximized] = useState(false)
useIpcRenderer(IpcChannels.IsMaximized, (e, value) => {
setIsMaximized(value)
})
const minimize = () => {
2022-04-09 00:28:37 +08:00
window.ipcRenderer?.send(IpcChannels.Minimize)
}
const maxRestore = () => {
2022-04-09 00:28:37 +08:00
window.ipcRenderer?.send(IpcChannels.MaximizeOrUnmaximize)
}
const close = () => {
2022-04-09 00:28:37 +08:00
window.ipcRenderer?.send(IpcChannels.Close)
}
2022-10-28 20:29:04 +08:00
const classNames = cx(
'flex items-center justify-center text-white/80 hover:text-white hover:bg-white/20 transition duration-400',
css`
height: 28px;
width: 48px;
border-radius: 4px;
`
)
return (
2022-10-28 20:29:04 +08:00
<div className='app-region-no-drag flex h-full items-center'>
<button onClick={minimize} className={classNames}>
2022-05-29 17:53:27 +08:00
<Icon className='h-3 w-3' name='windows-minimize' />
</button>
2022-10-28 20:29:04 +08:00
<button onClick={maxRestore} className={classNames}>
2022-05-29 17:53:27 +08:00
<Icon
className='h-3 w-3'
name={isMaximized ? 'windows-un-maximize' : 'windows-maximize'}
/>
</button>
<button
onClick={close}
2022-10-28 20:29:04 +08:00
className={cx(
classNames,
css`
2023-01-07 14:39:03 +08:00
border-radius: 4px 22px 4px 4px;
margin-right: 4px;
2022-10-28 20:29:04 +08:00
`
)}
>
2022-05-29 17:53:27 +08:00
<Icon className='h-3 w-3' name='windows-close' />
</button>
</div>
)
}
2022-04-04 17:51:07 +08:00
const TitleBar = () => {
return (
<div className='app-region-drag fixed z-30'>
2022-10-28 20:29:04 +08:00
<div className='flex h-9 w-screen items-center justify-between'>
<div></div>
<Controls />
</div>
2022-04-04 17:51:07 +08:00
</div>
)
}
export default TitleBar