Permalink
Browse files

Extending ScrollComponent.wrap to (optionally) take constructor options.

  • Loading branch information...
edwinvanrijkom committed Apr 3, 2015
1 parent c9b3cb0 commit 58ff015ac8c4bde850e9a8d1472946ffa4054ece
Showing with 21 additions and 3 deletions.
  1. +2 −2 framer/Components/ScrollComponent.coffee
  2. +19 −1 test/tests/ScrollComponentTest.coffee
@@ -376,12 +376,12 @@ class exports.ScrollComponent extends Layer
##############################################################
# Convenience function to make a single layer scrollable
@wrap = (layer) ->
@wrap = (layer, options = {}) ->
# This function wraps the given layer into a scroll or page component. This is
# great for importing from Sketch or Photoshop.
scroll = new @
scroll = new @(options)
for propKey in ["frame", "image", "name"]
scroll[propKey] = layer[propKey]
@@ -1,3 +1,5 @@
expect = chai.expect
describe "ScrollComponent", ->
it "should apply constructor options", ->
@@ -12,4 +14,20 @@ describe "ScrollComponent", ->
instance.scrollHorizontal.should.be.false
copy = instance.copy()
copy.scrollHorizontal.should.be.false
copy.scrollHorizontal.should.be.false
describe "wrap", ->
it "should forward constructor options", ->
options =
scrollVertical: false
mouseWheelEnabled: true
name: "is a name"
# 'wrap' ports the 'name' of the layer onto the ScrollComponent
layer = new Layer name: options.name
layer.name.should.equal(options.name)
scroller = ScrollComponent.wrap layer, options
for key in _.keys options
expect(scroller[key]).to.equal(options[key])

0 comments on commit 58ff015

Please sign in to comment.