-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
807 cannot set a number fontweight in typography #1197
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Commit SHA:70e27aec559b28f4d6d057c053389ff202d36366 Test coverage results 🧪
|
src/plugin/setValuesOnNode.ts
Outdated
@@ -29,7 +29,7 @@ export default async function setValuesOnNode( | |||
const stylePathPrefix = prefixStylesWithThemeName && activeThemeObject | |||
? activeThemeObject.name | |||
: null; | |||
|
|||
console.log('values', values); |
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.
logs
src/plugin/setTextValuesOnTarget.ts
Outdated
@@ -18,11 +19,12 @@ export default async function setTextValuesOnTarget(target: TextNode | TextStyle | |||
} = value; | |||
const family = fontFamily?.toString() || (target.fontName !== figma.mixed ? target.fontName.family : ''); | |||
const style = fontWeight?.toString() || (target.fontName !== figma.mixed ? target.fontName.style : ''); | |||
await figma.loadFontAsync({ family, style }); | |||
const transformedValue = transformValue(style, 'fontWeights'); |
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.
Can we change this so we
- First try to set font weight as it is
- If that fails try the mapping
Reason is that some (not a lot) fonts have weights actually named '500'
This works great so far! One more thing that I feel would be really great if we could get in, as that way we'd probably be able to cover a lot more font weights Some fonts define their weights not like Could we pass in our mapping an array of possible weight names? Then we could extend that with some mappings that map in certain font weights. We'd then try to set each of them, and if there's a match, it will apply that? In the case of |
Commit SHA:272e6fdba9d8737c3266dc9e01d9814fba531450 |
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.
Nice! some minor comments
expect(textNodeMock).toEqual({ ...textNodeMock, fontName: { ...textNodeMock.fontName, style: 'Medium' } }); | ||
}); | ||
|
||
it(`can't set number fontWeight to the node if there is no match fontWeight`, async () => { |
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.
it(`can't set number fontWeight to the node if there is no match fontWeight`, async () => { | |
it(`can't set number fontWeight to the node if there is no matching fontWeight`, async () => { |
@@ -35,6 +36,25 @@ describe('setTextValuesOnTarget', () => { | |||
expect(textNodeMock).toEqual({ ...textNodeMock, fontName: { ...textNodeMock.fontName, style: 'Bold' } }); | |||
}); | |||
|
|||
it('convert number fontWeight and sets to the node', async () => { |
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.
it('convert number fontWeight and sets to the node', async () => { | |
it('converts a numerical fontWeight and sets to the node', async () => { |
src/plugin/setTextValuesOnTarget.ts
Outdated
|
||
try { | ||
await figma.loadFontAsync({ family, style }); |
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.
can we move the await inside the if (fontFamily || fontWeight)
? Then it will only run if required
src/plugin/setTextValuesOnTarget.ts
Outdated
candidateStyles.map(async (candidateStyle) => ( | ||
await figma.loadFontAsync({ family, style: candidateStyle }) | ||
.then(() => { | ||
if (fontFamily || fontWeight) { |
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.
i think we don't even need this check? if we do, it should check for family
and candidateStyle
- as these are the properties we're setting here.
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.
Small change + can we get test coverage to pass?
src/plugin/setTextValuesOnTarget.ts
Outdated
candidateStyles.map(async (candidateStyle) => ( | ||
figma.loadFontAsync({ family, style: candidateStyle }) | ||
.then(() => { | ||
if (fontFamily || candidateStyle) { |
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.
We dont need to check for fontFamily here as we're in an if condition that already checks for that on line 23.
So can just be a check for candidateStyle?
Can we still get the test coverage to pass @swordEdge ? Then I'd merge this in 👍 |
@six7 Sorry to bother you! Has this fix been included in version 119? |
We released this today with version 120 👍 |
We can't set fontWeight with a number between 100 to 900 which is the most common way to set it.
After fixing:
In Figma, there is a match rule between font family and font-weight, so every font weight doesn't work to every font family.
To test this, we can use
Montserrat
fontfamily which support all font weights from 100 to 900.