Components and variants
Turn a frame into a component, add variants, and use copies that follow the original.
A component is a frame you've decided is reusable. Copies of it — instances — follow it: change the component, and every copy changes.
In the generated app, a component becomes a Vue component. So this isn't only tidiness in the design; it's the structure of the code that comes out.
Create one#
Select a frame and press Ctrl+Alt+K, or right-click → Create component. It appears under Assets → Components on the left.
Give it a name. The name becomes the component's name in the generated project, so ProductCard is more useful than Frame 8.
Use it#
From the Assets panel, drag it onto the canvas or click it to drop it into the selected frame. Each one is an instance.
What a copy can and can't change#
This is the part that takes a minute to get used to, and it's the whole point.
| Changed on the copy | What happens |
|---|---|
| Text | Kept — that's what copies are for |
| Colors | Kept |
| Images | Kept |
| Layout, sizes, structure | Comes from the component |
So a card component used twenty times has twenty different titles and one layout. Changing the layout once changes all twenty.
A changed property is an override, listed in the right panel with a button to reset it. Reset puts the whole instance back to the component; Detach (Ctrl+Alt+B) breaks the link entirely and leaves you with ordinary layers.
Go to main jumps from an instance to the component it came from.
Variants#
A variant is a version of the same component: a button that is primary or secondary, large or small, with an icon or without.
Press Make variants on a component and it becomes a set. Each variant has properties — name and value pairs like style: primary or size: large — and an instance picks its variant from dropdowns rather than from a list of separate components.
Interactions between variants#
A set of variants can define what happens on hover, on press and on click — each one pointing at another variant.
Hover and press become CSS in the generated app, so they work without any code. A click switches the instance to the variant you named, which is how a toggle, a checkbox or an open/closed menu works: give the second variant a click back to the first.
This is the reason variants are worth the effort. The states are designed once, and they are real behaviour in the app rather than a note for a developer.
Components inside components#
An instance can be used inside another component. A card containing a button instance is normal, and both keep following their own originals.
Next#
- Team libraries Share components with every file in your team.
- Prototype links Make a component navigate.
- Make it an app Where components become Vue components.