-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support icon string prop component (#6)
* feat: implements for Button * feat: support avatar and result * feat: support Modal.method()
- Loading branch information
Showing
21 changed files
with
518 additions
and
36 deletions.
There are no files selected for viewing
This file was deleted.
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
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
22 changes: 22 additions & 0 deletions
22
transforms/__testfixtures__/v3-Icon-to-v4-Icon/misc.input.js
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,22 @@ | ||
import { Icon, Result, Timeline } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<Result | ||
icon={<Icon type="smile" theme="twoTone" />} | ||
title="Great, we have done all the operations!" | ||
extra={<Button type="primary">Next</Button>} | ||
/>, | ||
mountNode, | ||
); | ||
|
||
ReactDOM.render( | ||
<Timeline> | ||
<Timeline.Item>Create a services site 2015-09-01</Timeline.Item> | ||
<Timeline.Item>Solve initial network problems 2015-09-01</Timeline.Item> | ||
<Timeline.Item dot={<Icon type="clock-circle-o" style={{ fontSize: '16px' }} />} color="red"> | ||
Technical testing 2015-09-01 | ||
</Timeline.Item> | ||
<Timeline.Item>Network problems being solved 2015-09-01</Timeline.Item> | ||
</Timeline>, | ||
mountNode, | ||
); |
23 changes: 23 additions & 0 deletions
23
transforms/__testfixtures__/v3-Icon-to-v4-Icon/misc.output.js
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,23 @@ | ||
import { ClockCircleOutlined, SmileTwoTone } from '@ant-design/icons'; | ||
import { Icon, Result, Timeline } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<Result | ||
icon={<SmileTwoTone />} | ||
title="Great, we have done all the operations!" | ||
extra={<Button type="primary">Next</Button>} | ||
/>, | ||
mountNode, | ||
); | ||
|
||
ReactDOM.render( | ||
<Timeline> | ||
<Timeline.Item>Create a services site 2015-09-01</Timeline.Item> | ||
<Timeline.Item>Solve initial network problems 2015-09-01</Timeline.Item> | ||
<Timeline.Item dot={<ClockCircleOutlined style={{ fontSize: '16px' }} />} color="red"> | ||
Technical testing 2015-09-01 | ||
</Timeline.Item> | ||
<Timeline.Item>Network problems being solved 2015-09-01</Timeline.Item> | ||
</Timeline>, | ||
mountNode, | ||
); |
52 changes: 52 additions & 0 deletions
52
transforms/__testfixtures__/v3-Modal-method-with-icon-to-v4/basic.input.js
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,52 @@ | ||
import { Modal } from 'antd'; | ||
|
||
function showConfirm() { | ||
Modal.confirm({ | ||
icon: 'ant-design', | ||
title: 'Do you Want to delete these items?', | ||
content: 'Some descriptions', | ||
onOk() { | ||
console.log('OK'); | ||
}, | ||
onCancel() { | ||
console.log('Cancel'); | ||
}, | ||
}); | ||
} | ||
|
||
function info() { | ||
Modal.info({ | ||
title: 'This is a notification message', | ||
icon: 'ant-design', | ||
content: ( | ||
<div> | ||
<p>some messages...some messages...</p> | ||
<p>some messages...some messages...</p> | ||
</div> | ||
), | ||
onOk() {}, | ||
}); | ||
} | ||
|
||
function success() { | ||
Modal.success({ | ||
icon: 'plus', | ||
content: 'some messages...some messages...', | ||
}); | ||
} | ||
|
||
function error() { | ||
Modal.error({ | ||
title: 'This is an error message', | ||
icon: 'minus', | ||
content: 'some messages...some messages...', | ||
}); | ||
} | ||
|
||
function warning() { | ||
Modal.warning({ | ||
title: 'This is a warning message', | ||
icon: 'question', | ||
content: 'some messages...some messages...', | ||
}); | ||
} |
53 changes: 53 additions & 0 deletions
53
transforms/__testfixtures__/v3-Modal-method-with-icon-to-v4/basic.output.js
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,53 @@ | ||
import { AntDesignOutlined, MinusOutlined, PlusOutlined, QuestionOutlined } from '@ant-design/icons'; | ||
import { Modal } from 'antd'; | ||
|
||
function showConfirm() { | ||
Modal.confirm({ | ||
icon: <AntDesignOutlined />, | ||
title: 'Do you Want to delete these items?', | ||
content: 'Some descriptions', | ||
onOk() { | ||
console.log('OK'); | ||
}, | ||
onCancel() { | ||
console.log('Cancel'); | ||
}, | ||
}); | ||
} | ||
|
||
function info() { | ||
Modal.info({ | ||
title: 'This is a notification message', | ||
icon: <AntDesignOutlined />, | ||
content: ( | ||
<div> | ||
<p>some messages...some messages...</p> | ||
<p>some messages...some messages...</p> | ||
</div> | ||
), | ||
onOk() {}, | ||
}); | ||
} | ||
|
||
function success() { | ||
Modal.success({ | ||
icon: <PlusOutlined />, | ||
content: 'some messages...some messages...', | ||
}); | ||
} | ||
|
||
function error() { | ||
Modal.error({ | ||
title: 'This is an error message', | ||
icon: <MinusOutlined />, | ||
content: 'some messages...some messages...', | ||
}); | ||
} | ||
|
||
function warning() { | ||
Modal.warning({ | ||
title: 'This is a warning message', | ||
icon: <QuestionOutlined />, | ||
content: 'some messages...some messages...', | ||
}); | ||
} |
23 changes: 23 additions & 0 deletions
23
transforms/__testfixtures__/v3-component-with-string-icon-props-to-v4/avatar.input.js
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,23 @@ | ||
import { UserFilled } from '@ant-design/icons'; | ||
import { Avatar, Badge } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<span style={{ marginRight: 24 }}> | ||
<Badge count={1}> | ||
<Avatar shape="square" icon="user" /> | ||
</Badge> | ||
</span> | ||
<span> | ||
<Badge dot> | ||
<Avatar shape="square" icon="user" /> | ||
</Badge> | ||
</span> | ||
<span> | ||
<Badge dot> | ||
<Avatar shape="square" icon={<UserFilled />} /> | ||
</Badge> | ||
</span> | ||
</div>, | ||
mountNode, | ||
); |
23 changes: 23 additions & 0 deletions
23
transforms/__testfixtures__/v3-component-with-string-icon-props-to-v4/avatar.output.js
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,23 @@ | ||
import { UserFilled, UserOutlined } from '@ant-design/icons'; | ||
import { Avatar, Badge } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<span style={{ marginRight: 24 }}> | ||
<Badge count={1}> | ||
<Avatar shape="square" icon={<UserOutlined />} /> | ||
</Badge> | ||
</span> | ||
<span> | ||
<Badge dot> | ||
<Avatar shape="square" icon={<UserOutlined />} /> | ||
</Badge> | ||
</span> | ||
<span> | ||
<Badge dot> | ||
<Avatar shape="square" icon={<UserFilled />} /> | ||
</Badge> | ||
</span> | ||
</div>, | ||
mountNode, | ||
); |
23 changes: 23 additions & 0 deletions
23
transforms/__testfixtures__/v3-component-with-string-icon-props-to-v4/button.input.js
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,23 @@ | ||
import { Button } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<Button type="primary" shape="circle" icon="search" /> | ||
<Button type="primary" shape="circle"> | ||
A | ||
</Button> | ||
<Button type="primary" icon="search"> | ||
Search | ||
</Button> | ||
<Button shape="circle" icon="search" /> | ||
<Button icon="search">Search</Button> | ||
<br /> | ||
<Button shape="circle" icon="search" /> | ||
<Button icon="search">Search</Button> | ||
<Button type="dashed" shape="circle" icon="search" /> | ||
<Button type="dashed" icon="search"> | ||
Search | ||
</Button> | ||
</div>, | ||
mountNode, | ||
); |
24 changes: 24 additions & 0 deletions
24
transforms/__testfixtures__/v3-component-with-string-icon-props-to-v4/button.output.js
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,24 @@ | ||
import { SearchOutlined } from '@ant-design/icons'; | ||
import { Button } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<Button type="primary" shape="circle" icon={<SearchOutlined />} /> | ||
<Button type="primary" shape="circle"> | ||
A | ||
</Button> | ||
<Button type="primary" icon={<SearchOutlined />}> | ||
Search | ||
</Button> | ||
<Button shape="circle" icon={<SearchOutlined />} /> | ||
<Button icon={<SearchOutlined />}>Search</Button> | ||
<br /> | ||
<Button shape="circle" icon={<SearchOutlined />} /> | ||
<Button icon={<SearchOutlined />}>Search</Button> | ||
<Button type="dashed" shape="circle" icon={<SearchOutlined />} /> | ||
<Button type="dashed" icon={<SearchOutlined />}> | ||
Search | ||
</Button> | ||
</div>, | ||
mountNode, | ||
); |
10 changes: 10 additions & 0 deletions
10
transforms/__testfixtures__/v3-component-with-string-icon-props-to-v4/result.input.js
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,10 @@ | ||
import { Result, Button } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<Result | ||
icon="question" | ||
title="Great, we have done all the operations!" | ||
extra={<Button type="primary">Next</Button>} | ||
/>, | ||
mountNode, | ||
); |
11 changes: 11 additions & 0 deletions
11
transforms/__testfixtures__/v3-component-with-string-icon-props-to-v4/result.output.js
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,11 @@ | ||
import { QuestionOutlined } from '@ant-design/icons'; | ||
import { Result, Button } from 'antd'; | ||
|
||
ReactDOM.render( | ||
<Result | ||
icon={<QuestionOutlined />} | ||
title="Great, we have done all the operations!" | ||
extra={<Button type="primary">Next</Button>} | ||
/>, | ||
mountNode, | ||
); |
11 changes: 11 additions & 0 deletions
11
transforms/__tests__/v3-Modal-method-with-icon-to-v4.test.js
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,11 @@ | ||
const tests = ['basic']; | ||
|
||
const defineTest = require('jscodeshift/dist/testUtils').defineTest; | ||
|
||
const testUnit = 'v3-Modal-method-with-icon-to-v4'; | ||
|
||
describe(testUnit, () => { | ||
tests.forEach(test => | ||
defineTest(__dirname, testUnit, null, `${testUnit}/${test}`), | ||
); | ||
}); |
11 changes: 11 additions & 0 deletions
11
transforms/__tests__/v3-component-with-string-icon-props-to-v4.test.js
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,11 @@ | ||
const tests = ['avatar', 'button', 'result']; | ||
|
||
const defineTest = require('jscodeshift/dist/testUtils').defineTest; | ||
|
||
const testUnit = 'v3-component-with-string-icon-props-to-v4'; | ||
|
||
describe(testUnit, () => { | ||
tests.forEach(test => | ||
defineTest(__dirname, testUnit, null, `${testUnit}/${test}`), | ||
); | ||
}); |
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,34 @@ | ||
const { | ||
withThemeSuffix, | ||
removeTypeTheme, | ||
alias, | ||
} = require('@ant-design/compatible/lib/icon/utils'); | ||
const allIcons = require('@ant-design/icons/lib/icons'); | ||
|
||
function getV4IconComponentName(type, theme) { | ||
const v4IconComponentName = withThemeSuffix( | ||
removeTypeTheme(alias(type)), | ||
theme || 'outlined', | ||
); | ||
|
||
// check if component is valid or not in v4 icons | ||
if (allIcons[v4IconComponentName]) { | ||
return v4IconComponentName; | ||
} | ||
|
||
console.warn(`The icon with type: ${type} and theme ${theme} cannot found`); | ||
} | ||
|
||
function createIconJSXElement(j, iconLocalName) { | ||
const openingElement = j.jsxOpeningElement( | ||
j.jsxIdentifier(iconLocalName), | ||
[], | ||
); | ||
openingElement.selfClosing = true; | ||
return j.jsxElement(openingElement); | ||
} | ||
|
||
module.exports = { | ||
getV4IconComponentName, | ||
createIconJSXElement, | ||
}; |
Oops, something went wrong.