-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11e1fc6
commit 4098388
Showing
13 changed files
with
478 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Copyright © 2022 Alexander Romanov | ||
// RowLabelStyle.swift | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct RowLabelStyle: LabelStyle { | ||
@Environment(\.sizeCategory) var sizeCategory | ||
@Environment(\.multilineTextAlignment) var multilineTextAlignment | ||
|
||
private let subtitle: String? | ||
|
||
public init(subtitle: String? = nil) { | ||
self.subtitle = subtitle | ||
} | ||
|
||
public func makeBody(configuration: Configuration) -> some View { | ||
HStack(spacing: .xSmall) { | ||
configuration.icon | ||
.headline() | ||
.foregroundColor(.onSurfaceHighEmphasis) | ||
|
||
VStack(alignment: textAlignment, spacing: .xxxSmall) { | ||
configuration.title | ||
.headline(.semibold) | ||
.foregroundColor(.onSurfaceHighEmphasis) | ||
|
||
if let subtitle, !subtitle.isEmpty { | ||
Text(subtitle) | ||
.subheadline() | ||
.foregroundColor(.onSurfaceMediumEmphasis) | ||
} | ||
} | ||
.multilineTextAlignment(multilineTextAlignment) | ||
} | ||
.multilineTextAlignment(multilineTextAlignment) | ||
} | ||
|
||
private var textAlignment: HorizontalAlignment { | ||
switch multilineTextAlignment { | ||
case .leading: | ||
return .leading | ||
case .center: | ||
return .center | ||
case .trailing: | ||
return .trailing | ||
} | ||
} | ||
} | ||
|
||
public extension LabelStyle where Self == RowLabelStyle { | ||
static var row: RowLabelStyle { .init() } | ||
|
||
static func row(_ subtitle: String?) -> RowLabelStyle { | ||
RowLabelStyle(subtitle: subtitle) | ||
} | ||
} | ||
|
||
struct RowLabelStyle_Previews: PreviewProvider { | ||
static var previews: some View { | ||
VStack(spacing: .large) { | ||
Label("Text", systemImage: "sun.max") | ||
.labelStyle(.row) | ||
|
||
Label("Text", systemImage: "sun.max") | ||
.labelStyle(.row("Subtitle")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.