Skip to content

Commit f0e47b2

Browse files
committed
fix(ui): style mono text with --apkt-font-family-mono falling back to base font
1 parent 7726bcd commit f0e47b2

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@reown/appkit-ui': patch
3+
---
4+
5+
Fix monospace text (WalletConnect "Copy link", wallet addresses, amount inputs) rendering in the browser default font when a custom `--apkt-font-family` is set. Added a `--apkt-font-family-mono` theme variable that falls back to `--apkt-font-family` when not provided, so a single custom font now styles monospace text too.

packages/ui/src/utils/ThemeHelperUtil.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ function normalizeThemeVariables(themeVariables?: ThemeVariables): Record<string
1717
normalized['font-family'] =
1818
themeVariables['--apkt-font-family'] ?? themeVariables['--w3m-font-family'] ?? 'KHTeka'
1919

20+
// Fall back to the base font (so one --apkt-font-family styles mono too), then the mono default.
21+
normalized['font-family-mono'] =
22+
themeVariables['--apkt-font-family-mono'] ??
23+
themeVariables['--w3m-font-family-mono'] ??
24+
themeVariables['--apkt-font-family'] ??
25+
themeVariables['--w3m-font-family'] ??
26+
'KHTekaMono'
27+
2028
normalized['accent'] =
2129
themeVariables['--apkt-accent'] ?? themeVariables['--w3m-accent'] ?? '#0988F0'
2230

@@ -183,6 +191,7 @@ export const ThemeHelperUtil = {
183191

184192
// Set default values and user overrides (keep --w3m-* names for backwards compatibility)
185193
variables['--w3m-font-family'] = normalized['font-family'] as string
194+
variables['--w3m-font-family-mono'] = normalized['font-family-mono'] as string
186195
variables['--w3m-accent'] = normalized['accent'] as string
187196
variables['--w3m-color-mix'] = normalized['color-mix'] as string
188197
variables['--w3m-color-mix-strength'] = `${normalized['color-mix-strength']}%`
@@ -216,6 +225,15 @@ export const ThemeHelperUtil = {
216225
overrides['--apkt-fontFamily-regular'] = normalized['font-family'] as string
217226
}
218227

228+
if (
229+
themeVariables['--apkt-font-family-mono'] ||
230+
themeVariables['--w3m-font-family-mono'] ||
231+
themeVariables['--apkt-font-family'] ||
232+
themeVariables['--w3m-font-family']
233+
) {
234+
overrides['--apkt-fontFamily-mono'] = normalized['font-family-mono'] as string
235+
}
236+
219237
if (normalized['z-index'] !== undefined) {
220238
overrides['--apkt-tokens-core-zIndex'] = `${normalized['z-index']}`
221239
}

packages/ui/src/utils/TypeUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ export type InputType =
376376

377377
export interface ThemeVariables {
378378
'--w3m-font-family'?: string
379+
'--w3m-font-family-mono'?: string
379380
'--w3m-accent'?: string
380381
'--w3m-color-mix'?: string
381382
'--w3m-color-mix-strength'?: number
@@ -384,6 +385,7 @@ export interface ThemeVariables {
384385
'--w3m-z-index'?: number
385386
'--w3m-qr-color'?: string
386387
'--apkt-font-family'?: string
388+
'--apkt-font-family-mono'?: string
387389
'--apkt-accent'?: string
388390
'--apkt-color-mix'?: string
389391
'--apkt-color-mix-strength'?: number

packages/ui/tests/ThemeHelperUtils.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,40 @@ describe('ThemeHelperUtil', () => {
169169
const emptyOverrides = ThemeHelperUtil.generateW3MOverrides({})
170170
expect(emptyOverrides['--apkt-tokens-core-zIndex']).toBeUndefined()
171171
})
172+
173+
it('should override the mono font family in generateW3MOverrides', () => {
174+
// A custom base font alone also drives the mono font, so monospace text
175+
// (Copy link, addresses, amount inputs) follows it instead of breaking.
176+
const baseFontOnly = ThemeHelperUtil.generateW3MOverrides({
177+
'--apkt-font-family': 'AppKit Font'
178+
})
179+
expect(baseFontOnly['--apkt-fontFamily-regular']).toBe('AppKit Font')
180+
expect(baseFontOnly['--apkt-fontFamily-mono']).toBe('AppKit Font')
181+
182+
// An explicit mono font wins over the base font.
183+
const explicitMono = ThemeHelperUtil.generateW3MOverrides({
184+
'--apkt-font-family': 'AppKit Font',
185+
'--apkt-font-family-mono': 'AppKit Mono'
186+
})
187+
expect(explicitMono['--apkt-fontFamily-regular']).toBe('AppKit Font')
188+
expect(explicitMono['--apkt-fontFamily-mono']).toBe('AppKit Mono')
189+
190+
// A mono override with no base font leaves the regular font at its default.
191+
const monoOnly = ThemeHelperUtil.generateW3MOverrides({
192+
'--w3m-font-family-mono': 'AppKit Mono'
193+
})
194+
expect(monoOnly['--apkt-fontFamily-regular']).toBeUndefined()
195+
expect(monoOnly['--apkt-fontFamily-mono']).toBe('AppKit Mono')
196+
197+
// No font variables -> no font overrides.
198+
const noFont = ThemeHelperUtil.generateW3MOverrides({ '--w3m-accent': '#ff0000' })
199+
expect(noFont['--apkt-fontFamily-regular']).toBeUndefined()
200+
expect(noFont['--apkt-fontFamily-mono']).toBeUndefined()
201+
})
202+
203+
it('should default the mono font to KHTekaMono when no font is provided', () => {
204+
const vars = ThemeHelperUtil.generateW3MVariables({ '--w3m-accent': '#ff0000' })
205+
expect(vars['--w3m-font-family']).toBe('KHTeka')
206+
expect(vars['--w3m-font-family-mono']).toBe('KHTekaMono')
207+
})
172208
})

0 commit comments

Comments
 (0)