1
- import { ActionIcon , ActionIconProps , Icon , Tag } from '@lobehub/ui' ;
1
+ import { ActionIcon , type ActionIconProps , Icon , Tag } from '@lobehub/ui' ;
2
2
import { Dropdown , Slider } from 'antd' ;
3
3
import { Download , PauseCircle , Play , StopCircle } from 'lucide-react' ;
4
- import React , { memo , useCallback , useMemo } from 'react' ;
4
+ import { type CSSProperties , memo , useCallback , useMemo } from 'react' ;
5
5
import { Flexbox } from 'react-layout-kit' ;
6
6
7
7
import { secondsToMinutesAndSeconds } from '@/core/utils/secondsToMinutesAndSeconds' ;
@@ -28,9 +28,9 @@ export interface AudioPlayerProps {
28
28
onPlay ?: ( ) => void ;
29
29
onStop ?: ( ) => void ;
30
30
showSlider ?: boolean ;
31
- style ?: React . CSSProperties ;
31
+ style ?: CSSProperties ;
32
32
timeRender ?: 'tag' | 'text' ;
33
- timeStyle ?: React . CSSProperties ;
33
+ timeStyle ?: CSSProperties ;
34
34
timeType ?: 'left' | 'current' | 'combine' ;
35
35
}
36
36
@@ -41,7 +41,16 @@ const AudioPlayer = memo<AudioPlayerProps>(
41
41
timeStyle,
42
42
buttonSize,
43
43
className,
44
- audio,
44
+ audio = {
45
+ currentTime : 0 ,
46
+ download : ( ) => { } ,
47
+ duration : 0 ,
48
+ isPlaying : false ,
49
+ pause : ( ) => { } ,
50
+ play : ( ) => { } ,
51
+ setTime : ( ) => { } ,
52
+ stop : ( ) => { } ,
53
+ } ,
45
54
allowPause = true ,
46
55
timeType = 'left' ,
47
56
showSlider = true ,
@@ -53,9 +62,9 @@ const AudioPlayer = memo<AudioPlayerProps>(
53
62
} ) => {
54
63
const { isPlaying, play, stop, pause, duration, setTime, currentTime, download } = audio ;
55
64
56
- const formatedLeftTime = secondsToMinutesAndSeconds ( duration - currentTime ) ;
57
- const formatedCurrentTime = secondsToMinutesAndSeconds ( currentTime ) ;
58
- const formatedDuration = secondsToMinutesAndSeconds ( duration ) ;
65
+ const formattedLeftTime = secondsToMinutesAndSeconds ( duration - currentTime ) ;
66
+ const formattedCurrentTime = secondsToMinutesAndSeconds ( currentTime ) ;
67
+ const formattedDuration = secondsToMinutesAndSeconds ( duration ) ;
59
68
60
69
const Time = useMemo (
61
70
( ) => ( timeRender === 'tag' ? Tag : ( props : any ) => < div { ...props } /> ) ,
@@ -122,12 +131,12 @@ const AudioPlayer = memo<AudioPlayerProps>(
122
131
placement = "top"
123
132
>
124
133
< Time style = { { cursor : 'pointer' , flex : 'none' , ...timeStyle } } >
125
- { timeType === 'left' && formatedLeftTime }
126
- { timeType === 'current' && formatedCurrentTime }
134
+ { timeType === 'left' && formattedLeftTime }
135
+ { timeType === 'current' && formattedCurrentTime }
127
136
{ timeType === 'combine' && (
128
137
< span >
129
- { formatedCurrentTime }
130
- < span style = { { opacity : 0.66 } } > { ` / ${ formatedDuration } ` } </ span >
138
+ { formattedCurrentTime }
139
+ < span style = { { opacity : 0.66 } } > { ` / ${ formattedDuration } ` } </ span >
131
140
</ span >
132
141
) }
133
142
</ Time >
0 commit comments