-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): added fill support for font face config
- Loading branch information
1 parent
3b5ef1c
commit 537d63a
Showing
2 changed files
with
38 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,44 @@ | ||
import { GenericFont } from './types' | ||
import { FontWeightSteps, GenericFont } from './types' | ||
|
||
const fontWeights: FontWeightSteps[] = [ | ||
'100', | ||
'200', | ||
'300', | ||
'400', | ||
'500', | ||
'600', | ||
'700', | ||
'800', | ||
'900', | ||
] | ||
|
||
const processSection = <T>( | ||
section: string | Record<string, T>, | ||
keys: string[] | ||
): string | Record<string, T> => { | ||
if (typeof section === 'string') return section | ||
|
||
let fillValue = section[Object.keys(section)[0]] | ||
|
||
return Object.fromEntries( | ||
keys.map((key) => { | ||
const value = section[key] ?? fillValue | ||
fillValue = value | ||
return [key, value] | ||
}) | ||
) | ||
} | ||
|
||
export const createFont = <A extends GenericFont>(font: A): A => { | ||
// fills in any missing values based on size keys being standard | ||
const sizeKeys = Object.keys(font.size) | ||
|
||
// fill in intermediate values | ||
for (const key in font) { | ||
if (key === 'size' || key === 'family' || key === 'face') { | ||
continue | ||
} | ||
const section = font[key] as Object | ||
const keys = Object.keys(section) | ||
|
||
// fill with first filled in value to start | ||
let fillVal = section[keys[0]] | ||
|
||
for (const sKey of sizeKeys) { | ||
if (!(sKey in section)) { | ||
section[sKey] = fillVal | ||
} else { | ||
// if exists, set as the fillVal | ||
fillVal = section[sKey] | ||
} | ||
} | ||
} | ||
Object.fromEntries( | ||
Object.entries(font).map(([key, section]) => { | ||
const fillKeys = key === 'face' ? fontWeights : sizeKeys | ||
|
||
return [key, processSection(section, fillKeys)] | ||
}) | ||
) | ||
|
||
return Object.freeze(font) | ||
} |
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
537d63a
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.
Successfully deployed to the following URLs:
site – ./
site-tamagui.vercel.app
site-beta-beige.vercel.app
site-git-master-tamagui.vercel.app