Skip to content

Instantly share code, notes, and snippets.

@japgolly
Created May 18, 2016 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japgolly/22baefb5f3a5abd8566994edfa5a6684 to your computer and use it in GitHub Desktop.
Save japgolly/22baefb5f3a5abd8566994edfa5a6684 to your computer and use it in GitHub Desktop.
import japgolly.scalajs.react._
import scalajs.js.{undefined, Dictionary, Dynamic, Object, UndefOr}
import shipreq.base.util.Memo
import ReactCollapse._
/**
* Component-wrapper for collapse animation with react-motion for elements with variable (and dynamic) height.
*
* https://github.com/nkbt/react-collapse
*/
object ReactCollapse {
type P = Object
type S = Nothing
val Factory: JsComponentC[P, S, TopNode] = {
val ReactCollapse = Dynamic.global.ReactCollapse.asInstanceOf[JsComponentType[P, S, TopNode]]
React.createFactory[P, S, TopNode](ReactCollapse)
}
@inline def apply(isOpened: Boolean): ReactCollapse =
applyFn(isOpened)
val applyFn: Boolean => ReactCollapse =
Memo.bool(b =>
new ReactCollapse(isOpened = b))
}
class ReactCollapse(isOpened : Boolean,
fixedHeight : UndefOr[Double] = undefined,
springConfig: UndefOr[Array[Double]] = undefined) {
val toJs: P = {
val o = Dictionary.empty[Any]
o("isOpened") = isOpened
fixedHeight foreach (o("fixedHeight") = _)
springConfig foreach (o("springConfig") = _)
o.asInstanceOf[P]
}
def apply(children: ReactNode*): ReactComponentU_ =
Factory(toJs, children: _*)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment