refactor: tabular figures only on dense numeric data; proportional by default (OK-57876)#12452
refactor: tabular figures only on dense numeric data; proportional by default (OK-57876)#12452PatrickChoo wants to merge 6 commits into
Conversation
…er book, tickers)
…story, home perps, staking, referral, fees)
…bulk send); order numbers stay proportional
| function PerpsTotalUsd({ | ||
| value, | ||
| isDegraded, | ||
| fontVariant = TABULAR_NUMS, |
There was a problem hiding this comment.
这里给 PerpsTotalUsd 设了 fontVariant = TABULAR_NUMS,但这个 wrapper 不只用于持仓列表,也直接被首页和桌面 Perps 头部的 $headingXl 账户总额复用。触发条件就是 Perps 头部展示总资产时;调用方没有显式覆盖的话,hero 数字会被强制切到等宽字形,1 会明显变宽,和这次把 tabular 收窄到 dense data 的目标相反。
建议把这里的默认值去掉或改回 proportional,只在真正的列式/列表场景显式传 fontVariant={TABULAR_NUMS}。
| <EarnText | ||
| text={description} | ||
| size="$bodyLgMedium" | ||
| fontVariant={TABULAR_NUMS} |
There was a problem hiding this comment.
这里把 GridItemV2 的 description 槽位统一传成了 fontVariant={TABULAR_NUMS}。触发 provider / profit 这类后端驱动卡片时,只要 description.text 不是纯数字而是普通 IEarnText,这个通用组件就会替调用方强行开启等宽数字。
结果是字体策略重新从业务调用点回流到了基础卡片层,后续任何带数字的说明文本都会被同一层默认值误伤。建议让 GridItemV2 默认保持 proportional,只在确认是数值字段的具体 item 或调用点显式传 fontVariant={TABULAR_NUMS}。
| */ | ||
| export function EarnAmountText({ | ||
| children: text, | ||
| fontVariant = TABULAR_NUMS, |
There was a problem hiding this comment.
这里把 EarnAmountText 默认成了 TABULAR_NUMS,但这个 wrapper 不只服务于密集数列,也被 UniversalWithdraw 这类单值大号金额直接复用,还会继续走下面的 passthrough / 混合文本分支。触发这些 one-off amount 或普通文本路径时,调用方没有显式覆盖的话,本来应该恢复 proportional 的金额也会被强制切成等宽数字。
这会把这次想收窄到业务调用点的字形决策又重新推回通用 wrapper,连组件注释里“suffix rendered as-is”的边界也一起变宽了。建议去掉这里的默认值,只让明确需要列对齐的调用点显式传 fontVariant={TABULAR_NUMS}。
OK-57876
Summary
Inverts the tabular-numerals policy shipped in #12391.
Before:
SizableTextdefaultedfontVariant = TABULAR_NUMSandweb-fonts.csscarried abody { font-variant-numeric: tabular-nums }rule — so every string in the app rendered with equal-width digits.After: text is proportional by default. Tabular figures are an explicit opt-in, applied only to numbers that are small, sit in a column, and tick — market/perps list columns, order books, trading tables, tickers, fee rows.
Supersedes #12443 (which was patching the symptoms) and fixes OK-57876.
Why invert
Tabular digits exist to keep a column aligned. A global default applies them to everything a human reads as words, where they are actively wrong:
A1787,OneKey Pro2-1-6. Roobert's tabular1is ~2× wider and grows a foot serif; a name reads like a typo. (This is OK-57876.)0x7a84...4444. Hex mixes digits and letters, so tabular equalizes only half the characters and the string comes out ragged — worse than either pure option.Under the old default each of these needed its own opt-out, and the list only ever grew. The set of surfaces that genuinely want tabular, by contrast, is bounded and enumerable: tables and tickers. So the default was on the wrong side.
Net effect: names, addresses, prose, inputs and hero numbers are now correct with zero annotations — the escape hatches for them are all deleted.
The rule
Documented on
TABULAR_NUMSinpackages/components/src/utils/tabularNums.ts.Changes
Core (
@onekeyhq/components)SizableText— dropped the app-widefontVariantdefault (it still translates an explicitfontVariantinto a real style, since Tamagui drops the raw prop).web-fonts.css— dropped the globalbodyrule.tabularNums.ts—TABULAR_NUMS_STYLEnow always builds a real style. It previously resolved toundefinedon web because the body rule covered it; without that rule, an explicit opt-in would have been a no-op on web.PROPORTIONAL_NUMSis gone — it has nothing left to escape from.Badge.Text— no longer hard-codes tabular; it now honors afontVariantprop (it is styled from raw tamagui text, which silently drops the prop).Opt-ins — market/perps list columns, order book (incl. the raw-RN
<Text>depth rows), ticker bars, perps trading tables, token/home lists, DeFi & Earn/Borrow/Staking tables, transaction history, Swap Pro, provider/quote lists, referral tables, gas-fee editors.New shared choke-point
PerpTableCellTextcollapses ~89 perps table cells into one component, so a new column can't silently forget.Verification
tsgo --noEmit: no new errors.oxlint --type-aware --deny-warningson all 120 files: clean.1nearly doubles in width and gains a foot serif; the proportional1does not.$0.00hero proportional.Review notes
A cross-review (local + Codex) caught real gaps in the first pass, all fixed here:
TxActionCommon's opt-in was dead. Real transfers pass the amount as aReactNode, which bypassed thetypeof change === 'string'branch the prop was added to — the wallet's whole transaction-history amount column was silently untouched. Fixed at theTxActionTransfer/TxActionTokenApprovesources.MarketHomeListwas half-converted, which is worse than untouched — its volume / market-cap / rank columns jittered against already-tabular price cells in the same table.