Skip to content

Commit be6c6f8

Browse files
committed
add initial documentation, update map-get to map.get for easier migration
1 parent f981c6d commit be6c6f8

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

polaris-migrator/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,58 @@ Replace lengths (`px`, `rem`) and legacy Sass functions (`rem()`,`border()`, `bo
168168
npx @shopify/polaris-migrator replace-border-declarations <path>
169169
```
170170

171+
### `replace-sass-z-index`
172+
173+
Replace the legacy Sass `z-index()` function with the supported CSS custom property token equivalent (ex: `var(--p-z-1)`).
174+
175+
Any invocations of `z-index()` that correspond to a z-index design-token i.e. `--p-z-1` will be replaced with a css variable declaration.
176+
This includes invocations to the `$fixed-element-stacking-order` sass map i.e. `z-index(modal, $fixed-element-stacking-order)`.
177+
178+
```diff
179+
- .decl-1 {
180+
- z-index: z-index(content);
181+
- }
182+
- .decl-2 {
183+
- z-index: z-index(modal, $fixed-element-stacking-order)
184+
- }
185+
+ decl-1 {
186+
+ z-index: var(--p-z-1);
187+
+ }
188+
+ .decl-2 {
189+
+ z-index: var(--p-z-11)
190+
+ }
191+
```
192+
193+
Invocations of `z-index` within an arithmetic expression will be appended with a comment for review and manual migration.
194+
Generally in these instances you'll want to wrap the suggested code change in a `calc` however this may defer on a case by case basis in your codebase.
195+
196+
```diff
197+
.decl-3 {
198+
+ /* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */
199+
+ /* z-index: var(--p-z-1) + 1 */
200+
z-index: z-index(content) + 1
201+
}
202+
```
203+
204+
Invocations of `z-index` with a custom sass map property, will also be appended with a comment for review and manual migration.
205+
206+
```diff
207+
.decl-3 {
208+
+ /* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */
209+
+ /* z-index: map.get($custom-sass-map, modal) */
210+
z-index: z-index(modal, $custom-sass-map)
211+
}
212+
```
213+
214+
In these cases you may also want to run `npx sass-migrator module <path> --migrate-deps --load-path <load-path>` to ensure that
215+
`map.get` is in scope\*\*.
216+
217+
Be aware that this may also create additional code changes in your codebase, we recommend running this only if there are large number of instances of migrations from `z-index` to `map.get`. Otherwise it may be easier to add `use 'sass:map'` to the top of your `.scss` file manually.
218+
219+
```sh
220+
npx @shopify/polaris-migrator replace-sass-spacing <path>
221+
```
222+
171223
## Creating a migration
172224

173225
### Setup

polaris-migrator/src/migrations/replace-sass-z-index/replace-sass-z-index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ const plugin = (options: PluginOptions = {}): Plugin => {
8484
},
8585
];
8686
} else {
87+
// map.get arguments are in the reverse order to z-index arguments.
88+
// map.get expects the map object first, and the key second.
8789
containsUnknownSecondArgument = true;
88-
node.value = 'map-get';
90+
node.value = 'map.get';
8991
node.nodes.reverse();
9092
}
91-
// map-get arguments are in the reverse order to z-index arguments.
92-
// map-get expects the map object first, and the key second.
9393
} else {
9494
const element = node.nodes[0]?.value ?? '';
9595
if (!isValidElement<typeof zIndexMap>(element, zIndexMap)) return;

polaris-migrator/src/migrations/replace-sass-z-index/tests/replace-sass-z-index.output.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $someElement: (
2828

2929
.scenario-5 {
3030
/* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */
31-
/* z-index: map-get($someElement, someKey); */
31+
/* z-index: map.get($someElement, someKey); */
3232
z-index: z-index(someKey, $someElement);
3333
background-color: var(--p-background);
3434
}

polaris-migrator/src/migrations/replace-sass-z-index/tests/with-namespace.output.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $someElement: (
2929

3030
.scenario-5 {
3131
/* polaris-migrator: Unable to migrate the following expression. Please upgrade manually. */
32-
/* z-index: map-get($someElement, someKey); */
32+
/* z-index: map.get($someElement, someKey); */
3333
z-index: legacy-polaris-v8.z-index(someKey, $someElement);
3434
background-color: var(--p-background);
3535
}

0 commit comments

Comments
 (0)