Feat: Working on pressure estimations feature
This commit is contained in:
52
Sources/Styleguide/TextLabel.swift
Normal file
52
Sources/Styleguide/TextLabel.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
import SwiftUI
|
||||
|
||||
/// A view that can be styled view the `.textLabelStyle` modifier, generally they will be
|
||||
/// simple `Text` views, however it will accept any content view and will apply the style to.
|
||||
///
|
||||
/// Custom styles can be created by conforming to the ``TextLabelStyle`` protocol.
|
||||
///
|
||||
public struct TextLabel<Content: View>: View {
|
||||
|
||||
@Environment(\.textLabelStyle) private var textLabelStyle
|
||||
|
||||
private let content: () -> Content
|
||||
|
||||
public init(@ViewBuilder content: @escaping () -> Content) {
|
||||
self.content = content
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
textLabelStyle.makeBody(
|
||||
configuration: TextLabelConfiguration(
|
||||
label: TextLabelConfiguration.Label(content: content())
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension TextLabel where Content == Text {
|
||||
public init<S>(_ text: S) where S: StringProtocol {
|
||||
self.init { Text(text) }
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
VStack {
|
||||
TextLabel("Automatic")
|
||||
|
||||
TextLabel("Secondary-Bold")
|
||||
.textLabelStyle(AnyTextLabelStyle.boldSecondary)
|
||||
|
||||
TextLabel("Secondary")
|
||||
.textLabelStyle(.secondary)
|
||||
.padding(.bottom)
|
||||
|
||||
Group {
|
||||
TextLabel("One")
|
||||
TextLabel("Two")
|
||||
TextLabel("Three")
|
||||
}
|
||||
.font(.title)
|
||||
.textLabelStyle(.boldSecondary)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user