swiftui-multiplatform/Shared/PostList/PostStatusBadgeView.swift

71 lines
2.3 KiB
Swift
Raw Permalink Normal View History

import SwiftUI
struct PostStatusBadgeView: View {
@ObservedObject var post: WFAPost
var body: some View {
let (badgeLabel, badgeColor) = setupBadgeProperties(for: PostStatus(rawValue: post.status)!)
Text(badgeLabel)
.font(.caption)
2020-08-07 13:44:34 +00:00
.fontWeight(.semibold)
.foregroundColor(.white)
.textCase(.uppercase)
.lineLimit(1)
.padding(EdgeInsets(top: 2.5, leading: 7.5, bottom: 2.5, trailing: 7.5))
.background(badgeColor)
.clipShape(RoundedRectangle(cornerRadius: 5.0, style: .circular))
}
func setupBadgeProperties(for status: PostStatus) -> (String, Color) {
var badgeLabel: String
var badgeColor: Color
switch status {
2020-09-01 13:54:43 +00:00
case .local:
badgeLabel = "local"
badgeColor = Color(red: 0.75, green: 0.5, blue: 0.85, opacity: 1.0)
case .edited:
badgeLabel = "edited"
badgeColor = Color(red: 0.75, green: 0.7, blue: 0.1, opacity: 1.0)
case .published:
badgeLabel = "published"
badgeColor = .gray
}
return (badgeLabel, badgeColor)
}
}
2020-09-09 16:12:19 +00:00
struct PostStatusBadge_LocalDraftPreviews: PreviewProvider {
static var previews: some View {
let context = LocalStorageManager.standard.container.viewContext
2020-09-09 16:12:19 +00:00
let testPost = WFAPost(context: context)
testPost.status = PostStatus.local.rawValue
return PostStatusBadgeView(post: testPost)
.environment(\.managedObjectContext, context)
}
}
struct PostStatusBadge_EditedPreviews: PreviewProvider {
static var previews: some View {
let context = LocalStorageManager.standard.container.viewContext
2020-09-09 16:12:19 +00:00
let testPost = WFAPost(context: context)
testPost.status = PostStatus.edited.rawValue
return PostStatusBadgeView(post: testPost)
.environment(\.managedObjectContext, context)
}
}
struct PostStatusBadge_PublishedPreviews: PreviewProvider {
static var previews: some View {
let context = LocalStorageManager.standard.container.viewContext
2020-09-09 16:12:19 +00:00
let testPost = WFAPost(context: context)
testPost.status = PostStatus.published.rawValue
return PostStatusBadgeView(post: testPost)
.environment(\.managedObjectContext, context)
}
}