@@ -3,10 +3,9 @@ import { CheckFilled, CloseFilled, InformationFilled, WarningFilled } from '@dti
33import { Modal as AntdModal , ModalFuncProps } from 'antd' ;
44import { ModalFunc , ModalStaticFunctions } from 'antd/lib/modal/confirm' ;
55
6+ import { getRunTimeLocale , ModalLocale } from './locale' ;
67import InternalModal from './modal' ;
78
8- const OK_TEXT = '确认' ;
9-
109type ModalType = typeof InternalModal &
1110 ModalStaticFunctions & {
1211 useModal : typeof AntdModal . useModal ;
@@ -17,31 +16,42 @@ type ModalType = typeof InternalModal &
1716
1817const { useModal, info, success, error, warning, confirm, destroyAll, config } = AntdModal ;
1918
20- const customProps : Record <
19+ const getCustomProps = (
20+ locale : ModalLocale
21+ ) : Record <
2122 | keyof Pick < ModalStaticFunctions , 'info' | 'success' | 'error' | 'warning' | 'confirm' >
2223 | 'delete' ,
2324 ModalFuncProps
24- > = {
25- info : { icon : < InformationFilled color = "#1D78FF" /> , okText : OK_TEXT } ,
26- success : { icon : < CheckFilled color = "#11D7B2" /> , okText : OK_TEXT } ,
27- error : {
28- icon : < CloseFilled color = "#F96C5B" /> ,
29- okText : OK_TEXT ,
30- okButtonProps : { danger : true } ,
31- } ,
32- warning : { icon : < WarningFilled color = "#FBB310" /> , okText : OK_TEXT } ,
33- confirm : { icon : < WarningFilled color = "#FBB310" /> , okText : OK_TEXT , cancelText : '取消' } ,
34- delete : {
35- icon : < CloseFilled color = "#F96C5B" /> ,
36- okButtonProps : { danger : true } ,
37- okText : OK_TEXT ,
38- cancelText : '暂不' ,
39- } ,
25+ > => {
26+ return {
27+ info : { icon : < InformationFilled color = "#1D78FF" /> , okText : locale . okText } ,
28+ success : { icon : < CheckFilled color = "#11D7B2" /> , okText : locale . okText } ,
29+ error : {
30+ icon : < CloseFilled color = "#F96C5B" /> ,
31+ okText : locale . okText ,
32+ okButtonProps : { danger : true } ,
33+ } ,
34+ warning : { icon : < WarningFilled color = "#FBB310" /> , okText : locale . okText } ,
35+ confirm : {
36+ icon : < WarningFilled color = "#FBB310" /> ,
37+ okText : locale . okText ,
38+ cancelText : locale . cancelText ,
39+ } ,
40+ delete : {
41+ icon : < CloseFilled color = "#F96C5B" /> ,
42+ okButtonProps : { danger : true } ,
43+ okText : locale . okText ,
44+ cancelText : locale . notYetText ,
45+ } ,
46+ } ;
4047} ;
4148
42- function withCustomIcon ( fn : ModalFunc , type : keyof typeof customProps ) {
43- return ( props : ModalFuncProps ) =>
44- fn ( { ...customProps [ type ] , wrapClassName : 'dtc-modal' , ...props } ) ;
49+ function withCustomIcon ( fn : ModalFunc , type : keyof ReturnType < typeof getCustomProps > ) {
50+ return ( props : ModalFuncProps ) => {
51+ const locale = getRunTimeLocale ( ) ;
52+ const customProps = getCustomProps ( locale ) ;
53+ return fn ( { ...customProps [ type ] , wrapClassName : 'dtc-modal' , ...props } ) ;
54+ } ;
4555}
4656
4757const Modal = InternalModal as unknown as ModalType ;
0 commit comments