78 lines
1.6 KiB
Swift
78 lines
1.6 KiB
Swift
|
//
|
||
|
// ListHeader.swift
|
||
|
// Piper ~ App
|
||
|
//
|
||
|
// Created by Javier Cicchelli on 06/10/2024.
|
||
|
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import SwiftUI
|
||
|
|
||
|
struct ListHeader: View {
|
||
|
|
||
|
// MARK: Properties
|
||
|
|
||
|
let title: LocalizedStringKey
|
||
|
let button: LocalizedStringKey
|
||
|
let showButton: Bool
|
||
|
let onAction: () -> Void
|
||
|
|
||
|
// MARK: Body
|
||
|
|
||
|
var body: some View {
|
||
|
HStack {
|
||
|
Text(title)
|
||
|
.font(.headline)
|
||
|
.foregroundStyle(.primary)
|
||
|
|
||
|
if showButton {
|
||
|
Spacer()
|
||
|
|
||
|
Button(
|
||
|
button,
|
||
|
action: onAction
|
||
|
)
|
||
|
.buttonStyle(.borderless)
|
||
|
}
|
||
|
}
|
||
|
.padding(.vertical)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// MARK: - Previews
|
||
|
|
||
|
#Preview("List Section component with title") {
|
||
|
List {
|
||
|
Section {
|
||
|
EmptyView()
|
||
|
} header: {
|
||
|
ListHeader(
|
||
|
title: "Some title goes here...",
|
||
|
button: "Some button goes here...",
|
||
|
showButton: false
|
||
|
) {
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
.frame(width: 400, height: 100)
|
||
|
}
|
||
|
|
||
|
#Preview("List Section component with title and button") {
|
||
|
List {
|
||
|
Section {
|
||
|
EmptyView()
|
||
|
} header: {
|
||
|
ListHeader(
|
||
|
title: "Some title goes here...",
|
||
|
button: "Some button goes here...",
|
||
|
showButton: true
|
||
|
) {
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
.frame(width: 400, height: 100)
|
||
|
}
|