Skip to content

Commit

Permalink
Added background colour to circled number (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiuliaAriu authored Sep 6, 2021
1 parent eef1f20 commit b4fe89c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Sources/UIExtensions/Components/SwiftUI/Pure/CircledNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@ public struct CircledNumber<Content: View, S: ShapeStyle>: View {
private let length: CGFloat
private let content: Content
private let strokeContent: S
private let backgroundColor: Color

public init(number: Int, length: CGFloat, strokeContent: S, @ViewBuilder content: @escaping (Int) -> Content) {
public init(number: Int, length: CGFloat, strokeContent: S, backgroundColor: Color = Color.clear, @ViewBuilder content: @escaping (Int) -> Content) {
self.content = content(number)
self.length = length
self.strokeContent = strokeContent
self.backgroundColor = backgroundColor
}
public var body: some View {
content
.squared(length: length)
.background(Circle().stroke(strokeContent), alignment: .center)

.frame(width: length, height: length, alignment: .center)
.background(Circle()
.stroke(strokeContent), alignment: .center)
.background(Circle().fill(backgroundColor))
}
}

#if DEBUG
struct CircledNumberPreviews: PreviewProvider {
static var previews: some View {
CircledNumber(number: 9, length: 18, strokeContent: Color.black) { Text("\($0)") }
VStack(spacing: 20) {
CircledNumber(number: 9, length: 18, strokeContent: Color.black, backgroundColor: Color.red) { Text("\($0)") }

CircledNumber(number: 9, length: 18, strokeContent: Color.red) { Text("\($0)") }
}
}
}
#endif

0 comments on commit b4fe89c

Please sign in to comment.