Nenhuma descrição

FilterFields.swift 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // FilterFields.swift
  3. // Flowerdex
  4. //
  5. // Created by Víctor A. Hernández on 12/1/20.
  6. //
  7. import SwiftUI
  8. struct FilterFields: View {
  9. @Binding var edible: Bool
  10. @Binding var vegetable: Bool
  11. @Binding var petalCount: Int
  12. @Binding var growthMonths: Int
  13. @Binding var bloomMonths: Int
  14. @Binding var scientificName: String
  15. @Binding var commonName: String
  16. @Binding var flowerColor: String
  17. var body: some View {
  18. VStack {
  19. MainText()
  20. EdibleField(edible: $edible)
  21. VegetableField(vegetable: $vegetable)
  22. PetalsField(petalCount: $petalCount)
  23. GrowthMonthsField(growthMonths: $growthMonths)
  24. BloomMonthsField(bloomMonths: $bloomMonths)
  25. CommonNameField(commonName: $commonName)
  26. ScientificNameField(scientificName: $scientificName)
  27. FlowerColorField(flowerColor: $flowerColor)
  28. }
  29. .padding()
  30. }
  31. }
  32. struct MainText: View {
  33. var body: some View {
  34. Text("Filters")
  35. .font(.title2)
  36. .bold()
  37. .foregroundColor(Color("Rausch"))
  38. }
  39. }
  40. struct FlowerColorField: View {
  41. @Binding var flowerColor: String
  42. @Environment(\.colorScheme) var colorScheme
  43. var body: some View {
  44. TextField("FlowerColor", text: $flowerColor)
  45. .disableAutocorrection(true)
  46. .autocapitalization(.none)
  47. .padding()
  48. .background(colorScheme == .dark ? Constants.Colors.darkGrayColor : Constants.Colors.lightGrayColor)
  49. .cornerRadius(5.0)
  50. .padding(.bottom, 5)
  51. }
  52. }
  53. struct CommonNameField: View {
  54. @Binding var commonName: String
  55. @Environment(\.colorScheme) var colorScheme
  56. var body: some View {
  57. TextField("Common Name", text: $commonName)
  58. .disableAutocorrection(true)
  59. .autocapitalization(.none)
  60. .padding()
  61. .background(colorScheme == .dark ? Constants.Colors.darkGrayColor : Constants.Colors.lightGrayColor)
  62. .cornerRadius(5.0)
  63. .padding(.bottom, 5)
  64. }
  65. }
  66. struct ScientificNameField: View {
  67. @Binding var scientificName: String
  68. @Environment(\.colorScheme) var colorScheme
  69. var body: some View {
  70. TextField("Scienfitic Name", text: $scientificName)
  71. .disableAutocorrection(true)
  72. .autocapitalization(.none)
  73. .padding()
  74. .background(colorScheme == .dark ? Constants.Colors.darkGrayColor : Constants.Colors.lightGrayColor)
  75. .cornerRadius(5.0)
  76. .padding(.bottom, 5)
  77. }
  78. }
  79. struct EdibleField: View {
  80. @Binding var edible: Bool
  81. var body: some View {
  82. Toggle(isOn: $edible, label: {
  83. Text("Edible")
  84. })
  85. }
  86. }
  87. struct VegetableField: View {
  88. @Binding var vegetable: Bool
  89. var body: some View {
  90. Toggle(isOn: $vegetable, label: {
  91. Text("Vegetable")
  92. })
  93. }
  94. }
  95. struct PetalsField: View {
  96. @Binding var petalCount: Int
  97. var body: some View {
  98. Stepper(onIncrement: {
  99. if self.petalCount < 10 { // 10 petals is a lot, but oh well
  100. self.petalCount += 1
  101. }
  102. }, onDecrement: {
  103. if self.petalCount > 0 {
  104. self.petalCount -= 1
  105. }
  106. }, label: {
  107. Text("Petals (\(self.petalCount))")
  108. })
  109. }
  110. }
  111. struct GrowthMonthsField: View {
  112. @Binding var growthMonths: Int
  113. var body: some View {
  114. Stepper(onIncrement: {
  115. if self.growthMonths < 10 { // 10 petals is a lot, but oh well
  116. self.growthMonths += 1
  117. }
  118. }, onDecrement: {
  119. if self.growthMonths > 0 {
  120. self.growthMonths -= 1
  121. }
  122. }, label: {
  123. Text("Growth Months (\(self.growthMonths))")
  124. })
  125. }
  126. }
  127. struct BloomMonthsField: View {
  128. @Binding var bloomMonths: Int
  129. var body: some View {
  130. Stepper(onIncrement: {
  131. if self.bloomMonths < 10 { // 10 petals is a lot, but oh well
  132. self.bloomMonths += 1
  133. }
  134. }, onDecrement: {
  135. if self.bloomMonths > 0 {
  136. self.bloomMonths -= 1
  137. }
  138. }, label: {
  139. Text("Bloom Months (\(self.bloomMonths))")
  140. })
  141. }
  142. }