Scoop API

scoop:scoop.ui.style.shadcn:0.1.0

src/theme.scoop

Selected production source · src/theme.scoop

1package scoop.ui.style.shadcn
3import scoop.graphics.*
4import scoop.graphics.text.*
5import scoop.surface.AnimationSpec
6import scoop.time.Duration
7import scoop.ui.style.*
9/** Base Nova / Neutral, using the shared geometry and painter. */
10public fun shadcnTheme(
11 mode: ThemeMode = ThemeMode.Light,
12 palette: ThemePalette? = None,
13 configure: ShapeThemeBuilder.() -> Unit = {}
14): ShapeTheme {
15 val dark = mode == ThemeMode.Dark
16 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.0
20 this.lineHeight = Some(20.0 / 14.0)
21 this.color = colors.background.foreground
22 }
23 val fonts = themeTypography(
24 body,
25 body
26 .copy {
27 this.fontSize = 12.0
28 this.lineHeight = Some(16.0 / 12.0)
29 this.color = colors.muted.foreground
30 },
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 colors
40 .destructive
41 .background
42 .withAlpha(
43 if (dark) 0.4 else 0.2
44 ),
45 3.0,
46 3.0,
47 Some(
48 colors
49 .destructive
50 .background
51 .withAlpha(
52 if (dark) 0.5 else 1.0
53 )
54 )
55 )
56 ) {
57 this.mode = mode
58 this.disabledOpacity = 0.5
59 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 else
74 Color.Transparent
75 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.outset
83 ),
84 StateColors(
85 inputFill,
86 inputFill,
87 inputFill,
88 colors
89 .input
90 .withAlpha(
91 colors.input.alpha * if (dark) 0.8 else 0.5
92 )
93 ),
94 states(colors.input),
95 foreground,
96 focus
97 )
98 val outlineFill = if (dark) inputFill else colors.background.background
99 val outlineHover = if (dark)
100 colors.input.withAlpha(colors.input.alpha * 0.5)
101 else
102 colors.muted.background
103 val outlinedAction = plain
104 .copy {
105 fill = StateColors(
106 outlineFill, outlineHover,
107 mixThemeColor(outlineHover, colors.background.foreground, 0.08), outlineFill
108 )
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.outset
119 ),
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.background
125 ),
126 StateColors.solid(Color.Transparent),
127 states(colors.primary.foreground),
128 focus
129 )
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.outset
138 ),
139 states(colors.popover.background),
140 states(colors.border),
141 states(colors.popover.foreground),
142 focus
143 ) { 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 focus
151 )
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.outset
164 ),
165 marker
166 ),
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 foreground
174 ),
175 configure
176 )
179private fun states(color: Color): StateColors = StateColors.solid(color)