1
1
import { Icon , IconSize } from '@blueprintjs/core'
2
+ import { Popover2InteractionKind , Tooltip2 } from '@blueprintjs/popover2'
2
3
3
4
import clsx from 'clsx'
4
5
import { FC } from 'react'
@@ -7,8 +8,21 @@ import Rating from 'react-rating'
7
8
import { Operation } from 'models/operation'
8
9
import { ratingLevelToString } from 'models/rating'
9
10
11
+ type PickedOperation = Pick <
12
+ Operation ,
13
+ 'notEnoughRating' | 'ratingRatio' | 'ratingLevel' | 'like' | 'dislike'
14
+ >
15
+
16
+ const GetLevelDescription = ( operation : PickedOperation ) => {
17
+ return `有${ Math . round (
18
+ ( operation . like / ( operation . like + operation . dislike ) ) * 100 ,
19
+ ) } %的人对本作业点了个赞(${ operation . like } /${
20
+ operation . like + operation . dislike
21
+ } )`
22
+ }
23
+
10
24
export const OperationRating : FC < {
11
- operation : Pick < Operation , 'notEnoughRating' | 'ratingRatio' | 'ratingLevel' >
25
+ operation : PickedOperation
12
26
layout ?: 'horizontal' | 'vertical'
13
27
className ?: string
14
28
} > = ( { operation, layout = 'vertical' , className } ) => {
@@ -60,11 +74,18 @@ export const OperationRating: FC<{
60
74
layout === 'horizontal' && ! operation . notEnoughRating && 'mr-1.5' ,
61
75
) }
62
76
>
63
- { operation . notEnoughRating
64
- ? layout === 'vertical'
65
- ? '还没有足够的评分'
66
- : '评分不足'
67
- : ratingLevelToString ( operation . ratingLevel ) }
77
+ < Tooltip2
78
+ className = "!inline-block !mt-0"
79
+ interactionKind = { Popover2InteractionKind . HOVER }
80
+ content = { GetLevelDescription ( operation ) }
81
+ position = "bottom-left"
82
+ >
83
+ { operation . notEnoughRating
84
+ ? layout === 'vertical'
85
+ ? '还没有足够的评分'
86
+ : '评分不足'
87
+ : ratingLevelToString ( operation . ratingLevel ) }
88
+ </ Tooltip2 >
68
89
</ div >
69
90
</ div >
70
91
)
0 commit comments