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

fix: transform logical #165

Merged
merged 2 commits into from
Dec 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
},
2 changes: 1 addition & 1 deletion src/hooks/useCompatibleInsertionEffect.tsx
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ const { useInsertionEffect } = fullClone;
type UseCompatibleInsertionEffect = (
renderEffect: EffectCallback,
effect: (polyfill?: boolean) => ReturnType<EffectCallback>,
deps?: React.DependencyList,
deps: React.DependencyList,
) => void;

/**
20 changes: 8 additions & 12 deletions src/transformers/legacyLogicalProperties.ts
Original file line number Diff line number Diff line change
@@ -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;
}, []),
21 changes: 21 additions & 0 deletions tests/transform.spec.tsx
Original file line number Diff line number Diff line change
@@ -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', () => {