-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue when a font size was specified but not a font name in a config
This would cause the font name to be 'undefined' on initial render
- Loading branch information
1 parent
ad9c4ec
commit 42f2208
Showing
7 changed files
with
60 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { makeMergedConfig } from './assetStyles' | ||
|
||
describe("font styles", () => { | ||
test("merged font config handles specified sizes but unspecified fonts", () => { | ||
let config = { | ||
"assetTypeFontSize": "1.03em", | ||
"assetTypeFont": undefined, | ||
"assetNameFontSize": "1.26em", | ||
"assetNameFont": undefined, | ||
"detailsFontSize": "0.97em", | ||
"detailsFont": undefined, | ||
"trackFontSize": "1.42em", | ||
"trackFont": undefined | ||
} | ||
|
||
let result = makeMergedConfig(config) | ||
|
||
expect(result.assetNameFont).toBe("Simonetta") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export const createGoogleFontString = (...fonts) => { | ||
let urlifiedFonts = Array.from(new Set(fonts)) | ||
.filter(font => font) | ||
.map(font => font.replace(/ /g, "+")) | ||
.join("|"); | ||
return urlifiedFonts ? `https://fonts.googleapis.com/css?family=${urlifiedFonts}&display=swap` : ""; | ||
}; | ||
|
||
const defaultFontConfig = { | ||
assetTypeFontSize: "1.03em", | ||
assetTypeFont: "Simonetta", | ||
assetNameFontSize: "1.26em", | ||
assetNameFont: "Simonetta", | ||
detailsFontSize: "0.97em", | ||
detailsFont: "PT Serif", | ||
trackFontSize: "1.42em", | ||
trackFont: "Simonetta" | ||
}; | ||
|
||
export const makeMergedConfig = (config): FontConfig => { | ||
let merged = Object.assign({}, defaultFontConfig) | ||
for (let key in merged) { | ||
merged[key] = config[key] || merged[key] | ||
} | ||
return merged | ||
}; | ||
|
||
export interface FontConfig { | ||
assetTypeFontSize: string; | ||
assetTypeFont: string; | ||
assetNameFontSize: string; | ||
assetNameFont: string; | ||
detailsFontSize: string; | ||
detailsFont: string; | ||
trackFontSize: string; | ||
trackFont: string; | ||
} |
File renamed without changes.
File renamed without changes.