Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/mono-font-family-variable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@reown/appkit-ui': patch
'@reown/appkit-common': patch
'@reown/appkit-controllers': patch
---

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.
2 changes: 2 additions & 0 deletions packages/common/src/utils/ThemeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type ThemeType = 'dark' | 'light'

export interface ThemeVariables {
'--w3m-font-family'?: string
'--w3m-font-family-mono'?: string
'--w3m-accent'?: string
'--w3m-color-mix'?: string
'--w3m-color-mix-strength'?: number
Expand All @@ -11,6 +12,7 @@ export interface ThemeVariables {
'--w3m-z-index'?: number
'--w3m-qr-color'?: string
'--apkt-font-family'?: string
'--apkt-font-family-mono'?: string
'--apkt-accent'?: string
'--apkt-color-mix'?: string
'--apkt-color-mix-strength'?: number
Expand Down
2 changes: 2 additions & 0 deletions packages/controllers/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export type ThemeMode = 'dark' | 'light'

export interface ThemeVariables {
'--w3m-font-family'?: string
'--w3m-font-family-mono'?: string
'--w3m-accent'?: string
'--w3m-color-mix'?: string
'--w3m-color-mix-strength'?: number
Expand All @@ -219,6 +220,7 @@ export interface ThemeVariables {
'--w3m-z-index'?: number
'--w3m-qr-color'?: string
'--apkt-font-family'?: string
'--apkt-font-family-mono'?: string
'--apkt-accent'?: string
'--apkt-color-mix'?: string
'--apkt-color-mix-strength'?: number
Expand Down
18 changes: 18 additions & 0 deletions packages/ui/src/utils/ThemeHelperUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ function normalizeThemeVariables(themeVariables?: ThemeVariables): Record<string
normalized['font-family'] =
themeVariables['--apkt-font-family'] ?? themeVariables['--w3m-font-family'] ?? 'KHTeka'

// Fall back to the base font (so one --apkt-font-family styles mono too), then the mono default.
normalized['font-family-mono'] =
themeVariables['--apkt-font-family-mono'] ??
themeVariables['--w3m-font-family-mono'] ??
themeVariables['--apkt-font-family'] ??
themeVariables['--w3m-font-family'] ??
'KHTekaMono'

normalized['accent'] =
themeVariables['--apkt-accent'] ?? themeVariables['--w3m-accent'] ?? '#0988F0'

Expand Down Expand Up @@ -183,6 +191,7 @@ export const ThemeHelperUtil = {

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

if (
themeVariables['--apkt-font-family-mono'] ||
themeVariables['--w3m-font-family-mono'] ||
themeVariables['--apkt-font-family'] ||
themeVariables['--w3m-font-family']
) {
overrides['--apkt-fontFamily-mono'] = normalized['font-family-mono'] as string
}

if (normalized['z-index'] !== undefined) {
overrides['--apkt-tokens-core-zIndex'] = `${normalized['z-index']}`
}
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export type InputType =

export interface ThemeVariables {
'--w3m-font-family'?: string
'--w3m-font-family-mono'?: string
'--w3m-accent'?: string
'--w3m-color-mix'?: string
'--w3m-color-mix-strength'?: number
Expand All @@ -384,6 +385,7 @@ export interface ThemeVariables {
'--w3m-z-index'?: number
'--w3m-qr-color'?: string
'--apkt-font-family'?: string
'--apkt-font-family-mono'?: string
Comment thread
spennyp marked this conversation as resolved.
'--apkt-accent'?: string
'--apkt-color-mix'?: string
'--apkt-color-mix-strength'?: number
Expand Down
25 changes: 25 additions & 0 deletions packages/ui/tests/ThemeUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ describe('ThemeUtil', () => {
expect(rootStyles).toContain('--apkt-fontFamily-regular:New Font')
})

it('should drive the monospace font from --apkt-font-family when no mono font is set', () => {
const themeVariables: ThemeVariables = {
'--apkt-font-family': 'New Font'
}
const rootStyles = ThemeHelperUtil.createRootStyles('dark', themeVariables)

expect(rootStyles).toContain('--apkt-fontFamily-mono:New Font')
})

it('should prioritize --apkt-font-family-mono over --apkt-font-family for monospace text', () => {
const themeVariables: ThemeVariables = {
'--apkt-font-family': 'New Font',
'--apkt-font-family-mono': 'New Mono'
}
const rootStyles = ThemeHelperUtil.createRootStyles('dark', themeVariables)

expect(rootStyles).toContain('--apkt-fontFamily-mono:New Mono')
})

it('should default the monospace font to KHTekaMono when no font is provided', () => {
const rootStyles = ThemeHelperUtil.createRootStyles('dark', { '--w3m-accent': '#ff0000' })

expect(rootStyles).toContain('--w3m-font-family-mono:KHTekaMono')
})

it('should always include keyframe animations regardless of font family setting', () => {
const withCustomFont: ThemeVariables = { '--w3m-font-family': 'Custom Font' }
const withoutCustomFont: ThemeVariables = {}
Expand Down
Loading