scoop:scoop.ui.component:0.1.0
src/navigation_menu/link.scoop
Selected production source · src/navigation_menu/link.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.ui.*6
import scoop.ui.style.*7
import scoop.ui.style.Theme8
import scoop.window.accessibility.*10
public class NavigationMenuLink public constructor(11
private val props: Props<NavigationMenuLinkProps>,12
scope: ComponentScope13
): Component(scope) {14
private val themes = ThemeAccess(scope)15
public override fun onMount() {16
themes.mount(props.value.button.theme)17
}18
public override fun render(): View {19
val input = props.value20
val button = input.button21
val theme = themes.read(button.theme)22
return semanticButton(23
ButtonProps(24
button.content,25
button.onClick,26
button.enabled,27
navMenuStyle(theme, button.style, input.active, input.inPanel, false),28
button.theme,29
button.focus,30
button.invalid,31
button.variant,32
button.size,33
button.group,34
button.labelTarget,35
button.semantics36
),37
SemanticRole.Link,38
button.semantics.properties(39
enabled = button.enabled,40
invalid = button.invalid,41
selected = Some(input.active)42
),43
SemanticActions(44
invoke =45
Some {46
if (!props.value.button.enabled)47
SemanticActionResult.Rejected48
else {49
props.value.button.onClick()50
SemanticActionResult.Completed51
}52
}53
)54
)55
}56
}58
internal fun navMenuStyle(59
theme: Theme,60
local: ButtonStyle,61
active: Boolean,62
inPanel: Boolean,63
trigger: Boolean64
): ButtonStyle {65
val d = theme.tokens.typography.body.fontSize / 14.066
val palette = theme.tokens.palette67
val hover = styleOverride { background(Some(Paint(palette.muted.background))) }68
return local.copy {69
surface {70
if (suggestedSize == None)71
suggestedSize = Some(Size(0.0, 36.0 * d))72
if (minimumSize == None)73
minimumSize = Some(Size(0.0, 0.0))74
if (padding == None)75
padding =76
Some(77
if (inPanel)78
Insets.all(8.0 * d)79
else80
Insets(10.0 * d, 6.0 * d, 10.0 * d, 6.0 * d)81
)82
style =83
styleOverride {84
border(None);85
boxShadows([]);86
corners(87
Corners.all(88
(89
if (inPanel)90
6.091
else92
8.093
) *94
d95
)96
)97
if (active)98
background(Some(Paint(palette.muted.background.withAlpha(0.5))))99
}.then(local.surface.style)100
}101
text =102
Some(103
(local.text ?: spanStyle()).copy {104
if (weight == None)105
weight =106
Some(107
if (trigger)108
500109
else110
400111
)112
}113
)114
states {115
hovered = hover.then(local.surface.style).then(local.states.hovered)116
pressed = hover.then(local.surface.style).then(local.states.pressed)117
focused = hover.then(local.surface.style).then(local.states.focused)118
}119
}120
}