DashBoardList.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // DashBoardList.swift
  3. // DashboardWidgetExtension
  4. //
  5. // Created by Marino Faggiana on 20/08/22.
  6. // Copyright © 2022 Marino Faggiana. All rights reserved.
  7. //
  8. import SwiftUI
  9. import WidgetKit
  10. struct DashBoardList: View {
  11. var data: [DashboardData]
  12. var body: some View {
  13. VStack(alignment: .center) {
  14. Text("Good morning")
  15. .font(.title)
  16. .bold()
  17. VStack {
  18. ForEach(data, id: \.id) { element in
  19. DashboardElement(element: element)
  20. }
  21. }
  22. }.padding()
  23. }
  24. }
  25. struct DashboardElement: View {
  26. var element: DashboardData
  27. var body: some View {
  28. Link(destination: element.url) {
  29. HStack {
  30. Image(element.image)
  31. .resizable()
  32. .aspectRatio(contentMode: .fit)
  33. .frame(width: 40, height: 40)
  34. .clipShape(Circle())
  35. VStack(alignment: .leading) {
  36. Text(element.title)
  37. .font(.headline)
  38. Text(element.subTitle)
  39. .font(.subheadline)
  40. .foregroundColor(.accentColor)
  41. }
  42. Spacer()
  43. }
  44. .padding(10)
  45. }
  46. }
  47. }
  48. struct NCElementDashboard_Previews: PreviewProvider {
  49. static var previews: some View {
  50. Group {
  51. DashBoardList(data: dataDashboardPreview).previewContext(WidgetPreviewContext(family: .systemLarge))
  52. }
  53. }
  54. }