jel/Jel/Views/Utility/TextRatingView.swift

59 lines
1.3 KiB
Swift
Raw Normal View History

2024-01-09 17:32:06 +00:00
//
// TextRatingView.swift
// Jel
//
// Created by zerocool on 1/9/24.
//
import SwiftUI
enum TextRatingViewStyle {
case stroke
case fill
}
struct TextRatingView: View {
var text: String
var fillStyle: TextRatingViewStyle
init(_ text: String, fillStyle: TextRatingViewStyle = .stroke) {
self.text = text
self.fillStyle = fillStyle
}
var body: some View {
switch (fillStyle) {
case .stroke:
Text(text)
.font(.caption)
.bold()
.padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4))
.overlay {
RoundedRectangle(cornerRadius: 2, style: .continuous)
.stroke(.gray, lineWidth: 1.5)
}
.foregroundStyle(.gray)
case .fill:
Text(text)
.font(.caption)
.bold()
.padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4))
.hidden()
.background {
Color(.gray)
.clipShape(RoundedRectangle(cornerRadius: 2, style: .continuous))
.inverseMask(
Text(text)
.font(.caption)
.bold()
.padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4))
)
}
}
}
}
//#Preview {
// TextRatingView()
//}