-
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
a5e17ce
commit 7d133be
Showing
1 changed file
with
14 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
import SwiftUI | ||
|
||
public struct CapsuleButtonStyle: ButtonStyle { | ||
@Environment(\.colorScheme) var colorScheme | ||
private let fontColor: Color | ||
private let backgroundColor: Color | ||
private let font: Font | ||
|
||
init(fontColor: Color, backgroundColor: Color, font: Font) { | ||
self.fontColor = fontColor | ||
self.backgroundColor = backgroundColor | ||
self.font = font | ||
} | ||
|
||
public func makeBody(configuration: Configuration) -> some View { | ||
configuration.label | ||
.padding() | ||
.font(.body.bold()) | ||
.foregroundColor(colorScheme == .dark ? .white : .black) | ||
.font(font) | ||
.foregroundColor(fontColor) | ||
.background( | ||
Capsule() | ||
.fill(colorScheme == .dark ? .white : .black) | ||
.fill(backgroundColor) | ||
) | ||
} | ||
} | ||
|
||
public extension ButtonStyle where Self == CapsuleButtonStyle { | ||
static var capsule: Self { | ||
return .init() | ||
static func capsule(fontColor: Color, backgroundColor: Color, font: Font = .body.bold()) -> Self { | ||
.init(fontColor: fontColor, backgroundColor: backgroundColor, font: font) | ||
} | ||
} |