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

Don't camelCase CSS custom properties #145

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ function createStyleJsonFromString(styleString) {
}

if (key != null && value != null && key.length > 0 && value.length > 0) {
jsonStyles[camelCase(key)] = value;
key = key.trim();

// Don't camelCase CSS custom properties
if (key.indexOf('--') !== 0) {
key = camelCase(key);
}

jsonStyles[key] = value;
}
}
return jsonStyles;
Expand Down
9 changes: 9 additions & 0 deletions test/html-to-react-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ describe('Html2React', () => {
assert.equal(reactHtml, htmlExpected);
});

it('should return a valid HTML string with custom properties in inline styles', () => {
const htmlInput = '<div style="color:var(--color-example);--color-example:black"></div>';

const reactComponent = parser.parse(htmlInput);
const reactHtml = ReactDOMServer.renderToStaticMarkup(reactComponent);

assert.equal(reactHtml, htmlInput);
});

it('should return a valid HTML string with data attributes', () => {
const htmlInput = '<div data-test-attribute="data attribute value"></div>';

Expand Down