scoop:scoop.ui.component:0.1.0
src/typography/roles.scoop
Selected production source · src/typography/roles.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.ui.style.*7
public enum TypographyRole {8
H1, H2, H3, H4, P, Blockquote, InlineCode, Lead, Large, Small, Muted9
}11
internal fun typographyStyle(role: TypographyRole, theme: Theme): TextStyle {12
val body = theme.tokens.typography.body13
val density = body.fontSize / 14.014
val(size, height, weight) =15
when (role) {16
case H1 -> (36.0, 40.0, 800)17
case H2 -> (30.0, 36.0, 600)18
case H3 -> (24.0, 32.0, 600)19
case H4 -> (20.0, 28.0, 600)20
case P -> (16.0, 28.0, 400)21
case Blockquote -> (16.0, 24.0, 400)22
case InlineCode -> (14.0, 20.0, 600)23
case Lead -> (20.0, 28.0, 400)24
case Large -> (18.0, 28.0, 600)25
case Small -> (14.0, 14.0, 500)26
case Muted -> (14.0, 20.0, 400)27
}28
return body.copy {29
this.fontSize = size * density30
this.lineHeight = Some(height / size)31
this.weight = weight32
this.color =33
if (role == TypographyRole.Lead || role == TypographyRole.Muted)34
theme.tokens.palette.muted.foreground35
else36
theme.tokens.palette.background.foreground37
this.letterSpacing =38
when (role) {39
case H1 -> -0.025 * size * density40
case H2 -> -0.025 * size * density41
case H3 -> -0.025 * size * density42
case H4 -> -0.025 * size * density43
else -> 0.044
}45
if (role == TypographyRole.Blockquote)46
this.slant = FontSlant.Italic47
if (role == TypographyRole.InlineCode)48
this.families = ["monospace"]49
}50
}52
internal fun typographyDecoration(role: TypographyRole, theme: Theme): StyleOverride {53
val density = theme.tokens.typography.body.fontSize / 14.054
return styleOverride {55
when (role) {56
case H2 -> this.border(Some(bottomBorder(theme.tokens.palette.border)))57
case Blockquote -> this.border(58
Some(Border.Logical(start = BorderEdge(2.0 * density, theme.tokens.palette.border)))59
)60
case InlineCode -> {61
this.background(Some(Paint(theme.tokens.palette.muted.background)))62
this.corners(Corners.all(theme.tokens.corners.small))63
}64
else -> {}65
}66
}67
}69
internal fun typographyPadding(role: TypographyRole, density: Double): LogicalInsets =70
when (role) {71
case H2 -> LogicalInsets(bottom = 8.0 * density)72
case Blockquote -> LogicalInsets(start = 24.0 * density)73
case InlineCode -> LogicalInsets(74
start = 4.8 * density,75
end = 4.8 * density,76
top = 3.2 * density,77
bottom = 3.2 * density78
)79
else -> LogicalInsets()80
}