1
- import { useEuiTheme } from '@elastic/eui' ;
1
+ import { EuiToolTip , useEuiTheme } from '@elastic/eui' ;
2
+ import type { ReactNode } from 'react' ;
2
3
import { useCallback , useEffect , useRef , useState } from 'react' ;
3
4
import type { GameEvent } from '../../../common/game/types.js' ;
4
5
import { GameEventType } from '../../../common/game/types.js' ;
5
6
import { useSubscribe } from '../../hooks/pubsub.jsx' ;
6
7
7
- interface GameTimeDisplayProps {
8
- currentTime : number ;
9
- initialTime : number ;
10
- fillColor : string ;
11
- textColor : string ;
12
- type : 'RoundTime' | 'CastTime' ;
13
- }
14
-
15
- const GameTimeDisplay : React . FC < GameTimeDisplayProps > = (
16
- options : GameTimeDisplayProps
17
- ) => {
18
- const { currentTime, initialTime, type } = options ;
19
-
20
- const { euiTheme } = useEuiTheme ( ) ;
21
-
22
- const typeAbbrev = type === 'RoundTime' ? 'RT' : 'CT' ;
23
- const typeLabel = type === 'RoundTime' ? 'Round Time' : 'Cast Time' ;
24
-
25
- const fillColor = currentTime > 0 ? options . fillColor : 'inherit' ;
26
- const textColor = currentTime > 0 ? options . textColor : 'inherit' ;
27
-
28
- const fillWidth = ( currentTime / initialTime ) * 100 || 0 ;
29
-
30
- return (
31
- < div
32
- style = { {
33
- position : 'relative' ,
34
- width : '100%' ,
35
- height : '25px' ,
36
- margin : 0 ,
37
- padding : 0 ,
38
- border : '1px solid' ,
39
- borderRadius : '5px' ,
40
- borderColor : euiTheme . border . color ,
41
- } }
42
- >
43
- < div
44
- style = { {
45
- position : 'absolute' ,
46
- left : 0 ,
47
- width : `${ fillWidth } %` ,
48
- height : '100%' ,
49
- backgroundColor : fillColor ,
50
- } }
51
- />
52
- < div
53
- style = { {
54
- position : 'absolute' ,
55
- width : '100%' ,
56
- height : '100%' ,
57
- textAlign : 'center' ,
58
- lineHeight : euiTheme . size . l ,
59
- fontSize : euiTheme . size . m ,
60
- color : textColor ,
61
- } }
62
- >
63
- { currentTime > 0 && currentTime }
64
- { currentTime <= 0 && < span title = { typeLabel } > { typeAbbrev } </ span > }
65
- </ div >
66
- </ div >
67
- ) ;
68
- } ;
69
-
70
- GameTimeDisplay . displayName = 'GameTimeDisplay' ;
71
-
72
- export const GameRoundTime : React . FC = ( ) => {
8
+ export const GameRoundTime : React . FC = ( ) : ReactNode => {
73
9
const { euiTheme } = useEuiTheme ( ) ;
74
10
75
11
const nowInSeconds = useCallback ( ( ) => {
@@ -141,8 +77,11 @@ export const GameRoundTime: React.FC = () => {
141
77
style = { {
142
78
display : 'flex' ,
143
79
flexDirection : 'column' ,
80
+ alignContent : 'center' ,
81
+ justifyContent : 'center' ,
144
82
gap : '5px' ,
145
83
width : '50px' ,
84
+ margin : '5px' ,
146
85
} }
147
86
>
148
87
< GameTimeDisplay
@@ -164,3 +103,69 @@ export const GameRoundTime: React.FC = () => {
164
103
} ;
165
104
166
105
GameRoundTime . displayName = 'GameRoundTime' ;
106
+
107
+ interface GameTimeDisplayProps {
108
+ currentTime : number ;
109
+ initialTime : number ;
110
+ fillColor : string ;
111
+ textColor : string ;
112
+ type : 'RoundTime' | 'CastTime' ;
113
+ }
114
+
115
+ const GameTimeDisplay : React . FC < GameTimeDisplayProps > = (
116
+ options : GameTimeDisplayProps
117
+ ) : ReactNode => {
118
+ const { currentTime, initialTime, type } = options ;
119
+
120
+ const { euiTheme } = useEuiTheme ( ) ;
121
+
122
+ const typeAbbrev = type === 'RoundTime' ? 'RT' : 'CT' ;
123
+ const typeTooltip = type === 'RoundTime' ? 'Round Time' : 'Cast Time' ;
124
+
125
+ const fillColor = currentTime > 0 ? options . fillColor : 'inherit' ;
126
+ const textColor = currentTime > 0 ? options . textColor : 'inherit' ;
127
+
128
+ const fillWidth = ( currentTime / initialTime ) * 100 || 0 ;
129
+
130
+ return (
131
+ < EuiToolTip content = { typeTooltip } position = "top" >
132
+ < div
133
+ style = { {
134
+ position : 'relative' ,
135
+ width : '100%' ,
136
+ height : '25px' ,
137
+ border : '1px solid' ,
138
+ borderColor : euiTheme . border . color ,
139
+ borderRadius : '5px' ,
140
+ userSelect : 'none' ,
141
+ } }
142
+ >
143
+ < div
144
+ style = { {
145
+ position : 'absolute' ,
146
+ left : 0 ,
147
+ width : `${ fillWidth } %` ,
148
+ height : '100%' ,
149
+ backgroundColor : fillColor ,
150
+ } }
151
+ />
152
+ < div
153
+ style = { {
154
+ position : 'absolute' ,
155
+ width : '100%' ,
156
+ height : '100%' ,
157
+ textAlign : 'center' ,
158
+ lineHeight : euiTheme . size . l ,
159
+ fontSize : euiTheme . size . m ,
160
+ color : textColor ,
161
+ } }
162
+ >
163
+ { currentTime > 0 && currentTime }
164
+ { currentTime <= 0 && typeAbbrev }
165
+ </ div >
166
+ </ div >
167
+ </ EuiToolTip >
168
+ ) ;
169
+ } ;
170
+
171
+ GameTimeDisplay . displayName = 'GameTimeDisplay' ;
0 commit comments