Scoop API

scoop:scoop.ui.component:0.1.0

src/conversation/bubble_colors.scoop

Selected production source · src/conversation/bubble_colors.scoop

1package scoop.ui.component
3import scoop.graphics.Color
4import scoop.ui.style.*
6internal struct BubbleColors(
7 val background: Color,
8 val foreground: Color,
9 val hover: Color,
10 val border: Color
13internal fun bubbleColors(variant: BubbleVariant, theme: Theme): BubbleColors {
14 val p = theme.tokens.palette
15 val dark = theme.tokens.mode == ThemeMode.Dark
16 val foreground =
17 when (variant) {
18 case Default -> p.primary.foreground
19 case Secondary -> p.secondary.foreground
20 case Destructive -> p.destructive.background
21 else -> p.background.foreground
22 }
23 val background =
24 when (variant) {
25 case Default -> p.primary.background
26 case Secondary -> p.secondary.background
27 case Muted -> p.muted.background
28 case Tinted -> bubbleTint(
29 p.primary.background,
30 if (dark)
31 0.3
32 else
33 0.93,
34 0.4
35 )
36 case Outline -> p.background.background
37 case Ghost -> Color.Transparent
38 case Destructive -> p.destructive.background.withAlpha(
39 if (dark)
40 0.2
41 else
42 0.1
43 )
44 }
45 val hover =
46 when (variant) {
47 case Default -> background.withAlpha(background.alpha * 0.8)
48 case Tinted -> bubbleTint(
49 p.primary.background,
50 if (dark)
51 0.35
52 else
53 0.88,
54 0.5
55 )
56 case Destructive -> p.destructive.background.withAlpha(
57 if (dark)
58 0.3
59 else
60 0.2
61 )
62 case Ghost -> p.muted.background.withAlpha(
63 if (dark)
64 0.5
65 else
66 1.0
67 )
68 case Outline -> p.muted.background
69 else -> secondaryHover(background, p.background.foreground)
70 }
71 return BubbleColors(
72 background,
73 foreground,
74 hover,
75 if (variant == BubbleVariant.Outline)
76 p.border
77 else
78 Color.Transparent
79 )