Skip to content

Commit

Permalink
1671 base font size token doesnt pick up tokens (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
swordEdge authored Mar 19, 2023
1 parent 5bb4a1d commit 1325d8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/app/components/Tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import parseJson from '@/utils/parseJson';
import AttentionIcon from '@/icons/attention.svg';
import { TokensContext } from '@/context';
import {
activeTokenSetSelector, manageThemesModalOpenSelector, scrollPositionSetSelector, showEditFormSelector, tokenFilterSelector, tokensSelector, tokenTypeSelector, usedTokenSetSelector,
activeTokenSetSelector, aliasBaseFontSizeSelector, manageThemesModalOpenSelector, scrollPositionSetSelector, showEditFormSelector, tokenFilterSelector, tokensSelector, tokenTypeSelector, usedTokenSetSelector,
} from '@/selectors';
import { ThemeSelector } from './ThemeSelector';
import IconToggleableDisclosure from '@/app/components/IconToggleableDisclosure';
Expand All @@ -31,6 +31,7 @@ import { ManageThemesModal } from './ManageThemesModal';
import { TokenSetStatus } from '@/constants/TokenSetStatus';
import { activeTokensTabSelector } from '@/selectors/activeTokensTabSelector';
import { stringTokensSelector } from '@/selectors/stringTokensSelector';
import { getAliasValue } from '@/utils/alias';

const StyledButton = styled('button', {
'&:focus, &:hover': {
Expand Down Expand Up @@ -98,6 +99,7 @@ function Tokens({ isActive }: { isActive: boolean }) {
const manageThemesModalOpen = useSelector(manageThemesModalOpenSelector);
const scrollPositionSet = useSelector(scrollPositionSetSelector);
const tokenFilter = useSelector(tokenFilterSelector);
const aliasBaseFontSize = useSelector(aliasBaseFontSizeSelector);
const dispatch = useDispatch<Dispatch>();
const [tokenSetsVisible, setTokenSetsVisible] = React.useState(true);
const { getStringTokens } = useTokens();
Expand Down Expand Up @@ -191,6 +193,11 @@ function Tokens({ isActive }: { isActive: boolean }) {
}
}, [dispatch, tokens, stringTokens, activeTokenSet]);

React.useEffect(() => {
const newBaseFontSize = getAliasValue(aliasBaseFontSize, resolvedTokens);
dispatch.settings.setBaseFontSize(String(newBaseFontSize));
}, [resolvedTokens, aliasBaseFontSize]);

const saveScrollPositionSet = React.useCallback((tokenSet: string) => {
if (tokenDiv.current) {
dispatch.uiState.setScrollPositionSet({ ...scrollPositionSet, [tokenSet]: tokenDiv.current?.scrollTop });
Expand Down
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: false });
},
setAliasBaseFontSize: (payload, rootState) => {
setUI(rootState.settings);
Expand Down
5 changes: 2 additions & 3 deletions src/plugin/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import setValuesOnNode from './setValuesOnNode';
import { Properties } from '@/constants/Properties';
import { NodeTokenRefMap } from '@/types/NodeTokenRefMap';
import { defaultNodeManager, NodeManagerNode } from './NodeManager';
import { UpdateNodesSettings } from '@/types/UpdateNodesSettings';
import { postToUI } from './notifiers';
import { MessageFromPluginTypes } from '@/types/messages';
import { BackgroundJobs } from '@/constants/BackgroundJobs';
Expand All @@ -26,6 +25,7 @@ import { AsyncMessageChannel } from '@/AsyncMessageChannel';
import { AsyncMessageTypes } from '@/types/AsyncMessages';
import { updatePluginData } from './pluginData';
import { extractColorInBorderTokenForAlias } from './extractColorInBorderTokenForAlias';
import { SettingsState } from '@/app/store/models/settings';

// @TODO fix typings

Expand Down Expand Up @@ -221,14 +221,13 @@ async function migrateTokens(entry: NodeManagerNode, values: MapValuesToTokensRe
export async function updateNodes(
entries: readonly NodeManagerNode[],
tokens: Map<string, AnyTokenList[number]>,
settings?: UpdateNodesSettings,
settings?: SettingsState,
) {
const { ignoreFirstPartForStyles, prefixStylesWithThemeName, baseFontSize } = settings ?? {};
const figmaStyleMaps = getAllFigmaStyleMaps();
const themeInfo = await AsyncMessageChannel.PluginInstance.message({
type: AsyncMessageTypes.GET_THEME_INFO,
});

postToUI({
type: MessageFromPluginTypes.START_JOB,
job: {
Expand Down

0 comments on commit 1325d8f

Please sign in to comment.