1
1
import { useEuiTheme } from '@elastic/eui' ;
2
- import { useState } from 'react' ;
2
+ import type { ReactNode } from 'react' ;
3
+ import { useMemo , 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' ;
7
+ import { TextTruncate } from '../text/text-truncate.jsx' ;
6
8
7
- export const GameHands : React . FC = ( ) => {
9
+ export const GameHands : React . FC = ( ) : ReactNode => {
8
10
const { euiTheme } = useEuiTheme ( ) ;
9
11
10
12
const [ leftHand , setLeftHand ] = useState < string > ( 'Empty' ) ;
@@ -25,29 +27,68 @@ export const GameHands: React.FC = () => {
25
27
}
26
28
} ) ;
27
29
30
+ const leftHandCmp = useMemo ( ( ) : ReactNode => {
31
+ return < GameHand label = "Left" value = { leftHand } /> ;
32
+ } , [ leftHand ] ) ;
33
+
34
+ const rightHandCmp = useMemo ( ( ) : ReactNode => {
35
+ return < GameHand label = "Right" value = { rightHand } /> ;
36
+ } , [ rightHand ] ) ;
37
+
38
+ const spellCmp = useMemo ( ( ) : ReactNode => {
39
+ return < GameHand label = "Spell" value = { spell } /> ;
40
+ } , [ spell ] ) ;
41
+
28
42
return (
29
43
< div
30
44
css = { {
31
- display : 'block ' ,
32
- justifyContent : 'center' ,
45
+ display : 'flex ' ,
46
+ alignItems : 'center' ,
33
47
alignContent : 'center' ,
34
- width : '300px' ,
35
- height : '100%' ,
48
+ gap : '5px' ,
49
+ width : '100%' ,
50
+ height : '25px' ,
36
51
fontSize : euiTheme . size . m ,
37
52
} }
38
53
>
39
- { [
40
- { label : 'Left' , value : leftHand } ,
41
- { label : 'Right' , value : rightHand } ,
42
- { label : 'Spell' , value : spell } ,
43
- ] . map ( ( { label, value } ) => (
44
- < div key = { label } css = { { display : 'flex' , gap : '5px' } } >
45
- < b css = { { textAlign : 'right' , minWidth : '45px' } } > { label } :</ b >
46
- { value }
47
- </ div >
48
- ) ) }
54
+ { leftHandCmp }
55
+ { rightHandCmp }
56
+ { spellCmp }
49
57
</ div >
50
58
) ;
51
59
} ;
52
60
53
61
GameHands . displayName = 'GameHands' ;
62
+
63
+ interface GameHandProps {
64
+ label : string ;
65
+ value : string ;
66
+ }
67
+
68
+ const GameHand : React . FC < GameHandProps > = ( props : GameHandProps ) : ReactNode => {
69
+ const { label, value } = props ;
70
+
71
+ const { euiTheme } = useEuiTheme ( ) ;
72
+
73
+ return (
74
+ < div
75
+ css = { {
76
+ display : 'flex' ,
77
+ gap : '5px' ,
78
+ width : '250px' ,
79
+ height : '100%' ,
80
+ padding : '5px' ,
81
+ border : '1px solid' ,
82
+ borderColor : euiTheme . border . color ,
83
+ borderRadius : '5px' ,
84
+ } }
85
+ >
86
+ < div css = { { userSelect : 'none' } } >
87
+ < b > { label } :</ b >
88
+ </ div >
89
+ < TextTruncate text = { value } />
90
+ </ div >
91
+ ) ;
92
+ } ;
93
+
94
+ GameHand . displayName = 'GameHand' ;
0 commit comments