Skip to content

Commit

Permalink
feat: Select组件支持
Browse files Browse the repository at this point in the history
  • Loading branch information
lili.21 committed Aug 11, 2023
1 parent 26f4f2e commit 213961a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 13 deletions.
3 changes: 2 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const TRANSFORMER_INQUIRER_CHOICES = [
'Row',
'Tag',
'Timeline',
'Collapse'
'Collapse',
'Select'
]
.sort((a, b) => a.localeCompare(b))
.map((v) => ({
Expand Down
21 changes: 9 additions & 12 deletions test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ export const test = () => {
Modal.success({
content: 'some messages...some messages...',
title: '拉取数据',
afterClose:true,
autoFocusButton:false,
closeIcon:<icon></icon>
afterClose: true,
autoFocusButton: false,
closeIcon: <icon></icon>
});
Modal.info({
Modal.info({
content: 'some messages...some messages...',
title: '拉取数据',
afterClose:true,
autoFocusButton:false,
closeIcon:<icon></icon>
afterClose: true,
autoFocusButton: false,
closeIcon: <icon></icon>
});
}

return <div>
return (<div>
<Modal
title="Modal 1000px width"
centered
Expand All @@ -39,8 +39,5 @@ export const test = () => {
<p>some contents...</p>
<p>some contents...</p>
</Modal>
</div>



</div>)
}
71 changes: 71 additions & 0 deletions transforms/Select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const { removeAntdImportAndAddSemiImport } = require('./utils')

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

removeAntdImportAndAddSemiImport(j, root, 'Select', 'Select')

// Find all Select JSXElements
const selectElements = root.findJSXElements('Select')

selectElements.forEach((element) => {
const { openingElement } = element.node

// options -> optionList
const optionsAttribute = openingElement.attributes.find(
(attr) => attr.name.name === 'options'
)
if (optionsAttribute) {
optionsAttribute.name.name = 'optionList'
}

// mode="multiple" -> multiple
const modeAttribute = openingElement.attributes.find(
(attr) => attr.name.name === 'mode' && attr.value.value === 'multiple'
)
if (modeAttribute) {
openingElement.attributes = openingElement.attributes.filter(
(attr) => attr !== modeAttribute
)
openingElement.attributes.push(
j.jsxAttribute(j.jsxIdentifier('multiple'))
)
}

// showSearch -> filter
const showSearchAttribute = openingElement.attributes.find(
(attr) => attr.name.name === 'showSearch'
)
if (showSearchAttribute) {
showSearchAttribute.name.name = 'filter'
}

// filterOption处理
const filterOptionAttribute = openingElement.attributes.find(
(attr) => attr.name.name === 'filterOption'
)
if (filterOptionAttribute) {
openingElement.attributes = openingElement.attributes.filter(
(attr) => attr !== filterOptionAttribute
)
if (filterOptionAttribute.value.expression.value === false) {
openingElement.attributes.push(
j.jsxAttribute(j.jsxIdentifier('remote'))
)
} else {
showSearchAttribute.value = filterOptionAttribute.value
}
}

// notFoundContent -> emptyContent
const notFoundContentAttribute = openingElement.attributes.find(
(attr) => attr.name.name === 'notFoundContent'
)
if (notFoundContentAttribute) {
notFoundContentAttribute.name.name = 'emptyContent'
}
})

return root.toSource()
}

0 comments on commit 213961a

Please sign in to comment.