diff --git a/web/src/components/FullModal.tsx b/web/src/components/FullModal.tsx new file mode 100644 index 00000000..8f1602f3 --- /dev/null +++ b/web/src/components/FullModal.tsx @@ -0,0 +1,58 @@ +import React, { useCallback, useEffect, useRef } from 'react'; +import _isFunction from 'lodash/isFunction'; +import { Icon } from '@iconify/react'; +import clsx from 'clsx'; + +/** + * 全屏模态框 + */ +interface FullModalProps { + visible?: boolean; + onChangeVisible?: (visible: boolean) => void; +} +export const FullModal: React.FC = React.memo((props) => { + const { visible = true, onChangeVisible } = props; + const ref = useRef(null); + + const handleClose = useCallback(() => { + _isFunction(onChangeVisible) && onChangeVisible(false); + }, [onChangeVisible]); + + useEffect(() => { + const handler = (e: KeyboardEvent) => { + if (e.code === 'Escape') { + handleClose(); + } + }; + window.addEventListener('keyup', handler); + + return () => { + window.removeEventListener('keyup', handler); + }; + }, [handleClose]); + + return ( +
+ {props.children} + + {_isFunction(onChangeVisible) && ( +
+ + ESC +
+ )} +
+ ); +}); +FullModal.displayName = 'FullModal'; diff --git a/web/src/components/Portal.tsx b/web/src/components/Portal.tsx index 4e632071..56618e42 100644 --- a/web/src/components/Portal.tsx +++ b/web/src/components/Portal.tsx @@ -7,7 +7,7 @@ const { PortalHost, PortalRender, add, remove } = buildPortal({ hostName: 'default', eventEmitter, // eslint-disable-next-line react/display-name - renderManagerView: (children) =>
{children}
, + renderManagerView: (children) =>
{children}
, }); export { PortalHost, PortalRender, add as PortalAdd, remove as PortalRemove }; diff --git a/web/src/routes/Main/Navbar/SettingBtn.tsx b/web/src/routes/Main/Navbar/SettingBtn.tsx new file mode 100644 index 00000000..900e41b6 --- /dev/null +++ b/web/src/routes/Main/Navbar/SettingBtn.tsx @@ -0,0 +1,23 @@ +import { FullModal } from '@/components/FullModal'; +import { closeModal, openModal } from '@/components/Modal'; +import { Icon } from '@iconify/react'; +import React, { useCallback } from 'react'; + +export const SettingBtn: React.FC = React.memo(() => { + const handleClick = useCallback(() => { + const key = openModal( + closeModal(key)}> + Setting View + + ); + }, []); + + return ( + + ); +}); +SettingBtn.displayName = 'SettingBtn'; diff --git a/web/src/routes/Main/Navbar/index.tsx b/web/src/routes/Main/Navbar/index.tsx index 5d563268..b0159aae 100644 --- a/web/src/routes/Main/Navbar/index.tsx +++ b/web/src/routes/Main/Navbar/index.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { t, useAppSelector } from 'tailchat-shared'; -import { Icon } from '@iconify/react'; import { Avatar } from '@/components/Avatar'; import { NavbarNavItem } from './NavItem'; import { GroupNav } from './GroupNav'; import { MobileMenuBtn } from './MobileMenuBtn'; +import { SettingBtn } from './SettingBtn'; /** * 导航栏组件 @@ -30,11 +30,9 @@ export const Navbar: React.FC = React.memo(() => { +
- +
);