From b7339a89b062bd35e45b4f0f878a3d7731469702 Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 3 May 2023 11:55:52 +0900 Subject: [PATCH 1/3] :sparkles: :: CTAButtonStyle --- .../Sources/Button/CTA/CTAButton.swift | 31 +++++++ .../Sources/Button/CTA/CTAButtonStyle.swift | 80 +++++++++++++++++++ .../DesignSystem/Sources/Font/Font+sms.swift | 18 +++++ 3 files changed, 129 insertions(+) create mode 100644 Projects/Core/DesignSystem/Sources/Button/CTA/CTAButton.swift create mode 100644 Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift diff --git a/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButton.swift b/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButton.swift new file mode 100644 index 00000000..7ecd2aca --- /dev/null +++ b/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButton.swift @@ -0,0 +1,31 @@ +import SwiftUI + +public struct CTAButton: View { + var text: String + var style: CTAStyle + var action: () -> Void + + public init( + text: String = "", + style: CTAStyle = .default, + action: @escaping () -> Void = {} + ) { + self.text = text + self.style = style + self.action = action + } + + public var body: some View { + Button(action: action) { + HStack { + Spacer() + + Text(text) + .padding(.vertical, 13.5) + + Spacer() + } + } + .buttonStyle(CTAButtonStyle(style: style)) + } +} diff --git a/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift b/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift new file mode 100644 index 00000000..06251777 --- /dev/null +++ b/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift @@ -0,0 +1,80 @@ +import SwiftUI + +public extension CTAButton { + enum CTAStyle { + case outline + case `default` + } +} + +public struct CTAButtonStyle: ButtonStyle { + var style: CTAButton.CTAStyle + + public func makeBody(configuration: Configuration) -> some View { + switch style { + case .outline: + OutlineButton(configuration: configuration) + + case .`default`: + DefaultButton(configuration: configuration) + } + } +} + +extension CTAButtonStyle { + struct DefaultButton: View { + let configuration: ButtonStyle.Configuration + @Environment(\.isEnabled) var isEnabled + var foregroundColor: Color { + isEnabled ? .sms(.system(.white)) : .sms(.neutral(.n30)) + } + var backgroundColor: Color { + isEnabled ? enabledBackgroundColor : .sms(.neutral(.n20)) + } + var enabledBackgroundColor: Color { + configuration.isPressed ? .sms(.primary(.p3)) : .sms(.primary(.p2)) + } + + var body: some View { + configuration.label + .smsFont(.title2) + .foregroundColor(foregroundColor) + .background(backgroundColor) + .cornerRadius(8) + } + } +} + +extension CTAButtonStyle { + struct OutlineButton: View { + let configuration: ButtonStyle.Configuration + @Environment(\.isEnabled) var isEnabled + var foregroundColor: Color { + isEnabled ? .sms(.system(.white)) : .sms(.neutral(.n30)) + } + var backgroundColor: Color { + isEnabled ? enabledBackgroundColor : .sms(.neutral(.n20)) + } + var enabledBackgroundColor: Color { + configuration.isPressed ? .sms(.neutral(.n10)) : .sms(.system(.white)) + } + var strokeColor: Color { + isEnabled ? enabledStrokeColor : .clear + } + var enabledStrokeColor: Color { + configuration.isPressed ? .sms(.neutral(.n20)) : .sms(.neutral(.n30)) + } + + var body: some View { + configuration.label + .smsFont(.title2) + .foregroundColor(foregroundColor) + .background(backgroundColor) + .cornerRadius(8) + .overlay { + RoundedRectangle(cornerRadius: 8) + .stroke(strokeColor, lineWidth: 1) + } + } + } +} diff --git a/Projects/Core/DesignSystem/Sources/Font/Font+sms.swift b/Projects/Core/DesignSystem/Sources/Font/Font+sms.swift index 5a415a56..261d1af3 100644 --- a/Projects/Core/DesignSystem/Sources/Font/Font+sms.swift +++ b/Projects/Core/DesignSystem/Sources/Font/Font+sms.swift @@ -1,5 +1,23 @@ import SwiftUI +public extension View { + func smsFont( + _ style: Font.SMSFontSystem, + color: Color.SMSColorSystem + ) -> some View { + self + .font(.sms(style)) + .foregroundColor(.sms(color)) + } + + func smsFont( + _ style: Font.SMSFontSystem + ) -> some View { + self + .font(.sms(style)) + } +} + public extension Font { enum SMSFontSystem: SMSFontable { case headline1 From 6fa006175698b1d54c346b2015d8cf5a6ecd2522 Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 3 May 2023 11:57:25 +0900 Subject: [PATCH 2/3] :sparkles: :: FillButton --- .../Sources/Button/Fill/FillButton.swift | 31 ++++++++ .../Sources/Button/Fill/FillButtonStyle.swift | 78 +++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 Projects/Core/DesignSystem/Sources/Button/Fill/FillButton.swift create mode 100644 Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift diff --git a/Projects/Core/DesignSystem/Sources/Button/Fill/FillButton.swift b/Projects/Core/DesignSystem/Sources/Button/Fill/FillButton.swift new file mode 100644 index 00000000..ee61bc3a --- /dev/null +++ b/Projects/Core/DesignSystem/Sources/Button/Fill/FillButton.swift @@ -0,0 +1,31 @@ +import SwiftUI + +public struct FillButton: View { + var text: String + var style: FillStyle + var action: () -> Void + + public init( + text: String = "", + style: FillStyle = .default, + action: @escaping () -> Void = {} + ) { + self.text = text + self.style = style + self.action = action + } + + public var body: some View { + Button(action: action) { + HStack { + Spacer() + + Text(text) + .padding(.vertical, 13.5) + + Spacer() + } + } + .buttonStyle(FillButtonStyle(style: style)) + } +} diff --git a/Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift b/Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift new file mode 100644 index 00000000..8c1f8969 --- /dev/null +++ b/Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift @@ -0,0 +1,78 @@ +import SwiftUI + +public extension FillButton { + enum FillStyle { + case outline + case `default` + } +} + +public struct FillButtonStyle: ButtonStyle { + var style: FillButton.FillStyle + + public func makeBody(configuration: Configuration) -> some View { + switch style { + case .outline: + OutlineButton(configuration: configuration) + + case .`default`: + DefaultButton(configuration: configuration) + } + } +} + +extension FillButtonStyle { + struct DefaultButton: View { + let configuration: ButtonStyle.Configuration + @Environment(\.isEnabled) var isEnabled + var foregroundColor: Color { + isEnabled ? .sms(.system(.white)) : .sms(.neutral(.n30)) + } + var backgroundColor: Color { + isEnabled ? enabledBackgroundColor : .sms(.neutral(.n20)) + } + var enabledBackgroundColor: Color { + configuration.isPressed ? .sms(.primary(.p3)) : .sms(.primary(.p2)) + } + + var body: some View { + configuration.label + .smsFont(.title2) + .foregroundColor(foregroundColor) + .background(backgroundColor) + } + } +} + +extension FillButtonStyle { + struct OutlineButton: View { + let configuration: ButtonStyle.Configuration + @Environment(\.isEnabled) var isEnabled + var foregroundColor: Color { + isEnabled ? .sms(.system(.white)) : .sms(.neutral(.n30)) + } + var backgroundColor: Color { + isEnabled ? enabledBackgroundColor : .sms(.neutral(.n20)) + } + var enabledBackgroundColor: Color { + configuration.isPressed ? .sms(.neutral(.n10)) : .sms(.system(.white)) + } + var strokeColor: Color { + isEnabled ? enabledStrokeColor : .clear + } + var enabledStrokeColor: Color { + configuration.isPressed ? .sms(.neutral(.n20)) : .sms(.neutral(.n30)) + } + + var body: some View { + configuration.label + .smsFont(.title2) + .foregroundColor(foregroundColor) + .background(backgroundColor) + .overlay { + Rectangle() + .stroke(strokeColor, lineWidth: 1) + } + } + } +} From b67fc706b213ffc43ad8143baa1091fa52983070 Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 3 May 2023 12:01:48 +0900 Subject: [PATCH 3/3] :sparkles: :: CTA, Fill Button Style --- .../Demo/Sources/AppDelegate.swift | 20 ----------------- .../DesignSystem/Demo/Sources/DemoView.swift | 22 +++++++++++++++++++ .../Demo/Sources/DesignSystemDemoApp.swift | 10 +++++++++ .../Sources/Button/CTA/CTAButtonStyle.swift | 2 +- .../Sources/Button/Fill/FillButtonStyle.swift | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) delete mode 100644 Projects/Core/DesignSystem/Demo/Sources/AppDelegate.swift create mode 100644 Projects/Core/DesignSystem/Demo/Sources/DemoView.swift create mode 100644 Projects/Core/DesignSystem/Demo/Sources/DesignSystemDemoApp.swift diff --git a/Projects/Core/DesignSystem/Demo/Sources/AppDelegate.swift b/Projects/Core/DesignSystem/Demo/Sources/AppDelegate.swift deleted file mode 100644 index d30d117b..00000000 --- a/Projects/Core/DesignSystem/Demo/Sources/AppDelegate.swift +++ /dev/null @@ -1,20 +0,0 @@ -import UIKit - -@UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - - var window: UIWindow? - - func application( - _ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil - ) -> Bool { - window = UIWindow(frame: UIScreen.main.bounds) - let viewController = UIViewController() - viewController.view.backgroundColor = .yellow - window?.rootViewController = viewController - window?.makeKeyAndVisible() - - return true - } -} diff --git a/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift new file mode 100644 index 00000000..ccd00c8d --- /dev/null +++ b/Projects/Core/DesignSystem/Demo/Sources/DemoView.swift @@ -0,0 +1,22 @@ +import DesignSystem +import SwiftUI + +struct DemoView: View { + var body: some View { + VStack { + Group { + CTAButton(text: "CTA Default", style: .default) + CTAButton(text: "CTA Outline", style: .outline) + FillButton(text: "Fill Default", style: .default) + FillButton(text: "Fill Default", style: .outline) + } + .padding(8) + } + } +} + +struct DemoView_Previews: PreviewProvider { + static var previews: some View { + DemoView() + } +} diff --git a/Projects/Core/DesignSystem/Demo/Sources/DesignSystemDemoApp.swift b/Projects/Core/DesignSystem/Demo/Sources/DesignSystemDemoApp.swift new file mode 100644 index 00000000..819186af --- /dev/null +++ b/Projects/Core/DesignSystem/Demo/Sources/DesignSystemDemoApp.swift @@ -0,0 +1,10 @@ +import SwiftUI + +@main +struct DesignSystemDemoApp: App { + var body: some Scene { + WindowGroup { + DemoView() + } + } +} diff --git a/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift b/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift index 06251777..dea497f4 100644 --- a/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift +++ b/Projects/Core/DesignSystem/Sources/Button/CTA/CTAButtonStyle.swift @@ -50,7 +50,7 @@ extension CTAButtonStyle { let configuration: ButtonStyle.Configuration @Environment(\.isEnabled) var isEnabled var foregroundColor: Color { - isEnabled ? .sms(.system(.white)) : .sms(.neutral(.n30)) + isEnabled ? .sms(.neutral(.n50)) : .sms(.neutral(.n30)) } var backgroundColor: Color { isEnabled ? enabledBackgroundColor : .sms(.neutral(.n20)) diff --git a/Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift b/Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift index 8c1f8969..f7b2193d 100644 --- a/Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift +++ b/Projects/Core/DesignSystem/Sources/Button/Fill/FillButtonStyle.swift @@ -49,7 +49,7 @@ extension FillButtonStyle { let configuration: ButtonStyle.Configuration @Environment(\.isEnabled) var isEnabled var foregroundColor: Color { - isEnabled ? .sms(.system(.white)) : .sms(.neutral(.n30)) + isEnabled ? .sms(.neutral(.n50)) : .sms(.neutral(.n30)) } var backgroundColor: Color { isEnabled ? enabledBackgroundColor : .sms(.neutral(.n20))