This commit is contained in:
archer
2023-07-04 23:00:24 +08:00
parent 6e1ef89d65
commit 8e9816d648
7 changed files with 158 additions and 174 deletions

View File

@@ -30,7 +30,7 @@ const Navbar = ({ unread }: { unread: number }) => {
label: '应用',
icon: 'model',
link: `/app/list`,
activeLink: ['/app/list']
activeLink: ['/app/list', '/app/detail']
},
{
label: '知识库',

View File

@@ -0,0 +1,72 @@
import React, { useMemo } from 'react';
import { Box, Flex, useTheme } from '@chakra-ui/react';
import type { GridProps } from '@chakra-ui/react';
import MyIcon, { type IconName } from '../Icon';
// @ts-ignore
export interface Props extends GridProps {
list: { id: string; label: string; icon: string }[];
activeId: string;
size?: 'sm' | 'md' | 'lg';
onChange: (id: string) => void;
}
const SlideTabs = ({ list, size = 'md', activeId, onChange, ...props }: Props) => {
const sizeMap = useMemo(() => {
switch (size) {
case 'sm':
return {
fontSize: 'sm',
inlineP: 1
};
case 'md':
return {
fontSize: 'md',
inlineP: 2
};
case 'lg':
return {
fontSize: 'lg',
inlineP: 3
};
}
}, [size]);
return (
<Box fontSize={sizeMap.fontSize} {...props}>
{list.map((item) => (
<Flex
key={item.id}
py={sizeMap.inlineP}
borderRadius={'md'}
px={3}
mb={2}
alignItems={'center'}
_hover={{
bg: 'myWhite.600'
}}
{...(activeId === item.id
? {
// backgroundImage: 'linear-gradient(to right, #85b1ff 0%, #EBF7FD 100%)',
bg: ' myBlue.300',
fontWeight: 'bold',
color: 'myBlue.700',
cursor: 'default'
}
: {
cursor: 'pointer'
})}
onClick={() => {
if (activeId === item.id) return;
onChange(item.id);
}}
>
<MyIcon mr={2} name={item.icon as IconName} w={'14px'} />
{item.label}
</Flex>
))}
</Box>
);
};
export default React.memo(SlideTabs);