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: transformer support calc grammar #112

Open
wants to merge 1 commit into
base: master
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
2 changes: 1 addition & 1 deletion docs/examples/logicalProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Demo = () => {
border: '1px solid #000',
position: 'relative',
// css logical-properties
paddingInline: 10,
paddingInline: 'calc(10px - 2px)',
borderBlockEndWidth: 3,
marginBlock: 10,
borderEndEndRadius: '50%',
Expand Down
12 changes: 6 additions & 6 deletions src/transformers/legacyLogicalProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ function splitValues(
.split(/\s+/);

// Combine styles split in brackets, like `calc(1px + 2px)`
let temp = '';
let temp: string[] = [];
let brackets = 0;
return [
splitStyle.reduce<string[]>((list, item) => {
if (item.includes('(')) {
temp += item;
temp.push(item);
brackets += item.split('(').length - 1;
} else if (item.includes(')')) {
temp += item;
temp.push(item);
brackets -= item.split(')').length - 1;
if (brackets === 0) {
list.push(temp);
temp = '';
list.push(temp.join(' '));
temp = [];
}
} else if (brackets > 0) {
temp += item;
temp.push(item);
} else {
list.push(item);
}
Expand Down