@@ -2,10 +2,11 @@ import { EuiText, useEuiTheme } from '@elastic/eui';
2
2
import { type SerializedStyles , css } from '@emotion/react' ;
3
3
import type { ReactNode } from 'react' ;
4
4
import { memo , useMemo } from 'react' ;
5
- import type { GameLogLine } from '../../types/game.types.jsx' ;
5
+ import type { GameLogLine , GameStreamStyle } from '../../types/game.types.jsx' ;
6
6
7
7
export interface GameStreamTextProps {
8
8
logLine : GameLogLine ;
9
+ style ?: GameStreamStyle ;
9
10
}
10
11
11
12
/**
@@ -17,46 +18,70 @@ export interface GameStreamTextProps {
17
18
*/
18
19
export const GameStreamText : React . FC < GameStreamTextProps > = memo (
19
20
( props : GameStreamTextProps ) : ReactNode => {
20
- const { logLine } = props ;
21
+ const { logLine, style } = props ;
21
22
22
23
const { euiTheme } = useEuiTheme ( ) ;
23
24
24
- const textStyles = useMemo ( ( ) : SerializedStyles => {
25
- let fontSize = euiTheme . size . m ;
26
- let fontFamily = euiTheme . font . family ;
27
- let fontWeight = euiTheme . font . weight . regular ;
28
- let fontColor = euiTheme . colors . text ;
25
+ const defaultStyles = useMemo ( ( ) => {
26
+ const fontSize = style ?. fontSize ?? euiTheme . size . m ;
27
+ const fontFamily = style ?. fontFamily ?? euiTheme . font . family ;
28
+ const fontWeight = euiTheme . font . weight . regular ;
29
+ const foregroundColor = style ?. foregroundColor ?? euiTheme . colors . text ;
30
+ const backgroundColor = style ?. backgroundColor ?? 'inherit' ;
29
31
30
- if ( logLine . styles ?. outputClass === 'mono' ) {
31
- fontFamily = euiTheme . font . familyCode ?? fontFamily ;
32
+ return {
33
+ fontSize,
34
+ fontFamily,
35
+ fontWeight,
36
+ foregroundColor,
37
+ backgroundColor,
38
+ } ;
39
+ } , [ euiTheme , style ] ) ;
40
+
41
+ const textStyles = useMemo ( ( ) : SerializedStyles => {
42
+ let fontSize = defaultStyles . fontSize ;
43
+ let fontFamily = defaultStyles . fontFamily ;
44
+ let fontWeight = defaultStyles . fontWeight ;
45
+ let foregroundColor = defaultStyles . foregroundColor ;
46
+ const backgroundColor = defaultStyles . backgroundColor ;
47
+
48
+ // TODO add to user customizations in game stream style
49
+ if ( logLine . style ?. outputClass === 'mono' ) {
32
50
fontSize = euiTheme . size . m ;
51
+ fontFamily = euiTheme . font . familyCode ?? fontFamily ;
33
52
}
34
53
35
- if ( logLine . styles ?. stylePreset === 'roomName' ) {
36
- fontColor = euiTheme . colors . title ;
54
+ // TODO add presets to user customizations in game stream style
55
+ if ( logLine . style ?. stylePreset === 'roomName' ) {
56
+ foregroundColor = euiTheme . colors . title ;
37
57
fontWeight = euiTheme . font . weight . bold ;
38
58
}
39
59
40
- if ( logLine . styles ?. bold === true ) {
60
+ if ( logLine . style ?. bold === true ) {
41
61
fontWeight = euiTheme . font . weight . bold ;
42
62
}
43
63
44
- if ( logLine . styles ?. subdued === true ) {
45
- fontColor = euiTheme . colors . subduedText ;
64
+ if ( logLine . style ?. subdued === true ) {
65
+ foregroundColor = euiTheme . colors . subduedText ;
46
66
}
47
67
48
68
const textStyles = css ( {
49
69
fontSize,
50
70
fontFamily,
51
71
fontWeight,
52
- color : fontColor ,
72
+ color : foregroundColor ,
73
+ backgroundColor,
53
74
lineHeight : 'initial' ,
54
75
paddingLeft : euiTheme . size . s ,
55
76
paddingRight : euiTheme . size . s ,
77
+ b : {
78
+ color : '#FFD200' , // TODO add 'monster bold' user customization to game stream style
79
+ fontWeight : euiTheme . font . weight . regular ,
80
+ } ,
56
81
} ) ;
57
82
58
83
return textStyles ;
59
- } , [ euiTheme , logLine . styles ] ) ;
84
+ } , [ euiTheme , defaultStyles , logLine . style ] ) ;
60
85
61
86
// We output the text using inner html because the text may contain tags.
62
87
// For example, tags to highlight a single word or phrases.
@@ -91,8 +116,8 @@ const isSameLogLine = (options: {
91
116
} ) : boolean => {
92
117
const { oldLogLine, newLogLine } = options ;
93
118
94
- const { eventId : oldEventId , styles : oldTheme } = oldLogLine ;
95
- const { eventId : newEventId , styles : newTheme } = newLogLine ;
119
+ const { eventId : oldEventId , style : oldTheme } = oldLogLine ;
120
+ const { eventId : newEventId , style : newTheme } = newLogLine ;
96
121
97
122
const isSameEventId = oldEventId === newEventId ;
98
123
const isSameColorMode = oldTheme ?. colorMode === newTheme ?. colorMode ;
0 commit comments