feat: Styles views for macos
This commit is contained in:
50
Sources/Styleguide/SectionHeaderLabel.swift
Normal file
50
Sources/Styleguide/SectionHeaderLabel.swift
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user