-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use faster object syntax for postcss-mixins
- Loading branch information
1 parent
b605cc6
commit 1c9eb9c
Showing
4 changed files
with
45 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/polaris': patch | ||
--- | ||
|
||
Fix build performance regression from using postcss-mixins. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
const postcss = require('postcss'); | ||
const staggerInterval = 50; | ||
|
||
module.exports = (mixin) => { | ||
const rules = []; | ||
module.exports = () => { | ||
const rules = {}; | ||
for (let i = 1; i <= 12; i++) { | ||
const rule = postcss.rule({ | ||
selector: `&:nth-child(${i})`, | ||
}); | ||
rule.append({ | ||
prop: 'animation-delay', | ||
value: `calc((${i} - 1) * 50ms)`, | ||
}); | ||
rules.push(rule); | ||
rules[`&:nth-child(${i})`] = { | ||
animationDelay: `${(i - 1) * staggerInterval}ms`, | ||
}; | ||
} | ||
mixin.replaceWith(rules); | ||
return rules; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
const postcss = require('postcss'); | ||
|
||
const breakpoints = ['sm', 'md', 'lg', 'xl']; | ||
module.exports = (mixin) => { | ||
const rules = []; | ||
const atRules = []; | ||
for (let i = 1; i <= 6; i++) { | ||
const rule = postcss.rule({ | ||
selector: `.Cell-${i}-column-xs`, | ||
}); | ||
rule.append({ | ||
prop: 'grid-column-end', | ||
value: `span ${i}`, | ||
}); | ||
rules.push(rule); | ||
function cellColumnEndRules(columns, breakpoint) { | ||
const rules = {}; | ||
for (let column = 1; column <= columns; column++) { | ||
rules[`.Cell-${column}-column-${breakpoint}`] = { | ||
gridColumnEnd: `span ${column}`, | ||
}; | ||
} | ||
for (const i of breakpoints) { | ||
const atRule = postcss.atRule({ | ||
name: 'media', | ||
params: `(--p-breakpoints-${i}-up)`, | ||
}); | ||
for (let j = 1; j <= (i === 'lg' || i === 'xl' ? 12 : 6); j++) { | ||
const rule = postcss.rule({ | ||
selector: `.Cell-${j}-column-${i}`, | ||
}); | ||
rule.append({ | ||
prop: 'grid-column-end', | ||
value: `span ${j}`, | ||
}); | ||
atRule.append(rule); | ||
} | ||
atRules.push(atRule); | ||
return rules; | ||
} | ||
|
||
function wrapInBreakpoint(breakpoints, getRules) { | ||
const rules = {}; | ||
for (const breakpoint of breakpoints) { | ||
rules[`@media (--p-breakpoints-${breakpoint}-up)`] = getRules(breakpoint); | ||
} | ||
mixin.replaceWith([].concat(rules, atRules)); | ||
}; | ||
return rules; | ||
} | ||
|
||
module.exports = () => ({ | ||
...cellColumnEndRules(6, 'xs'), | ||
...wrapInBreakpoint(['sm', 'md'], (breakpoint) => | ||
cellColumnEndRules(6, breakpoint), | ||
), | ||
...wrapInBreakpoint(['lg', 'xl'], (breakpoint) => | ||
cellColumnEndRules(12, breakpoint), | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters