DefinitionRow.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import Foundation
  2. import SwiftUI
  3. struct DefinitionRow<DefinitionView: View>: View {
  4. var term: String
  5. var definition: DefinitionView
  6. var color: Color?
  7. var fontSize: Font?
  8. var iconString: String?
  9. var shouldRotateIcon: Bool?
  10. init(
  11. term: String,
  12. definition: DefinitionView,
  13. color: Color? = nil,
  14. fontSize: Font? = nil,
  15. iconString: String? = nil,
  16. shouldRotateIcon: Bool = false
  17. ) {
  18. self.term = term
  19. self.definition = definition
  20. self.color = color
  21. self.fontSize = fontSize
  22. self.iconString = iconString
  23. self.shouldRotateIcon = shouldRotateIcon
  24. }
  25. var body: some View {
  26. VStack(alignment: .leading) {
  27. HStack {
  28. if let color = color {
  29. if let iconString = iconString {
  30. Image(systemName: iconString)
  31. .foregroundStyle(color)
  32. .rotationEffect(shouldRotateIcon == true ? .degrees(180) : .degrees(0))
  33. } else {
  34. Image(systemName: "circle.fill")
  35. .foregroundStyle(color)
  36. }
  37. }
  38. Text(term).font(fontSize ?? .subheadline).fontWeight(.semibold)
  39. }.padding(.bottom, 5)
  40. definition
  41. .font(fontSize ?? .subheadline)
  42. .foregroundColor(.secondary)
  43. }
  44. .padding(.vertical, 5)
  45. }
  46. }