Skip to content

Commit

Permalink
update: Extension method
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Apr 28, 2023
1 parent a5e17ce commit 7d133be
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Sources/TsuzuKit/CapsuleButtonStyle.swift
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)
}
}

0 comments on commit 7d133be

Please sign in to comment.