perf: modal add size props&menu add menuItemStyles (#2600)

* perf: modal add size props&menu add menuItemStyles

* delete minH

* mobile adaptation

* 优化部分代码
This commit is contained in:
papapatrick
2024-09-03 14:56:09 +08:00
committed by GitHub
parent 4726034344
commit a7569037fe
6 changed files with 79 additions and 58 deletions

View File

@@ -23,7 +23,7 @@ export type Props = {
trigger?: 'hover' | 'click'; trigger?: 'hover' | 'click';
iconSize?: string; iconSize?: string;
iconRadius?: string; iconRadius?: string;
menuItemStyles?: MenuItemProps;
placement?: PlacementWithLogical; placement?: PlacementWithLogical;
menuList: { menuList: {
label?: string; label?: string;
@@ -34,6 +34,7 @@ export type Props = {
label: string | React.ReactNode; label: string | React.ReactNode;
description?: string; description?: string;
onClick?: () => any; onClick?: () => any;
menuItemStyles?: MenuItemProps;
}[]; }[];
}[]; }[];
}; };
@@ -46,15 +47,7 @@ const MyMenu = ({
Button, Button,
menuList, menuList,
iconRadius, iconRadius,
placement = 'bottom-start', placement = 'bottom-start'
menuItemStyles = {
borderRadius: 'sm',
py: 2,
px: 3,
display: 'flex',
alignItems: 'center',
fontSize: 'sm'
}
}: Props) => { }: Props) => {
const typeMapStyle: Record<MenuItemType, MenuItemProps> = { const typeMapStyle: Record<MenuItemType, MenuItemProps> = {
primary: { primary: {
@@ -167,7 +160,7 @@ const MyMenu = ({
{item.children.map((child, index) => ( {item.children.map((child, index) => (
<MenuItem <MenuItem
key={index} key={index}
{...menuItemStyles} borderRadius={'sm'}
onClick={(e) => { onClick={(e) => {
e.stopPropagation(); e.stopPropagation();
if (child.onClick) { if (child.onClick) {
@@ -175,10 +168,15 @@ const MyMenu = ({
child.onClick(); child.onClick();
} }
}} }}
py={2}
px={3}
alignItems={'center'}
fontSize={'sm'}
color={child.isActive ? 'primary.700' : 'myGray.600'} color={child.isActive ? 'primary.700' : 'myGray.600'}
whiteSpace={'pre-wrap'} whiteSpace={'pre-wrap'}
_notLast={{ mb: 0.5 }} _notLast={{ mb: 0.5 }}
{...typeMapStyle[child.type || 'primary']} {...typeMapStyle[child.type || 'primary']}
{...child.menuItemStyles}
> >
{!!child.icon && ( {!!child.icon && (
<Avatar <Avatar

View File

@@ -21,6 +21,7 @@ export interface MyModalProps extends ModalContentProps {
isOpen?: boolean; isOpen?: boolean;
onClose?: () => void; onClose?: () => void;
closeOnOverlayClick?: boolean; closeOnOverlayClick?: boolean;
size?: 'md' | 'lg';
} }
const MyModal = ({ const MyModal = ({
@@ -35,6 +36,7 @@ const MyModal = ({
maxW = ['90vw', '600px'], maxW = ['90vw', '600px'],
closeOnOverlayClick = true, closeOnOverlayClick = true,
iconColor, iconColor,
size = 'md',
...props ...props
}: MyModalProps) => { }: MyModalProps) => {
const { isPc } = useSystem(); const { isPc } = useSystem();
@@ -43,6 +45,7 @@ const MyModal = ({
<Modal <Modal
isOpen={isOpen} isOpen={isOpen}
onClose={() => onClose && onClose()} onClose={() => onClose && onClose()}
size={size}
autoFocus={false} autoFocus={false}
isCentered={isPc ? isCentered : true} isCentered={isPc ? isCentered : true}
blockScrollOnMount={false} blockScrollOnMount={false}

View File

@@ -470,15 +470,29 @@ const Checkbox = checkBoxMultiStyle({
}); });
const Modal = modalMultiStyle({ const Modal = modalMultiStyle({
baseStyle: modalPart({ sizes: {
body: { md: modalPart({
py: 4, body: {
px: 7 py: 4,
}, px: 7
footer: { },
pt: 2 footer: {
} pt: 2
}) }
}),
lg: modalPart({
body: {
pt: 8,
pb: 6,
px: '3.25rem'
},
footer: {
pb: 8,
px: '3.25rem',
pt: 0
}
})
}
}); });
const Table = tableMultiStyle({ const Table = tableMultiStyle({

View File

@@ -74,7 +74,11 @@ const AppCard = ({
label: ExportPopover({ label: ExportPopover({
chatConfig: appDetail.chatConfig, chatConfig: appDetail.chatConfig,
appName: appDetail.name appName: appDetail.name
}) }),
menuItemStyles: {
p: 0,
cursor: 'default'
}
} }
] ]
} }
@@ -213,12 +217,12 @@ function ExportPopover({
return ( return (
<MyPopover <MyPopover
placement={'right-start'} placement={'right-start'}
offset={[-5, 20]} offset={[-5, 5]}
hasArrow={false} hasArrow={false}
trigger={'hover'} trigger={'hover'}
w={'8.6rem'} w={'8.6rem'}
Trigger={ Trigger={
<Flex align={'center'} w={'100%'}> <Flex align={'center'} w={'100%'} py={2} px={3}>
<Avatar src={'export'} borderRadius={'sm'} w={'1rem'} mr={3} /> <Avatar src={'export'} borderRadius={'sm'} w={'1rem'} mr={3} />
{t('app:export_configs')} {t('app:export_configs')}
</Flex> </Flex>
@@ -232,7 +236,8 @@ function ExportPopover({
color={'myGray.600'} color={'myGray.600'}
_hover={{ _hover={{
bg: 'myGray.05', bg: 'myGray.05',
color: 'primary.600' color: 'primary.600',
cursor: 'pointer'
}} }}
borderRadius={'xs'} borderRadius={'xs'}
onClick={onExportWorkflow} onClick={onExportWorkflow}
@@ -246,7 +251,8 @@ function ExportPopover({
color={'myGray.600'} color={'myGray.600'}
_hover={{ _hover={{
bg: 'myGray.05', bg: 'myGray.05',
color: 'primary.600' color: 'primary.600',
cursor: 'pointer'
}} }}
borderRadius={'xs'} borderRadius={'xs'}
onClick={() => { onClick={() => {

View File

@@ -73,7 +73,6 @@ const ImportSettings = ({ onClose }: Props) => {
return ( return (
<MyModal <MyModal
isOpen isOpen
w={'600px'}
onClose={onClose} onClose={onClose}
title={ title={
<Flex align={'center'} ml={-3}> <Flex align={'center'} ml={-3}>
@@ -81,15 +80,16 @@ const ImportSettings = ({ onClose }: Props) => {
<Box lineHeight={'1.25rem'}>{appT('import_configs')}</Box> <Box lineHeight={'1.25rem'}>{appT('import_configs')}</Box>
</Flex> </Flex>
} }
size={isPc ? 'lg' : 'md'}
> >
<ModalBody py={'2rem'} px={'3.25rem'}> <ModalBody>
<File onSelect={onSelectFile} /> <File onSelect={onSelectFile} />
{isDragging ? ( {isDragging ? (
<Flex <Flex
align={'center'} align={'center'}
justify={'center'} justify={'center'}
w={'31rem'} w={'31rem'}
h={'21.25rem'} h={'17.5rem'}
borderRadius={'md'} borderRadius={'md'}
border={'1px dashed'} border={'1px dashed'}
borderColor={'myGray.400'} borderColor={'myGray.400'}
@@ -106,7 +106,7 @@ const ImportSettings = ({ onClose }: Props) => {
</Flex> </Flex>
</Flex> </Flex>
) : ( ) : (
<Box w={'31rem'} minH={'21.25rem'}> <Box w={['100%', '31rem']}>
<Flex justify={'space-between'} align={'center'} pb={2}> <Flex justify={'space-between'} align={'center'} pb={2}>
<Box fontSize={'sm'} color={'myGray.900'} fontWeight={'500'}> <Box fontSize={'sm'} color={'myGray.900'} fontWeight={'500'}>
{t('common:common.json_config')} {t('common:common.json_config')}
@@ -141,36 +141,36 @@ const ImportSettings = ({ onClose }: Props) => {
onChange={(e) => setValue(e.target.value)} onChange={(e) => setValue(e.target.value)}
/> />
</Box> </Box>
<Flex justify={'flex-end'} pt={5}>
<Button
p={0}
onClick={() => {
if (!value) {
return onClose();
}
try {
const data = JSON.parse(value);
initData(data);
onClose();
} catch (error) {
toast({
title: appT('import_configs_failed')
});
}
toast({
title: t('app:import_configs_success'),
status: 'success'
});
}}
>
<Flex px={5} py={2} fontWeight={'500'}>
{t('common:common.Save')}
</Flex>
</Button>
</Flex>
</Box> </Box>
)} )}
</ModalBody> </ModalBody>
<ModalFooter justifyItems={'flex-end'}>
<Button
px={5}
py={2}
onClick={async () => {
if (!value) {
return onClose();
}
try {
const data = JSON.parse(value);
await initData(data);
toast({
title: t('app:import_configs_success'),
status: 'success'
});
onClose();
} catch (error) {
toast({
title: t('app:import_configs_failed')
});
}
}}
fontWeight={'500'}
>
{t('common:common.Save')}
</Button>
</ModalFooter>
</MyModal> </MyModal>
); );
}; };

View File

@@ -353,7 +353,7 @@ const InputTab = ({
return ( return (
<> <>
<Flex h={'100%'} gap={6} flexDir={['column', 'row']} w={'100%'} pr={2}> <Flex h={'100%'} gap={6} flexDir={['column', 'row']} w={'100%'}>
<Flex flexDir={'column'} flex={1}> <Flex flexDir={'column'} flex={1}>
<Flex mb={2} fontWeight={'medium'} fontSize={'sm'} alignItems={'center'} h={8}> <Flex mb={2} fontWeight={'medium'} fontSize={'sm'} alignItems={'center'} h={8}>
<Box color={'red.600'}>*</Box> <Box color={'red.600'}>*</Box>
@@ -435,7 +435,7 @@ const DataIndex = ({
return ( return (
<> <>
<Flex mt={3} gap={3} flexDir={'column'} pr={2}> <Flex mt={3} gap={3} flexDir={'column'}>
<Box <Box
p={4} p={4}
borderRadius={'md'} borderRadius={'md'}