Reusing Artboards
In this tutorial, we will learn how to reuse your Artboards in two ways:
- Referencing the Artboard
- Creating components
Referencing an Artboard
Referencing an Artboard is useful when you have a visual element that repeats on multiple Artboards, and this element is always the same, such as headers, sidebars, and footers.
In our example, we will reuse this sidebar. Click on the Copy
button below, and paste the Artboard into your Builder.
Start by creating a new Artboard, double-clicking the Builder background and selecting Artboard from the menu that opens.
Next, draw a Block to be the sidebar. Select it and:
- In
Children Mode
, set it toreference
. - In
Children Reference
, which appears whenChildren Mode
is set toreference
, inComponent
selectdata2-core-primitives@Artboard
, and inReference
select the sidebar Artboard.
Any changes in the sidebar Artboard will be reflected in the blocks that reference this Artboard.
Creating Components
Components are another way to reuse your elements, however, components have configurable parameters, that is, unlike the reference which is an exact copy of the Artboard, the component is not.
As an example, we will build a component that is a button. Copy and paste the Artboard below into your Builder.
Select the created Artboard and:
- Enable the
Component Class
parameter. - Give a name to your component, such as
Button
. - Click on
Create Component
.
And just like that your component was created, let's use this component in the Artboard
that references the Sidebar, for that:
- Draw two blocks.
- Select both by clicking on one, holding
SHIFT
, and clicking the other. - At the top of the Inspector, click on the control that is written
data2-core-primitives@Block
to change the component type. Search for your new component and select it. - Both blocks should have changed in appearance, and now they are identical to the button's Artboard.
- Make visual adjustments, such as removing the
Fill
from the blocks, adjusting the size, etc.
Now we will make the button text a configurable parameter.
- Select the button's Artboard.
- In the
Component Class
control, click onAdd Prop
. - In the added card, under
Prop
, typelabel
, keep the type asString
, and inMock
, typeButton Text
. - Select the Block inside the
Artboard
that has theText
parameter filled. - Change the type of
Text
by clicking on the button withf()
and in the menu that opens, click onContext Reference
. - Click on the control to navigate and configure the
Reference
. - Write or select
label
in the reference.
Notice that the text in the button Block
is no longer Button Label
, but rather Button Text
, which was the parameter set up in the Mock
. This behavior makes it easier to develop components and only occurs in the Artboard that is used as a component, i.e., other blocks, like the two Button
s in the Artboard with the sidebar, will not show the value of the Mock
.
To put different texts on each of the created buttons:
- Select the
Button
, click on theBlock
title at the beginning of the inspector to close theBlock
parameters, and only theButton
parameters should be visible. - In the
Label
parameter, write whatever you want, such asConfirm
. - Do the same for the other
Button
, where we will writeCancel
instead ofConfirm
.
Components x Artboard Reference
As we could see in the examples, the main difference between reusing Artboards through components or references is the possibility of using parameters, which are accessible within the Artboard that is a component through the Context Reference
(a component of the type data2-core-types@Reference
). In both cases, components and references, changes in the "original" Artboard affect all Blocks of that component type and blocks that reference that Artboard
.
There are other differences that we will explore in other tutorials.
Final result
The final result, that is, the Artboard with a sidebar, the Artboard that is a button component, and the Artboard that references the sidebar and has 2 buttons, is available below and can be copied and pasted into your Builder!