Skip to content

Commit

Permalink
#43: Fix some code smells.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed May 20, 2022
1 parent 91a0a3f commit 5218705
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
40 changes: 20 additions & 20 deletions DesignKit/Sources/Fonts/ElementFonts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,102 +57,102 @@ public class ElementFonts {
extension ElementFonts {

public var largeTitle: SharedFont {
let uiFont = self.font(forTextStyle: .largeTitle)
let uiFont = font(forTextStyle: .largeTitle)
return SharedFont(uiFont: uiFont, font: .largeTitle)
}

public var largeTitleB: SharedFont {
let uiFont = self.largeTitle.uiFont.vc_bold
let uiFont = largeTitle.uiFont.vc_bold
return SharedFont(uiFont: uiFont, font: .largeTitle.bold())
}

public var title1: SharedFont {
let uiFont = self.font(forTextStyle: .title1)
let uiFont = font(forTextStyle: .title1)
return SharedFont(uiFont: uiFont, font: .title)
}

public var title1B: SharedFont {
let uiFont = self.title1.uiFont.vc_bold
let uiFont = title1.uiFont.vc_bold
return SharedFont(uiFont: uiFont, font: .title.bold())
}

public var title2: SharedFont {
let uiFont = self.font(forTextStyle: .title2)
let uiFont = font(forTextStyle: .title2)
return SharedFont(uiFont: uiFont, font: .title2)
}

public var title2B: SharedFont {
let uiFont = self.title2.uiFont.vc_bold
let uiFont = title2.uiFont.vc_bold
return SharedFont(uiFont: uiFont, font: .title2.bold())
}

public var title3: SharedFont {
let uiFont = self.font(forTextStyle: .title3)
let uiFont = font(forTextStyle: .title3)
return SharedFont(uiFont: uiFont, font: .title3)
}

public var title3SB: SharedFont {
let uiFont = self.title3.uiFont.vc_semiBold
let uiFont = title3.uiFont.vc_semiBold
return SharedFont(uiFont: uiFont, font: .title3.weight(.semibold))
}

public var headline: SharedFont {
let uiFont = self.font(forTextStyle: .headline)
let uiFont = font(forTextStyle: .headline)
return SharedFont(uiFont: uiFont, font: .headline)
}

public var subheadline: SharedFont {
let uiFont = self.font(forTextStyle: .subheadline)
let uiFont = font(forTextStyle: .subheadline)
return SharedFont(uiFont: uiFont, font: .subheadline)
}

public var body: SharedFont {
let uiFont = self.font(forTextStyle: .body)
let uiFont = font(forTextStyle: .body)
return SharedFont(uiFont: uiFont, font: .body)
}

public var bodySB: SharedFont {
let uiFont = self.body.uiFont.vc_semiBold
let uiFont = body.uiFont.vc_semiBold
return SharedFont(uiFont: uiFont, font: .body.weight(.semibold))
}

public var callout: SharedFont {
let uiFont = self.font(forTextStyle: .callout)
let uiFont = font(forTextStyle: .callout)
return SharedFont(uiFont: uiFont, font: .callout)
}

public var calloutSB: SharedFont {
let uiFont = self.callout.uiFont.vc_semiBold
let uiFont = callout.uiFont.vc_semiBold
return SharedFont(uiFont: uiFont, font: .callout.weight(.semibold))
}

public var footnote: SharedFont {
let uiFont = self.font(forTextStyle: .footnote)
let uiFont = font(forTextStyle: .footnote)
return SharedFont(uiFont: uiFont, font: .footnote)
}

public var footnoteSB: SharedFont {
let uiFont = self.footnote.uiFont.vc_semiBold
let uiFont = footnote.uiFont.vc_semiBold
return SharedFont(uiFont: uiFont, font: .footnote.weight(.semibold))
}

public var caption1: SharedFont {
let uiFont = self.font(forTextStyle: .caption1)
let uiFont = font(forTextStyle: .caption1)
return SharedFont(uiFont: uiFont, font: .caption)
}

public var caption1SB: SharedFont {
let uiFont = self.caption1.uiFont.vc_semiBold
let uiFont = caption1.uiFont.vc_semiBold
return SharedFont(uiFont: uiFont, font: .caption.weight(.semibold))
}

public var caption2: SharedFont {
let uiFont = self.font(forTextStyle: .caption2)
let uiFont = font(forTextStyle: .caption2)
return SharedFont(uiFont: uiFont, font: .caption2)
}

public var caption2SB: SharedFont {
let uiFont = self.caption2.uiFont.vc_semiBold
let uiFont = caption2.uiFont.vc_semiBold
return SharedFont(uiFont: uiFont, font: .caption2.weight(.semibold))
}
}
10 changes: 6 additions & 4 deletions DesignKit/Sources/Fonts/UIFont.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public extension UIFont {
guard let descriptor = fontDescriptor.withSymbolicTraits(traits) else {
return self
}
return UIFont(descriptor: descriptor, size: 0) // Size 0 means keep the size as it is

// Size 0 means keep the size as it is
return UIFont(descriptor: descriptor, size: 0)
}

/// Update current font with a given Weight
Expand All @@ -42,14 +44,14 @@ public extension UIFont {
// MARK: - Shortcuts

var vc_bold: UIFont {
return self.vc_withTraits(.traitBold)
return vc_withTraits(.traitBold)
}

var vc_semiBold: UIFont {
return self.vc_withWeight(weight: .semibold)
return vc_withWeight(weight: .semibold)
}

var vc_italic: UIFont {
return self.vc_withTraits(.traitItalic)
return vc_withTraits(.traitItalic)
}
}
3 changes: 2 additions & 1 deletion DesignKit/Sources/TextFields/BorderedInputFieldStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public struct BorderedInputFieldStyle: TextFieldStyle {
return .element.alert
} else if isEditing {
return .element.accent
} else {
return .element.quaternaryContent
}
return .element.quaternaryContent
}

private var accentColor: Color {
Expand Down
2 changes: 1 addition & 1 deletion DesignKit/StyleDictionary/ElementColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ public struct ElementColorsUIKit {
public var quaternaryContent: UIColor { UIColor(named: "quaternaryContent", in: Bundle.module, compatibleWith: nil)! }
public var quinaryContent: UIColor { UIColor(named: "quinaryContent", in: Bundle.module, compatibleWith: nil)! }
public var background: UIColor { UIColor(named: "background", in: Bundle.module, compatibleWith: nil)! }
}
}
2 changes: 1 addition & 1 deletion ElementStyle/formats/swiftColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ dictionary.allProperties.map(token => {
return ` public var ${token.name}: UIColor { ${value} }`
}
}).join(`\n`) +
`\n}`
`\n}\n`
}

0 comments on commit 5218705

Please sign in to comment.