Skip to content

Commit f2ab8da

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

6 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@reown/appkit-ui': patch
3+
'@reown/appkit-common': patch
4+
'@reown/appkit-controllers': patch
5+
---
6+
7+
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/common/src/utils/ThemeUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type ThemeType = 'dark' | 'light'
33

44
export interface ThemeVariables {
55
'--w3m-font-family'?: string
6+
'--w3m-font-family-mono'?: string
67
'--w3m-accent'?: string
78
'--w3m-color-mix'?: string
89
'--w3m-color-mix-strength'?: number
@@ -11,6 +12,7 @@ export interface ThemeVariables {
1112
'--w3m-z-index'?: number
1213
'--w3m-qr-color'?: string
1314
'--apkt-font-family'?: string
15+
'--apkt-font-family-mono'?: string
1416
'--apkt-accent'?: string
1517
'--apkt-color-mix'?: string
1618
'--apkt-color-mix-strength'?: number

packages/controllers/src/utils/TypeUtil.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export type ThemeMode = 'dark' | 'light'
211211

212212
export interface ThemeVariables {
213213
'--w3m-font-family'?: string
214+
'--w3m-font-family-mono'?: string
214215
'--w3m-accent'?: string
215216
'--w3m-color-mix'?: string
216217
'--w3m-color-mix-strength'?: number
@@ -219,6 +220,7 @@ export interface ThemeVariables {
219220
'--w3m-z-index'?: number
220221
'--w3m-qr-color'?: string
221222
'--apkt-font-family'?: string
223+
'--apkt-font-family-mono'?: string
222224
'--apkt-accent'?: string
223225
'--apkt-color-mix'?: string
224226
'--apkt-color-mix-strength'?: number

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/ThemeUtil.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,31 @@ describe('ThemeUtil', () => {
5252
expect(rootStyles).toContain('--apkt-fontFamily-regular:New Font')
5353
})
5454

55+
it('should drive the monospace font from --apkt-font-family when no mono font is set', () => {
56+
const themeVariables: ThemeVariables = {
57+
'--apkt-font-family': 'New Font'
58+
}
59+
const rootStyles = ThemeHelperUtil.createRootStyles('dark', themeVariables)
60+
61+
expect(rootStyles).toContain('--apkt-fontFamily-mono:New Font')
62+
})
63+
64+
it('should prioritize --apkt-font-family-mono over --apkt-font-family for monospace text', () => {
65+
const themeVariables: ThemeVariables = {
66+
'--apkt-font-family': 'New Font',
67+
'--apkt-font-family-mono': 'New Mono'
68+
}
69+
const rootStyles = ThemeHelperUtil.createRootStyles('dark', themeVariables)
70+
71+
expect(rootStyles).toContain('--apkt-fontFamily-mono:New Mono')
72+
})
73+
74+
it('should default the monospace font to KHTekaMono when no font is provided', () => {
75+
const rootStyles = ThemeHelperUtil.createRootStyles('dark', { '--w3m-accent': '#ff0000' })
76+
77+
expect(rootStyles).toContain('--w3m-font-family-mono:KHTekaMono')
78+
})
79+
5580
it('should always include keyframe animations regardless of font family setting', () => {
5681
const withCustomFont: ThemeVariables = { '--w3m-font-family': 'Custom Font' }
5782
const withoutCustomFont: ThemeVariables = {}

0 commit comments

Comments
 (0)