Implemented the FakeLabel component in the UI library.
This commit is contained in:
parent
2da8f417c4
commit
408e90d53f
95
Libraries/UI/Kit/Sources/Components/FakeLabel.swift
Normal file
95
Libraries/UI/Kit/Sources/Components/FakeLabel.swift
Normal file
@ -0,0 +1,95 @@
|
||||
//
|
||||
// FakeLabel.swift
|
||||
// ReviewsUIKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 20/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import ReviewsFoundationKit
|
||||
import SwiftUI
|
||||
|
||||
public struct FakeLabel: View {
|
||||
|
||||
// MARK: Constants
|
||||
private let systemIcon: String
|
||||
private let title: String
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(
|
||||
systemIcon: String,
|
||||
title: String
|
||||
) {
|
||||
self.systemIcon = systemIcon
|
||||
self.title = title
|
||||
}
|
||||
|
||||
// MARK: Body
|
||||
public var body: some View {
|
||||
HStack(
|
||||
alignment: .bottom,
|
||||
spacing: 8
|
||||
) {
|
||||
iconOrQuestionMark
|
||||
|
||||
Text(titleOrDash)
|
||||
.font(.body)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
private extension FakeLabel {
|
||||
|
||||
// MARK: Computed
|
||||
var iconOrQuestionMark: Image {
|
||||
.init(systemName: systemIcon.isEmpty
|
||||
? .Icon.questionMark
|
||||
: systemIcon
|
||||
)
|
||||
}
|
||||
|
||||
var titleOrDash: String {
|
||||
title.isEmpty
|
||||
? .Title.none
|
||||
: title
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - String+Constants
|
||||
private extension String {
|
||||
enum Title {
|
||||
static let none = "-"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
#Preview("Fake Label with system icon and title") {
|
||||
FakeLabel(
|
||||
systemIcon: .Icon.person,
|
||||
title: "Some title goes here..."
|
||||
)
|
||||
}
|
||||
|
||||
#Preview("Fake Label with empty system icon and title") {
|
||||
FakeLabel(
|
||||
systemIcon: .empty,
|
||||
title: "Some title goes here..."
|
||||
)
|
||||
}
|
||||
|
||||
#Preview("Fake Label with system icon and empty title") {
|
||||
FakeLabel(
|
||||
systemIcon: .Icon.person,
|
||||
title: .empty
|
||||
)
|
||||
}
|
||||
|
||||
#Preview("Fake Label with both empty system icon and title") {
|
||||
FakeLabel(
|
||||
systemIcon: .empty,
|
||||
title: .empty
|
||||
)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
//
|
||||
// StarRating.swift
|
||||
// Feed
|
||||
// ReviewsUIKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 19/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||||
@ -62,9 +62,11 @@ private extension StarRating {
|
||||
}
|
||||
|
||||
// MARK: - Image+Constants
|
||||
private extension Image.Icon {
|
||||
static let star: Image = .init(systemName: "star")
|
||||
static let starFill: Image = .init(systemName: "star.fill")
|
||||
private extension Image {
|
||||
enum Icon {
|
||||
static let star: Image = .init(systemName: "star")
|
||||
static let starFill: Image = .init(systemName: "star.fill")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
@ -1,19 +0,0 @@
|
||||
//
|
||||
// Image+Icons.swift
|
||||
// ReviewsUIKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 20/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
public extension Image {
|
||||
enum Icon {
|
||||
|
||||
// MARK: Constants
|
||||
public static let info = Image(systemName: .Icon.info)
|
||||
public static let person = Image(systemName: .Icon.person)
|
||||
|
||||
}
|
||||
}
|
@ -6,12 +6,13 @@
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
extension String {
|
||||
public extension String {
|
||||
enum Icon {
|
||||
|
||||
// MARK: Constants
|
||||
static let info = "info.circle.fill"
|
||||
static let person = "person.crop.circle.fill"
|
||||
|
||||
static let questionMark = "questionmark.circle.fill"
|
||||
|
||||
public static let info = "info.circle.fill"
|
||||
public static let person = "person.crop.circle.fill"
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
//
|
||||
// UIImage+Icons.swift
|
||||
// ReviewsUIKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 20/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
public extension UIImage {
|
||||
enum Icon {
|
||||
|
||||
// MARK: Constants
|
||||
public static let info = UIImage(systemName: .Icon.info)
|
||||
public static let person = UIImage(systemName: .Icon.person)
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user