Created
May 18, 2016 08:33
-
-
Save japgolly/22baefb5f3a5abd8566994edfa5a6684 to your computer and use it in GitHub Desktop.
This file contains 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
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