init
This commit is contained in:
35
src/components/Stars/StarModal/index.tsx
Normal file
35
src/components/Stars/StarModal/index.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import React, { useEffect, useState, ReactNode } from 'react';
|
||||
import Modal, { ModalProps } from 'antd/lib/modal';
|
||||
import { StarProps } from '../interface';
|
||||
|
||||
/**
|
||||
* 星级模态框组件,基于Antd Modal的增强组件
|
||||
* 提供国际化和组件生命周期管理功能
|
||||
*/
|
||||
const StarModal: React.FC<ModalProps & StarProps & { children: ReactNode }> = (props) => {
|
||||
const { open, destroyOnClose, children, format: formate, ...rest } = props;
|
||||
const [exist, setExist] = useState<boolean | undefined>(open);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) setExist(open);
|
||||
}, [open]);
|
||||
|
||||
const elements = exist ? (
|
||||
<Modal
|
||||
destroyOnClose={destroyOnClose}
|
||||
open={open}
|
||||
afterClose={() => setExist(false)}
|
||||
okText={formate ? formate({ id: 'confirm' }) : '确定'}
|
||||
cancelText={formate ? formate({ id: 'cancel' }) : '取消'}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</Modal>
|
||||
) : (
|
||||
<div />
|
||||
);
|
||||
|
||||
return elements;
|
||||
};
|
||||
|
||||
export default StarModal;
|
||||
Reference in New Issue
Block a user