Skip to content

Commit

Permalink
Allow adding a SF Symbol for the tag view
Browse files Browse the repository at this point in the history
  • Loading branch information
mszpro committed Feb 2, 2023
1 parent dbc719e commit fdcb7dc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/SwiftUILibrary/TagView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct TagView: View {
}

var tagContent: String
var sfSymbolImageName: String

var textFont: Font
var textPadding: CGFloat
Expand All @@ -31,16 +32,17 @@ public struct TagView: View {

var tagStyle: TagStyle

public init(tagContent: String, tagBackgroundColor: Color = .blue, textFont: Font = .headline, textPadding: CGFloat = 8, style: TagStyle = .borderedProminent, onTagSelected: @escaping (String) -> Void = { _ in } ) {
public init(tagContent: String, tagBackgroundColor: Color = .blue, textFont: Font = .headline, textPadding: CGFloat = 8, style: TagStyle = .borderedProminent, sfSymbolImageName: String = "", onTagSelected: @escaping (String) -> Void = { _ in } ) {
self.tagContent = tagContent
self.textFont = textFont
self.textPadding = textPadding
self.onTagSelected = onTagSelected
self.tagBackgroundColor = tagBackgroundColor
self.tagStyle = style
self.sfSymbolImageName = sfSymbolImageName
}
public var body: some View {
Text(tagContent)
Label(tagContent, systemImage: sfSymbolImageName)
.font(textFont)
.foregroundColor((tagStyle == .borderedProminent) ? .white : tagBackgroundColor)
.padding(textPadding)
Expand All @@ -62,7 +64,7 @@ public struct TagView: View {
@available(watchOS 6.0, *)
struct TagView_Previews: PreviewProvider {
static var previews: some View {
TagView(tagContent: "Testing")
TagView(tagContent: "Testing", sfSymbolImageName: "checkmark.circle")
TagView(tagContent: "Testing", style: .bordered)
}
}

0 comments on commit fdcb7dc

Please sign in to comment.