scoop:scoop.ui.style.shadcn:0.1.0
src/theme.scoop
Selected production source · src/theme.scoop
1
package scoop.ui.style.shadcn3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.surface.AnimationSpec6
import scoop.time.Duration7
import scoop.ui.style.*9
/** Base Nova / Neutral, using the shared geometry and painter. */10
public fun shadcnTheme(11
mode: ThemeMode = ThemeMode.Light,12
palette: ThemePalette? = None,13
configure: ShapeThemeBuilder.() -> Unit = {}14
): ShapeTheme {15
val dark = mode == ThemeMode.Dark16
val colors = palette ?: if (dark) darkPalette() else lightPalette()17
val body = textStyle {18
this.families = ["Inter", "Helvetica Neue", "Arial", "sans-serif"]19
this.fontSize = 14.020
this.lineHeight = Some(20.0 / 14.0)21
this.color = colors.background.foreground22
}23
val fonts = themeTypography(24
body,25
body26
.copy {27
this.fontSize = 12.028
this.lineHeight = Some(16.0 / 12.0)29
this.color = colors.muted.foreground30
},31
body.copy { this.weight = 500 }32
)33
val tokens = themeTokens(34
colors,35
fonts,36
ThemeSpacing(4.0, 8.0, 16.0),37
ThemeCorners(6.0, 8.0, 10.0),38
OutlineStyle(39
colors40
.destructive41
.background42
.withAlpha(43
if (dark) 0.4 else 0.244
),45
3.0,46
3.0,47
Some(48
colors49
.destructive50
.background51
.withAlpha(52
if (dark) 0.5 else 1.053
)54
)55
)56
) {57
this.mode = mode58
this.disabledOpacity = 0.559
motion {60
this.hover = Some(AnimationSpec.Tween(Duration.milliseconds(150L)))61
this.press = Some(AnimationSpec.Tween(Duration.milliseconds(75L)))62
this.selection = Some(AnimationSpec.Tween(Duration.milliseconds(150L)))63
}64
effects {65
this.raised = [BoxShadow(Point(0.0, 1.0), 1.0, 1.0, colors.shadow)]66
this.floating = [BoxShadow(Point(0.0, 4.0), 6.0, 6.0, colors.shadow)]67
}68
}69
val focus = OutlineStyle(colors.ring.withAlpha(0.5), 3.0, 3.0, Some(colors.ring))70
val foreground = states(colors.background.foreground)71
val inputFill = if (dark)72
colors.input.withAlpha(colors.input.alpha * 0.3)73
else74
Color.Transparent75
val plain = surfacePart(76
SurfaceMetrics(77
Size(0.0, 32.0),78
Size(0.0, 0.0),79
Insets(10.0, 4.0, 10.0, 4.0),80
Insets.all(1.0),81
CornerRadii.all(10.0),82
focus.outset83
),84
StateColors(85
inputFill,86
inputFill,87
inputFill,88
colors89
.input90
.withAlpha(91
colors.input.alpha * if (dark) 0.8 else 0.592
)93
),94
states(colors.input),95
foreground,96
focus97
)98
val outlineFill = if (dark) inputFill else colors.background.background99
val outlineHover = if (dark)100
colors.input.withAlpha(colors.input.alpha * 0.5)101
else102
colors.muted.background103
val outlinedAction = plain104
.copy {105
fill = StateColors(106
outlineFill, outlineHover,107
mixThemeColor(outlineHover, colors.background.foreground, 0.08), outlineFill108
)109
border = states(if (dark) colors.input else colors.border)110
}111
val action = surfacePart(112
SurfaceMetrics(113
Size(0.0, 32.0),114
Size(0.0, 0.0),115
Insets(10.0, 4.0, 10.0, 4.0),116
Insets.all(1.0),117
CornerRadii.all(10.0),118
focus.outset119
),120
StateColors(121
colors.primary.background,122
colors.primary.background.withAlpha(colors.primary.background.alpha * 0.8),123
colors.primary.background.withAlpha(colors.primary.background.alpha * 0.65),124
colors.primary.background125
),126
StateColors.solid(Color.Transparent),127
states(colors.primary.foreground),128
focus129
)130
val elevated = surfacePart(131
SurfaceMetrics(132
Size(0.0, 0.0),133
Size(0.0, 0.0),134
Insets.all(16.0),135
Insets.all(1.0),136
CornerRadii.all(10.0),137
focus.outset138
),139
states(colors.popover.background),140
states(colors.border),141
states(colors.popover.foreground),142
focus143
) { this.shadows = tokens.effects.floating }144
val marker = markerAppearance(145
states(inputFill),146
states(colors.primary.background),147
states(colors.input),148
states(colors.primary.background),149
states(colors.primary.foreground),150
focus151
)152
return shapeTheme(153
tokens,154
surfaceParts(plain, action, outlinedAction, elevated),155
checkboxPart(156
CheckboxMetrics(157
Size(16.0, 16.0),158
Size(16.0, 16.0),159
Insets.all(1.0),160
CornerRadii.all(4.0),161
3.0,162
2.0,163
focus.outset164
),165
marker166
),167
radioPart(RadioMetrics(Size(16.0, 16.0), Size(16.0, 16.0), 1.0, 4.0, focus.outset), marker),168
scrollbarPart(169
ScrollbarMetrics(10.0, 24.0, 0.0, 2.0, 5.0, None),170
StateColors.solid(Color.Transparent),171
states(colors.border),172
StateColors.solid(Color.Transparent),173
foreground174
),175
configure176
)177
}179
private fun states(color: Color): StateColors = StateColors.solid(color)