Skip to content

Commit

Permalink
Remove automatic camel-casing of CSS custom properties
Browse files Browse the repository at this point in the history
Fix #50
  • Loading branch information
necolas committed Apr 18, 2024
1 parent 15dd106 commit 60710ee
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ import { errorMsg } from '../../shared/errorMsg';
export type MutableCustomProperties = { [string]: string | number };
export type CustomProperties = $ReadOnly<MutableCustomProperties>;

function camelize(s: string): string {
return s.replace(/-./g, (x) => x.toUpperCase()[1]);
}

function normalizeVariableName(name: string): string {
if (!name.startsWith('--')) {
throw new Error("Invalid variable name, must begin with '--'");
}
return camelize(name.substring(2));
return name.substring(2);
}

export function stringContainsVariables(input: string): boolean {
Expand Down
25 changes: 0 additions & 25 deletions packages/react-strict-dom/tests/css-test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,31 +1119,6 @@ describe('properties: custom property', () => {
).toEqual('blue');
});

// TODO: this transform should not be supported. Custom properties are case sensitive.
test('parses kebab case var to camel case', () => {
const customProperties = { testVar: 'red' };
expect(
resolveCustomPropertyValue(customProperties, ['color', 'var(--test-var)'])
).toEqual('red');
});

// TODO: this transform should not be supported. Custom properties are case sensitive.
test('parses kebab case var with a default value', () => {
const customProperties = { testVar: 'red' };
expect(
resolveCustomPropertyValue(customProperties, [
'color',
'var(--test-var, blue)'
])
).toEqual('red');
expect(
resolveCustomPropertyValue(customProperties, [
'color',
'var(--not-found, blue)'
])
).toEqual('blue');
});

test('parses a var with a default value containing spaces', () => {
const customProperties = { color: 'rgb(0,0,0)' };
expect(
Expand Down

0 comments on commit 60710ee

Please sign in to comment.