-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
Theme.kt
171 lines (160 loc) · 5.2 KB
/
Theme.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.jetsnack.ui.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.Colors
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
private val LightColorPalette = JetsnackColors(
brand = Shadow5,
brandSecondary = Ocean3,
uiBackground = Neutral0,
uiBorder = Neutral4,
uiFloated = FunctionalGrey,
textSecondary = Neutral7,
textHelp = Neutral6,
textInteractive = Neutral0,
textLink = Ocean11,
iconSecondary = Neutral7,
iconInteractive = Neutral0,
iconInteractiveInactive = Neutral1,
error = FunctionalRed,
gradient6_1 = listOf(Shadow4, Ocean3, Shadow2, Ocean3, Shadow4),
gradient6_2 = listOf(Rose4, Lavender3, Rose2, Lavender3, Rose4),
gradient3_1 = listOf(Shadow2, Ocean3, Shadow4),
gradient3_2 = listOf(Rose2, Lavender3, Rose4),
gradient2_1 = listOf(Shadow4, Shadow11),
gradient2_2 = listOf(Ocean3, Shadow3),
gradient2_3 = listOf(Lavender3, Rose2),
tornado1 = listOf(Shadow4, Ocean3),
isDark = false
)
private val DarkColorPalette = JetsnackColors(
brand = Shadow1,
brandSecondary = Ocean2,
uiBackground = Neutral8,
uiBorder = Neutral3,
uiFloated = FunctionalDarkGrey,
textPrimary = Shadow1,
textSecondary = Neutral0,
textHelp = Neutral1,
textInteractive = Neutral7,
textLink = Ocean2,
iconPrimary = Shadow1,
iconSecondary = Neutral0,
iconInteractive = Neutral7,
iconInteractiveInactive = Neutral6,
error = FunctionalRedDark,
gradient6_1 = listOf(Shadow5, Ocean7, Shadow9, Ocean7, Shadow5),
gradient6_2 = listOf(Rose11, Lavender7, Rose8, Lavender7, Rose11),
gradient3_1 = listOf(Shadow9, Ocean7, Shadow5),
gradient3_2 = listOf(Rose8, Lavender7, Rose11),
gradient2_1 = listOf(Ocean3, Shadow3),
gradient2_2 = listOf(Ocean4, Shadow2),
gradient2_3 = listOf(Lavender3, Rose3),
tornado1 = listOf(Shadow4, Ocean3),
isDark = true
)
@Composable
fun JetsnackTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = if (darkTheme) DarkColorPalette else LightColorPalette
ProvideJetsnackColors(colors) {
MaterialTheme(
colors = debugColors(darkTheme),
typography = Typography,
shapes = Shapes,
content = content
)
}
}
object JetsnackTheme {
val colors: JetsnackColors
@Composable
get() = LocalJetsnackColors.current
}
/**
* Jetsnack custom Color Palette
*/
@Immutable
data class JetsnackColors(
val gradient6_1: List<Color>,
val gradient6_2: List<Color>,
val gradient3_1: List<Color>,
val gradient3_2: List<Color>,
val gradient2_1: List<Color>,
val gradient2_2: List<Color>,
val gradient2_3: List<Color>,
val brand: Color,
val brandSecondary: Color,
val uiBackground: Color,
val uiBorder: Color,
val uiFloated: Color,
val interactivePrimary: List<Color> = gradient2_1,
val interactiveSecondary: List<Color> = gradient2_2,
val interactiveMask: List<Color> = gradient6_1,
val textPrimary: Color = brand,
val textSecondary: Color,
val textHelp: Color,
val textInteractive: Color,
val textLink: Color,
val tornado1: List<Color>,
val iconPrimary: Color = brand,
val iconSecondary: Color,
val iconInteractive: Color,
val iconInteractiveInactive: Color,
val error: Color,
val notificationBadge: Color = error,
val isDark: Boolean
)
@Composable
fun ProvideJetsnackColors(
colors: JetsnackColors,
content: @Composable () -> Unit
) {
CompositionLocalProvider(LocalJetsnackColors provides colors, content = content)
}
private val LocalJetsnackColors = staticCompositionLocalOf<JetsnackColors> {
error("No JetsnackColorPalette provided")
}
/**
* A Material [Colors] implementation which sets all colors to [debugColor] to discourage usage of
* [MaterialTheme.colors] in preference to [JetsnackTheme.colors].
*/
fun debugColors(
darkTheme: Boolean,
debugColor: Color = Color.Magenta
) = Colors(
primary = debugColor,
primaryVariant = debugColor,
secondary = debugColor,
secondaryVariant = debugColor,
background = debugColor,
surface = debugColor,
error = debugColor,
onPrimary = debugColor,
onSecondary = debugColor,
onBackground = debugColor,
onSurface = debugColor,
onError = debugColor,
isLight = !darkTheme
)