-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fueled typography #1
base: fueled
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,13 +61,15 @@ ios: | |
|
||
# Parameters for exporting typography | ||
typography: | ||
# Path to directory where to place UIFont+extension.swift file | ||
# Choose what font system you want to use SwiftUI or UIKit | ||
fontSystem: UIKit | ||
# Path to directory where to place UIFont+extension.swift file required for both SwiftUI and UIKit | ||
Comment on lines
+64
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we include this in |
||
fontSwift: "./UIComponents/Source/Typography/UIFont+extension.swift" | ||
# [optional] Absolute or relative path to swift file where to generate LabelStyle extensions for each style (LabelStyle extension). | ||
labelStyleSwift: "./UIComponents/Source/Typography/LabelStyle+extension.swift" | ||
# Will FigmaExport generate UILabel for each text style (font) e.g. HeaderLabel, BodyLabel, CaptionLabel. | ||
generateLabels: true | ||
# Path to directory where to place UILabel for each text style (font) (Required if generateLabels = true) | ||
labelsDirectory: "./UIComponents/Source/Typography" | ||
# Should FigmaExport generate TextStyles or Labels (based on fontSystem) for each text style (font)? E.g. Header, Body, Caption | ||
generateStyles: true | ||
# Relative or absolute path to directory where to place TextStyles or Labels (based on fontSystem) for each text style (font) (Required if generateStyles = true) | ||
stylesDirectory: "./UIComponents/Source/Typography" | ||
Comment on lines
+70
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# Typography name style: camelCase or snake_case | ||
nameStyle: camelCase |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ ios: | |
fontSwift: "./ExampleSwiftUI/View/Common/UIFont+extension.swift" | ||
# [optional] Absolute or relative path to swift file where to export SwiftUI fonts (Font extension). | ||
swiftUIFontSwift: "./ExampleSwiftUI/View/Common/Font+extension.swift" | ||
# Will FigmaExport generate UILabel for each text style (font) e.g. HeaderLabel, BodyLabel, CaptionLabel. | ||
generateLabels: false | ||
# Should FigmaExport generate TextStyles for each text style (font)? E.g. Header, Body, Caption | ||
generateTextStyles: true | ||
Comment on lines
+68
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# Typography name style: camelCase or snake_case | ||
nameStyle: camelCase |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,13 +204,15 @@ If name of an image contains idiom at the end (e.g. ~ipad), it will be exported | |
#### Typography | ||
|
||
When your execute `figma-export typography` command `figma-export` generates 3 files: | ||
1. `UIFont+extension.swift` extension for UIFont that declares your custom fonts. Use these fonts like this `UIFont.header()`, `UIFont.caption1()`. | ||
2. `LabelStyle.swift` struct for generating attributes for NSAttributesString with custom lineHeight and tracking (letter spacing). | ||
3. `Label.swift` file that contains base Label class and class for each text style. E.g. HeaderLabel, BodyLabel, Caption1Label. Specify these classes in xib files on in code. | ||
1. `TextStyle.swift` struct for generating TextStyles for SwiftUI with custom line spacing, kerning (letter spacing) and text case. | ||
2. `TextStyle+extension.swift` extension including all the custom TextStyles from the Figma file. | ||
3. `Font+extension` extension for Font that declares your custom fonts. | ||
4. `UIFont+extension.swift` extension for UIFont that declares your custom fonts. Mainly used to get the default font lineHeight. | ||
|
||
Example of these files: | ||
- [./Examples/Example/UIComponents/Source/Typography/Label.swift](./Examples/Example/UIComponents/Source/Typography/Label.swift) | ||
- [./Examples/Example/UIComponents/Source/Typography/LabelStyle.swift](./Examples/Example/UIComponents/Source/Typography/LabelStyle.swift) | ||
- [./Examples/Example/UIComponents/Source/Typography/TextStyle.swift](./Examples/Example/UIComponents/Source/Typography/TextStyle.swift) | ||
- [./Examples/Example/UIComponents/Source/Typography/TextStyle+extension.swift](./Examples/Example/UIComponents/Source/Typography/TextStyle+extension.swift) | ||
- [./Examples/Example/UIComponents/Source/Typography/Font+extension.swift](./Examples/Example/UIComponents/Source/Typography/Font+extension.swift) | ||
- [./Examples/Example/UIComponents/Source/Typography/UIFont+extension.swift](./Examples/Example/UIComponents/Source/Typography/UIFont+extension.swift) | ||
|
||
### Android | ||
|
@@ -430,11 +432,10 @@ Custom Stencil templates for colors and images must have the following names: | |
- Image+extension.swift.stencil for SwiftUI images | ||
|
||
Custom Stencil templates for typography must have the following names: | ||
- Label.swift.stencil, | ||
- LabelStyle.swift.stencil, | ||
- LabelStyle+extension.swift.stencil, | ||
- TextStyle.swift.stencil, | ||
- TextStyle+extension.swift.stencil, | ||
- Font+extension.swift.stencil | ||
- UIFont+extension.swift.stencil | ||
Comment on lines
+435
to
438
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question - are we removing support for |
||
- Font+extension.swift.stencil.stencil | ||
|
||
##### Android | ||
|
||
|
@@ -453,7 +454,7 @@ Custom Stencil templates must have the following names: | |
#### iOS | ||
1. Add a custom font to the Xcode project. Drag & drop font file to the Xcode project, set target membership, and add font file name in the Info.plist file. [See developer documentation for more info.](https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app)<br><img src="images/fonts.png" width="400" /> | ||
2. Run `figma-export typography` to export text styles | ||
3. Use generated fonts and labels in your code. E.g. `button.titleLabel?.font = UIFont.body()`, `let label = HeaderLabel()`. | ||
3. Use generated fonts and text styles in your code. E.g. `Text("Header").textStyle(.header)`. | ||
|
||
#### Android | ||
1. Place font file under the `res` directory of your module | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import Foundation | ||
import FigmaExportCore | ||
import XcodeExport | ||
|
||
extension NameStyle: Decodable {} | ||
|
||
|
@@ -92,11 +93,13 @@ struct Params: Decodable { | |
} | ||
|
||
struct Typography: Decodable { | ||
let fontSystem: FontSystem? | ||
let fontSwift: URL? | ||
let labelStyleSwift: URL? | ||
let textStyleSwift: URL? | ||
let labelStyleSwift: URL? | ||
let swiftUIFontSwift: URL? | ||
let generateLabels: Bool | ||
let labelsDirectory: URL? | ||
let generateStyles: Bool | ||
let stylesDirectory: URL? | ||
let nameStyle: NameStyle | ||
} | ||
Comment on lines
95
to
104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation is not consistent here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh good one, its difficult on the project since the default is spaces, so I need to change this for every file I'm working on. |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
{% include "header.stencil" %} | ||
import SwiftUI | ||
|
||
public extension Font { | ||
{% for textStyle in textStyles %}{% if textStyle.supportsDynamicType %} | ||
static func {{ textStyle.name }}() -> Font { | ||
if #available(iOS 14.0, *) { | ||
return Font.custom("{{ textStyle.fontName }}", size: {{ textStyle.fontSize }}, relativeTo: .{{ textStyle.type }}) | ||
} else { | ||
return Font.custom("{{ textStyle.fontName }}", size: {{ textStyle.fontSize }}) | ||
} | ||
}{% else %} | ||
static func {{ textStyle.name }}() -> Font { | ||
Font.custom("{{ textStyle.fontName }}", size: {{ textStyle.fontSize }}) | ||
}{% endif %}{% endfor %} | ||
public extension Font {{ '{' }}{% for textStyle in textStyles %}{% if textStyle.supportsDynamicType %} | ||
static let {{ textStyle.name }} = Font.custom("{{ textStyle.fontName }}", size: {{ textStyle.fontSize }}, relativeTo: .{{ textStyle.type }}){% else %} | ||
static let {{ textStyle.name }} = Font.custom("{{ textStyle.fontName }}", size: {{ textStyle.fontSize }}){% endif %}{% endfor %} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be in addition to the original
labelStyleSwift
,generateLabels
, andlabelsDirectory
properties instead of replacing them? Since we are still supporting generating theLabel
,LabelStyle
,LabelStyle+extension
files for UIKit