Skip to content

Commit

Permalink
Fix false usage of themeMap (#25)
Browse files Browse the repository at this point in the history
* Fix false usage of themeMap

* Simplify and format code

Co-authored-by: Teemu Taskula <[email protected]>
  • Loading branch information
alexaragao and Temzasse authored Jun 5, 2022
1 parent f555d71 commit 300f515
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/internals/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ export const BORDER_STYLE_PROPERTIES = {
};

export const DEFAULT_THEME_MAP = {
borderStyles: BORDER_STYLE_PROPERTIES,
borderWidths: BORDER_WIDTH_PROPERTIES,
colors: COLOR_PROPERTIES,
fonts: FONT_PROPERTIES,
fontSizes: FONT_SIZE_PROPERTIES,
fontWeights: FONT_WEIGHT_PROPERTIES,
letterSpacings: LETTER_SPACING_PROPERTIES,
lineHeights: LINE_HEIGHT_PROPERTIES,
radii: RADII_PROPERTIES,
sizes: SIZE_PROPERTIES,
space: SPACE_PROPERTIES,
zIndices: Z_INDEX_PROPERTIES,
...BORDER_STYLE_PROPERTIES,
...BORDER_WIDTH_PROPERTIES,
...COLOR_PROPERTIES,
...FONT_PROPERTIES,
...FONT_SIZE_PROPERTIES,
...FONT_WEIGHT_PROPERTIES,
...LETTER_SPACING_PROPERTIES,
...LINE_HEIGHT_PROPERTIES,
...RADII_PROPERTIES,
...SIZE_PROPERTIES,
...SPACE_PROPERTIES,
...Z_INDEX_PROPERTIES,
};

const THEME_VALUES = {
Expand Down
19 changes: 18 additions & 1 deletion src/internals/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ export function resolveMediaRangeQuery(query, windowWidth) {
return result;
}

export function processThemeMap(themeMap) {
const definition = {};

Object.keys(themeMap).forEach((token) => {
const scale = themeMap[token];

if (!definition[scale]) {
definition[scale] = {};
}

definition[scale][token] = scale;
});

return definition;
}

export function processTheme(theme) {
const definition = {};
const values = {};
Expand Down Expand Up @@ -88,7 +104,8 @@ export function processTheme(theme) {
}

export function processStyles({ styles, theme, config }) {
const { utils, themeMap = DEFAULT_THEME_MAP } = config;
const { utils, themeMap: customThemeMap } = config;
const themeMap = processThemeMap(customThemeMap || DEFAULT_THEME_MAP);

return Object.entries(styles).reduce((acc, [key, val]) => {
if (utils && key in utils) {
Expand Down

0 comments on commit 300f515

Please sign in to comment.