Skip to content

Commit

Permalink
swapping over coupling button to the new system, which required updat…
Browse files Browse the repository at this point in the history
…ing the library to handle unset keys properly
  • Loading branch information
robertfmurdock committed Jul 6, 2023
1 parent 4d3431d commit 014b971
Show file tree
Hide file tree
Showing 29 changed files with 141 additions and 175 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.zegreatrob.coupling.client.components

import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.children
import com.zegreatrob.minreact.ntmFC
import com.zegreatrob.minreact.ReactFunc
import com.zegreatrob.minreact.nfc
import csstype.PropertiesBuilder
import emotion.react.css
import react.PropsWithChildren
import react.dom.html.ButtonHTMLAttributes
import react.dom.html.ReactHTML.button
import web.cssom.AnimationPlayState
Expand Down Expand Up @@ -152,31 +152,37 @@ val black: PropertiesBuilder.() -> Unit = {
}
}

data class CouplingButton(
val sizeRuleSet: PropertiesBuilder.() -> Unit = medium,
val colorRuleSet: PropertiesBuilder.() -> Unit = black,
@JsName("className")
val className: ClassName = ClassName(""),
val onClick: () -> Unit = {},
val attrs: ButtonHTMLAttributes<*>.() -> Unit = {},
val css: PropertiesBuilder.() -> Unit = {},
) : DataPropsBind<CouplingButton>(couplingButton)
external interface CouplingButtonProps : PropsWithChildren {
var sizeRuleSet: ((PropertiesBuilder) -> Unit)?
var colorRuleSet: ((PropertiesBuilder) -> Unit)?
var className: (ClassName)?
var onClick: (() -> Unit)?
var attrs: ((ButtonHTMLAttributes<*>) -> Unit)?
var css: ((PropertiesBuilder) -> Unit)?
}

@ReactFunc
val CouplingButton by nfc<CouplingButtonProps> { props ->
val sizeRuleSet = props.sizeRuleSet ?: medium
val colorRuleSet = props.colorRuleSet ?: black
val className = props.className ?: ClassName("")
val onClick = props.onClick ?: {}
val attrs = props.attrs ?: {}
val css = props.css ?: {}

val couplingButton by ntmFC<CouplingButton> { props ->
val (sizeRuleSet, colorRuleSet, className, onClick, block, css) = props
button {
type = ButtonType.button
this.onClick = { onClick() }
block(this)
attrs(this)

css(className, ClassName("button")) {
"*" { verticalAlign = VerticalAlign.middle }
buttonRuleset()
sizeRuleSet()
colorRuleSet()
css()
sizeRuleSet(this)
colorRuleSet(this)
css(this)
}

children(props)
+props.children
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.zegreatrob.coupling.client.components

import com.zegreatrob.minreact.add
import react.ChildrenBuilder
import react.dom.html.ButtonHTMLAttributes
import web.html.ButtonType

fun ChildrenBuilder.configSaveButton(isSaving: Boolean) = add(
com.zegreatrob.coupling.client.components.CouplingButton(
sizeRuleSet = com.zegreatrob.coupling.client.components.supersize,
colorRuleSet = com.zegreatrob.coupling.client.components.blue,
attrs = {
type = ButtonType.submit
tabIndex = 0
value = "Save"
disabled = isSaving
},
),
fun ChildrenBuilder.configSaveButton(isSaving: Boolean) = CouplingButton(
sizeRuleSet = supersize,
colorRuleSet = blue,
attrs = fun ButtonHTMLAttributes<*>.() {
type = ButtonType.submit
tabIndex = 0
value = "Save"
disabled = isSaving
},
) {
+"Save"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.zegreatrob.coupling.client.components

import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import react.Props
import react.dom.html.ReactHTML.i
Expand All @@ -13,7 +12,7 @@ val DemoButton by nfc<Props> {
to = "/demo"
tabIndex = -1
draggable = false
add(CouplingButton(large, lightGreen)) {
CouplingButton(large, lightGreen) {
i { className = ClassName("fa fa-play") }
span { +" Demo" }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.zegreatrob.coupling.client.components

import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import react.Props
import react.dom.html.ReactHTML.img
Expand All @@ -11,7 +10,7 @@ val GqlButton by nfc<Props> {
to = "/graphiql"
tabIndex = -1
draggable = false
add(CouplingButton(large, white)) {
CouplingButton(large, white) {
img {
src = svgPath("graphql")
height = 18.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.zegreatrob.coupling.client.components

import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import react.Props
import react.dom.html.ReactHTML.i
Expand All @@ -13,7 +12,7 @@ val LogoutButton by nfc<Props> {
to = "/logout"
tabIndex = -1
draggable = false
add(CouplingButton(large, red)) {
CouplingButton(large, red) {
i { className = ClassName("fa fa-sign-out-alt") }
span { +"Sign Out" }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.zegreatrob.coupling.client.components

import com.zegreatrob.minreact.add
import react.ChildrenBuilder

fun ChildrenBuilder.retireButton(onRetire: () -> Unit) = add(CouplingButton(small, red, onClick = onRetire)) {
+"Retire"
}
fun ChildrenBuilder.retireButton(onRetire: () -> Unit) = CouplingButton(small, red, onClick = onRetire) { +"Retire" }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.zegreatrob.coupling.client.components

import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.minreact.add
import csstype.PropertiesBuilder
import react.ChildrenBuilder
import react.dom.html.ReactHTML.i
import react.router.dom.Link
Expand All @@ -13,12 +13,10 @@ fun ChildrenBuilder.settingsButton(party: PartyDetails, className: ClassName = C
to = "/${party.id.value}/edit"
tabIndex = -1
draggable = false
add(
CouplingButton(large, black, className) {
fontSize = 24.px
padding = Padding(1.px, 4.px, 2.px)
},
) {
CouplingButton(large, black, className, css = fun PropertiesBuilder.() {
fontSize = 24.px
padding = Padding(1.px, 4.px, 2.px)
}) {
i { this.className = ClassName("fa fa-cog") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.zegreatrob.coupling.model.pin.Pin
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.ntmFC
import csstype.PropertiesBuilder
import emotion.react.css
import react.ChildrenBuilder
import react.dom.html.ReactHTML.div
Expand Down Expand Up @@ -148,23 +149,19 @@ private fun List<PinnedCouplingPair>.findPairContainingPlayer(droppedPlayerId: S
pair.pinnedPlayers.any { player -> player.player.id == droppedPlayerId }
}

private fun ChildrenBuilder.saveButton(onSave: () -> Unit) = add(
CouplingButton(
sizeRuleSet = supersize,
colorRuleSet = green,
onClick = onSave,
css = { margin = 4.px },
),
private fun ChildrenBuilder.saveButton(onSave: () -> Unit) = CouplingButton(
sizeRuleSet = supersize,
colorRuleSet = green,
onClick = onSave,
css = fun PropertiesBuilder.() { margin = 4.px },
) {
+"Save!"
}

private fun ChildrenBuilder.cancelButton(onCancel: () -> Unit) = add(
CouplingButton(
sizeRuleSet = small,
colorRuleSet = red,
onClick = onCancel,
),
private fun ChildrenBuilder.cancelButton(onCancel: () -> Unit) = CouplingButton(
sizeRuleSet = small,
colorRuleSet = red,
onClick = onCancel,
) {
+"Cancel"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.zegreatrob.coupling.model.pairassignmentdocument.PairAssignmentDocume
import com.zegreatrob.coupling.model.pairassignmentdocument.PinnedPlayer
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.ntmFC
import emotion.css.ClassName
import emotion.react.css
Expand Down Expand Up @@ -78,12 +77,10 @@ private val pairAssignmentRow by ntmFC<PairAssignmentRow> { (party, document, co
}
}

private fun ChildrenBuilder.deleteButton(onClickFunc: () -> Unit) = add(
CouplingButton(
sizeRuleSet = small,
colorRuleSet = red,
onClick = onClickFunc,
),
private fun ChildrenBuilder.deleteButton(onClickFunc: () -> Unit) = CouplingButton(
sizeRuleSet = small,
colorRuleSet = red,
onClick = onClickFunc,
) {
+"DELETE"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.browser.window
import org.w3c.dom.DataTransfer
import react.ChildrenBuilder
import react.MutableRefObject
import react.dom.html.ButtonHTMLAttributes
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.i
import react.useRef
Expand Down Expand Up @@ -60,13 +61,11 @@ private val pairSection by ntmFC<PairSection> { (party, players, pairs, allowSav

private fun ChildrenBuilder.copyToClipboardButton(ref: MutableRefObject<HTMLElement>) {
if (js("!!global.ClipboardItem").unsafeCast<Boolean>()) {
add(
CouplingButton(
sizeRuleSet = large,
colorRuleSet = white,
onClick = { ref.current?.copyToClipboardOnClick()?.invoke() },
attrs = { tabIndex = -1 },
),
CouplingButton(
sizeRuleSet = large,
colorRuleSet = white,
onClick = { ref.current?.copyToClipboardOnClick()?.invoke() },
attrs = fun ButtonHTMLAttributes<*>.() { tabIndex = -1 },
) {
i { className = ClassName("fa fa-clipboard") }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.zegreatrob.coupling.client.components.pink
import com.zegreatrob.coupling.client.components.supersize
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.minreact.DataPropsBind
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.ntmFC
import csstype.PropertiesBuilder
import react.router.dom.Link
import web.cssom.AnimationIterationCount
import web.cssom.ClassName
Expand All @@ -22,20 +22,18 @@ private val prepareToSpinButton by ntmFC<PrepareToSpinButton> { (party) ->
to = "/${party.id.value}/prepare/"
tabIndex = -1
draggable = false
add(
CouplingButton(
sizeRuleSet = supersize,
colorRuleSet = pink,
className = prepareToSpinButtonClassName,
css = {
animationName = ident("pulsate")
animationDuration = 2.s
animationIterationCount = AnimationIterationCount.infinite
hover {
animationDuration = 0.75.s
}
},
),
CouplingButton(
sizeRuleSet = supersize,
colorRuleSet = pink,
className = prepareToSpinButtonClassName,
css = fun PropertiesBuilder.() {
animationName = ident("pulsate")
animationDuration = 2.s
animationIterationCount = AnimationIterationCount.infinite
hover {
animationDuration = 0.75.s
}
},
) {
+"Prepare to spin!"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.zegreatrob.coupling.client.components.CouplingButton
import com.zegreatrob.coupling.client.components.large
import com.zegreatrob.coupling.client.components.lightGreen
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.minreact.add
import react.ChildrenBuilder
import react.dom.html.ReactHTML.i
import react.router.dom.Link
Expand All @@ -14,7 +13,7 @@ fun ChildrenBuilder.viewHistoryButton(party: PartyDetails) = Link {
to = "/${party.id.value}/history/"
tabIndex = -1
draggable = false
add(CouplingButton(large, lightGreen)) {
CouplingButton(large, lightGreen) {
i { this.className = ClassName("fa fa-history") }
+" History!"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.zegreatrob.coupling.client.components.party

import com.zegreatrob.coupling.client.components.CouplingButton
import com.zegreatrob.coupling.client.components.large
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import react.Props
import react.dom.html.ReactHTML.i
Expand All @@ -15,7 +14,7 @@ val PartySelectButton by nfc<Props> {
to = "/parties/"
tabIndex = -1
draggable = false
add(CouplingButton(large)) {
CouplingButton(large) {
i { className = ClassName("fa fa-arrow-circle-up") }
span { +"Party select" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.zegreatrob.coupling.client.components.CouplingButton
import com.zegreatrob.coupling.client.components.large
import com.zegreatrob.coupling.client.components.white
import com.zegreatrob.coupling.model.party.PartyDetails
import com.zegreatrob.minreact.add
import react.ChildrenBuilder
import react.dom.html.ReactHTML.i
import react.router.dom.Link
Expand All @@ -14,7 +13,7 @@ fun ChildrenBuilder.pinListButton(party: PartyDetails) = Link {
to = "/${party.id.value}/pins/"
tabIndex = -1
draggable = false
add(CouplingButton(large, white)) {
CouplingButton(large, white) {
i { this.className = ClassName("fa fa-peace") }
+" Pin Bag!"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.zegreatrob.coupling.client.components.CouplingButton
import com.zegreatrob.coupling.client.components.large
import com.zegreatrob.coupling.client.components.orange
import com.zegreatrob.coupling.model.party.PartyId
import com.zegreatrob.minreact.add
import com.zegreatrob.minreact.nfc
import react.Props
import react.router.dom.Link
Expand All @@ -19,7 +18,7 @@ val addPlayerButton by nfc<AddPlayerButtonProps> { props ->
to = "/${props.partyId.value}/player/new/"
tabIndex = -1
draggable = false
add(CouplingButton(large, orange)) {
CouplingButton(large, orange) {
+"Add Player!"
}
}
Expand Down
Loading

0 comments on commit 014b971

Please sign in to comment.