Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 7d92ea4

Browse files
committed
Add children property
1 parent 096d0a4 commit 7d92ea4

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

facade/src/main/scala/react/virtualized/AutoSizer.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package virtualized
33

44
import japgolly.scalajs.react._
55
import japgolly.scalajs.react.vdom.VdomNode
6+
import japgolly.scalajs.react.raw.ReactNode
67
import japgolly.scalajs.react.component.Js.{RawMounted, UnmountedMapped}
78
import japgolly.scalajs.react.internal.Effect.Id
9+
import defs._
810

911
import scala.scalajs.js
1012
import scala.scalajs.js.annotation.JSImport
@@ -15,11 +17,13 @@ object AutoSizer {
1517
object RawComponent extends js.Object
1618

1719
type OnResize = js.Function1[Size, Unit]
20+
type RawChildren = js.Function1[Size, ReactNode]
21+
type Children = js.Function1[Size, VdomNode]
1822

1923
@js.native
2024
trait Props extends js.Object {
2125
/** Function responsible for rendering children.*/
22-
// children: (warams: Size) => React.Element<*>, = js.native
26+
var children: RawChildren = js.native
2327

2428
/** Disable dynamic :height property */
2529
var disableHeight: js.UndefOr[Boolean] = js.native
@@ -35,6 +39,7 @@ object AutoSizer {
3539
}
3640

3741
def props(
42+
children: Children,
3843
disableHeight: js.UndefOr[Boolean] = js.undefined,
3944
disableWidth: js.UndefOr[Boolean] = js.undefined,
4045
nonce: js.UndefOr[String] = js.undefined,
@@ -45,6 +50,7 @@ object AutoSizer {
4550
p.disableWidth = disableWidth
4651
p.nonce = nonce
4752
p.onResize = (s: Size) => onResize(s).runNow
53+
p.children = (s: Size) => {println(s);toRawNode(children(s))}
4854
p
4955
}
5056

facade/src/test/scala/react/virtualized/AutoSizerSpec.scala

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,40 @@ package virtualized
33

44
import org.scalatest._
55
import japgolly.scalajs.react._
6+
import japgolly.scalajs.react.test._
7+
import japgolly.scalajs.react.vdom.html_<^.{< => <<, _}
68

79
class AutoSizerSpec extends FlatSpec with Matchers with NonImplicitAssertions with TestUtils {
10+
def children(s: Size): VdomNode =
11+
<<.div(
12+
^.width := s.width.px,
13+
^.height := s.height.px,
14+
<<.span("text")
15+
)
816

917
"AutoSizer" should
10-
"require width and dataKey" in {
11-
Column(Column.props(200, "key")).props.width should be (200)
12-
Column(Column.props(200, "key")).props.dataKey should be ("key")
18+
"render" in {
19+
val autoSizer = AutoSizer(AutoSizer.props(children = children))
20+
ReactTestUtils.withRenderedIntoDocument(autoSizer) { m =>
21+
val html =
22+
"""<div style="overflow: visible; height: 0px; width: 0px;">
23+
|<div style="width: 0px; height: 0px;">
24+
|<span>text</span>
25+
|</div>
26+
|</div>""".stripMargin.replaceAll("[\n\r]", "")
27+
assert(m.outerHtmlScrubbed() == html)
28+
}
1329
}
1430
it should "support disableWidth" in {
15-
AutoSizer(AutoSizer.props()).props.disableWidth.toOption should contain(false)
16-
AutoSizer(AutoSizer.props(disableWidth = true)).props.disableWidth.toOption should contain(true)
31+
AutoSizer(AutoSizer.props(children = children)).props.disableWidth.toOption should contain(false)
32+
AutoSizer(AutoSizer.props(children = children, disableWidth = true)).props.disableWidth.toOption should contain(true)
1733
}
1834
it should "support disableHeight" in {
19-
AutoSizer(AutoSizer.props()).props.disableHeight.toOption should contain(false)
20-
AutoSizer(AutoSizer.props(disableHeight = true)).props.disableHeight.toOption should contain(true)
35+
AutoSizer(AutoSizer.props(children = children)).props.disableHeight.toOption should contain(false)
36+
AutoSizer(AutoSizer.props(children = children, disableHeight = true)).props.disableHeight.toOption should contain(true)
2137
}
2238
it should "support onResize" in {
2339
val size = Size(height = 10, width = 20)
24-
AutoSizer(AutoSizer.props(onResize = x => Callback.log(x))).props.onResize(size) should be(())
40+
AutoSizer(AutoSizer.props(children = children, onResize = x => Callback.log(x))).props.onResize(size) should be(())
2541
}
2642
}

0 commit comments

Comments
 (0)