Files
letro-ios/ElementX/Sources/Other/SwiftUI/Views/SFNumberedListView.swift
manuroe c29f4cc9b4 Dual licensing: AGPL + Element Commercial (#3657)
* New LICENSE-COMMERCIAL file

* Apply dual licenses: AGPL + Element Commercial to file headers

* Update README with dual licensing
2025-01-06 11:27:37 +01:00

73 lines
1.9 KiB
Swift

//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import SFSafeSymbols
import SwiftUI
/// The view can only display a max 9 items as of right now
struct SFNumberedListView: View {
let items: [AttributedString]
var body: some View {
VStack(alignment: .leading, spacing: 24) {
ForEach(0..<items.count, id: \.self) { index in
Label {
Text(items[index])
} icon: {
Image(systemSymbol: getSymbol(for: index))
.imageScale(.large)
.fontWeight(.light)
.foregroundColor(.compound.textSecondary)
}
.foregroundColor(.compound.textPrimary)
.font(.compound.bodyMD)
}
}
}
private func getSymbol(for index: Int) -> SFSymbol {
switch index {
case 0:
return ._1Circle
case 1:
return ._2Circle
case 2:
return ._3Circle
case 3:
return ._4Circle
case 4:
return ._5Circle
case 5:
return ._6Circle
case 6:
return ._7Circle
case 7:
return ._8Circle
case 8:
return ._9Circle
default:
return ._0Circle
}
}
}
struct SFNumberedListView_Previews: PreviewProvider, TestablePreview {
static let items = {
var results: [AttributedString] = []
for index in 1...9 {
results.append(AttributedString("Item \(index)"))
}
return results
}()
static var previews: some View {
SFNumberedListView(items: items)
.padding()
.previewLayout(.sizeThatFits)
}
}