From 8b8f0d9f1f751ae583e0a49e0fe244be7d3f9ea0 Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 12 Dec 2022 02:50:32 +0100 Subject: [PATCH] Implemented the ProfileSection UI component for the Profile module. --- .../UI/Components/ProfileSection.swift | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Modules/Sources/Profile/UI/Components/ProfileSection.swift diff --git a/Modules/Sources/Profile/UI/Components/ProfileSection.swift b/Modules/Sources/Profile/UI/Components/ProfileSection.swift new file mode 100644 index 0000000..1246c44 --- /dev/null +++ b/Modules/Sources/Profile/UI/Components/ProfileSection.swift @@ -0,0 +1,75 @@ +// +// ProfileSection.swift +// Profile +// +// Created by Javier Cicchelli on 12/12/2022. +// + +import SwiftUI + +struct ProfileSection: View { + + // MARK: Properties + + let header: LocalizedStringKey + let items: [Item] + + // MARK: Body + + var body: some View { + Section { + ForEach(items) { item in + Label { + Text(item.value) + } icon: { + Text( + item.key, + bundle: .module + ) + } + .labelStyle(.nameAndValue) + } + } header: { + Text( + header, + bundle: .module + ) + } + } + +} + +// MARK: - Structs + +extension ProfileSection { + struct Item { + let key: LocalizedStringKey + let value: String + } +} + +// MARK: - Identifiable + +extension ProfileSection.Item: Identifiable { + var id: String { UUID().uuidString } +} + +// MARK: - Previews + +struct ProfileSection_Previews: PreviewProvider { + static var previews: some View { + ProfileSection( + header: "some-localised-header-key", + items: [ + .init( + key: "some-localized-key", + value: "some value" + ), + .init( + key: "some-other-localised-key", + value: "some other value" + ) + ] + ) + } +}