Home

Awesome

framer-DesignComponents

A module for converting your designs in design mode into full scalable classes.

Supported native components:

Links

Installation

Automatic installation with Framer Modules

<a href='https://open.framermodules.com/design-components-symbols'> <img alt='Install with Framer Modules' src='https://www.framermodules.com/assets/badge@2x.png' width='160' height='40' /> </a>

Manual installation

Download and move the <code>Constraints.coffee</code> and <code>DesignComponents.coffee</code> files to your modules folder.

At the top of your file, place this line of code:

Design = require "DesignComponents"

Done! That is all the code you need to do to get this module started. Now onto the fun stuff.

Native components

For the native slider components, all you need to do is design a slider with the correct child names inside, and prefix the whole group with an <code>_</code>.

For example the layer structure will look like this:

Layer List

The <code>_SliderComponent</code> or <code>_RangeSliderComponent</code> layers are the background fill for the slider.

Custom classes

A custom class will be generated from your design, including all of the layer's children. You will then be able to add this class as many times as you want in the code view, without having to declare a class extension and constructor.

To create a custom class in design mode, simply name the layer in design mode with the following syntax:

Custom_{className}

where <code>{className}</code> is replaced by the name of your class.

For example:

Custom Button Custom Card

Note: You do not have to create a target for these layers.

Using your class in your prototype

To add the class to your prototype, simply create a new instance of the class as you would a layer:

button = new Design.Button

card = new Design.Card

The layers within your class are also accessible within the the creation of the new instance, and oyu can change their properties as oyu would any other layer in code.

Card structure in Design mode

Custom Card

IMPORTANT: Any SVG Layer in Design mode must be wrapped inside of a frame for this module to work.

Editing the contents of the class in code

card = new Design.Card
  avatar:
    borderRadius: 0
    image: Utils.randomImage()
  subheader:
    text: "This is a new subheader"
  content:
    text: "This is some content that has changed"

Edited Card

Constraints

With this module comes the ability to set constraints to your layers in code as well as design.

When oyu initiate an instance of your symbol, it will automatically copy over the constraints of the design layer, but you are now able to override these upon initialisation, and later.

Setting constraints on a new layer

Arguments

layer = new Layer
  size: 50

layer.constraints =
  top: null
  left: 20
  bottom: null
  right: 20
  centerX: null
  centerY: 0.5
  scaleX: null
  scaleY: 0.8
  aspectRatioLocked: true
  pushDown: true
  pushRight: null

Setting constraints on a layer within a custom class

If you are using a custom class from the Design mode, you can set the constraints upon initilisation.

card = new Design.Card
  constraints:
    left: 10
    right: 10
  avatar:
    image: Utils.randomImage()
    constraints:
      right: 15
      top: 15
      aspectRatioLocked: true
  content:
    text: "Lorem ipsum dolor sit amet.\nNew content\nMore new content"
    constraints:
    	pushDown: true

See it in action:

Card Expand Gif

States

Single states

The syntax for adding a single state on an event is:

State_{className}_{event}

eg:

Single state

Multiple states

Adding multiple states for a event (toggling):

{stateName}_State_{className}_{event}

eg:

Multiple states

This will automatically add a switch event to the layer to switch the properties of the layer and all of its children upon the triggering of the event.

Animating states

By default, the design states will not animate between each other. To add default animation options to the events, simply append <code>_Animate</code> to the end of the layer name.

For example:

{stateName}_State_{className}_{eventName}_Animate

With your custom classes, there is a new animate function. This will enable the class to animate itself, and all of its descendants at the same time.

animateState(stateName, animate, options)

Arguments

layer = new Design.Class

layer.animateState "Error",
  time: 1
  curve: Spring(damping: 0.8)