Skip to content

Commit e324e7c

Browse files
committed
new blog post
1 parent ada96db commit e324e7c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: "Announcing a new Vite Plugin for integrating Capsizecss & Radix-ui"
3+
date: "2024-03-28T18:33:49.008Z"
4+
---
5+
6+
I really enjoy typography — which causes pain when developing for the web. Because the web
7+
makes it hard to deeply control text layout.
8+
9+
This [talk](https://fantasai.inkedblade.net/style/talks/atypi-2021/atypi-2021-precise-text-alignment.mp4)
10+
(about some in-progress fixes for the web's typographic woes) has a slide which sums up the issue.
11+
12+
![slide showing inconsistent text boxes across font families](./slide-screenshot.png)
13+
14+
The same `font-size` and `line-height` settings result in vastly different
15+
layouts on the page. You might think that setting your font-size to `16px`
16+
would mean that the text would thent take up `16px` of height on the page — but
17+
you would then be very wrong.
18+
19+
There's platform fixes in progress (as the video above discusses) but in the meantime,
20+
a number of folks across the industry have created a fix called [Capsize](https://seek-oss.github.io/capsize/).
21+
A lot of research and code has gone into wrestling fonts and browsers into consistently rendering fonts.
22+
23+
It's brilliant and you should drop whatever you're doing to integrate it into your current project.
24+
25+
Precise layout gets a lot lot easier.
26+
27+
The one downside of Capsize is it's pretty low-level. You have to write quite a bit of code to
28+
fully integrate it into your design system.
29+
30+
I've recently standardized on [Radix](https://www.radix-ui.com/) for my projects as it has a very
31+
well-thought out layout, typography, and color system & a growing list of
32+
components to choose from. It's really brilliant and I think anyone looking to
33+
build a design system should build on their work.
34+
35+
And as they have a simple way to [customize typography through CSS
36+
variables](https://www.radix-ui.com/themes/docs/theme/typography#customization),
37+
after some digging and experimentation, I created a Vite plugin which takes a
38+
small config object and spits out a Capsize/Radix typography css file.
39+
40+
The code and docs are at https://github.com/KyleAMathews/vite-plugin-capsize-radix-ui
41+
42+
[Check out the demo](https://vite-plugin-capsize-radix.bricolage.io/) — notice
43+
how the text doesn't move even a pixel up and down as I switch between fonts — this
44+
is incredible and impossible without Capsize. The practical benefit of this is
45+
it makes it trivial to try out different fonts as you're building your app
46+
without breaking your layout.
47+
48+
<video controls width="100%">
49+
<source src="https://github.com/KyleAMathews/vite-plugin-capsize-radix-ui/assets/71047/3ec5d6ca-bf00-4b79-8552-4e3da3454f52" type="video/mp4" />
50+
</video>
51+
52+
I'm curious what people think — I love each of these tools and together they're 🧑‍🍳
53+
54+
I think a similar tool could be built for integration with other popular
55+
component libraries. Feel free to copy the approach.
56+
468 KB
Loading

0 commit comments

Comments
 (0)