Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sticky: remove deprecated dangerouslySetZIndex (#1224)
- Loading branch information
1 parent
51ac423
commit 5d15918
Showing
4 changed files
with
82 additions
and
12 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
50 changes: 50 additions & 0 deletions
50
packages/gestalt-codemods/13.14.0-14.0.0/sticky-find-deprecated-dangerouslySetZIndex.js
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,50 @@ | ||
/* | ||
* Log an error when `dangerouslySetZIndex` is specified on `<Sticky />` | ||
*/ | ||
|
||
export default function transformer(file, api) { | ||
const j = api.jscodeshift; | ||
const src = j(file.source); | ||
let localIdentifierName; | ||
|
||
src.find(j.ImportDeclaration).forEach(path => { | ||
const decl = path.node; | ||
if (decl.source.value !== 'gestalt') { | ||
return null; | ||
} | ||
|
||
localIdentifierName = decl.specifiers | ||
.filter(node => node.imported.name === 'Sticky') | ||
.map(node => node.local.name); | ||
return null; | ||
}); | ||
|
||
if (!localIdentifierName) { | ||
return null; | ||
} | ||
|
||
src | ||
.find(j.JSXElement) | ||
.forEach(jsxElement => { | ||
const { node } = jsxElement; | ||
|
||
if (!localIdentifierName.includes(node.openingElement.name.name)) { | ||
return null; | ||
} | ||
|
||
const attrs = node.openingElement.attributes; | ||
|
||
attrs.forEach(attr => { | ||
if (attr.name && attr.name.name === 'dangerouslySetZIndex') { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`Replace legacy dangerouslySetZIndex with zIndex on Sticky: ${file.path}:${attr.loc.start.line}:${attr.loc.start.column}` | ||
); | ||
} | ||
}); | ||
return null; | ||
}) | ||
.toSource(); | ||
|
||
return null; | ||
} |
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 @@ | ||
// @flow strict | ||
import React from 'react'; | ||
import Sticky from './Sticky.js'; | ||
import { FixedZIndex } from './zIndex.js'; | ||
|
||
const ValidDefaultStickyType = <Sticky top={0}>Content</Sticky>; | ||
|
||
const ValidZIndex = ( | ||
<Sticky top={0} zIndex={new FixedZIndex(1)}> | ||
Content | ||
</Sticky> | ||
); | ||
|
||
const InValidZIndex = ( | ||
// $FlowExpectedError[incompatible-type] | ||
<Sticky top={0} zIndex={1}> | ||
Content | ||
</Sticky> | ||
); | ||
|
||
// $FlowExpectedError[incompatible-type] | ||
const MissingProp = <Sticky />; | ||
|
||
const IncompatibleLegacyZIndexProp = ( | ||
// $FlowExpectedError[incompatible-type] | ||
<Sticky top={0} dangerouslySetZIndex={1}> | ||
Content | ||
</Sticky> | ||
); |
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