diff options
| author | Christian Cleberg <[email protected]> | 2026-04-12 18:53:13 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-12 18:53:13 -0500 |
| commit | b526cddd8ec421eba00feecbdffae3978cb61b34 (patch) | |
| tree | f8426032d07a92d034975e90decd1ec0f85bd452 /Hutch/Views/Home/HomeSectionView.swift | |
| parent | 92fb89cd35588ee36190c95b1af1e9595b397fae (diff) | |
| download | hutch-b526cddd8ec421eba00feecbdffae3978cb61b34.tar.gz hutch-b526cddd8ec421eba00feecbdffae3978cb61b34.tar.bz2 hutch-b526cddd8ec421eba00feecbdffae3978cb61b34.zip | |
feat: improve Home structure and navigationv2.16.0
implements: https://todo.sr.ht/~ccleberg/hutch/14
implements: https://todo.sr.ht/~ccleberg/hutch/15
implements: https://todo.sr.ht/~ccleberg/hutch/16
Diffstat (limited to 'Hutch/Views/Home/HomeSectionView.swift')
| -rw-r--r-- | Hutch/Views/Home/HomeSectionView.swift | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Hutch/Views/Home/HomeSectionView.swift b/Hutch/Views/Home/HomeSectionView.swift new file mode 100644 index 0000000..5f04d58 --- /dev/null +++ b/Hutch/Views/Home/HomeSectionView.swift @@ -0,0 +1,63 @@ +import SwiftUI + +struct HomeSectionView<Accessory: View, Content: View>: View { + let title: String + @Binding var isExpanded: Bool + let accessory: Accessory + let content: Content + + init( + _ title: String, + isExpanded: Binding<Bool>, + @ViewBuilder accessory: () -> Accessory, + @ViewBuilder content: () -> Content + ) { + self.title = title + self._isExpanded = isExpanded + self.accessory = accessory() + self.content = content() + } + + var body: some View { + Section { + if isExpanded { + content + } + } header: { + HomeSectionHeader( + title: title, + isExpanded: $isExpanded, + accessory: accessory + ) + } + } +} + +private struct HomeSectionHeader<Accessory: View>: View { + let title: String + @Binding var isExpanded: Bool + let accessory: Accessory + + var body: some View { + HStack(spacing: 12) { + Button { + isExpanded.toggle() + } label: { + HStack(spacing: 8) { + Image(systemName: isExpanded ? "chevron.down" : "chevron.right") + .font(.caption.weight(.semibold)) + .foregroundStyle(.secondary) + Text(title) + } + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .accessibilityLabel(isExpanded ? "Collapse \(title)" : "Expand \(title)") + + Spacer(minLength: 8) + + accessory + } + .textCase(nil) + } +} |
