-
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.
feat: Upload, Input, InputNumber, Radio组件支持
- Loading branch information
lili.21
committed
Oct 10, 2023
1 parent
834f7b2
commit ff609b9
Showing
9 changed files
with
83 additions
and
11 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,9 +1,5 @@ | ||
import { Table, Space, Button } from 'antd' | ||
import { Table, Space, Button, Upload } from 'antd' | ||
|
||
export const test = () => { | ||
return ( | ||
<Button type="link" danger> | ||
数据大盘 | ||
</Button> | ||
) | ||
return <Upload /> | ||
} |
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,9 @@ | ||
const { removeAntdImportAndAddSemiImport } = require('./utils') | ||
module.exports = function transformer(file, api) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
removeAntdImportAndAddSemiImport(j, root, 'Input', 'Input') | ||
|
||
return root.toSource() | ||
} |
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,9 @@ | ||
const { removeAntdImportAndAddSemiImport } = require('./utils') | ||
module.exports = function transformer(file, api) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
removeAntdImportAndAddSemiImport(j, root, 'InputNumber', 'InputNumber') | ||
|
||
return root.toSource() | ||
} |
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,9 @@ | ||
const { removeAntdImportAndAddSemiImport } = require('./utils') | ||
module.exports = function transformer(file, api) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
removeAntdImportAndAddSemiImport(j, root, 'Radio', 'Radio') | ||
|
||
return root.toSource() | ||
} |
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 chalk = require('chalk') | ||
|
||
const { removeAntdImportAndAddSemiImport } = require('./utils') | ||
module.exports = function transformer(file, api) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
removeAntdImportAndAddSemiImport(j, root, 'Upload', 'Upload') | ||
|
||
// todo - 暂时没想好怎么自动处理 customRequest 的差异 | ||
console.log( | ||
chalk.yellow(` | ||
Upload组件 customRequest函数的参数有差异,如果有用到,记得手动更改一下 | ||
Antd | ||
---- | ||
<Upload customRequest={({ file } => {})} /> | ||
Semi | ||
---- | ||
<Upload customRequest={({ fileInstance: file }) => {}} /> | ||
Semi中fileInstance参数和Antd中的file等价 | ||
`) | ||
) | ||
|
||
// Find the Upload component and update its props | ||
root.findJSXElements('Upload').forEach((path) => { | ||
const { openingElement } = path.value | ||
|
||
const actionAttribute = openingElement.attributes.find( | ||
(attr) => attr.name.name === 'action' | ||
) | ||
// Semi组件<Upload /> action是必须 | ||
if (!actionAttribute) { | ||
openingElement.attributes.push( | ||
j.jsxAttribute(j.jsxIdentifier('action'), j.literal('')) | ||
) | ||
} | ||
}) | ||
|
||
return root.toSource() | ||
} |