Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions packages/web/components/common/MyMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type Props = {
trigger?: 'hover' | 'click';
iconSize?: string;
iconRadius?: string;
menuItemStyles?: MenuItemProps;

placement?: PlacementWithLogical;
menuList: {
label?: string;
Expand All @@ -33,7 +33,8 @@ export type Props = {
icon?: IconNameType | string;
label: string | React.ReactNode;
description?: string;
onClick?: () => any;
onClick: () => any;
menuItemStyles?: MenuItemProps;
}[];
}[];
};
Expand All @@ -46,15 +47,7 @@ const MyMenu = ({
Button,
menuList,
iconRadius,
placement = 'bottom-start',
menuItemStyles = {
borderRadius: 'sm',
py: 2,
px: 3,
display: 'flex',
alignItems: 'center',
fontSize: 'sm'
}
placement = 'bottom-start'
}: Props) => {
const typeMapStyle: Record<MenuItemType, MenuItemProps> = {
primary: {
Expand Down Expand Up @@ -167,18 +160,23 @@ const MyMenu = ({
{item.children.map((child, index) => (
<MenuItem
key={index}
{...menuItemStyles}
borderRadius={'sm'}
onClick={(e) => {
e.stopPropagation();
if (child.onClick) {
setIsOpen(false);
child.onClick();
}
}}
py={2}
px={3}
alignItems={'center'}
fontSize={'sm'}
color={child.isActive ? 'primary.700' : 'myGray.600'}
whiteSpace={'pre-wrap'}
_notLast={{ mb: 0.5 }}
{...typeMapStyle[child.type || 'primary']}
{...child.menuItemStyles}
>
{!!child.icon && (
<Avatar
Expand Down
3 changes: 3 additions & 0 deletions packages/web/components/common/MyModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface MyModalProps extends ModalContentProps {
isOpen?: boolean;
onClose?: () => void;
closeOnOverlayClick?: boolean;
size?: 'md' | 'lg';
}

const MyModal = ({
Expand All @@ -35,6 +36,7 @@ const MyModal = ({
maxW = ['90vw', '600px'],
closeOnOverlayClick = true,
iconColor,
size = 'md',
...props
}: MyModalProps) => {
const { isPc } = useSystem();
Expand All @@ -43,6 +45,7 @@ const MyModal = ({
<Modal
isOpen={isOpen}
onClose={() => onClose && onClose()}
size={size}
autoFocus={false}
isCentered={isPc ? isCentered : true}
blockScrollOnMount={false}
Expand Down
32 changes: 23 additions & 9 deletions packages/web/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,29 @@ const Checkbox = checkBoxMultiStyle({
});

const Modal = modalMultiStyle({
baseStyle: modalPart({
body: {
py: 4,
px: 7
},
footer: {
pt: 2
}
})
sizes: {
md: modalPart({
body: {
py: 4,
px: 7
},
footer: {
pt: 2
}
}),
lg: modalPart({
body: {
pt: 8,
pb: 6,
px: '3.25rem'
},
footer: {
pb: 8,
px: '3.25rem',
pt: 0
}
})
}
});

const Table = tableMultiStyle({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ const AppCard = ({
label: ExportPopover({
chatConfig: appDetail.chatConfig,
appName: appDetail.name
})
}),
onClick: () => {},
Patrickill marked this conversation as resolved.
Show resolved Hide resolved
menuItemStyles: {
p: 0
}
}
]
}
Expand Down Expand Up @@ -213,12 +217,12 @@ function ExportPopover({
return (
<MyPopover
placement={'right-start'}
offset={[-5, 20]}
offset={[-5, 5]}
hasArrow={false}
trigger={'hover'}
w={'8.6rem'}
Trigger={
<Flex align={'center'} w={'100%'}>
<Flex align={'center'} w={'100%'} py={2} px={3}>
<Avatar src={'export'} borderRadius={'sm'} w={'1rem'} mr={3} />
{t('app:export_configs')}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,23 @@ const ImportSettings = ({ onClose }: Props) => {
return (
<MyModal
isOpen
w={'600px'}
onClose={onClose}
title={
<Flex align={'center'} ml={-3}>
<MyIcon name={'common/importLight'} color={'primary.600'} w={'1.25rem'} mr={'0.62rem'} />
<Box lineHeight={'1.25rem'}>{appT('import_configs')}</Box>
</Flex>
}
size="lg"
>
<ModalBody py={'2rem'} px={'3.25rem'}>
<ModalBody>
<File onSelect={onSelectFile} />
{isDragging ? (
<Flex
align={'center'}
justify={'center'}
w={'31rem'}
h={'21.25rem'}
h={'17.5rem'}
Patrickill marked this conversation as resolved.
Show resolved Hide resolved
borderRadius={'md'}
border={'1px dashed'}
borderColor={'myGray.400'}
Expand All @@ -106,7 +106,7 @@ const ImportSettings = ({ onClose }: Props) => {
</Flex>
</Flex>
) : (
<Box w={'31rem'} minH={'21.25rem'}>
<Box w={'31rem'}>
<Flex justify={'space-between'} align={'center'} pb={2}>
<Box fontSize={'sm'} color={'myGray.900'} fontWeight={'500'}>
{t('common:common.json_config')}
Expand Down Expand Up @@ -141,36 +141,38 @@ const ImportSettings = ({ onClose }: Props) => {
onChange={(e) => setValue(e.target.value)}
/>
</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>
)}
</ModalBody>
<ModalFooter>
<Flex justify={'flex-end'}>
Patrickill marked this conversation as resolved.
Show resolved Hide resolved
<Button
p={0}
Patrickill marked this conversation as resolved.
Show resolved Hide resolved
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>
</ModalFooter>
</MyModal>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ const InputTab = ({

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 mb={2} fontWeight={'medium'} fontSize={'sm'} alignItems={'center'} h={8}>
<Box color={'red.600'}>*</Box>
Expand Down Expand Up @@ -435,7 +435,7 @@ const DataIndex = ({

return (
<>
<Flex mt={3} gap={3} flexDir={'column'} pr={2}>
<Flex mt={3} gap={3} flexDir={'column'}>
<Box
p={4}
borderRadius={'md'}
Expand Down
Loading