feat: Styles views for macos

This commit is contained in:
2024-06-17 09:30:47 -04:00
parent 50e80d39eb
commit bd758fac90
7 changed files with 115 additions and 16 deletions

View File

@@ -0,0 +1,50 @@
import SwiftUI
public struct SectionHeaderLabel<Content: View>: View {
@Environment(\.sectionHeaderLabelStyle) var style
let content: () -> Content
public init(@ViewBuilder _ content: @escaping () -> Content) {
self.content = content
}
public var body: some View {
style.makeBody(
configuration: TextLabelConfiguration(
label: TextLabelConfiguration.Label(content: content())
)
)
}
}
extension SectionHeaderLabel where Content == Text {
public init(_ text: LocalizedStringKey) {
self.init { Text(text) }
}
public init<S>(_ text: S) where S: StringProtocol {
self.init { Text(text) }
}
}
#Preview {
Form {
Section {
Text("Content")
} header: {
SectionHeaderLabel("One")
}
Section {
Text("Content")
} header: {
SectionHeaderLabel("Two")
}
}
.formStyle(.grouped)
#if os(macOS)
.frame(width: 400, height: 400)
#endif
}