-
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.
Adds migration for polaris media queries to @Custom-Media
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 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-migrator': minor | ||
--- | ||
|
||
Added `admin-legacy-media-queries` migration |
29 changes: 29 additions & 0 deletions
29
...tor/src/migrations/admin-legacy-media-queries/tests/admin-legacy-media-queries.input.scss
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,29 @@ | ||
@use 'global-styles/media-queries'; | ||
|
||
.Selector { | ||
max-width: 100px; | ||
|
||
@media #{media-queries.$p-breakpoints-md-down} { | ||
max-width: 200px; | ||
} | ||
|
||
@media only screen and #{media-queries.$p-breakpoints-md-only} { | ||
max-width: 300px; | ||
} | ||
|
||
@media #{media-queries.$p-breakpoints-md-up} and #{media-queries.$p-breakpoints-lg-down} { | ||
max-width: 400px; | ||
} | ||
|
||
@container app-card #{media-queries.$p-breakpoints-sm-down} { | ||
max-width: 500px; | ||
} | ||
|
||
@media #{media-queries.$p-breakpoints-md-up} and #{legacy-polaris-v8.breakpoints-down(variables.$home-scroll-greeting-sidebar-hidden)} { | ||
max-width: 600px; | ||
} | ||
|
||
@media #{legacy-polaris-v8.breakpoints-down(variables.$home-scroll-greeting-sidebar-hidden)} and #{media-queries.$p-breakpoints-md-up} { | ||
max-width: 700px; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...or/src/migrations/admin-legacy-media-queries/tests/admin-legacy-media-queries.output.scss
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,29 @@ | ||
@use 'global-styles/media-queries'; | ||
|
||
.Selector { | ||
max-width: 100px; | ||
|
||
@media (--p-breakpoints-md-down) { | ||
max-width: 200px; | ||
} | ||
|
||
@media only screen and (--p-breakpoints-md-only) { | ||
max-width: 300px; | ||
} | ||
|
||
@media (--p-breakpoints-md-up) and (--p-breakpoints-lg-down) { | ||
max-width: 400px; | ||
} | ||
|
||
@container app-card (--p-breakpoints-sm-down) { | ||
max-width: 500px; | ||
} | ||
|
||
@media (--p-breakpoints-md-up) and #{legacy-polaris-v8.breakpoints-down(variables.$home-scroll-greeting-sidebar-hidden)} { | ||
max-width: 600px; | ||
} | ||
|
||
@media #{legacy-polaris-v8.breakpoints-down(variables.$home-scroll-greeting-sidebar-hidden)} and (--p-breakpoints-md-up) { | ||
max-width: 700px; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
polaris-migrator/src/migrations/admin-legacy-media-queries/tests/transform.test.ts
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,17 @@ | ||
import {check} from '../../../utilities/check'; | ||
|
||
const transform = 'admin-legacy-media-queries'; | ||
const fixtures = ['admin-legacy-media-queries']; | ||
|
||
for (const fixture of fixtures) { | ||
check(__dirname, { | ||
fixture, | ||
transform, | ||
extension: 'scss', | ||
options: { | ||
customSyntax: 'postcss-scss', | ||
reportDescriptionlessDisables: true, | ||
rules: {}, | ||
}, | ||
}); | ||
} |
23 changes: 23 additions & 0 deletions
23
polaris-migrator/src/migrations/admin-legacy-media-queries/transform.ts
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,23 @@ | ||
import type {API, FileInfo} from 'jscodeshift'; | ||
import type {Plugin} from 'postcss'; | ||
import postcss from 'postcss'; | ||
|
||
export default async function transformer(file: FileInfo, _: API) { | ||
return postcss(plugin()).process(file.source, { | ||
syntax: require('postcss-scss'), | ||
}).css; | ||
} | ||
|
||
const plugin = (): Plugin => { | ||
return { | ||
postcssPlugin: 'admin-legacy-media-queries', | ||
AtRule(atRule) { | ||
if (atRule.name === 'media' || atRule.name === 'container') { | ||
atRule.params = atRule.params.replace( | ||
/#\{media-queries\.\$(?<breakpoint>[^}]*)}/g, | ||
'(--$1)', | ||
); | ||
} | ||
}, | ||
}; | ||
}; |