Skip to content

Commit d784ca3

Browse files
authored
[Rich text editor] Update code and links style (#1362)
1 parent f1ad735 commit d784ca3

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencyanalysis = "1.22.0"
4646
stem = "2.3.0"
4747
sqldelight = "1.5.5"
4848
telephoto = "0.6.0"
49-
wysiwyg = "2.10.2"
49+
wysiwyg = "2.12.0"
5050

5151
# DI
5252
dagger = "2.48"

libraries/designsystem/src/main/kotlin/io/element/android/libraries/designsystem/theme/ColorAliases.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ val SemanticColors.iconSuccessPrimaryBackground
8484
Color(0xff002513)
8585
}
8686

87+
// This color is not present in Semantic color, so put hard-coded value for now
88+
val SemanticColors.bgSubtleTertiary
89+
get() = if (isLight) {
90+
// We want LightDesignTokens.colorGray100
91+
Color(0xfffbfcfd)
92+
} else {
93+
// We want DarkDesignTokens.colorGray100
94+
Color(0xff14171b)
95+
}
96+
8797
// Temporary color, which is not in the token right now
8898
val SemanticColors.temporaryColorBgSpecial
8999
get() = if (isLight) Color(0xFFE4E8F0) else Color(0xFF3A4048)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2023 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.element.android.libraries.textcomposer
18+
19+
import androidx.compose.material3.MaterialTheme
20+
import androidx.compose.runtime.Composable
21+
import androidx.compose.ui.unit.dp
22+
import io.element.android.libraries.designsystem.theme.bgSubtleTertiary
23+
import io.element.android.libraries.theme.ElementTheme
24+
import io.element.android.wysiwyg.compose.RichTextEditorDefaults
25+
import io.element.android.wysiwyg.compose.RichTextEditorStyle
26+
27+
internal object ElementRichTextEditorStyle {
28+
@Composable
29+
fun create(
30+
hasFocus: Boolean,
31+
) : RichTextEditorStyle {
32+
val colors = ElementTheme.colors
33+
val m3colors = MaterialTheme.colorScheme
34+
val codeCornerRadius = 4.dp
35+
val codeBorderWidth = 1.dp
36+
return RichTextEditorDefaults.style(
37+
text = RichTextEditorDefaults.textStyle(
38+
color = if (hasFocus) {
39+
m3colors.primary
40+
} else {
41+
m3colors.secondary
42+
}
43+
),
44+
cursor = RichTextEditorDefaults.cursorStyle(
45+
color = colors.iconAccentTertiary,
46+
),
47+
link = RichTextEditorDefaults.linkStyle(
48+
color = colors.textLinkExternal,
49+
),
50+
codeBlock = RichTextEditorDefaults.codeBlockStyle(
51+
leadingMargin = 8.dp,
52+
background = RichTextEditorDefaults.codeBlockBackgroundStyle(
53+
color = colors.bgSubtleTertiary,
54+
borderColor = colors.borderInteractiveSecondary,
55+
cornerRadius = codeCornerRadius,
56+
borderWidth = codeBorderWidth,
57+
)
58+
),
59+
inlineCode = RichTextEditorDefaults.inlineCodeStyle(
60+
verticalPadding = 0.dp,
61+
background = RichTextEditorDefaults.inlineCodeBackgroundStyle(
62+
color = colors.bgSubtleTertiary,
63+
borderColor = colors.borderInteractiveSecondary,
64+
cornerRadius = codeCornerRadius,
65+
borderWidth = codeBorderWidth,
66+
)
67+
),
68+
)
69+
}
70+
}

libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ import io.element.android.libraries.textcomposer.components.FormattingOptionStat
8181
import io.element.android.libraries.theme.ElementTheme
8282
import io.element.android.libraries.ui.strings.CommonStrings
8383
import io.element.android.wysiwyg.compose.RichTextEditor
84-
import io.element.android.wysiwyg.compose.RichTextEditorDefaults
8584
import io.element.android.wysiwyg.compose.RichTextEditorState
8685
import io.element.android.wysiwyg.view.models.InlineFormat
8786
import io.element.android.wysiwyg.view.models.LinkAction
@@ -274,17 +273,8 @@ private fun TextInput(
274273
modifier = Modifier
275274
.padding(top = 6.dp, bottom = 6.dp)
276275
.fillMaxWidth(),
277-
style = RichTextEditorDefaults.style(
278-
text = RichTextEditorDefaults.textStyle(
279-
color = if (state.hasFocus) {
280-
MaterialTheme.colorScheme.primary
281-
} else {
282-
MaterialTheme.colorScheme.secondary
283-
}
284-
),
285-
cursor = RichTextEditorDefaults.cursorStyle(
286-
color = ElementTheme.colors.iconAccentTertiary,
287-
)
276+
style = ElementRichTextEditorStyle.create(
277+
hasFocus = state.hasFocus
288278
),
289279
onError = onError
290280
)

0 commit comments

Comments
 (0)