Skip to content

Commit

Permalink
pr suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Nov 18, 2024
1 parent 73ca6e3 commit 1c35aee
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
55 changes: 42 additions & 13 deletions Sources/Compound/List/ListRowDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,77 @@ import SwiftUI
public struct ListRowDetails<Icon: View> {
var title: String?
var icon: Icon?
var counter: Int?

var isWaiting = false

// MARK: - Initialisers

public static func label(title: String,
icon: Icon,
counter: Int? = nil,
isWaiting: Bool = false) -> Self {
ListRowDetails(title: title, icon: icon, isWaiting: isWaiting)
ListRowDetails(title: title,
icon: icon,
counter: counter,
isWaiting: isWaiting)
}

public static func label(title: String,
icon: KeyPath<CompoundIcons, Image>,
counter: Int? = nil,
isWaiting: Bool = false) -> Self where Icon == CompoundIcon {
ListRowDetails(title: title, icon: CompoundIcon(icon), isWaiting: isWaiting)
ListRowDetails(title: title,
icon: CompoundIcon(icon),
counter: counter,
isWaiting: isWaiting)
}

public static func label(title: String,
systemIcon: SFSymbol,
counter: Int? = nil,
isWaiting: Bool = false) -> Self where Icon == Image {
ListRowDetails(title: title, icon: Image(systemSymbol: systemIcon), isWaiting: isWaiting)
ListRowDetails(title: title,
icon: Image(systemSymbol: systemIcon),
counter: counter,
isWaiting: isWaiting)
}

public static func icon(_ icon: Icon, isWaiting: Bool = false) -> Self {
ListRowDetails(icon: icon, isWaiting: isWaiting)
public static func icon(_ icon: Icon,
counter: Int? = nil,
isWaiting: Bool = false) -> Self {
ListRowDetails(icon: icon,
counter: counter,
isWaiting: isWaiting)
}

public static func icon(_ icon: KeyPath<CompoundIcons, Image>, isWaiting: Bool = false) -> Self where Icon == CompoundIcon {
ListRowDetails(icon:CompoundIcon(icon), isWaiting: isWaiting)
public static func icon(_ icon: KeyPath<CompoundIcons, Image>,
counter: Int? = nil,
isWaiting: Bool = false) -> Self where Icon == CompoundIcon {
ListRowDetails(icon:CompoundIcon(icon),
counter: counter,
isWaiting: isWaiting)
}

public static func systemIcon(_ systemIcon: SFSymbol, isWaiting: Bool = false) -> Self where Icon == Image {
ListRowDetails(icon: Image(systemSymbol: systemIcon), isWaiting: isWaiting)
public static func systemIcon(_ systemIcon: SFSymbol,
counter: Int? = nil,
isWaiting: Bool = false) -> Self where Icon == Image {
ListRowDetails(icon: Image(systemSymbol: systemIcon),
counter: counter,
isWaiting: isWaiting)
}
}

public extension ListRowDetails where Icon == Image {
static func title(_ title: String, isWaiting: Bool = false) -> Self {
ListRowDetails(title: title, isWaiting: isWaiting)
static func title(_ title: String,
counter: Int? = nil,
isWaiting: Bool = false) -> Self {
ListRowDetails(title: title,
counter: counter,
isWaiting: isWaiting)
}

static func isWaiting(_ isWaiting: Bool) -> Self {
ListRowDetails(isWaiting: isWaiting)
static func isWaiting(counter: Int? = nil, _ isWaiting: Bool) -> Self {
ListRowDetails(counter: counter, isWaiting: isWaiting)
}
}
18 changes: 9 additions & 9 deletions Sources/Compound/List/ListRowTrailingSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ private struct ListRowDetailsLabelStyle: LabelStyle {
/// The view shown to the right of the `ListRowLabel` inside of a `ListRow`.
/// This consists of both the `ListRowDetails` and the `ListRowAccessory`.
public struct ListRowTrailingSection<Icon: View>: View {
var title: String?
var icon: Icon?

var solidCounter: Int?
var isWaiting = false
var accessory: ListRowAccessory?
@Environment(\.isEnabled) private var isEnabled

private var title: String?
private var icon: Icon?
private var counter: Int?
private var isWaiting = false
private var accessory: ListRowAccessory?

@ScaledMetric private var iconSize = 24
private var hideAccessory: Bool { isWaiting && accessory?.kind == .unselected }
Expand All @@ -43,8 +43,8 @@ public struct ListRowTrailingSection<Icon: View>: View {
title = details?.title
icon = details?.icon
isWaiting = details?.isWaiting ?? false
counter = details?.counter
self.accessory = accessory
self.solidCounter = solidCounter
}

public var body: some View {
Expand All @@ -62,8 +62,8 @@ public struct ListRowTrailingSection<Icon: View>: View {
.labelStyle(ListRowDetailsLabelStyle())
}

if let solidCounter {
Text("\(solidCounter)")
if let counter {
Text("\(counter)")
.font(.compound.bodyXSSemibold)
.foregroundStyle(.compound.textOnSolidPrimary)
.padding(.horizontal, 6)
Expand Down

0 comments on commit 1c35aee

Please sign in to comment.