Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/react-strict-dom/src/native/css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ function _create<S extends { +[string]: { +[string]: unknown } }>(styles: S): {
}
export const create: IStyleX['create'] = _create as $FlowFixMe;

const RE_CAPTURE_VAR_NAME = /^var\(--(.*)\)$/;
const VAR_FUNCTION_PREFIX = 'var(--';
export const createTheme = (
baseTokens: Tokens,
overrides: CustomProperties
): CustomProperties => {
const result: MutableCustomProperties = { $$theme: 'theme' };
for (const key in baseTokens) {
const varName: string = baseTokens[key];
const normalizedKey = varName.replace(RE_CAPTURE_VAR_NAME, '$1');
const normalizedKey =
varName.startsWith(VAR_FUNCTION_PREFIX) && varName.endsWith(')')
? varName.slice(VAR_FUNCTION_PREFIX.length, -1)
: varName;
result[normalizedKey] = overrides[key];
}
return result;
Expand Down
Loading