Giter Site home page Giter Site logo

sebcglbailey / framer-designcomponents Goto Github PK

View Code? Open in Web Editor NEW
31.0 6.0 3.0 3.2 MB

A module for converting your designs in design mode into full scalable classes in code, without a single line of code!

CoffeeScript 88.20% JavaScript 6.38% CSS 2.43% HTML 3.00%

framer-designcomponents's Introduction

framer-DesignComponents

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

Supported native components:

  • SliderComponent
  • RangeSliderComponent

Links

Installation

Automatic installation with Framer Modules

Install with Framer Modules

Manual installation

Download and move the Constraints.coffee and DesignComponents.coffee 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 _.

For example the layer structure will look like this:

Layer List

The _SliderComponent or _RangeSliderComponent 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 {className} 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

  • top – the distance of the top edge from the top of the parent layer.
  • left – the distance of the left edge from the left of the parent layer.
  • bottom – the distance of the bottom edge from the bottom of the parent layer.
  • right – the distance of the right edge from the right of the parent layer.
  • centerX – the position of the layer within its parent on horizontal axis as a ratio between 0 - 1.
  • centerY – the position of the layer within its parent on the vertical axis as a ratio between 0 - 1.
  • scaleX – the width of the layer relative to its parent width as a ratio between 0 - 1.
  • scaleY – the height of the layer relative to its parent height as a ratio between 0 - 1.
  • aspectRatioLocked – the original ratio of width/height of the layer stays the same if set to true.
  • pushDown – If you want the layer to resize its parent when it resizes or moves, keeping the same original margin. I.e. when you add multiple lines to a text layer. NOTE: The layer cannot have a bottom constraint set for this to work.
  • pushRight – The same as pushDown but with the width of the parent. NOTE: The layer cannot have a right constraints set for this to work.
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 _Animate 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

  • stateName – the name of the state to animate to.
  • animate – A boolean, set to override the default animation option for the class. (Optional)
  • options – animation options. (Optional)
layer = new Design.Class

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

framer-designcomponents's People

Contributors

sebcglbailey avatar alanpilgrim avatar

Stargazers

Stefan Ciprian Hotoleanu avatar Parker Henderson avatar Ben avatar Bruno Borella avatar John Canelis avatar Angel Ceballos avatar Afnizar Nur Ghifari avatar Aalok Trivedi avatar Richard Quay avatar Alex Raduca avatar  avatar  avatar Tiago Mergulhão avatar  avatar Hanno ten Hoor avatar Lukas Guschlbauer avatar Joshua Crowley avatar Blaine Billingsley avatar uxnstuff avatar Maxim Melnikov avatar Dan Jones avatar  avatar Agustín Isasa avatar Derek Nguyen avatar Marc Krenn avatar  avatar  avatar DO avatar  avatar Davo Galavotti avatar Sergiy Voronov avatar

Watchers

 avatar Nicolas Elizaga avatar James Cloos avatar Blaine Billingsley avatar robooneus avatar  avatar

framer-designcomponents's Issues

Constraints standalone

Hey!

I really love the idea of this module - I've been working on something with a kind of similar goal (https://github.com/der-lukas/framer-Symbols)

I've experimented around with the Constraints.coffee (without DesignComponents), since I was interested in achieving dynamic layouts as for example a container where children get added and the container(s) grows automatically.

I think it would be a good idea to make Constraints a seperate module that can be used as standalone and make it an external dependency for DesignComponents, because just having the power of setting constraints via code and for example not having to update the height of every parent would be a great module on its own.

What do you think about that?

(feature request) Tie into Input module?

Love this and has been super helpful!

Wondering if you have thought about adding support to easily create text fields with the Input module? I could see this super helpful for showing default view, text entered, disabled, and error states for one text field.

Thanks again!

Issue in Framer App

Hi! I'm receiving an error in the Framer app when using this module - TypeError:component.addDesignChildren is not a function. (Sorry, I can't read the rest in the app somehow).

No errors in Framer desktop, nothing in the console.

Possibly incorrect usage? My file:
https://framer.cloud/cbyvW/

States don't carry over text values

Nice module.

Tested it with a button that had a text layer. I created a variation of it for a pressed state, but it doesn't carry over the text value. Layers are named the same

image

bug

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.