Skip to content

Commit

Permalink
[WEAV-32] DesignSystem - Typography 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jisu15-kim committed Sep 14, 2024
1 parent 2e36c84 commit 87e9876
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 14 deletions.
14 changes: 0 additions & 14 deletions Projects/DesignSystem/DesignCore/Sources/Pretendard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,6 @@ public enum PretendardWeight {
}
}

//public extension Font {
// static func pretendard(_ weight: PretendardWeight, size: CGFloat) -> Font {
// return weight.font.font(size: size)
// }
//
// static func pretendard(
// _ weight: PretendardWeight,
// size: CGFloat,
// lineHeight: CGFloat
// ) -> Font {
// return weight.font.font(size: size)
// }
//}

public extension UIFont {
static func pretendard(_ weight: PretendardWeight, size: CGFloat) -> UIFont {
return .init(font: weight.font, size: size)!
Expand Down
106 changes: 106 additions & 0 deletions Projects/DesignSystem/DesignCore/Sources/Typography.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// Typography.swift
// DesignCore
//
// Created by 김지수 on 9/14/24.
// Copyright © 2024 com.studentcenter. All rights reserved.
//

import SwiftUI

public enum Typography {
// EN - Medium
case en_medium_20
case en_medium_16

// Pretendard - semibold
case semibold_28
case semibold_24
case semibold_20
case semibold_14

// Pretendard - medium
case medium_18
case medium_16
case medium_14

// Pretendard - regular
case regular_15
case regular_14
case regular_12
}

extension Typography {
var fontSize: CGFloat {
switch self {
case .en_medium_20: return 20
case .en_medium_16: return 16
case .semibold_28: return 28
case .semibold_24: return 24
case .semibold_20: return 20
case .semibold_14: return 14
case .medium_18: return 18
case .medium_16: return 16
case .medium_14: return 14
case .regular_15: return 15
case .regular_14: return 14
case .regular_12: return 12
}
}

var lineHeight: CGFloat {
switch self {
case .en_medium_20: return 20
case .en_medium_16: return 16
default: return fontSize * 1.5
}
}
}

extension Typography {
var pretendardWeight: PretendardWeight? {
switch self {
case .en_medium_20, .en_medium_16:
return nil

case .semibold_28, .semibold_24, .semibold_20, .semibold_14:
return ._600

case .medium_18, .medium_16, .medium_14:
return ._500

case .regular_15, .regular_14, .regular_12:
return ._400
}
}
}

private struct TypographyViewModifier: ViewModifier {
let typography: Typography

func body(content: Content) -> some View {
switch typography {
case .en_medium_16, .en_medium_20:
content
.robotoSlab(
size: typography.fontSize,
lineHeight: typography.lineHeight
)
default:
content
.pretendard(
weight: typography.pretendardWeight!,
size: typography.fontSize,
lineHeight: typography.lineHeight
)
}
}
}

public extension View {
func typography(_ typograpy: Typography) -> some View {
return modifier(
TypographyViewModifier(typography: typograpy)
)
}
}

0 comments on commit 87e9876

Please sign in to comment.