Skip to content

Commit

Permalink
fix: transform logical (#165)
Browse files Browse the repository at this point in the history
* fix: transform logical

* chore: fix compile
  • Loading branch information
MadCcc authored Dec 7, 2023
1 parent ea446af commit 94528e0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@emotion/hash": "^0.8.0",
"@emotion/unitless": "^0.7.5",
"classnames": "^2.3.1",
"csstype": "^3.0.10",
"csstype": "3.1.2",
"rc-util": "^5.35.0",
"stylis": "^4.0.13"
},
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useCompatibleInsertionEffect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { useInsertionEffect } = fullClone;
type UseCompatibleInsertionEffect = (
renderEffect: EffectCallback,
effect: (polyfill?: boolean) => ReturnType<EffectCallback>,
deps?: React.DependencyList,
deps: React.DependencyList,
) => void;

/**
Expand Down
20 changes: 8 additions & 12 deletions src/transformers/legacyLogicalProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@ function splitValues(
let brackets = 0;
return [
splitStyle.reduce<string[]>((list, item) => {
if (item.includes('(')) {
temp += item;
brackets += item.split('(').length - 1;
} else if (item.includes(')')) {
temp += item;
brackets -= item.split(')').length - 1;
if (brackets === 0) {
list.push(temp);
temp = '';
}
if (item.includes('(') || item.includes(')')) {
const left = item.split('(').length - 1;
const right = item.split(')').length - 1;
brackets += left - right;
}
if (brackets === 0) {
list.push(temp + item);
temp = '';
} else if (brackets > 0) {
temp += item;
} else {
list.push(item);
}
return list;
}, []),
Expand Down
21 changes: 21 additions & 0 deletions tests/transform.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,27 @@ describe('transform', () => {
const styleText = document.head.querySelector('style')?.innerHTML;
expect(styleText).toContain('33px!important');
});

it('split with calc() and var()', () => {
const { container } = render(
<Wrapper
css={{
'.box': {
marginBlock: 'calc(var(--a) + var(--b)) calc(2px + var(--c))',
marginInline: 'calc(2px + 1px)',
marginInlineEnd: '3px',
},
}}
/>,
);

expect(container.querySelector('.box')).toHaveStyle({
marginTop: 'calc(var(--a) + var(--b))',
marginBottom: 'calc(2px + var(--c))',
marginLeft: 'calc(2px + 1px)',
marginRight: '3px',
});
});
});

describe('px2rem', () => {
Expand Down

0 comments on commit 94528e0

Please sign in to comment.