Skip to content

Commit 3d77e6f

Browse files
committed
Fix SwiftUI font style name
Closes #241
1 parent 5f2cf07 commit 3d77e6f

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

Sources/FigmaExportCore/TextStyle.swift

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public enum DynamicTypeStyle: String, RawRepresentable {
1010
case footnote = "Footnote"
1111
case caption1 = "Caption 1"
1212
case caption2 = "Caption 2"
13-
14-
public var textStyleName: String {
13+
14+
public var uiKitStyleName: String {
1515
switch self {
1616
case .largeTitle:
1717
return "largeTitle"
@@ -37,16 +37,43 @@ public enum DynamicTypeStyle: String, RawRepresentable {
3737
return "caption2"
3838
}
3939
}
40+
41+
public var swiftUIStyleName: String {
42+
switch self {
43+
case .largeTitle:
44+
return "largeTitle"
45+
case .title1:
46+
return "title"
47+
case .title2:
48+
return "title2"
49+
case .title3:
50+
return "title3"
51+
case .headline:
52+
return "headline"
53+
case .body:
54+
return "body"
55+
case .callout:
56+
return "callout"
57+
case .subheadline:
58+
return "subheadline"
59+
case .footnote:
60+
return "footnote"
61+
case .caption1:
62+
return "caption"
63+
case .caption2:
64+
return "caption2"
65+
}
66+
}
4067
}
4168

4269
public struct TextStyle: Asset {
43-
70+
4471
public enum TextCase: String {
4572
case original
4673
case uppercased
4774
case lowercased
4875
}
49-
76+
5077
public var name: String
5178
public var platform: Platform?
5279
public let fontName: String
@@ -64,8 +91,8 @@ public struct TextStyle: Asset {
6491
fontStyle: DynamicTypeStyle?,
6592
lineHeight: Double? = nil,
6693
letterSpacing: Double,
67-
textCase: TextCase = .original) {
68-
94+
textCase: TextCase = .original
95+
) {
6996
self.name = name
7097
self.fontName = fontName
7198
self.fontSize = fontSize

Sources/XcodeExport/XcodeTypographyExporter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final public class XcodeTypographyExporter: XcodeExporterBase {
5353
"fontName": $0.fontName,
5454
"fontSize": $0.fontSize,
5555
"supportsDynamicType": $0.fontStyle != nil,
56-
"type": $0.fontStyle?.textStyleName ?? ""
56+
"type": $0.fontStyle?.uiKitStyleName ?? ""
5757
]
5858
}
5959
let env = makeEnvironment(templatesPath: output.templatesPath)
@@ -71,7 +71,7 @@ final public class XcodeTypographyExporter: XcodeExporterBase {
7171
"fontName": $0.fontName,
7272
"fontSize": $0.fontSize,
7373
"supportsDynamicType": $0.fontStyle != nil,
74-
"type": $0.fontStyle?.textStyleName ?? ""
74+
"type": $0.fontStyle?.swiftUIStyleName ?? ""
7575
]
7676
}
7777
let env = makeEnvironment(templatesPath: output.templatesPath)
@@ -83,7 +83,7 @@ final public class XcodeTypographyExporter: XcodeExporterBase {
8383

8484
private func makeLabelStyleExtensionFileContents(textStyles: [TextStyle], labelStyleExtensionURL: URL) throws -> FileContents {
8585
let dict = textStyles.map { style -> [String: Any] in
86-
let type: String = style.fontStyle?.textStyleName ?? ""
86+
let type: String = style.fontStyle?.uiKitStyleName ?? ""
8787
return [
8888
"className": style.name.first!.uppercased() + style.name.dropFirst(),
8989
"varName": style.name,
@@ -103,7 +103,7 @@ final public class XcodeTypographyExporter: XcodeExporterBase {
103103

104104
private func makeLabel(textStyles: [TextStyle], labelsDirectory: URL, separateStyles: Bool) throws -> FileContents {
105105
let dict = textStyles.map { style -> [String: Any] in
106-
let type: String = style.fontStyle?.textStyleName ?? ""
106+
let type: String = style.fontStyle?.uiKitStyleName ?? ""
107107
return [
108108
"className": style.name.first!.uppercased() + style.name.dropFirst(),
109109
"varName": style.name,

0 commit comments

Comments
 (0)