Skip to content

Commit

Permalink
💄 :: [#332] DesignSystem / Chip
Browse files Browse the repository at this point in the history
  • Loading branch information
kimsh153 committed May 24, 2024
1 parent 30284a3 commit 6c36c32
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Projects/Core/DesignSystem/Sources/Chip/SMSChip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import ViewUtil
public struct SMSChip<Content: View>: View {
var iconLabel: Content
var text: String
var style: ChipStyle
var action: () -> Void

public init(
_ text: String,
style: ChipStyle = .default,
action: @escaping () -> Void = {},
iconLabel: @escaping () -> Content = {
SMSIcon(.plus, renderingMode: .template, width: 12, height: 12)
}
) {
self.text = text
self.style = style
self.iconLabel = iconLabel()
self.action = action
}
Expand All @@ -24,9 +27,8 @@ public struct SMSChip<Content: View>: View {

Text(text)
}
.smsFont(.body1, color: .neutral(.n30))
.buttonWrapper(action)
.buttonStyle(SMSChipButtonStyle())
.buttonStyle(SMSChipButtonStyle(style: style))
}
}

Expand Down
56 changes: 49 additions & 7 deletions Projects/Core/DesignSystem/Sources/Chip/SMSChipButtonStyle.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,54 @@
import SwiftUI

public enum ChipStyle {
case outline
case `default`
}

struct SMSChipButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.padding(8)
.background {
configuration.isPressed ? Color.sms(.neutral(.n10)) : .sms(.system(.white))
}
.cornerRadius(8)
var style: ChipStyle

public func makeBody(configuration: Configuration) -> some View {
switch style {
case .outline:
OutlineChip(configuration: configuration)

case .`default`:
DefaultChip(configuration: configuration)
}
}
}

extension SMSChipButtonStyle {
struct DefaultChip: View {
let configuration: ButtonStyle.Configuration

var body: some View {
configuration.label
.smsFont(.body1, color: .neutral(.n30))
.padding(8)
.background {
configuration.isPressed ? Color.sms(.neutral(.n10)) : .sms(.system(.white))
}
.cornerRadius(8)
}
}
}

extension SMSChipButtonStyle {
struct OutlineChip: View {
let configuration: ButtonStyle.Configuration
var body: some View {
configuration.label
.padding(8)
.smsFont(.body1, color: .system(.black))
.background {
configuration.isPressed ? Color.sms(.neutral(.n10)) : .sms(.system(.white))
}
.overlay {
RoundedRectangle(cornerRadius: 8).stroke(Color.sms(.system(.black)), lineWidth: 1)
}
.cornerRadius(8)
}
}
}

0 comments on commit 6c36c32

Please sign in to comment.