summaryrefslogtreecommitdiff
path: root/Jel/Views/Utility/TextRatingView.swift
blob: 760d251203413a703a0b3ba129c2204e7db66dd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
//  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()
//}