|
| 1 | +/* |
| 2 | + * Copyright 2025 New Vector Ltd. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial |
| 5 | + * Please see LICENSE files in the repository root for full details. |
| 6 | + */ |
| 7 | + |
| 8 | +package io.element.android.libraries.matrix.ui.components |
| 9 | + |
| 10 | +import androidx.compose.foundation.layout.Column |
| 11 | +import androidx.compose.foundation.layout.Spacer |
| 12 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 13 | +import androidx.compose.foundation.layout.height |
| 14 | +import androidx.compose.foundation.layout.padding |
| 15 | +import androidx.compose.material3.Text |
| 16 | +import androidx.compose.runtime.Composable |
| 17 | +import androidx.compose.ui.Alignment |
| 18 | +import androidx.compose.ui.Modifier |
| 19 | +import androidx.compose.ui.res.pluralStringResource |
| 20 | +import androidx.compose.ui.res.stringResource |
| 21 | +import androidx.compose.ui.text.style.TextAlign |
| 22 | +import androidx.compose.ui.unit.dp |
| 23 | +import io.element.android.compound.theme.ElementTheme |
| 24 | +import io.element.android.libraries.designsystem.components.avatar.Avatar |
| 25 | +import io.element.android.libraries.designsystem.components.avatar.AvatarData |
| 26 | +import io.element.android.libraries.designsystem.components.avatar.AvatarSize |
| 27 | +import io.element.android.libraries.designsystem.components.avatar.AvatarType |
| 28 | +import io.element.android.libraries.designsystem.components.avatar.anAvatarData |
| 29 | +import io.element.android.libraries.designsystem.preview.ElementPreview |
| 30 | +import io.element.android.libraries.designsystem.preview.PreviewsDayNight |
| 31 | +import io.element.android.libraries.ui.strings.CommonPlurals |
| 32 | +import io.element.android.libraries.ui.strings.CommonStrings |
| 33 | + |
| 34 | +/** |
| 35 | + * Ref: https://www.figma.com/design/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?node-id=3643-2048&m=dev |
| 36 | + */ |
| 37 | +@Composable |
| 38 | +fun OrganizationHeader( |
| 39 | + avatarData: AvatarData, |
| 40 | + name: String, |
| 41 | + numberOfSpaces: Int, |
| 42 | + numberOfRooms: Int, |
| 43 | + modifier: Modifier = Modifier, |
| 44 | +) { |
| 45 | + Column( |
| 46 | + modifier = modifier |
| 47 | + .fillMaxWidth() |
| 48 | + .padding(top = 16.dp, bottom = 24.dp, start = 16.dp, end = 16.dp), |
| 49 | + horizontalAlignment = Alignment.CenterHorizontally, |
| 50 | + ) { |
| 51 | + Avatar( |
| 52 | + avatarData = avatarData, |
| 53 | + avatarType = AvatarType.Space(false), |
| 54 | + ) |
| 55 | + Spacer(modifier = Modifier.height(16.dp)) |
| 56 | + Text( |
| 57 | + text = name, |
| 58 | + style = ElementTheme.typography.fontHeadingLgBold, |
| 59 | + color = ElementTheme.colors.textPrimary, |
| 60 | + textAlign = TextAlign.Center, |
| 61 | + ) |
| 62 | + Spacer(modifier = Modifier.height(12.dp)) |
| 63 | + val subtitle = stringResource( |
| 64 | + id = CommonStrings.screen_space_list_details, |
| 65 | + pluralStringResource(CommonPlurals.common_spaces, numberOfSpaces, numberOfSpaces), |
| 66 | + pluralStringResource(CommonPlurals.common_rooms, numberOfRooms, numberOfRooms), |
| 67 | + ) |
| 68 | + Text( |
| 69 | + text = subtitle, |
| 70 | + style = ElementTheme.typography.fontBodyLgRegular, |
| 71 | + color = ElementTheme.colors.textSecondary, |
| 72 | + textAlign = TextAlign.Center, |
| 73 | + ) |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +@PreviewsDayNight |
| 78 | +@Composable |
| 79 | +internal fun OrganizationHeaderPreview() = ElementPreview { |
| 80 | + OrganizationHeader( |
| 81 | + avatarData = anAvatarData( |
| 82 | + url = "anUrl", |
| 83 | + size = AvatarSize.OrganizationHeader, |
| 84 | + ), |
| 85 | + name = "Space name", |
| 86 | + numberOfSpaces = 9, |
| 87 | + numberOfRooms = 88, |
| 88 | + ) |
| 89 | +} |
0 commit comments