Small rows, big components
Building big UI components out of tiny server-driven rows.
Contents
Near-duplicates everywhere#
So you decided to go with server-driven UI. Your API no longer sends plain data, it speaks UI with your clients and tells the apps what to show and how. However, the API can only send components the apps already know how to draw.
Let’s say you have a card. Then product asks for a card with a subtitle. Then a card with a subtitle and an icon on the right, and a week later one with a delete button. Each one gets its own implementation, because it’s “just a little different”, or even worse, you end up with one god-like component that tries to be all of them.
Every new component type has to be built on the API, on Android and on iOS, and the apps only know about it after a release goes out. So a “little different” card ends up being a cross-codebase project 😅
The other way around is to keep the building blocks small, really really small, and build the big things by putting small ones together.
What a row is#
On the API side a row is a pretty small object. It has a type and a couple of attributes that hold primitive objects like a Text, an Icon or a Radio.
Here is a simplified radio button row:
Ruby
class RadioRow
include Row
include Tappable
include Stylable
TYPE = :radio
def initialize(title:)
@radio = Radio.new(text: title)
end
def attributes
{ radio: @radio }
end
endWell, that’s all of it. Everything else comes from small mixins that a row can opt into:
Tappable, the row can carry an action, so tapping it actually does somethingStylable, the row can have padding, a border, rounded corners, a background and a container that itself has a background color and padding
Building blocks and components#
A “title with value” row doesn’t reimplement titles, it takes the title row’s attributes and adds a value on top. Same story for a “radio with icons” row, like the saved cards in the image below. It holds three small objects:
- a
Radio, the radio from the design system, so it looks and behaves the same everywhere - an
Icon, which holds the URLs for both light and dark mode, so the app just picks the right one - a
Text, which can be styled like any other text in the app
Here is roughly how it looks:
Ruby
RadioWithIconsRow.new(
radio: Radio.new,
icon: Icon.new(light_url: light_url, dark_url: dark_url),
title: Text.new('Work card').with_color('body/emphasis')
)None of these objects is specific to this row, the same Radio, Icon and Text show up in a lot of other rows.
Fluent styling#
Common variants come from chaining styles onto an existing row. A warning message, for example, is just a title row with some styling on top:
Ruby
TitleRow.new(title: title).
with_text_color('body/emphasis').
with_padding(Padding.all(3)).
with_background('primary/subtle').
with_border(Border.color('primary/border-subtle')).
with_corner_radius(CornerRadius.one)That takes no new row type and no app release. Colors and sizes come from design-system tokens, so it stays consistent with the rest of the app.
One card, many rows#

Each colored band is a separate row. The header with the installments promo, each saved card, the cardholder and expiry details under it, the installments link and the new card option. The outline around them makes them look like one card.
The apps never see a “card” with children inside it. They get a flat list of rows, each one with its own styling, and the API figures out which piece of the card each row should draw.
Without a styler you would probably handle the edges by hand. Add top padding to the first row, bottom padding to the last one, and hope nobody inserts something in between.
You describe the style of the card once and apply it to the whole group:
Ruby
style = RowGroupStyle.new(
padding: Padding.horizontal(4),
border: Border.new(color: 'secondary/border-subtle', width: 1),
corner_radius: CornerRadius.three
)
Rows.new([header, card_one, card_two, footer]).with_style(style)Then a styler spreads that style across the rows based on their position:
for padding, container, border and corner radius:
if there is only one row:
it gets everything
else:
the first row gets the top part
the last row gets the bottom part
every row gets the start and end parts, if any
merge it with what the row already hasThe end result looks like one rounded card with a border 🎉
Underneath it’s still four independent rows, and each one can be reused, reordered, updated or removed according to business needs.
Rows live in a list, which takes care of a couple of boring things:
- Styling, it applies a
RowGroupStylelike the one above. - Separators, it puts a row (a divider for example) between every pair.
Checkout, the coupon and loyalty cards, product recommendations and size suggestions are all built this way.
Testing#
When your UI is a list of rows, your tests become questions about that list, so there are matchers for exactly that:
Ruby
it { is_expected.to have_row(type: :title_with_value, title: 'Total') }The same matcher works whether you’re testing a presenter, a controller or a raw API response.
Closing thoughts#
Small rows are not free, though. You need some discipline about what goes into a row. Too specific and you’re back to near-duplicates, too generic and composing anything takes a pile of configuration.
Another drawback is that the style is computed up front and burned into each row. The styler decides which row gets the top corners and which gets the bottom border when the list is built, and the app just draws what it gets. That gets in the way of Hotwire-like partial updates. More on that in a later blog post.