@@ -11,6 +11,7 @@ import IconWarning from '~icons/material-symbols/error-rounded';
1111import IconInfo from '~icons/material-symbols/info-rounded' ;
1212
1313import { type BaseProps , type BaseRef , joinClass , type Palette , type RefProps } from '@components/base' ;
14+ import { useLocale , useOptions } from '@components/context' ;
1415import styles from './style.module.css' ;
1516
1617export const types = [ 'error' , 'warning' , 'success' , 'info' ] as const ;
@@ -92,14 +93,6 @@ export interface Props extends BaseProps, RefProps<Ref> {
9293 * 在将当前组件从 DOM 中移除之前执行的操作,返回 true 将阻止后续的移除操作。
9394 */
9495 onClose ?: ( ) => Promise < boolean | undefined > ;
95-
96- // 指定动画时间,因为在 notify 中使用了 render 渲染到 Portal 中,无法在 Message 中使用 useOptions 获取动画时长。
97- transitionDuration : number ;
98-
99- /**
100- * 关闭按钮的 aria-label,与 transitionDuration 相同的理由,不能放在 Message 组件内部。
101- */
102- closeAriaLabel ?: string ;
10396}
10497
10598/**
@@ -108,6 +101,9 @@ export interface Props extends BaseProps, RefProps<Ref> {
108101export function Message ( props : Props ) : JSX . Element {
109102 props = mergeProps ( { type : 'info' as Type } , props ) ;
110103
104+ const l = useLocale ( ) ;
105+ const [ opt ] = useOptions ( ) ;
106+
111107 let rootRef : HTMLDivElement ;
112108 let buttonRef : HTMLButtonElement ;
113109
@@ -116,12 +112,12 @@ export function Message(props: Props): JSX.Element {
116112 return ;
117113 }
118114
119- if ( ! props . transitionDuration ) {
115+ if ( ! opt . getTransitionDuration ( ) ) {
120116 return ;
121117 }
122118
123119 rootRef . style . height = '0' ;
124- await sleep ( props . transitionDuration ) ; // 待动画结束
120+ await sleep ( opt . getTransitionDuration ( ) ) ; // 待动画结束
125121 rootRef . remove ( ) ;
126122 } ;
127123
@@ -219,7 +215,7 @@ export function Message(props: Props): JSX.Element {
219215 type = "button"
220216 class = { styles [ 'close-wrap' ] }
221217 ref = { el => ( buttonRef = el ) }
222- aria-label = { props . closeAriaLabel }
218+ aria-label = { l . t ( '_c.close' ) }
223219 >
224220 < IconClose onClick = { close } class = { styles . close } />
225221 </ button >
0 commit comments