scoop:scoop.ui.component:0.1.0
src/otp/style.scoop
Selected production source · src/otp/style.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.ui.style.*7
public class InputOtpStyle internal constructor(8
public val cellSize: Size? = None,9
public val gap: Double = 8.0,10
public val surface: StyleOverride = styleOverride(),11
public val text: SpanStyle? = None,12
public val focusOutline: OutlineStyle? = None,13
public val validation: OutlineStyle? = None,14
public val selectionColor: Color? = None,15
public val inactiveSelectionColor: Color? = None,16
public val caretColor: Color? = None,17
public val markedColor: Color? = None,18
public val caretWidth: Double? = None,19
/** Uses the theme pair by default; a local selection background keeps original glyph colors. */20
public val selectionTextColor: Color? = None,21
public val inactiveSelectionTextColor: Color? = None22
) {23
init {24
nonnegative(gap, "invalid OTP gap")25
when (caretWidth) {26
case Some(val value) -> requireComponent(27
value.isFinite() && value > 0.0,28
"invalid OTP caret width"29
)30
case None -> {}31
}32
when (cellSize) {33
case Some(val size) -> requireComponent(34
size.width.isFinite() &&35
size.height.isFinite() &&36
size.width >37
0.0 &&38
size.height >39
0.0,40
"invalid OTP cell size"41
)42
case None -> {}43
}44
}45
public fun copy(configure: InputOtpStyleBuilder.() -> Unit = {}): InputOtpStyle {46
val builder = InputOtpStyleBuilder(this)47
builder.configure()48
return builder.snapshot()49
}50
}52
public fun inputOtpStyle(configure: InputOtpStyleBuilder.() -> Unit = {}): InputOtpStyle =53
InputOtpStyle().copy(configure)55
public class InputOtpStyleBuilder internal constructor(initial: InputOtpStyle) {56
public var cellSize: Size? = initial.cellSize57
public var gap: Double = initial.gap58
public var surface: StyleOverride = initial.surface59
public var text: SpanStyle? = initial.text60
public var focusOutline: OutlineStyle? = initial.focusOutline61
public var validation: OutlineStyle? = initial.validation62
public var selectionColor: Color? = initial.selectionColor63
public var inactiveSelectionColor: Color? = initial.inactiveSelectionColor64
public var selectionTextColor: Color? = initial.selectionTextColor65
public var inactiveSelectionTextColor: Color? = initial.inactiveSelectionTextColor66
public var caretColor: Color? = initial.caretColor67
public var markedColor: Color? = initial.markedColor68
public var caretWidth: Double? = initial.caretWidth69
public fun surface(configure: StyleOverrideBuilder.() -> Unit) {70
surface = surface.copy(configure)71
}72
public fun text(configure: SpanStyleBuilder.() -> Unit) {73
text = Some(configureOptionalSpanStyle(text, configure))74
}75
internal fun snapshot(): InputOtpStyle =76
InputOtpStyle(77
cellSize,78
gap,79
surface,80
text,81
focusOutline,82
validation,83
selectionColor,84
inactiveSelectionColor,85
caretColor,86
markedColor,87
caretWidth,88
selectionTextColor,89
inactiveSelectionTextColor90
)91
}93
internal fun otpOptions(94
theme: Theme,95
style: InputOtpStyle,96
visual: InteractionVisual97
): SurfaceOptions {98
val options =99
surfaceOptions {100
this.focus = style.focusOutline;101
this.validation = style.validation102
}103
val color = controlBorder(theme, options, visual, theme.tokens.palette.input)104
val base =105
styleOverride {106
this.background(107
Some(108
Paint(109
if (theme.preferences.highContrast || theme.preferences.reduceTransparency)110
theme.tokens.palette.background.background111
else112
if (theme.tokens.mode == ThemeMode.Dark)113
theme.tokens.palette.input.withAlpha(114
theme.tokens.palette.input.alpha * 0.3115
)116
else117
Color.Transparent118
)119
)120
)121
this.border(Some(Border.all(1.0, color)))122
this.corners(Corners.all(theme.tokens.corners.medium))123
this.boxShadows([])124
}125
return options.copy {126
this.style = base.then(style.surface)127
this.padding = Some(Insets.all(0.0))128
this.minimumSize = Some(Size(0.0, 0.0))129
}130
}