Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ”€ :: λ²„νŠΌ λ””μžμΈ μ‹œμŠ€ν…œ #29

Merged
merged 3 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions Projects/Core/DesignSystem/Demo/Sources/AppDelegate.swift

This file was deleted.

22 changes: 22 additions & 0 deletions Projects/Core/DesignSystem/Demo/Sources/DemoView.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

@main
struct DesignSystemDemoApp: App {
var body: some Scene {
WindowGroup {
DemoView()
}
}
}
31 changes: 31 additions & 0 deletions Projects/Core/DesignSystem/Sources/Button/CTA/CTAButton.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}
Original file line number Diff line number Diff line change
@@ -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(.neutral(.n50)) : .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)
}
}
}
}
31 changes: 31 additions & 0 deletions Projects/Core/DesignSystem/Sources/Button/Fill/FillButton.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}
Original file line number Diff line number Diff line change
@@ -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(.neutral(.n50)) : .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)
}
}
}
}
18 changes: 18 additions & 0 deletions Projects/Core/DesignSystem/Sources/Font/Font+sms.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down