Skip to content

Commit

Permalink
Add status text to ListRowLabel.avatar (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored Apr 8, 2024
1 parent 6d42477 commit 5c8ee9b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Sources/Compound/List/ListRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ public struct ListRow_Previews: PreviewProvider, PrefireProvider {
description: "@bob:element.io",
icon: Circle().foregroundStyle(.compound.decorativeColors[1].background)),
kind: .multiSelection(isSelected: false) { })
ListRow(label: .avatar(title: "Dan",
status: "Pending",
description: "@dan:element.io",
icon: Circle().foregroundStyle(.compound.decorativeColors[3].background)),
kind: .multiSelection(isSelected: false) { })
.disabled(true)
ListRow(label: .avatar(title: "@charlie:fake.com",
description: "This user can't be found, so the invite may not be received.",
icon: Circle().foregroundStyle(.compound.decorativeColors[2].background),
Expand Down
30 changes: 26 additions & 4 deletions Sources/Compound/List/ListRowLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public struct ListRowLabel<Icon: View>: View {
@ScaledMetric private var iconSize = 30.0

var title: String?
var status: String?
var description: String?
var icon: Icon?

Expand All @@ -87,6 +88,10 @@ public struct ListRowLabel<Icon: View>: View {
}
var titleLineLimit: Int? { layout == .avatar ? 1 : lineLimit }

var statusColor: Color {
isEnabled ? .compound.textSecondary : .compound.textDisabled
}

var descriptionColor: Color {
isEnabled ? .compound.textSecondary : .compound.textDisabled
}
Expand Down Expand Up @@ -166,10 +171,21 @@ public struct ListRowLabel<Icon: View>: View {
var titleAndDescription: some View {
VStack(alignment: .leading, spacing: 2) {
if let title {
Text(title)
.font(.compound.bodyLG)
.foregroundColor(titleColor)
.lineLimit(titleLineLimit)
HStack(alignment: .firstTextBaseline, spacing: 8) {
Text(title)
.font(.compound.bodyLG)
.foregroundColor(titleColor)
.lineLimit(titleLineLimit)

// Status is only available in the avatar init which requires a title,
// so no need to worry about the outer `if let` being nil in this instance.
if let status {
Text(status)
.font(.compound.bodySM)
.foregroundColor(statusColor)
.lineLimit(1)
}
}
}

if let description {
Expand Down Expand Up @@ -282,10 +298,12 @@ public struct ListRowLabel<Icon: View>: View {

/// A label that displays an avatar as it's icon, such as a user profile row or for a room picker.
public static func avatar(title: String,
status: String? = nil,
description: String? = nil,
icon: Icon,
role: ListRowLabel.Role? = nil) -> ListRowLabel {
ListRowLabel(title: title,
status: status,
description: description,
icon: icon,
role: role,
Expand Down Expand Up @@ -343,6 +361,10 @@ struct ListRowLabel_Previews: PreviewProvider, PrefireProvider {
ListRowLabel.avatar(title: "Alice",
description: "@alice:example.com",
icon: Circle().foregroundStyle(.compound.decorativeColors[0].background))
ListRowLabel.avatar(title: "Alice",
status: "Pending",
description: "@alice:example.com",
icon: Circle().foregroundStyle(.compound.decorativeColors[0].background))
ListRowLabel.avatar(title: "@bob:idontexist.com",
description: "This user can't be found, so the invite may not be received.",
icon: Circle().foregroundStyle(.compound.decorativeColors[0].background),
Expand Down

0 comments on commit 5c8ee9b

Please sign in to comment.