-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated YesNoPopup, YesNoCancelPopup to the latest react features
- Loading branch information
1 parent
5d67bfb
commit 3e26ccf
Showing
4 changed files
with
68 additions
and
138 deletions.
There are no files selected for viewing
82 changes: 35 additions & 47 deletions
82
ui/src/main/scala/scommons/client/ui/popup/YesNoCancelPopup.scala
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 |
---|---|---|
@@ -1,63 +1,51 @@ | ||
package scommons.client.ui.popup | ||
|
||
import io.github.shogowada.scalajs.reactjs.React | ||
import io.github.shogowada.scalajs.reactjs.VirtualDOM._ | ||
import io.github.shogowada.scalajs.reactjs.classes.ReactClass | ||
import scommons.client.ui.{Buttons, SimpleButtonData} | ||
import scommons.client.ui.popup.YesNoCancelOption._ | ||
import scommons.client.ui.{Buttons, SimpleButtonData} | ||
import scommons.client.util.ActionsData | ||
import scommons.react.UiComponent | ||
import scommons.react._ | ||
import scommons.react.hooks._ | ||
|
||
case class YesNoCancelPopupProps(show: Boolean, | ||
message: String, | ||
onSelect: YesNoCancelOption => Unit, | ||
selected: YesNoCancelOption = Yes, | ||
image: Option[String] = None) | ||
|
||
object YesNoCancelPopup extends UiComponent[YesNoCancelPopupProps] { | ||
object YesNoCancelPopup extends FunctionComponent[YesNoCancelPopupProps] { | ||
|
||
private case class YesNoCancelPopupState(opened: Boolean = false) | ||
protected def render(compProps: Props): ReactElement = { | ||
val (opened, setOpened) = useState(false) | ||
|
||
val props = compProps.wrapped | ||
|
||
protected def create(): ReactClass = React.createClass[PropsType, YesNoCancelPopupState]( | ||
getInitialState = { _ => | ||
YesNoCancelPopupState() | ||
}, | ||
componentWillReceiveProps = { (self, nextProps) => | ||
val props = nextProps.wrapped | ||
if (self.props.wrapped != props) { | ||
self.setState(_.copy(opened = false)) | ||
<(Modal())(^.wrapped := ModalProps( | ||
show = props.show, | ||
header = None, | ||
buttons = List( | ||
SimpleButtonData(Yes.command, "Yes", props.selected == Yes), | ||
SimpleButtonData(No.command, "No", props.selected == No), | ||
Buttons.CANCEL.copy(command = Cancel.command, primary = props.selected == Cancel) | ||
), | ||
actions = ActionsData(Set(Yes.command, No.command, Cancel.command), _ => { | ||
case Yes.command => props.onSelect(Yes) | ||
case No.command => props.onSelect(No) | ||
case _ => props.onSelect(Cancel) | ||
}, | ||
if (opened) Some(props.selected.command) | ||
else None | ||
), | ||
onClose = () => props.onSelect(Cancel), | ||
onOpen = { () => | ||
setOpened(true) | ||
} | ||
}, | ||
render = { self => | ||
val props = self.props.wrapped | ||
|
||
<(Modal())(^.wrapped := ModalProps(props.show, | ||
None, | ||
List( | ||
SimpleButtonData(Yes.command, "Yes", props.selected == Yes), | ||
SimpleButtonData(No.command, "No", props.selected == No), | ||
Buttons.CANCEL.copy(command = Cancel.command, primary = props.selected == Cancel) | ||
), | ||
ActionsData(Set(Yes.command, No.command, Cancel.command), _ => { | ||
case Yes.command => props.onSelect(Yes) | ||
case No.command => props.onSelect(No) | ||
case _ => props.onSelect(Cancel) | ||
}, | ||
if (self.state.opened) Some(props.selected.command) | ||
else None | ||
), | ||
onClose = () => props.onSelect(Cancel), | ||
onOpen = { () => | ||
self.setState(_.copy(opened = true)) | ||
} | ||
))( | ||
<.div(^.className := "row-fluid")( | ||
props.image.map { image => | ||
<.img(^.className := image, ^.src := "")() | ||
}, | ||
<.p()(props.message) | ||
) | ||
))( | ||
<.div(^.className := "row-fluid")( | ||
props.image.map { image => | ||
<.img(^.className := image, ^.src := "")() | ||
}, | ||
<.p()(props.message) | ||
) | ||
} | ||
) | ||
) | ||
} | ||
} |
78 changes: 33 additions & 45 deletions
78
ui/src/main/scala/scommons/client/ui/popup/YesNoPopup.scala
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 |
---|---|---|
@@ -1,62 +1,50 @@ | ||
package scommons.client.ui.popup | ||
|
||
import io.github.shogowada.scalajs.reactjs.React | ||
import io.github.shogowada.scalajs.reactjs.VirtualDOM._ | ||
import io.github.shogowada.scalajs.reactjs.classes.ReactClass | ||
import scommons.client.ui.SimpleButtonData | ||
import scommons.client.ui.popup.YesNoCancelOption._ | ||
import scommons.client.util.ActionsData | ||
import scommons.react.UiComponent | ||
import scommons.react._ | ||
import scommons.react.hooks._ | ||
|
||
case class YesNoPopupProps(show: Boolean, | ||
message: String, | ||
onSelect: YesNoCancelOption => Unit, | ||
selected: YesNoCancelOption = Yes, | ||
image: Option[String] = None) | ||
|
||
object YesNoPopup extends UiComponent[YesNoPopupProps] { | ||
object YesNoPopup extends FunctionComponent[YesNoPopupProps] { | ||
|
||
private case class YesNoPopupState(opened: Boolean = false) | ||
protected def render(compProps: Props): ReactElement = { | ||
val (opened, setOpened) = useState(false) | ||
|
||
val props = compProps.wrapped | ||
|
||
protected def create(): ReactClass = React.createClass[PropsType, YesNoPopupState]( | ||
getInitialState = { _ => | ||
YesNoPopupState() | ||
}, | ||
componentWillReceiveProps = { (self, nextProps) => | ||
val props = nextProps.wrapped | ||
if (self.props.wrapped != props) { | ||
self.setState(_.copy(opened = false)) | ||
<(Modal())(^.wrapped := ModalProps( | ||
show = props.show, | ||
header = None, | ||
buttons = List( | ||
SimpleButtonData(Yes.command, "Yes", props.selected == Yes), | ||
SimpleButtonData(No.command, "No", props.selected == No) | ||
), | ||
actions = ActionsData(Set(Yes.command, No.command), _ => { | ||
case Yes.command => props.onSelect(Yes) | ||
case No.command => props.onSelect(No) | ||
}, | ||
if (opened) Some(props.selected.command) | ||
else None | ||
), | ||
onClose = () => (), | ||
closable = false, | ||
onOpen = { () => | ||
setOpened(true) | ||
} | ||
}, | ||
render = { self => | ||
val props = self.props.wrapped | ||
|
||
<(Modal())(^.wrapped := ModalProps(props.show, | ||
None, | ||
List( | ||
SimpleButtonData(Yes.command, "Yes", props.selected == Yes), | ||
SimpleButtonData(No.command, "No", props.selected == No) | ||
), | ||
ActionsData(Set(Yes.command, No.command), _ => { | ||
case Yes.command => props.onSelect(Yes) | ||
case No.command => props.onSelect(No) | ||
}, | ||
if (self.state.opened) Some(props.selected.command) | ||
else None | ||
), | ||
onClose = () => (), | ||
closable = false, | ||
onOpen = { () => | ||
self.setState(_.copy(opened = true)) | ||
} | ||
))( | ||
<.div(^.className := "row-fluid")( | ||
props.image.map { image => | ||
<.img(^.className := image, ^.src := "")() | ||
}, | ||
<.p()(props.message) | ||
) | ||
))( | ||
<.div(^.className := "row-fluid")( | ||
props.image.map { image => | ||
<.img(^.className := image, ^.src := "")() | ||
}, | ||
<.p()(props.message) | ||
) | ||
} | ||
) | ||
) | ||
} | ||
} |
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