Created
January 21, 2016 14:22
-
-
Save oyvindberg/f1faaeb5658b999863a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chandu0101.scalajs.react.components | |
import chandu0101.macros.tojs.JSMacro | |
import chandu0101.macros.tojs.JSMacro._ | |
import japgolly.scalajs.react.{Callback, ReactElement, ReactComponentU_, React} | |
import scala.scalajs.js | |
import scala.scalajs.js.annotation.JSName | |
object ReactSlickComponent { | |
import js.`|` | |
@js.native | |
trait Unslick extends js.Any | |
val Unslick: Unslick = "unslick".asInstanceOf[Unslick] | |
@js.native | |
trait ResponsiveObject extends js.Any { | |
var breakpoint: Int | |
var settings: ResponsiveObjectDetail | Unslick | |
} | |
@js.native | |
trait ResponsiveObjectDetail extends js.Any { | |
var slidesToShow: Int | |
} | |
object ResponsiveObject { | |
def apply(breakpoint: Int, settings: ResponsiveObjectDetail | Unslick): ResponsiveObject = { | |
val ret = js.Dynamic.literal().asInstanceOf[ResponsiveObject] | |
ret.breakpoint = breakpoint | |
ret.settings = settings | |
ret | |
} | |
} | |
object ResponsiveObjectDetail { | |
def apply(slidesToShow: Int): ResponsiveObjectDetail = | |
js.Dynamic.literal( | |
slidesToShow = slidesToShow | |
).asInstanceOf[ResponsiveObjectDetail] | |
} | |
@js.native @JSName("ReactSlick") | |
private object Component extends js.Object | |
case class ReactSlick ( | |
/* "Additional class name for the inner slider div" */ | |
className: js.UndefOr[Int] = js.undefined, | |
/* "Adjust the slide's height automatically" */ | |
adaptiveHeight: js.UndefOr[Boolean] = js.undefined, | |
/* "Should we show Left and right nav arrows" */ | |
arrows: js.UndefOr[Boolean] = js.undefined, | |
/* "Should the scroller auto scroll?" */ | |
autoplay: js.UndefOr[Boolean] = js.undefined, | |
/* "delay between each auto scoll. in ms" */ | |
autoplaySpeed: js.UndefOr[Int] = js.undefined, | |
/* "Should we centre to a single item?" */ | |
centerMode: js.UndefOr[Boolean] = js.undefined, | |
/* "Should we show the dots at the bottom of the gallery" */ | |
dots: js.UndefOr[Boolean] = js.undefined, | |
/* "Class applied to the dots if they are enabled " */ | |
dotsClass: js.UndefOr[Int] = js.undefined, | |
/* "Is the gallery scrollable via dragging on desktop?" */ | |
draggable: js.UndefOr[Boolean] = js.undefined, | |
/* "Slides use fade for transition" */ | |
fade: js.UndefOr[Boolean] = js.undefined, | |
/* "should the gallery wrap around it's contents" */ | |
infinite: js.UndefOr[Boolean] = js.undefined, | |
/* "which item should be the first to be displayed" */ | |
initialSlide: js.UndefOr[Int] = js.undefined, | |
/* "Loads images or renders components on demands" */ | |
lazyLoad: js.UndefOr[Boolean] = js.undefined, | |
/* Array of objects in the form of { breakpoint: int, settings: { ... } } The breakpoint int is the maxWidth so the settings will be applied when resolution is below this value. Breakpoints in the array should be ordered from smalles to greatest. Use 'unslick' in place of the settings object to disable rendering the carousel at that breakpoint. Example: [ { breakpoint: 768, settings: { slidesToShow: 3 } }, { breakpoint: 1024, settings: { slidesToShow: 5 } }, { breakpoint: 100000, settings: 'unslick' } ] | |
*/ | |
responsive: js.UndefOr[js.Array[ResponsiveObject]] = js.undefined, | |
/* "Reverses the slide order " */ | |
rtl: js.UndefOr[Boolean] = js.undefined, | |
/* "Number of slides to be visible at a time" */ | |
slidesToShow: js.UndefOr[Int] = js.undefined, | |
/* "Number of slides to scroll for each navigation item" */ | |
slidesToScroll: js.UndefOr[Int] = js.undefined, | |
/* "Enable/Disable CSS Transitions" */ | |
useCSS: js.UndefOr[Boolean] = js.undefined, | |
/* "callback function called after the current index changes" */ | |
afterChange: js.UndefOr[Int => Callback] = js.undefined, | |
/* "callback function called before the current index changes " */ | |
beforeChange: js.UndefOr[(Int, Int) => Callback] = js.undefined, | |
/* "go to the specified slide number" */ | |
slickGoTo: js.UndefOr[Int] = js.undefined){ | |
def apply(children: ReactElement*) = { | |
val f = React.asInstanceOf[js.Dynamic].createFactory(Component) | |
val props = JSMacro[ReactSlick](this) | |
if (children.isEmpty) | |
f(props).asInstanceOf[ReactComponentU_] | |
else if (children.size == 1) | |
f(props, children.head).asInstanceOf[ReactComponentU_] | |
else | |
f(props, children.toJsArray).asInstanceOf[ReactComponentU_] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment