1
1
import cn from 'bem-cn-lite' ;
2
2
3
- import { ValueOf } from '../../types/common' ;
3
+ import type { ValueOf } from '../../types/common' ;
4
4
5
5
import './ProgressViewer.scss' ;
6
6
@@ -20,20 +20,19 @@ type ProgressViewerSize = ValueOf<typeof PROGRESS_VIEWER_SIZE_IDS>;
20
20
21
21
/*
22
22
23
- Описание props:
24
- 1) value - величина прогресса
25
- 2) capacity - предельно возможный прогресс
26
- 3) formatValues - функция форматирования value и capacity
27
- 4) percents - отображать ли заполненость в виде процентов
28
- 5) className - кастомный класс
29
- 6) colorizeProgress - менять ли цвет полосы прогресса в зависимости от его величины
30
- 7) inverseColorize - инвертировать ли цвета при разукрашивании прогресса
23
+ Props description:
24
+ 1) value - the amount of progress
25
+ 2) capacity - maximum possible progress value
26
+ 3) formatValues - function for formatting the value and capacity
27
+ 4) percents - display progress in percents
28
+ 5) colorizeProgress - change the color of the progress bar depending on its value
29
+ 6) inverseColorize - invert the colors of the progress bar
31
30
*/
32
31
33
32
interface ProgressViewerProps {
34
33
value ?: number | string ;
35
34
capacity ?: number | string ;
36
- formatValues ?: ( value ?: number , total ?: number ) => ( string | undefined ) [ ] ;
35
+ formatValues ?: ( value ?: number , capacity ?: number ) => ( string | undefined ) [ ] ;
37
36
percents ?: boolean ;
38
37
className ?: string ;
39
38
size ?: ProgressViewerSize ;
@@ -54,13 +53,11 @@ export function ProgressViewer({
54
53
let fillWidth = Math . round ( ( parseFloat ( String ( value ) ) / parseFloat ( String ( capacity ) ) ) * 100 ) ;
55
54
fillWidth = fillWidth > 100 ? 100 : fillWidth ;
56
55
57
- let valueText = String ( Math . round ( Number ( value ) ) ) ,
58
- capacityText = capacity ,
56
+ let valueText : number | string | undefined = Math . round ( Number ( value ) ) ,
57
+ capacityText : number | string | undefined = capacity ,
59
58
divider = '/' ;
60
- let formattedValue : string | undefined ;
61
- let formattedCapacity : string | undefined ;
62
59
if ( formatValues ) {
63
- [ formattedValue , formattedCapacity ] = formatValues ( Number ( value ) , Number ( capacity ) ) ;
60
+ [ valueText , capacityText ] = formatValues ( Number ( value ) , Number ( capacity ) ) ;
64
61
} else if ( percents ) {
65
62
valueText = fillWidth + '%' ;
66
63
capacityText = '' ;
@@ -86,9 +83,9 @@ export function ProgressViewer({
86
83
return (
87
84
< div className = { b ( { size} , className ) } >
88
85
< div className = { b ( 'line' , { bg} ) } style = { lineStyle } > </ div >
89
- < span className = { b ( 'text' , { text } ) } > { ` ${ formattedValue || valueText } ${ divider } ${
90
- formattedCapacity || capacityText
91
- } `} </ span >
86
+ < span
87
+ className = { b ( 'text' , { text } ) }
88
+ > { ` ${ valueText } ${ divider } ${ capacityText } `} </ span >
92
89
</ div >
93
90
) ;
94
91
}
0 commit comments