Skip to content
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

1671 base font size token doesnt pick up tokens #1672

Merged
merged 9 commits into from
Mar 19, 2023
3 changes: 2 additions & 1 deletion src/app/store/models/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export const settings = createModel<RootModel>()({
};
},
},
effects: () => ({
effects: (dispatch) => ({
setWindowSize: (payload) => {
AsyncMessageChannel.ReactInstance.message({
type: AsyncMessageTypes.RESIZE_WINDOW,
Expand Down Expand Up @@ -196,6 +196,7 @@ export const settings = createModel<RootModel>()({
},
setBaseFontSize: (payload, rootState) => {
setUI(rootState.settings);
dispatch.tokenState.updateDocument({ shouldUpdateNodes: true });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you set this to shouldUpdateNodes: false?

We wouldnt want a change in the base font size trigger a document wide update, which could mean the users would have to wait a long time. So instead lets just update the document, but not the nodes.

},
setAliasBaseFontSize: (payload, rootState) => {
setUI(rootState.settings);
Expand Down
14 changes: 2 additions & 12 deletions src/plugin/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,21 +223,11 @@ export async function updateNodes(
tokens: Map<string, AnyTokenList[number]>,
settings?: SettingsState,
) {
const { ignoreFirstPartForStyles, prefixStylesWithThemeName, aliasBaseFontSize } = settings ?? {};
const { ignoreFirstPartForStyles, prefixStylesWithThemeName, baseFontSize } = settings ?? {};
const figmaStyleMaps = getAllFigmaStyleMaps();
const themeInfo = await AsyncMessageChannel.PluginInstance.message({
type: AsyncMessageTypes.GET_THEME_INFO,
});
let nameToLookFor = '';
if (aliasBaseFontSize) {
if (aliasBaseFontSize.startsWith('{')) {
nameToLookFor = aliasBaseFontSize.slice(1, aliasBaseFontSize.length - 1);
} else if (aliasBaseFontSize.startsWith('$')) {
nameToLookFor = aliasBaseFontSize.substring(1);
}
}
const resolvedToken = tokens.get(nameToLookFor);
const resolvedBaseFontSize = resolvedToken ? String(resolvedToken.value) : aliasBaseFontSize;
postToUI({
type: MessageFromPluginTypes.START_JOB,
job: {
Expand Down Expand Up @@ -268,7 +258,7 @@ export async function updateNodes(
themeInfo,
ignoreFirstPartForStyles,
prefixStylesWithThemeName,
resolvedBaseFontSize,
baseFontSize,
);
store.successfulNodes.add(entry.node);
returnedValues.add(entry.tokens);
Expand Down