Skip to content

Commit

Permalink
feat: Empty组件支持
Browse files Browse the repository at this point in the history
  • Loading branch information
lili.21 committed Aug 1, 2023
1 parent 9085316 commit bafb698
Show file tree
Hide file tree
Showing 3 changed files with 37 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 @@ -77,6 +77,10 @@ const TRANSFORMER_INQUIRER_CHOICES = [
{
name: 'Spin',
value: 'Spin'
},
{
name: 'Empty',
value: 'Empty'
}
].sort((a, b) => a.name.localeCompare(b.name))

Expand Down
8 changes: 4 additions & 4 deletions test.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button, Drawer, Spin } from 'antd'
import { Button, Empty } from 'antd'

import { Divider, Tabs, TabPane } from '@douyinfe/semi-ui'

function Test() {
return (
<Spin spinning={loading}>
<p>hello</p>
</Spin>
<Empty>
<button>hello</button>
</Empty>
)
}
29 changes: 29 additions & 0 deletions transforms/Empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { removeAntdImportAndAddSemiImport } = require('./utils')

module.exports = function (file, api) {
const j = api.jscodeshift
const root = j(file.source)

removeAntdImportAndAddSemiImport(j, root, 'Empty', 'Empty')

// Find all JSXElements with the name "Empty"
const emptyElements = root.findJSXElements('Empty')

// Modify each Empty element
emptyElements.forEach((element) => {
const { openingElement } = element.node

const descriptionAttribute = openingElement.attributes.find(
(attr) => attr.name.name === 'description'
)

if (!descriptionAttribute) {
// Add the "description" attribute with the value "暂无数据"
element.node.openingElement.attributes.push(
j.jsxAttribute(j.jsxIdentifier('description'), j.literal('暂无数据'))
)
}
})

return root.toSource()
}

0 comments on commit bafb698

Please sign in to comment.