Skip to content

Commit

Permalink
feat: Drawer组件支持
Browse files Browse the repository at this point in the history
  • Loading branch information
lili.21 committed Aug 1, 2023
1 parent 7bcda8f commit a72e2f2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
4 changes: 4 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const TRANSFORMER_INQUIRER_CHOICES = [
name: 'Message',
value: 'Message'
},
{
name: 'Drawer',
value: 'Drawer'
}
]

function expandFilePathsIfNeeded(filesBeforeExpansion) {
Expand Down
11 changes: 7 additions & 4 deletions test.jsx
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>
)
}
42 changes: 42 additions & 0 deletions transforms/Drawer.js
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()
}

0 comments on commit a72e2f2

Please sign in to comment.