secretive/Sources/Secretive/Views/ConfigurationItemView.swift
Max Goedjen fa658646d7
WIP
2025-08-31 13:24:37 -07:00

55 lines
1.6 KiB
Swift

import SwiftUI
struct ConfigurationItemView<Content: View>: View {
enum Action: Hashable {
case copy(String)
case revealInFinder(String)
}
let title: LocalizedStringResource
let content: Content
let action: Action?
init(title: LocalizedStringResource, value: String, action: Action? = nil) where Content == Text {
self.title = title
self.content = Text(value)
.font(.subheadline)
.foregroundStyle(.secondary)
self.action = action
}
init(title: LocalizedStringResource, action: Action? = nil, content: () -> Content) {
self.title = title
self.content = content()
self.action = action
}
var body: some View {
VStack(alignment: .leading) {
HStack {
Text(title)
Spacer()
switch action {
case .copy(let string):
Button("Reveal in Finder", systemImage: "folder") {
NSWorkspace.shared.selectFile(string, inFileViewerRootedAtPath: string)
}
.labelStyle(.iconOnly)
.buttonStyle(.borderless)
case .revealInFinder(let string):
Button("Reveal in Finder", systemImage: "folder") {
NSWorkspace.shared.selectFile(string, inFileViewerRootedAtPath: string)
}
.labelStyle(.iconOnly)
.buttonStyle(.borderless)
case nil:
EmptyView()
}
}
content
}
}
}