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

feat: camelCase CSS properties in style objects #259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions packages/babel-plugin-jsx-dom-expressions/src/dom/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const alwaysClose = [
"fieldset"
];

const upperCaseChars = /[A-Z]/g;

export function transformElement(path, info) {
let tagName = getTagName(path.node),
config = getConfig(path),
Expand Down Expand Up @@ -137,6 +139,8 @@ export function setAttr(path, elem, name, value, { isSVG, dynamic, prevId, isCE,

// TODO: consider moving to a helper
if (namespace === "style") {
if (upperCaseChars.test(name)) name = name.replace(upperCaseChars, "-$&").toLowerCase();

if (t.isStringLiteral(value)) {
return t.callExpression(
t.memberExpression(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,10 @@ const template32 = (
<div
style={{ "background-color": undefined }}
/>
);

const template33 = (
<div
style={{ backgroundColor: color(), marginRight: "40px" }}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,14 @@ const template32 = (() => {
_el$45.style.removeProperty("background-color");
return _el$45;
})();
_$delegateEvents(["click", "input"]);
const template33 = (() => {
const _el$46 = _tmpl$4();
_el$46.style.setProperty("margin-right", "40px");
_$effect(() =>
color() != null
? _el$46.style.setProperty("background-color", color())
: _el$46.style.removeProperty("background-color")
);
return _el$46;
})();
_$delegateEvents(["click", "input"]);
2 changes: 1 addition & 1 deletion packages/dom-expressions/src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export namespace JSX {
onwheel?: EventHandlerUnion<T, WheelEvent>;
}

interface CSSProperties extends csstype.PropertiesHyphen {
interface CSSProperties extends csstype.PropertiesHyphen, csstype.Properties {
// Override
[key: `-${string}`]: string | number | undefined;
}
Expand Down