InstructionList.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // InstructionList.swift
  3. // LoopKitUI
  4. //
  5. // Created by Nathaniel Hamming on 2020-02-20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. public struct InstructionList: View {
  10. let instructions: [String]
  11. let stepsColor: Color
  12. public init(instructions: [String], stepsColor: Color = Color.accentColor) {
  13. self.instructions = instructions
  14. self.stepsColor = stepsColor
  15. }
  16. public var body: some View {
  17. VStack(alignment: .leading, spacing: 10) {
  18. ForEach(instructions.indices, id: \.self) { index in
  19. HStack(alignment: .top) {
  20. Text("\(index+1)")
  21. .padding(6)
  22. .background(Circle().fill(self.stepsColor))
  23. .foregroundColor(.white)
  24. .font(.caption)
  25. .accessibility(label: Text("\(index+1), ")) // Adds a pause after the number
  26. Text(self.instructions[index])
  27. .fixedSize(horizontal: false, vertical: true)
  28. .padding(2)
  29. }
  30. .accessibilityElement(children: .combine)
  31. }
  32. }
  33. }
  34. }
  35. struct InstructionList_Previews: PreviewProvider {
  36. static var previews: some View {
  37. let instructions: [String] = [
  38. "This is the first step.",
  39. "This second step is a bit more tricky and needs more description to support the user, albeit it could be more concise.",
  40. "With this final step, the task will be accomplished."
  41. ]
  42. return InstructionList(instructions: instructions)
  43. }
  44. }