scoop:scoop.ui.component:0.1.0
src/actions/semantic_button.scoop
Selected production source · src/actions/semantic_button.scoop
1
package scoop.ui.component3
import scoop.ui.*4
import scoop.window.accessibility.*6
private class SemanticButtonProps(7
val input: ButtonProps,8
val role: SemanticRole,9
val state: SemanticProperties,10
val actions: SemanticActions,11
val fallbackName: String?12
)14
private class SemanticButton(15
private val props: Props<SemanticButtonProps>,16
scope: ComponentScope17
): Component(scope) {18
private val button =19
ButtonControl(20
{ props.value.input },21
scope,22
props.value.role,23
{ Some(props.value.state) },24
{ Some(props.value.actions) },25
{ props.value.fallbackName }26
)27
public override fun onMount() {28
button.mount()29
}30
public override fun render(): View = button.render()31
}33
/** Uses the ordinary button's layout, press, focus and visual state for semantic variants. */34
internal fun semanticButton(35
input: ButtonProps,36
role: SemanticRole,37
state: SemanticProperties,38
actions: SemanticActions,39
fallbackName: String? = None40
): View =41
component(42
SemanticButtonProps(input, role, state, actions, fallbackName),43
{ props, mount -> SemanticButton(props, scope = mount) },44
// A role change retires its identity even when the surrounding component is reused.45
key =46
ViewKey.Number(47
when (role) {48
case Button -> 2L49
case Link -> 13L50
case MenuItem -> 18L51
case Cell -> 23L52
case Disclosure -> 26L53
else -> throw IllegalArgumentException(54
Some("unsupported semantic button variant")55
)56
}57
)58
)60
internal fun popupSemanticButton(61
input: ButtonProps,62
expanded: Boolean,63
change: (Boolean) -> SemanticActionResult,64
value: String? = None,65
fallbackName: String? = None66
): View =67
semanticButton(68
input,69
SemanticRole.Button,70
input.semantics.properties(71
value = value,72
enabled = input.enabled,73
invalid = input.invalid,74
expanded = Some(expanded)75
),76
SemanticActions(invoke = Some { change(!expanded) }, setExpanded = Some(change)),77
fallbackName78
)