Merge develop into feature/fga/update_rust_sdk
This commit is contained in:
commit
22fd4ac7f0
410 changed files with 2937 additions and 607 deletions
|
|
@ -30,8 +30,12 @@ import androidx.compose.ui.geometry.Offset
|
|||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.ParagraphStyle
|
||||
import androidx.compose.ui.text.TextLayoutResult
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import kotlinx.collections.immutable.ImmutableMap
|
||||
import kotlinx.collections.immutable.persistentMapOf
|
||||
|
|
@ -88,3 +92,24 @@ fun ClickableLinkText(
|
|||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun ClickableLinkTextLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun ClickableLinkTextDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
ClickableLinkText(
|
||||
text = AnnotatedString("Hello", ParagraphStyle()),
|
||||
linkAnnotationTag = "",
|
||||
onClick = {},
|
||||
onLongClick = {},
|
||||
interactionSource = MutableInteractionSource(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ fun LabelledCheckbox(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun LabelledCheckboxLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun LabelledCheckboxLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun LabelledCheckboxDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun LabelledCheckboxDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -73,11 +73,11 @@ fun ProgressDialog(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ProgressDialogLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun ProgressDialogLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ProgressDialogDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun ProgressDialogDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.designsystem.components
|
||||
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
|
||||
@Composable
|
||||
fun VectorIcon(
|
||||
resourceId: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
tint: Color = LocalContentColor.current,
|
||||
) {
|
||||
androidx.compose.material3.Icon(
|
||||
painter = painterResource(id = resourceId),
|
||||
contentDescription = null,
|
||||
modifier = modifier,
|
||||
tint = tint
|
||||
)
|
||||
}
|
||||
|
|
@ -29,12 +29,14 @@ import androidx.compose.ui.graphics.Brush
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import io.element.android.libraries.designsystem.AvatarGradientEnd
|
||||
import io.element.android.libraries.designsystem.AvatarGradientStart
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.preview.debugPlaceholderAvatar
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import timber.log.Timber
|
||||
|
||||
|
|
@ -68,6 +70,7 @@ private fun ImageAvatar(
|
|||
},
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
placeholder = debugPlaceholderAvatar(),
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
|
|
@ -90,7 +93,7 @@ private fun InitialsAvatar(
|
|||
) {
|
||||
Text(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
text = avatarData.name.first().uppercase(),
|
||||
text = avatarData.getInitial(),
|
||||
fontSize = (avatarData.size.value / 2).sp,
|
||||
color = Color.White,
|
||||
)
|
||||
|
|
@ -99,13 +102,15 @@ private fun InitialsAvatar(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun AvatarLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
fun AvatarLightPreview(@PreviewParameter(AvatarDataProvider::class) avatarData: AvatarData) =
|
||||
ElementPreviewLight { ContentToPreview(avatarData) }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun AvatarDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
fun AvatarDarkPreview(@PreviewParameter(AvatarDataProvider::class) avatarData: AvatarData) =
|
||||
ElementPreviewDark { ContentToPreview(avatarData) }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
Avatar(AvatarData(name = "A"))
|
||||
private fun ContentToPreview(avatarData: AvatarData) {
|
||||
Avatar(avatarData)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,13 @@ import androidx.compose.runtime.Immutable
|
|||
|
||||
@Immutable
|
||||
data class AvatarData(
|
||||
val name: String = "",
|
||||
val id: String,
|
||||
val name: String?,
|
||||
val url: String? = null,
|
||||
val size: AvatarSize = AvatarSize.MEDIUM
|
||||
)
|
||||
) {
|
||||
fun getInitial(): String {
|
||||
val firstChar = name?.firstOrNull() ?: id.getOrNull(1) ?: '?'
|
||||
return firstChar.uppercase()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.designsystem.components.avatar
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
|
||||
open class AvatarDataProvider : PreviewParameterProvider<AvatarData> {
|
||||
override val values: Sequence<AvatarData>
|
||||
get() = sequenceOf(
|
||||
anAvatarData(),
|
||||
anAvatarData().copy(name = null),
|
||||
anAvatarData().copy(url = "aUrl"),
|
||||
)
|
||||
}
|
||||
|
||||
fun anAvatarData() = AvatarData(
|
||||
// Let's the id not start with a 'a'.
|
||||
id = "@id_of_alice:server.org",
|
||||
name = "Alice",
|
||||
)
|
||||
|
|
@ -117,11 +117,11 @@ fun ConfirmationDialog(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ConfirmationDialogLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun ConfirmationDialogLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ConfirmationDialogDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun ConfirmationDialogDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -86,11 +86,11 @@ fun ErrorDialog(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ErrorDialogLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun ErrorDialogLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ErrorDialogDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun ErrorDialogDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -60,11 +60,11 @@ fun PreferenceCategory(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceCategoryLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun PreferenceCategoryLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceCategoryDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun PreferenceCategoryDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -116,11 +116,11 @@ fun PreferenceTopAppBar(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceViewLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun PreferenceViewLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceViewDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun PreferenceViewDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -88,11 +88,11 @@ fun PreferenceSlide(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceSlideLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun PreferenceSlideLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceSlideDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun PreferenceSlideDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -79,11 +79,11 @@ fun PreferenceSwitch(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceSwitchLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun PreferenceSwitchLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceSwitchDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun PreferenceSwitchDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@ fun PreferenceText(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceTextLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun PreferenceTextLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreferenceTextDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun PreferenceTextDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.designsystem.components.preferences.components
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.BugReport
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
|
||||
open class ImageVectorProvider : PreviewParameterProvider<ImageVector?> {
|
||||
override val values: Sequence<ImageVector?>
|
||||
get() = sequenceOf(
|
||||
null,
|
||||
Icons.Default.BugReport,
|
||||
)
|
||||
}
|
||||
|
|
@ -22,7 +22,11 @@ import androidx.compose.foundation.layout.width
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||
import io.element.android.libraries.designsystem.toEnabledColor
|
||||
|
||||
|
|
@ -45,3 +49,18 @@ fun PreferenceIcon(
|
|||
Spacer(modifier = modifier.width(56.dp))
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun PreferenceIconLightPreview(@PreviewParameter(ImageVectorProvider::class) content: ImageVector?) =
|
||||
ElementPreviewLight { ContentToPreview(content) }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun PreferenceIconDarkPreview(@PreviewParameter(ImageVectorProvider::class) content: ImageVector?) =
|
||||
ElementPreviewDark { ContentToPreview(content) }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview(content: ImageVector?) {
|
||||
PreferenceIcon(content)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.designsystem.preview
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import io.element.android.libraries.designsystem.R
|
||||
|
||||
/**
|
||||
* I wanted to set up a FakeImageLoader as per https://github.com/coil-kt/coil/issues/1327
|
||||
* but it does not render in preview. In the meantime, you can use this trick to have image.
|
||||
*/
|
||||
@Composable
|
||||
fun debugPlaceholder(
|
||||
@DrawableRes debugPreview: Int,
|
||||
nonDebugPainter: Painter? = null,
|
||||
) = if (LocalInspectionMode.current) {
|
||||
painterResource(id = debugPreview)
|
||||
} else {
|
||||
nonDebugPainter
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun debugPlaceholderBackground(nonDebugPainter: Painter? = null): Painter? {
|
||||
return debugPlaceholder(debugPreview = R.drawable.sample_background, nonDebugPainter)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun debugPlaceholderAvatar(nonDebugPainter: Painter? = null): Painter? {
|
||||
return debugPlaceholder(debugPreview = R.drawable.sample_avatar, nonDebugPainter)
|
||||
}
|
||||
|
|
@ -47,11 +47,11 @@ fun ElementColors.roomListPlaceHolder() = if (isLight) SystemGrey6Light else Sys
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ColorAliasesLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun ColorAliasesLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ColorAliasesDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun ColorAliasesDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ fun elementColorsDark() = ElementColors(
|
|||
// TODO Lots of colors are missing
|
||||
val materialColorSchemeDark = darkColorScheme(
|
||||
primary = Color.White,
|
||||
// TODO onPrimary = ColorDarkTokens.OnPrimary,
|
||||
onPrimary = Color.Black,
|
||||
// TODO primaryContainer = ColorDarkTokens.PrimaryContainer,
|
||||
// TODO onPrimaryContainer = ColorDarkTokens.OnPrimaryContainer,
|
||||
// TODO inversePrimary = ColorDarkTokens.InversePrimary,
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ fun elementColorsLight() = ElementColors(
|
|||
// TODO Lots of colors are missing
|
||||
val materialColorSchemeLight = lightColorScheme(
|
||||
primary = Color.Black,
|
||||
// TODO onPrimary = ColorLightTokens.OnPrimary,
|
||||
onPrimary = Color.White,
|
||||
// TODO primaryContainer = ColorLightTokens.PrimaryContainer,
|
||||
// TODO onPrimaryContainer = ColorLightTokens.OnPrimaryContainer,
|
||||
// TODO inversePrimary = ColorLightTokens.InversePrimary,
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ fun Button(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ButtonsLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun ButtonsLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ButtonsDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun ButtonsDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -48,11 +48,11 @@ fun Checkbox(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun CheckboxesLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun CheckboxesLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun CheckboxesDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun CheckboxesDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -40,11 +40,11 @@ fun Divider(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun DividerLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun DividerLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun DividerDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun DividerDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@
|
|||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.FloatingActionButtonDefaults
|
||||
import androidx.compose.material3.FloatingActionButtonElevation
|
||||
import androidx.compose.material3.contentColorFor
|
||||
|
|
@ -25,6 +29,10 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
|
||||
@Composable
|
||||
fun FloatingActionButton(
|
||||
|
|
@ -48,3 +56,22 @@ fun FloatingActionButton(
|
|||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun FloatingActionButtonLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun FloatingActionButtonDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
Box(modifier = Modifier.padding(8.dp)) {
|
||||
FloatingActionButton(onClick = {}) {
|
||||
Icon(imageVector = Icons.Filled.Close, contentDescription = "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,19 @@
|
|||
|
||||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
|
||||
@Composable
|
||||
fun Icon(
|
||||
|
|
@ -52,3 +59,33 @@ fun Icon(
|
|||
tint = tint,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Icon(
|
||||
@DrawableRes resourceId: Int,
|
||||
contentDescription: String?,
|
||||
modifier: Modifier = Modifier,
|
||||
tint: Color = LocalContentColor.current,
|
||||
) {
|
||||
androidx.compose.material3.Icon(
|
||||
painter = painterResource(id = resourceId),
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier,
|
||||
tint = tint
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun IconImageVectorLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun IconImageVectorDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
Icon(imageVector = Icons.Filled.Close, contentDescription = "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,15 @@
|
|||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.IconButtonDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
|
||||
@Composable
|
||||
fun IconButton(
|
||||
|
|
@ -39,3 +44,20 @@ fun IconButton(
|
|||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun IconButtonLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun IconButtonDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
IconButton(onClick = {}) {
|
||||
Icon(imageVector = Icons.Filled.Close, contentDescription = "")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@file:OptIn(ExperimentalMaterial3Api::class)
|
||||
|
||||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
|
|
@ -24,6 +26,9 @@ import androidx.compose.material3.TopAppBarDefaults
|
|||
import androidx.compose.material3.TopAppBarScrollBehavior
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -46,3 +51,18 @@ fun MediumTopAppBar(
|
|||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun MediumTopAppBarLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun MediumTopAppBarDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
MediumTopAppBar(title = { Text(text = "Title") })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@file:OptIn(ExperimentalMaterialApi::class, ExperimentalMaterialApi::class)
|
||||
|
||||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
import androidx.compose.material.MaterialTheme
|
||||
|
|
@ -28,7 +31,10 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class)
|
||||
@Composable
|
||||
|
|
@ -55,3 +61,25 @@ fun ModalBottomSheetLayout(
|
|||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun ModalBottomSheetLayoutLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun ModalBottomSheetLayoutDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
ModalBottomSheetLayout(
|
||||
sheetState = ModalBottomSheetState(ModalBottomSheetValue.Expanded),
|
||||
sheetContent = {
|
||||
Text(text = "Sheet Content", modifier = Modifier.background(color = Color.Green))
|
||||
}
|
||||
) {
|
||||
Text(text = "Content", modifier = Modifier.background(color = Color.Red))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ package io.element.android.libraries.designsystem.theme.components
|
|||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
|
|
@ -31,8 +34,11 @@ import androidx.compose.ui.graphics.Shape
|
|||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.utils.allBooleans
|
||||
import io.element.android.libraries.designsystem.utils.asInt
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -84,22 +90,29 @@ fun OutlinedTextField(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun OutlinedTextFieldsLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun OutlinedTextFieldsLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun OutlinedTextFieldsDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun OutlinedTextFieldsDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
Column {
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = false, enabled = true, readOnly = true)
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = false, enabled = true, readOnly = false)
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = false, enabled = false, readOnly = true)
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = false, enabled = false, readOnly = false)
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = true, enabled = true, readOnly = true)
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = true, enabled = true, readOnly = false)
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = true, enabled = false, readOnly = true)
|
||||
OutlinedTextField(onValueChange = {}, value = "Content", isError = true, enabled = false, readOnly = false)
|
||||
Column(modifier = Modifier.padding(4.dp)) {
|
||||
allBooleans.forEach { isError ->
|
||||
allBooleans.forEach { enabled ->
|
||||
allBooleans.forEach { readonly ->
|
||||
OutlinedTextField(
|
||||
onValueChange = {},
|
||||
label = { Text(text = "label") },
|
||||
value = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
||||
isError = isError,
|
||||
enabled = enabled,
|
||||
readOnly = readonly,
|
||||
)
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,11 +55,11 @@ fun Slider(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun SlidersLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun SlidersLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun SlidersDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun SlidersDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.contentColorFor
|
||||
import androidx.compose.runtime.Composable
|
||||
|
|
@ -24,8 +26,11 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.RectangleShape
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
|
||||
@Composable
|
||||
fun Surface(
|
||||
|
|
@ -49,3 +54,20 @@ fun Surface(
|
|||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun SurfaceLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun SurfaceDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
Surface {
|
||||
Spacer(modifier = Modifier.size(64.dp))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,11 +132,11 @@ fun Text(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun TextLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun TextLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun TextDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun TextDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@
|
|||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
|
|
@ -29,6 +33,12 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.utils.allBooleans
|
||||
import io.element.android.libraries.designsystem.utils.asInt
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -77,3 +87,34 @@ fun TextField(
|
|||
colors = colors,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TextFieldLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TextFieldDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
Column(modifier = Modifier.padding(4.dp)) {
|
||||
allBooleans.forEach { isError ->
|
||||
allBooleans.forEach { enabled ->
|
||||
allBooleans.forEach { readonly ->
|
||||
TextField(
|
||||
onValueChange = {},
|
||||
label = { Text(text = "label") },
|
||||
value = "Hello er=${isError.asInt()}, en=${enabled.asInt()}, ro=${readonly.asInt()}",
|
||||
isError = isError,
|
||||
enabled = enabled,
|
||||
readOnly = readonly,
|
||||
)
|
||||
Spacer(modifier = Modifier.height(2.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@file:OptIn(ExperimentalMaterial3Api::class)
|
||||
|
||||
package io.element.android.libraries.designsystem.theme.components
|
||||
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
|
|
@ -24,6 +26,9 @@ import androidx.compose.material3.TopAppBarDefaults
|
|||
import androidx.compose.material3.TopAppBarScrollBehavior
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -46,3 +51,18 @@ fun TopAppBar(
|
|||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TopAppBarLightPreview() =
|
||||
ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
internal fun TopAppBarDarkPreview() =
|
||||
ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
TopAppBar(title = { Text(text = "Title") })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.designsystem.utils
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
|
||||
open class BooleanProvider : PreviewParameterProvider<Boolean> {
|
||||
override val values: Sequence<Boolean>
|
||||
get() = sequenceOf(false, true)
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.designsystem.utils
|
||||
|
||||
internal fun Boolean.asInt(): Int = if (this) 1 else 0
|
||||
|
||||
val allBooleans = listOf(false, true)
|
||||
|
|
@ -18,7 +18,7 @@ package io.element.android.libraries.designsystem.utils
|
|||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
|
||||
open class PairCombinedPreviewParameter<T1, T2>(
|
||||
open class PairCombinedProvider<T1, T2>(
|
||||
private val provider: Pair<PreviewParameterProvider<T1>, PreviewParameterProvider<T2>>
|
||||
) : PreviewParameterProvider<Pair<T1, T2>> {
|
||||
override val values: Sequence<Pair<T1, T2>>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.designsystem.utils
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
|
||||
open class StringProvider(val strings: List<String>) : PreviewParameterProvider<String> {
|
||||
override val values: Sequence<String>
|
||||
get() = strings.asSequence()
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<!--
|
||||
~ Copyright 2015 Google Inc. All Rights Reserved.
|
||||
~
|
||||
~ 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
|
||||
~
|
||||
~ http://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.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="128dp"
|
||||
android:height="128dp"
|
||||
android:viewportHeight="128.0"
|
||||
android:viewportWidth="128.0">
|
||||
<path
|
||||
android:fillColor="#448AFF"
|
||||
android:pathData="M0 0h128v128h-128z" />
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M73 18.7c-4.8 0,-9.7 0.8,-14 2.3,-0.1 0.1,-0.2 0.2,-0.4 0.3l-7.3 4.6c-0.6 0.4,-1.4 0.4,-2 0.1,-0.3,-0.2,-0.6,-0.4,-0.8,-0.7l-0.7,-1.1c-0.6,-1,-0.3,-2.2 0.6,-2.8l7.3,-4.6c0.4,-0.2 0.8,-0.3 1.2,-0.3,-5.5,-3,-23.7,-10.7,-33.7 10.7,-11.8 25.4 11 50.2,-14.4 62.6 0 0 26.2 13.7 40.9,-24.8 3.7 3.2 8.8 5.8 16 7.4,-0.6,-5.6 0.8,-9.8,-2.1,-12.8,-1.3,-1.4,-2.7,-1.5,-4,-2.4,-0.7,-0.5,-1.4,-0.9,-2,-1.3,-1.5,-0.9,-2.6,-1.3,-2.8,-1.4,-1.1,-1,-1.9,-2.4,-2.1,-4.1,-0.5,-3.6,-2.2,-6.9 1.1,-7.4 0.8,-0.1 1.6,-0.1 2.4 0.2 8,-1.5 11.6,-6.7 12.8,-8.9 3.4 4.8 11.7 9.8 31.9 6.8 0.3 1.1 0.6 1.2 0.8 2.4l0.5,-1.3c-0.1,-13,-13.2,-23.5,-29.2,-23.5zM56.1 43.2zM61.4 89.7s6 8.6 19.4 9.7c5.1 0.4 11.3,-0.3 18.6,-2.9,-0.1,-0.6,-0.3,-1.2,-0.4,-1.7,-0.2,-1.1,-3.2,-18,-3.4,-23.6,-0.2,-6.2 0.6,-10 1.6,-12.4h7.3l-2.1,-8.5c-0.1,-2,-0.4,-3.9,-0.6,-5.6 0,-0.3,-0.1,-0.7,-0.2,-1,-0.2,-1.1,-0.4,-2.3,-0.8,-3.4,-20.2 3,-28.5,-2,-31.9,-6.8,-1.2 2.1,-4.8 7.4,-12.8 8.9,-0.8,-0.2,-1.6,-0.3,-2.4,-0.2,-3.3 0.5,-5.6 3.8,-5.1 7.4 0.2 1.7 1 3.1 2.1 4.1 0.2 0.1 1.3 0.5 2.8 1.4 0.6 0.4 1.3 0.8 2 1.3 1.3 0.9 2.6 2 4 3.4 2.9 3 5.6 7.2 6.1 12.8 0.5 4.5,-0.6 10.2,-4.2 17.1zm27.5,-41.2c0.7 0 1.3 0.6 1.3 1.3s-0.6 1.3,-1.3 1.3,-1.3,-0.6,-1.3,-1.3 0.6,-1.3 1.3,-1.3zM56.1 43.2c0.1,-0.1 0,-0.1 0 0zM53.7 100.9l0.2,-0.2,-0.2 0.2z" />
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M88.9,49.8 m-2.0, 0 a 2.0,2.0 0 1,1 4.0,0 a2.0,2.0 0 1,1 -4.0,0" />
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M80.8 99.3c-13.3,-1.1,-19.4,-9.7,-19.4,-9.7,-1.8 3.4,-4.3 7.1,-7.5 11l-0.3 0.3c-0.4 0.5,-0.9 1.1,-1.4 1.7,-0.7 0.9,-1.6 2.1,-2.8 3.7,-2.3 3.2,-5.4 7.8,-8.8 13.5,-1.4 2.4,-2.9 5.1,-4.4 8 0 0 0 0.1,-0.1 0.1h71.3c-0.6,-1.6,-1.3,-3.2,-1.7,-4.8,-2.2,-8.6,-4.6,-17.9,-6.5,-26.8,-7.2 2.8,-13.3 3.5,-18.4 3zM55.7 16.7l-7.3 4.6c-1 0.6,-1.3 1.9,-0.6 2.8l0.7 1.1c0.2 0.3 0.5 0.6 0.8 0.7 0.6 0.3 1.4 0.3 2,-0.1l7.3,-4.6 0.4,-0.3c0.7,-0.7 0.8,-1.7 0.3,-2.5l-0.7,-1.1c-0.4,-0.6,-1,-0.9,-1.6,-1,-0.5 0,-1 0.1,-1.3 0.4z" />
|
||||
<path
|
||||
android:fillColor="#444"
|
||||
android:pathData="M73 18.7c-4.8 0,-9.7 0.8,-14 2.3,-0.1 0.1,-0.2 0.2,-0.4 0.3l-7.3 4.6c-0.6 0.4,-1.4 0.4,-2 0.1,-0.3,-0.2,-0.6,-0.4,-0.8,-0.7l-0.7,-1.1c-0.6,-1,-0.3,-2.2 0.6,-2.8l7.3,-4.6c0.4,-0.2 0.8,-0.3 1.2,-0.3,-5.5,-3,-23.7,-10.7,-33.7 10.7,-11.8 25.4 11 50.2,-14.4 62.6 0 0 26.2 13.7 40.9,-24.8 3.7 3.2 8.8 5.8 16 7.4,-0.6,-5.6 0.8,-9.8,-2.1,-12.8,-1.3,-1.4,-2.7,-1.5,-4,-2.4,-0.7,-0.5,-1.4,-0.9,-2,-1.3,-1.5,-0.9,-2.6,-1.3,-2.8,-1.4,-1.1,-1,-1.9,-2.4,-2.1,-4.1,-0.5,-3.6,-2.2,-6.9 1.1,-7.4 0.8,-0.1 1.6,-0.1 2.4 0.2 8,-1.5 11.6,-6.7 12.8,-8.9 3.4 4.8 11.7 9.8 31.9 6.8 0.3 1.1 0.6 1.2 0.8 2.4l0.5,-1.3c-0.1,-13,-13.2,-23.5,-29.2,-23.5zM56.1 43.2z" />
|
||||
<path
|
||||
android:fillColor="#FFE0B2"
|
||||
android:pathData="M61.4 89.7s6 8.6 19.4 9.7c5.1 0.4 11.3,-0.3 18.6,-2.9,-0.1,-0.6,-0.3,-1.2,-0.4,-1.7,-0.2,-1.1,-3.2,-18,-3.4,-23.6,-0.2,-6.2 0.6,-10 1.6,-12.4h7.3l-2.1,-8.5c-0.1,-2,-0.4,-3.9,-0.6,-5.6 0,-0.3,-0.1,-0.7,-0.2,-1,-0.2,-1.1,-0.4,-2.3,-0.8,-3.4,-20.2 3,-28.5,-2,-31.9,-6.8,-1.2 2.1,-4.8 7.4,-12.8 8.9,-0.8,-0.2,-1.6,-0.3,-2.4,-0.2,-3.3 0.5,-5.6 3.8,-5.1 7.4 0.2 1.7 1 3.1 2.1 4.1 0.2 0.1 1.3 0.5 2.8 1.4 0.6 0.4 1.3 0.8 2 1.3 1.3 0.9 2.6 2 4 3.4 2.9 3 5.6 7.2 6.1 12.8 0.5 4.5,-0.6 10.2,-4.2 17.1zm27.5,-41.2c0.7 0 1.3 0.6 1.3 1.3s-0.6 1.3,-1.3 1.3,-1.3,-0.6,-1.3,-1.3 0.6,-1.3 1.3,-1.3zM56.1 43.2c0.1,-0.1 0,-0.1 0 0z" />
|
||||
<path
|
||||
android:fillColor="#FFCC80"
|
||||
android:pathData="M53.7 100.9l0.2,-0.2,-0.2 0.2z" />
|
||||
<path
|
||||
android:fillColor="#444"
|
||||
android:pathData="M88.9,49.8 m-2.0, 0 a 2.0,2.0 0 1,1 4.0,0 a2.0,2.0 0 1,1 -4.0,0" />
|
||||
<path
|
||||
android:fillColor="#FF5722"
|
||||
android:pathData="M80.8 99.3c-13.3,-1.1,-19.4,-9.7,-19.4,-9.7,-1.8 3.4,-4.3 7.1,-7.5 11l-0.3 0.3c-0.4 0.5,-0.9 1.1,-1.4 1.7,-0.7 0.9,-1.6 2.1,-2.8 3.7,-2.3 3.2,-5.4 7.8,-8.8 13.5,-1.4 2.4,-2.9 5.1,-4.4 8 0 0 0 0.1,-0.1 0.1h71.3c-0.6,-1.6,-1.3,-3.2,-1.7,-4.8,-2.2,-8.6,-4.6,-17.9,-6.5,-26.8,-7.2 2.8,-13.3 3.5,-18.4 3z" />
|
||||
<path
|
||||
android:fillColor="#00BFA5"
|
||||
android:pathData="M55.7 16.7l-7.3 4.6c-1 0.6,-1.3 1.9,-0.6 2.8l0.7 1.1c0.2 0.3 0.5 0.6 0.8 0.7 0.6 0.3 1.4 0.3 2,-0.1l7.3,-4.6 0.4,-0.3c0.7,-0.7 0.8,-1.7 0.3,-2.5l-0.7,-1.1c-0.4,-0.6,-1,-0.9,-1.6,-1,-0.5 0,-1 0.1,-1.3 0.4z" />
|
||||
</vector>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
|
|
@ -19,6 +19,7 @@
|
|||
plugins {
|
||||
id("io.element.android-compose-library")
|
||||
alias(libs.plugins.anvil)
|
||||
alias(libs.plugins.ksp)
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
@ -38,4 +39,6 @@ dependencies {
|
|||
implementation(projects.libraries.designsystem)
|
||||
implementation(projects.libraries.core)
|
||||
implementation(libs.coil.compose)
|
||||
|
||||
ksp(libs.showkase.processor)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ class MatrixItemHelper @Inject constructor(
|
|||
val userDisplayName = client.loadUserDisplayName().getOrNull()
|
||||
val avatarData =
|
||||
AvatarData(
|
||||
userDisplayName ?: client.userId().value,
|
||||
client.userId().value,
|
||||
userDisplayName,
|
||||
userAvatarUrl,
|
||||
avatarSize
|
||||
)
|
||||
|
|
|
|||
|
|
@ -30,15 +30,14 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.matrix.core.UserId
|
||||
import io.element.android.libraries.matrix.ui.model.MatrixUser
|
||||
import io.element.android.libraries.matrix.ui.model.getBestName
|
||||
|
||||
|
|
@ -68,7 +67,7 @@ fun MatrixUserHeader(
|
|||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
)
|
||||
// Id
|
||||
if (matrixUser.username.isNullOrEmpty().not()) {
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
|
@ -85,38 +84,15 @@ fun MatrixUserHeader(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun MatrixUserHeaderLightPreview() = ElementPreviewLight { ContentToPreview1() }
|
||||
fun MatrixUserHeaderLightPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
|
||||
ElementPreviewLight { ContentToPreview(matrixUser) }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun MatrixUserHeaderDarkPreview() = ElementPreviewDark { ContentToPreview1() }
|
||||
fun MatrixUserHeaderDarkPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
|
||||
ElementPreviewDark { ContentToPreview(matrixUser) }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview1() {
|
||||
MatrixUserHeader(
|
||||
MatrixUser(
|
||||
id = UserId("@alice:server.org"),
|
||||
username = "Alice",
|
||||
avatarData = AvatarData("Alice")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun MatrixUserHeaderNoUserNameLightPreview() = ElementPreviewLight { ContentToPreview2() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun MatrixUserHeaderNoUserNameDarkPreview() = ElementPreviewDark { ContentToPreview2() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview2() {
|
||||
MatrixUserHeader(
|
||||
MatrixUser(
|
||||
id = UserId("@alice:server.org"),
|
||||
username = null,
|
||||
avatarData = AvatarData("Alice")
|
||||
)
|
||||
)
|
||||
private fun ContentToPreview(matrixUser: MatrixUser) {
|
||||
MatrixUserHeader(matrixUser)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2023 New Vector Ltd
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 io.element.android.libraries.matrix.ui.components
|
||||
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import io.element.android.libraries.designsystem.components.avatar.anAvatarData
|
||||
import io.element.android.libraries.matrix.core.UserId
|
||||
import io.element.android.libraries.matrix.ui.model.MatrixUser
|
||||
|
||||
open class MatrixUserProvider : PreviewParameterProvider<MatrixUser> {
|
||||
override val values: Sequence<MatrixUser>
|
||||
get() = sequenceOf(
|
||||
aMatrixUser(),
|
||||
aMatrixUser().copy(
|
||||
username = null,
|
||||
avatarData = anAvatarData().copy(name = null)
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fun aMatrixUser() = MatrixUser(
|
||||
id = UserId("@id_of_alice:server.org"),
|
||||
username = "Alice",
|
||||
avatarData = anAvatarData()
|
||||
)
|
||||
|
||||
open class MatrixUserWithNullProvider : PreviewParameterProvider<MatrixUser?> {
|
||||
override val values: Sequence<MatrixUser?>
|
||||
get() = sequenceOf(
|
||||
aMatrixUser(),
|
||||
aMatrixUser().copy(
|
||||
username = null,
|
||||
avatarData = anAvatarData().copy(name = null)
|
||||
),
|
||||
null,
|
||||
)
|
||||
}
|
||||
|
|
@ -30,17 +30,17 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import io.element.android.libraries.designsystem.components.avatar.Avatar
|
||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewDark
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreviewLight
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.matrix.core.UserId
|
||||
import io.element.android.libraries.matrix.ui.model.MatrixUser
|
||||
import io.element.android.libraries.matrix.ui.model.getBestName
|
||||
|
||||
// FIXME Row are not the same height if there is a name or not.
|
||||
@Composable
|
||||
fun MatrixUserRow(
|
||||
matrixUser: MatrixUser,
|
||||
|
|
@ -89,19 +89,15 @@ fun MatrixUserRow(
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun MatrixUserRowLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun MatrixUserRowLightPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
|
||||
ElementPreviewLight { ContentToPreview(matrixUser) }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun MatrixUserRowDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun MatrixUserRowDarkPreview(@PreviewParameter(MatrixUserProvider::class) matrixUser: MatrixUser) =
|
||||
ElementPreviewDark { ContentToPreview(matrixUser) }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
MatrixUserRow(
|
||||
MatrixUser(
|
||||
id = UserId("@alice:server.org"),
|
||||
username = "Alice",
|
||||
avatarData = AvatarData("Alice")
|
||||
)
|
||||
)
|
||||
private fun ContentToPreview(matrixUser: MatrixUser) {
|
||||
MatrixUserRow(matrixUser)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import io.element.android.libraries.matrix.core.UserId
|
|||
data class MatrixUser(
|
||||
val id: UserId,
|
||||
val username: String? = null,
|
||||
val avatarData: AvatarData = AvatarData(),
|
||||
val avatarData: AvatarData = AvatarData(id.value, username),
|
||||
)
|
||||
|
||||
fun MatrixUser.getBestName(): String {
|
||||
|
|
|
|||
|
|
@ -149,11 +149,11 @@ private fun MessageComposerView.setup(isDarkMode: Boolean, composerMode: Message
|
|||
|
||||
@Preview
|
||||
@Composable
|
||||
fun TextComposerLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
internal fun TextComposerLightPreview() = ElementPreviewLight { ContentToPreview() }
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun TextComposerDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
internal fun TextComposerDarkPreview() = ElementPreviewDark { ContentToPreview() }
|
||||
|
||||
@Composable
|
||||
private fun ContentToPreview() {
|
||||
|
|
|
|||
|
|
@ -1823,7 +1823,7 @@
|
|||
<!-- Terms -->
|
||||
<string name="terms_of_service">Terms of Service</string>
|
||||
<string name="terms_description_for_identity_server">Be discoverable by others</string>
|
||||
<string name="terms_description_for_integration_manager">Use Bots, bridges, widgets and sticker packs</string>
|
||||
<string name="terms_description_for_integration_manager">Use bots, bridges, widgets and sticker packs</string>
|
||||
|
||||
<string name="identity_server">Identity server</string>
|
||||
<string name="disconnect_identity_server">Disconnect identity server</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue