-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lili.21
committed
Aug 1, 2023
1 parent
7bcda8f
commit a72e2f2
Showing
3 changed files
with
53 additions
and
4 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
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,8 +1,11 @@ | ||
import { message } from 'antd' | ||
import { Button, Drawer } from 'antd' | ||
|
||
import { Divider, Tabs, TabPane } from '@douyinfe/semi-ui' | ||
|
||
function Test() { | ||
|
||
message.error('123'); | ||
message.error('123'); | ||
return ( | ||
<Drawer open={open} onClose={onClose}> | ||
<p>hello</p> | ||
</Drawer> | ||
) | ||
} |
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,42 @@ | ||
const { removeAntdImportAndAddSemiImport } = require('./utils') | ||
module.exports = function transformer(file, api) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
removeAntdImportAndAddSemiImport(j, root, 'Drawer', 'SideSheet') | ||
|
||
// Find all JSXElements with the name "Drawer" | ||
root | ||
.find(j.JSXElement, { | ||
openingElement: { | ||
name: { | ||
name: 'Drawer' | ||
} | ||
} | ||
}) | ||
.forEach((path) => { | ||
const { openingElement, closingElement } = path.value | ||
|
||
// Replace the name "Drawer" with "SideSheet" | ||
openingElement.name.name = 'SideSheet' | ||
closingElement.name.name = 'SideSheet' | ||
|
||
// Find the "open" attribute and replace it with "visible" | ||
const openAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'open' | ||
) | ||
if (openAttribute) { | ||
openAttribute.name.name = 'visible' | ||
} | ||
|
||
// Find the "onClose" attribute and replace it with "onCancel" | ||
const onCloseAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'onClose' | ||
) | ||
if (onCloseAttribute) { | ||
onCloseAttribute.name.name = 'onCancel' | ||
} | ||
}) | ||
|
||
return root.toSource() | ||
} |