Skip to content

Commit e957c65

Browse files
committed
fix(ui): preserve semantic font sizes and status colors
1 parent 21b8ff3 commit e957c65

3 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎DESIGN.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ The global body size is `var(--font-size-form)` (14px), and `src/assets/index.cs
140140

141141
The type scale is token-driven. `index.css` defines `--font-size-caption / dense / body / form / title / page-title` (11 / 12 / 13 / 14 / 16 / 20px); `uno.config.ts` maps the two sizes missing from the default scale (`text-caption` = 11px, `text-body` = 13px), and the rest reuse default utilities (`text-xs` = 12, `text-sm` = 14, `text-base` = 16, `text-xl` = 20). Business components must use these utilities or the CSS variables — never a bare px/rem font size. Monaco's editor font size remains a user setting.
142142

143+
Custom font-size utilities must also be registered in the shared `cn()` helper so component overrides merge sizes independently of semantic text colors.
144+
143145
The following hierarchy constrains new UI; it does not require rewriting all existing page titles.
144146

145147
| Role | Token / utility | Usage |

‎src/lib/utils.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import type { ClassValue } from 'clsx'
22
import { clsx } from 'clsx'
3-
import { twMerge } from 'tailwind-merge'
3+
import { extendTailwindMerge } from 'tailwind-merge'
44

5-
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs))
5+
const mergeClasses = extendTailwindMerge({
6+
extend: {
7+
classGroups: {
8+
'font-size': ['text-caption', 'text-body'],
9+
},
10+
},
11+
})
12+
13+
export const cn = (...inputs: ClassValue[]): string => mergeClasses(clsx(inputs))

‎tests/common/classNames.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { cn } from '@/lib/utils'
2+
3+
describe('semantic font sizes', () => {
4+
it.each(['text-caption', 'text-body'])(
5+
'overrides the default size with %s while preserving the text color',
6+
(size) => {
7+
const classes = cn('text-sm font-medium', `${size} text-muted-foreground`).split(' ')
8+
9+
expect(classes).toEqual(expect.arrayContaining([size, 'text-muted-foreground', 'font-medium']))
10+
expect(classes).not.toContain('text-sm')
11+
},
12+
)
13+
14+
it.each(['text-caption', 'text-body'])(
15+
'preserves status colors when %s follows a component variant',
16+
(size) => {
17+
const classes = cn('text-xs text-destructive-text bg-destructive-muted', size).split(' ')
18+
19+
expect(classes).toEqual(expect.arrayContaining([size, 'text-destructive-text', 'bg-destructive-muted']))
20+
expect(classes).not.toContain('text-xs')
21+
},
22+
)
23+
24+
it('allows a standard size to override a semantic size', () => {
25+
expect(cn('text-caption text-primary-text', 'text-sm')).toBe('text-primary-text text-sm')
26+
})
27+
28+
it('merges sizes within the same responsive variant independently of color', () => {
29+
expect(cn('md:text-caption md:text-destructive-text', 'md:text-body'))
30+
.toBe('md:text-destructive-text md:text-body')
31+
})
32+
})

0 commit comments

Comments
 (0)