HomeNewsHow to create amazing things in Framer Design with reusable components

How to create amazing things in Framer Design with reusable components

medium bookmark / Raindrop.io |

1*mlAYOYObWQ0UEmYwT-yVTw.gif<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/2000/1*mlAYOYObWQ0UEmYwT-yVTw.gif”>

The Problem

Let’s say you downloaded a nice UI kit for Framer (this one for example). Or you have elements in design mode that you want to reuse several times in your prototypes once you’ve designed them, like buttons, elements of lists, alerts, and so on. Previously, long-bearded prototypers were doing components with code, which meant that if the visual part was changed significantly the code should be changed too.

Right now we have the power of the Design tab in Framer, and though some early adopters are skeptical, people are doing some amazing things with it.

The example below by Alex Manthei was made only with Framer layers in Design mode and it blows my mind. 🙂

1*DC-Y539LDJ2sUffNq7X44w.gif<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1600/1*DC-Y539LDJ2sUffNq7X44w.gif”>

https://dribbble.com/shots/3612312-Joining-Trainline

Framer design mode allows us to validate different ideas quickly, without jumping back and forth between Framer and Sketch/Figma/Photoshop.


Basic exploration

A simple thing we can do with reusing design made components is just copy the object. If you’re copying a parent object with several children inside , the children will also be copied. We can apply a loop to create even more copies.

Keep in mind that in order to copy a layer from design in code, you must create the target for this layer in design mode.

for i in [0..4]
newContact=contact.copy()

1*UL3IHifiPfLCJOuU5al15Q.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*UL3IHifiPfLCJOuU5al15Q.png”>
1*LeAqIiBhlyRHFY3snh72xg.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*LeAqIiBhlyRHFY3snh72xg.png”>

https://framer.cloud/FWhAc


Selectors

We have multiple blocks now, but they all have the same content. We can play a guessing game and talk to the children in our list element with an index like this:

for i in [0..4]
newContact=contact.copy()
newContact.y=newContact.height*(i+1)
newContact.children[1].text=i
newContact.children[0].image=Utils.randomImage()
1*KpDqcijnNuYoph0iBkiD3Q.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1600/1*KpDqcijnNuYoph0iBkiD3Q.png”>

It’s closer to our needs, but if we have complex components with lots of children inside, guessing the index of children can be complicated.

Andrew Cunliffe pointed me to new things in Framer — selectors made by Andreas.

Here is the basic overview of how they work:

<div class=”iframeContainer”><IFRAME data-width=”500″ data-height=”185″ width=”500″ height=”185″ src=”/media/3f75c990c30245520a56a61f5802b7a1?postId=6fce6bf4bcdd” data-media-id=”3f75c990c30245520a56a61f5802b7a1″ data-thumbnail=”https://i.embed.ly/1/image?url=https%3A%2F%2Fpbs.twimg.com%2Fmedia%2FDJEIcgEXoAATOt8.jpg%3Alarge&key=a19fcc184b9711e1b4764040d3dc5c07″ allowfullscreen frameborder=”0″></IFRAME></div>

Knowing the name of the child layer makes it a little a bit easier to change its properties. Below I’m using some dummy JSON data to bring our prototype to life.

data = [{name: “Callum Boddy”, company: “Linkedin”, userpic: “”}
{name: “Justo Inceptos”, company: “Mollis”, userpic: “”}
{name: “Pharetra Euismod”, company: “Tristique”, userpic: “”}
{name: “Egestas Sollicitudin”, company: “Sit”, userpic: “”}
{name: “Tellus Etiam”, company: “Egestas”, userpic: “”}
]
for i in [0..4]
newContact=contact.copy()
newContact.selectChild(‘company’).text=data[i].company
newContact.selectChild(‘name’).text=data[i].name
newContact.selectChild(‘userpic’).image=Utils.randomImage()
newContact.y=newContact.height*(i+1)
1*_cPomUTVlKl0aU5YWjSwyQ.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1600/1*_cPomUTVlKl0aU5YWjSwyQ.png”>

https://framer.cloud/vQUen


Classes

We can obviously use the copy function and arrays for simple things. But if we want to add more interaction to our components — add event listeners, states, animations, and so on — it’s time to use classes.

In case you are new to this thing, here are a couple of useful links:

Official guide by Framer team:

And a proper article by Øyvind Nordbø:

For example, if you’re working on a chat app and you designed your chat bubbles in design mode, set up border-radius, background, paddings, font-sizes, and so on. From there you need to go dynamic. You can create a class for chat bubble that will read certain properties from your Design mock in Framer.

class chatBubble extends TextLayer
constructor: (options = {}) ->
if options.type==answer
stylingLayer=answer
stylingText=answer_text
else
stylingLayer=question
stylingText=question_text
super _.defaults options,
backgroundColor: stylingLayer.backgroundColor

borderRadius:stylingLayer.borderRadius
color:stylingText.color
fontSize:stylingText.fontSize
padding:
top:stylingText.y
bottom:stylingText.y
left:stylingText.x
right:stylingText.x
lineHeight:stylingText.lineHeight
question1=new chatBubble
text:”Hey, whatsup?”
type:question
answer1=new chatBubble
text:”Trying to create reusable components from Design mode”
type:answer
y:question1.maxY+10
1*5WwTNMulcHMMK7vVn1u3eA.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*5WwTNMulcHMMK7vVn1u3eA.png”>
1*HIPIFuxUTvVm8IuSc3DW7w.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*HIPIFuxUTvVm8IuSc3DW7w.png”>

https://framer.cloud/HbYJL

If you change something in Design mode, your prototype will be updated automatically.

1*XIRvAvSvTGTSdT7dpUKQ-A.gif<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1600/1*XIRvAvSvTGTSdT7dpUKQ-A.gif”>

Extending layer prototypes

Here’s another approach to this problem as suggested by Callum Boddy.

1*KHn9lXe7p-29zvzW7KZj0w.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1600/1*KHn9lXe7p-29zvzW7KZj0w.png”>

https://framer.cloud/Mhrks

States

If you have a UI kit in Framer Design, you can attach states you defined in Design to your class in Code.

1*6agf3_L54mXpdy9nYMQJGg.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*6agf3_L54mXpdy9nYMQJGg.png”>
1*YS_B2ihjO5ZGNcd2RKy12w.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*YS_B2ihjO5ZGNcd2RKy12w.png”>

https://framer.cloud/xjWUc

class button extends TextLayer
constructor: (options = {}) ->

super _.defaults options,
backgroundColor: button_default.backgroundColor

borderRadius:button_default.borderRadius
color:text.color
fontSize:text.fontSize
fontWeight:text.fontWeight
padding:
top:text.y
bottom:text.y
left:text.x
right:text.x
lineHeight:text.lineHeight
animationOptions:
time:0.2
@.states.active=
backgroundColor: button_active.backgroundColor
color:text_1.color

@.onTouchStart ->
@.animate(“active”)
@.onTouchEnd ->
@.animate(“default”)
press=new button
text:”Press me”
x:Align.center
y:Align.center

Complex components

One of the interesting ways to create reusable components from Design mode is the styled slider.

1*j95_tYNEhd1ndRkXZZZv8A.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*j95_tYNEhd1ndRkXZZZv8A.png”>
1*97X02D7G-Pl7vuG6RlOEbg.png<img class=”progressiveMedia-noscript js-progressiveMedia-inner” src=”https://cdn-images-1.medium.com/max/1200/1*97X02D7G-Pl7vuG6RlOEbg.png”>

https://framer.cloud/apeKU

class Slider extends SliderComponent
constructor: (options = {}) ->
super _.defaults options,
height: track.height
borderRadius:knob.borderRadius
knobSize: knob.Size
backgroundColor: track.backgroundColor

min: 1, max: 10
@.fill.backgroundColor=highlight.backgroundColor
@.knob.backgroundColor=knob.backgroundColor

#u can put here individual properties like shadows and borderradius of knob for example, if u are going to change that
@.knob.shadow1=knob.shadow1
mySlider=new Slider
x:Align.center
y:Align.center

Conclusion

Spending time on reusable components makes sense if you’re working on long projects and have UI kits in place, or if you are using JSON data for example that you want to test with your Framer designs.

In most cases, people prototype several small screen interactions, which doesn’t require going crazy and coding components and just drawing everything in Design mode. Framer’s Fiber UI kit, for example, is divided into small interactions that you can work with together or separately.


Useful resources

I came across this amazing module by Lukas Guschlbauer that does most of the things I described:

Featured articles on Prototypr: