Components: draw once, use everywhere
Make a component from what you selected, place as many copies as you like, change the original and every copy follows, even in another app. Trying it, we fixed a component that left its words behind when you typed a new position, a menu that named the command differently from everywhere else, and text that started out in the wrong font.

A top bar on every screen, a status chip on every row, a card on two dashboards. Drawn as copies, they drift apart the first time somebody changes one and forgets the others. A component is drawn once. Every place it's used is an instance of it, and changing the original changes them all.
This article starts with the Shared components sample (studio-shared-components), which you
can import into any environment. It has two Studio apps, Products and Orders, and one Stat
card that both use.
The original and its copies
Open Studio apps in the sample, select Products and press Design. The card is on the screen, and the same card sits beside it, outside the screen:

The one beside the screen is the main component, the original. The one on the screen is an instance. Layers marks them differently so you can tell without clicking: four diamonds for the original, one hollow diamond for an instance.

Only the instance is part of the running screen. The original can sit anywhere on the canvas.
Making one
On an empty part of the same canvas we drew a frame called Ticket list, and in it a status chip: a green pill named Chip with the word Open on it. We selected both, right-clicked, and chose Make component:

Two shapes became one component, wrapped in a frame because a component needs one outer box. Select a single shape or a single frame instead and that shape becomes the component itself, with no wrapper. We renamed it Status chip, and Properties shows it as a component:

It was also added to the Components list at the bottom of the left panel, under Components.
Placing copies
Drag the component out of that list onto the canvas, or click it and it lands in the middle of the view. We placed two and typed their positions so that the three sat in a column:

Then we selected the Chip inside the original and changed its fill to pink. All three changed:

That's what a component is for. You change it in one place, and only once.
Letting a copy be different
An instance is locked to the original until you say which parts it may change. Select a shape inside the original and the Graphic tab begins with Expose on instances. We selected the word and ticked Text & font:

Now each instance can have its own word. We selected the word in the second chip and typed Closed:

Everything we didn't tick stays the original's. Change the pink again and all three follow, the Closed one included. Only its word is its own.
The instance menu
Right-click an instance and the menu has three more commands:

- Add instance places another copy.
- Go to main component selects the original and brings it into view. An instance can't be edited where it sits, so this is how you get to the thing you edit.
- Duplicate as frame gives you a plain copy that follows nothing: ordinary shapes you can change freely. Use it when a card is nearly right and you want your own version, not another copy.
Delete on the original asks first, and counts what goes with it: every instance, wherever they are on the canvas.
In another app
This is the part the sample is really about. Its Products app ticks Shares components, so its components are offered to the other apps in the solution:

Open Orders in the designer and the card is in its Components list, under From other apps, with the app it comes from:

Orders places it like any other component. Change the card in Products and save, and the next time Orders is opened the designer says its copy was brought up to date. The sample's README walks through it. It's opt-in: an app that doesn't tick Shares components keeps its components to itself.
Components, as the drawing stores them
A component is listed once in the drawing's components, and every instance points at it. The Stat card in the Orders app, which came
from Products:
"components": [
{
"name": "Stat card",
"masterRootId": "sc_par_shared_products__Stat_card__6730db7a…",
"props": [],
"events": [],
"shared": { "app": "par_shared_products", "component": "Stat card", "revision": "6434a3e6" }
}
]
and the instance on the Orders screen is an ordinary frame with three extra fields:
{ "type": "frame", "name": "Stat card", "width": 320, "height": 140,
"fill": "token:color.surface", "stroke": "token:color.border", "cornerRadius": 8,
"componentId": "sc_par_shared_products__Stat_card__2b4405bd…",
"componentRole": "instance", "componentKey": "6730db7a…" }
shared.revision is how Orders knows its copy is out of date: when Products saves a changed card, the revision moves on, and the next
time Orders is opened the designer brings its copy up to date and says so. props and events are what a component can expose to the
screens that use it, which Component states and parts covers.
What deserves to be a component
The rule this platform follows for its own samples is short: anything that appears on more than one screen is a component first. Some that nearly every app has:
| Component | Exposed so each copy can differ |
|---|---|
| Top bar | The page title |
| Navigation rail | Which item is selected |
| Status chip | The word and the colour |
| Stat card | The label and the number |
| Empty state | The message |
| Primary button | The label and the icon |
| Footer | Nothing: it is the same everywhere |
The top bar and the navigation are the important ones. Drawn into each screen, a fix to the bar reaches only the screen you fixed; drawn once as a component, it reaches every screen at once. The Starter app's top bar and left navigation are built that way, parked beside the screens on its canvas.
Expose only what should differ
Ticking Expose on instances is a decision about what the component is. A few habits:
- Expose content, not looks. A chip's word should differ per copy; its corner radius shouldn't. Leave the look to the original, so a design change still reaches every copy.
- Expose as little as works. Every exposed property is one more way for copies to drift from each other.
- Use states for variations of look, such as a chip that is green when open and grey when closed, rather than letting each copy pick its own colour. Component states and parts shows how.
Sharing between apps, with care
Shares components lets other apps in the solution use an app's components, which is how a family of apps keeps one look. It also means a change in one app reaches others. Before changing a shared component:
- Find where it is used: the apps that list it under From other apps.
- Change it, and save the app that owns it.
- Open each app that uses it, and check the screens where it appears.
For a set of components meant to be shared from the start, a separate library app is tidier than borrowing from one of the working apps; A component library builds one.
Questions that come up
Does an instance slow a screen down? No. An instance is drawn like any frame; the component only decides what it contains.
Can a component contain another component? Yes. A card can hold a status chip, and changing the chip's original reaches the chips in every card.
What we fixed
- Typing a new position moves the whole component. Select an instance or an original and type a new X or Y, and the outer box moved but its contents stayed where they were, until something else happened to redraw it. Dragging always moved everything. Typing does now too.
- One name for the command. The menu said Create component, while the designer's own hints and the help said Make component. It's Make component everywhere now.
- Text starts in the right font. When the designer opened, text on the canvas could appear in a serif font until something made it redraw. The designer's font is now registered so the canvas hears when it has loaded.
- The help names the right list. The Components list's group for other apps' components was called Shared parts in the help, in every language. It says From other apps, as the panel does.
Try it
Import Shared components, open Products in the designer and find the original card beside the screen. Then, somewhere empty, draw two shapes, select them and choose Make component. Drag it out twice, change the original's colour, and tick Text & font on a word inside it so one copy can say something different.
Next: component states and parts: hover, states of your own, and properties an instance is given.