scoop:scoop.ui.component:0.1.0
src/tabs/control.scoop
Selected production source · src/tabs/control.scoop
1
package scoop.ui.component3
import scoop.ui.*4
import scoop.ui.style.*5
import scoop.window.accessibility.*7
internal class TabControlProps(8
val content: ButtonContent,9
val selected: Boolean,10
val enabled: Boolean,11
val variant: TabsVariant,12
val axis: FlexAxis,13
val style: ButtonStyle,14
val focus: FocusOptions,15
val theme: Theme,16
val activate: () -> Unit,17
val select: () -> SemanticActionResult,18
val semantics: ComponentSemantics19
)21
internal class TabControl(22
private val props: Props<TabControlProps>,23
scope: ComponentScope24
): Component(scope) {25
private val control =26
PressControl(27
scope,28
PressOptions(props.value.enabled),29
props.value.focus,30
{ props.value.activate() }31
)32
private val text = ActionTextStyle()33
private val semantics = createComponentSemantics(scope, SemanticRole.Tab)34
init {35
when (semantics) {36
case Some(val handle) -> {37
handle.bindFocus(Some(control.focus))38
handle.mergeLabels = true39
scope.routeSemanticsChildren(Some(handle))40
}41
case None -> {}42
}43
}45
public override fun render(): View {46
val input = props.value47
val interaction = control.press.interaction48
val visual = SurfaceVisual(input.style.kind, interaction.asVisual(input.enabled, false))49
val shape = ActionShape.Tab(input.variant, input.selected)50
val base =51
text.resolve(52
input.theme.tokens.typography.action,53
actionTextColor(input.theme, shape, ButtonVariant.Ghost, visual),54
input.style.text,55
actionFontScale(shape),56
actionLineHeight(shape)57
)58
return element(59
TabIndicatorProps(60
input.selected && input.variant == TabsVariant.Line,61
input.axis,62
input.theme,63
input.enabled64
),65
{ current, mount -> TabIndicator(current, scope = mount) },66
[67
element(68
ActionInkProps(69
input.theme,70
shape,71
ButtonVariant.Ghost,72
input.style,73
visual,74
ActionBehavior.Press(control, input.activate, input.focus),75
semantics = semantics,76
semanticOptions = input.semantics,77
semanticState =78
Some(79
input.semantics.properties(80
enabled = input.enabled,81
selected = Some(input.selected)82
)83
),84
semanticActions =85
Some(86
SemanticActions(87
invoke = Some(input.select),88
setSelected =89
Some {90
value -> if (value)91
input.select()92
else93
SemanticActionResult.Rejected94
}95
)96
)97
),98
{ current, mount -> ActionInk(current, scope = mount) },99
[100
actionContent(101
input.content,102
actionContentStyle(base, shape, ButtonVariant.Ghost, visual.interaction)103
)104
]105
)106
]107
)108
}109
}