-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81d1a0a
commit 7150f49
Showing
5 changed files
with
95 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package farclone.ui | ||
|
||
import scommons.react._ | ||
import scommons.react.blessed._ | ||
|
||
case class TextBoxProps(pos: (Int, Int), | ||
width: Int, | ||
value: String, | ||
style: BlessedStyle, | ||
onChange: String => Unit) | ||
|
||
object TextBox extends FunctionComponent[TextBoxProps] { | ||
|
||
protected def render(compProps: Props): ReactElement = { | ||
val props = compProps.wrapped | ||
val (left, top) = props.pos | ||
|
||
<.input( | ||
^.rbMouse := true, | ||
^.rbKeyable := true, | ||
^.rbWidth := props.width, | ||
^.rbHeight := 1, | ||
^.rbLeft := left, | ||
^.rbTop := top, | ||
^.rbStyle := props.style, | ||
^.content := props.value | ||
)() | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package farclone.ui | ||
|
||
import scommons.react.blessed._ | ||
import scommons.react.test.TestSpec | ||
import scommons.react.test.raw.ShallowInstance | ||
import scommons.react.test.util.ShallowRendererUtils | ||
|
||
class TextBoxSpec extends TestSpec with ShallowRendererUtils { | ||
|
||
it should "render component" in { | ||
//given | ||
val props = getTextBoxProps() | ||
|
||
//when | ||
val result = shallowRender(<(TextBox())(^.wrapped := props)()) | ||
|
||
//then | ||
assertTextBox(result, props) | ||
} | ||
|
||
private def getTextBoxProps(value: String = "initial name", | ||
onChange: String => Unit = _ => () | ||
): TextBoxProps = TextBoxProps( | ||
pos = (1, 2), | ||
width = 10, | ||
value = value, | ||
style = new BlessedStyle { | ||
override val bg = "cyan" | ||
override val fg = "black" | ||
}, | ||
onChange = onChange | ||
) | ||
|
||
private def assertTextBox(result: ShallowInstance, props: TextBoxProps): Unit = { | ||
val (left, top) = props.pos | ||
|
||
assertNativeComponent(result, | ||
<.input( | ||
^.rbMouse := true, | ||
^.rbKeyable := true, | ||
^.rbWidth := props.width, | ||
^.rbHeight := 1, | ||
^.rbLeft := left, | ||
^.rbTop := top, | ||
^.rbStyle := props.style, | ||
^.content := props.value | ||
)() | ||
) | ||
} | ||
} |
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