Skip to content

Commit a3a31e5

Browse files
Merge pull request #10 from IncredibleDevHQ/fix/issue-5
fix(webfront): make the font of code 'Roboto Mono'
2 parents ce4549e + a168707 commit a3a31e5

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

apps/webfront/src/components/flick/canvas/CodeAnimations.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export interface Position {
3131
export const TypingEffect = ({
3232
token,
3333
fontSize,
34+
fontFamily,
3435
}: {
3536
token: ComputedToken
3637
fontSize: number
38+
fontFamily: string
3739
}) => {
3840
const [text, setText] = useState('')
3941
useEffect(() => {
@@ -54,6 +56,7 @@ export const TypingEffect = ({
5456
x={token?.x}
5557
y={token?.y}
5658
align='left'
59+
fontFamily={fontFamily}
5760
/>
5861
)
5962
}
@@ -63,11 +66,13 @@ const RenderTokens = ({
6366
startIndex,
6467
endIndex,
6568
fontSize,
69+
fontFamily,
6670
}: {
6771
tokens: ComputedToken[]
6872
startIndex: number
6973
endIndex: number
7074
fontSize: number
75+
fontFamily: string
7176
}) => {
7277
const tokenSegment = tokens.slice(startIndex, endIndex)
7378

@@ -92,8 +97,13 @@ const RenderTokens = ({
9297
<Group>
9398
{renderState.tokens.length > 0 &&
9499
renderState.tokens.map((token, index) => (
95-
// eslint-disable-next-line
96-
<TypingEffect fontSize={fontSize} key={index} token={token} />
100+
<TypingEffect
101+
fontSize={fontSize}
102+
// eslint-disable-next-line react/no-array-index-key
103+
key={index}
104+
token={token}
105+
fontFamily={fontFamily}
106+
/>
97107
))}
98108
</Group>
99109
)
@@ -106,11 +116,13 @@ export const RenderHighlight = ({
106116
startLineNumber,
107117
endLineNumber,
108118
fontSize,
119+
fontFamily,
109120
}: {
110121
tokens: ComputedToken[]
111122
startLineNumber: number
112123
endLineNumber: number
113124
fontSize: number
125+
fontFamily: string
114126
}) => (
115127
<Group>
116128
{tokens
@@ -129,6 +141,7 @@ export const RenderHighlight = ({
129141
x={token.x}
130142
y={token.y}
131143
align='left'
144+
fontFamily={fontFamily}
132145
/>
133146
))}
134147
</Group>
@@ -138,10 +151,12 @@ export const RenderLines = ({
138151
tokens,
139152
lineNumbers,
140153
fontSize,
154+
fontFamily,
141155
}: {
142156
tokens: ComputedToken[]
143157
lineNumbers: number[]
144158
fontSize: number
159+
fontFamily: string
145160
}) => (
146161
<Group>
147162
{tokens
@@ -156,6 +171,7 @@ export const RenderLines = ({
156171
x={token.x}
157172
y={token.y}
158173
align='left'
174+
fontFamily={fontFamily}
159175
/>
160176
))}
161177
</Group>
@@ -333,7 +349,8 @@ export const RenderMultipleLineFocus = ({
333349
export const getRenderedTokens = (
334350
tokens: ComputedToken[],
335351
position: Position,
336-
fontSize: number
352+
fontSize: number,
353+
fontFamily: string
337354
) => {
338355
const startFromIndex = Math.max(
339356
...tokens
@@ -353,6 +370,7 @@ export const getRenderedTokens = (
353370
x={token.x}
354371
y={token.y}
355372
align='left'
373+
fontFamily={fontFamily}
356374
/>
357375
))
358376
}
@@ -363,12 +381,12 @@ export const getTokens = ({
363381
tokens,
364382
opacity,
365383
fontSize,
366-
font,
384+
fontFamily,
367385
}: {
368386
tokens: ComputedToken[]
369387
opacity: number
370-
font?: string
371388
fontSize: number
389+
fontFamily: string
372390
}) => {
373391
let computedLineNumber = 0
374392
let lineNumber = 0
@@ -391,7 +409,7 @@ export const getTokens = ({
391409
y={(fontSize + 8) * computedLineNumber}
392410
opacity={opacity}
393411
align='left'
394-
fontFamily={font}
412+
fontFamily={fontFamily}
395413
/>
396414
)
397415
})

apps/webfront/src/components/flick/canvas/fragments/CodeFragment.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ const CodeFragment = ({
347347
gutter: 8,
348348
fontSize,
349349
codeAnimation: codeAnimation || CodeAnimation.TypeLines,
350-
// fontFamily: branding?.font?.heading?.family,
350+
fontFamily: 'Roboto Mono',
351351
})
352352
)
353353
}, [colorCodes, objectRenderConfig, fontSize])
@@ -578,7 +578,12 @@ const CodeFragment = ({
578578
{
579579
'Type lines': (
580580
<>
581-
{getRenderedTokens(computedTokens[0], position, fontSize)}
581+
{getRenderedTokens(
582+
computedTokens[0],
583+
position,
584+
fontSize,
585+
'Roboto Mono'
586+
)}
582587
{computedTokens.length > 0 &&
583588
computedTokens[0].length > 0 && (
584589
<RenderTokens
@@ -587,6 +592,7 @@ const CodeFragment = ({
587592
startIndex={position.prevIndex}
588593
endIndex={position.currentIndex}
589594
fontSize={fontSize}
595+
fontFamily='Roboto Mono'
590596
/>
591597
)}
592598
</>
@@ -603,6 +609,7 @@ const CodeFragment = ({
603609
tokens: computedTokens[0],
604610
opacity: highlightBlockCode ? 0.2 : 1,
605611
fontSize,
612+
fontFamily: 'Roboto Mono',
606613
})}
607614
</Group>
608615
</>
@@ -624,6 +631,7 @@ const CodeFragment = ({
624631
0
625632
}
626633
fontSize={fontSize}
634+
fontFamily='Roboto Mono'
627635
/>
628636
</Group>
629637
)}
@@ -665,6 +673,7 @@ const CodeFragment = ({
665673
tokens: computedTokens[0],
666674
opacity: 1,
667675
fontSize,
676+
fontFamily: 'Roboto Mono',
668677
})}
669678
</Group>
670679
</Group>

0 commit comments

Comments
 (0)