Skip to content

Commit 5bbe640

Browse files
authored
Migrate Custom design system page to M3 (#325)
* Migrate Custom design system page to M3 * Apply Spotless --------- Co-authored-by: riggaroo <[email protected]>
1 parent 1dbad15 commit 5bbe640

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/designsystems/CustomDesignSystem.kt

+16-31
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
package com.example.compose.snippets.designsystems
1818

19+
import androidx.compose.foundation.isSystemInDarkTheme
1920
import androidx.compose.foundation.layout.RowScope
2021
import androidx.compose.foundation.shape.RoundedCornerShape
2122
import androidx.compose.foundation.shape.ZeroCornerSize
22-
import androidx.compose.material.Colors
23-
import androidx.compose.material.ContentAlpha
2423
import androidx.compose.material3.Button
2524
import androidx.compose.material3.ButtonDefaults
25+
import androidx.compose.material3.ColorScheme
2626
import androidx.compose.material3.MaterialTheme
2727
import androidx.compose.material3.ProvideTextStyle
2828
import androidx.compose.material3.Shapes
@@ -38,28 +38,13 @@ import androidx.compose.ui.text.TextStyle
3838
import androidx.compose.ui.unit.Dp
3939
import androidx.compose.ui.unit.dp
4040
import androidx.compose.ui.unit.sp
41-
import com.example.compose.snippets.designsystems.FullyCustomDesignSystem.CustomTheme.elevation
4241

43-
/*
44-
* Copyright 2022 The Android Open Source Project
45-
*
46-
* Licensed under the Apache License, Version 2.0 (the "License");
47-
* you may not use this file except in compliance with the License.
48-
* You may obtain a copy of the License at
49-
*
50-
* http://www.apache.org/licenses/LICENSE-2.0
51-
*
52-
* Unless required by applicable law or agreed to in writing, software
53-
* distributed under the License is distributed on an "AS IS" BASIS,
54-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55-
* See the License for the specific language governing permissions and
56-
* limitations under the License.
57-
*/
5842
private object CustomDesignSystemExtend {
5943
// [START android_compose_designsystems_custom_extend]
60-
// Use with MaterialTheme.colors.snackbarAction
61-
val Colors.snackbarAction: Color
62-
get() = if (isLight) Red300 else Red700
44+
// Use with MaterialTheme.colorScheme.snackbarAction
45+
val ColorScheme.snackbarAction: Color
46+
@Composable
47+
get() = if (isSystemInDarkTheme()) Red300 else Red700
6348

6449
// Use with MaterialTheme.typography.textFieldInput
6550
val Typography.textFieldInput: TextStyle
@@ -78,14 +63,14 @@ private object CustomDesignSystemExtendTheme {
7863
// [START android_compose_designsystems_custom_extend_theme]
7964
@Immutable
8065
data class ExtendedColors(
81-
val tertiary: Color,
82-
val onTertiary: Color
66+
val caution: Color,
67+
val onCaution: Color
8368
)
8469

8570
val LocalExtendedColors = staticCompositionLocalOf {
8671
ExtendedColors(
87-
tertiary = Color.Unspecified,
88-
onTertiary = Color.Unspecified
72+
caution = Color.Unspecified,
73+
onCaution = Color.Unspecified
8974
)
9075
}
9176

@@ -95,8 +80,8 @@ private object CustomDesignSystemExtendTheme {
9580
content: @Composable () -> Unit
9681
) {
9782
val extendedColors = ExtendedColors(
98-
tertiary = Color(0xFFA8EFF0),
99-
onTertiary = Color(0xFF002021)
83+
caution = Color(0xFFFFCC02),
84+
onCaution = Color(0xFF2C2D30)
10085
)
10186
CompositionLocalProvider(LocalExtendedColors provides extendedColors) {
10287
MaterialTheme(
@@ -106,7 +91,7 @@ private object CustomDesignSystemExtendTheme {
10691
}
10792
}
10893

109-
// Use with eg. ExtendedTheme.colors.tertiary
94+
// Use with eg. ExtendedTheme.colors.caution
11095
object ExtendedTheme {
11196
val colors: ExtendedColors
11297
@Composable
@@ -123,8 +108,8 @@ private object CustomDesignSystemExtendTheme {
123108
) {
124109
Button(
125110
colors = ButtonDefaults.buttonColors(
126-
containerColor = ExtendedTheme.colors.tertiary,
127-
contentColor = ExtendedTheme.colors.onTertiary
111+
containerColor = ExtendedTheme.colors.caution,
112+
contentColor = ExtendedTheme.colors.onCaution
128113
/* Other colors use values from MaterialTheme */
129114
),
130115
onClick = onClick,
@@ -340,7 +325,7 @@ object FullyCustomDesignSystem {
340325
.copy(alpha = 0.12f)
341326
.compositeOver(CustomTheme.colors.component),
342327
disabledContentColor = CustomTheme.colors.content
343-
.copy(alpha = ContentAlpha.disabled)
328+
.copy(alpha = 0.38f)
344329
),
345330
shape = ButtonShape,
346331
elevation = ButtonDefaults.elevatedButtonElevation(

0 commit comments

Comments
 (0)