-
-
Notifications
You must be signed in to change notification settings - Fork 49k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Feature tag component icon prop support #22418
Changes from 4 commits
1fba719
39f8dfb
218856e
488eb04
40a1394
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
order: 7 | ||
title: | ||
zh-CN: 图标按钮 | ||
en-US: Icon | ||
--- | ||
|
||
## zh-CN | ||
|
||
当需要在 `Tag` 内嵌入 `Icon` 时,可以设置 `icon` 属性,或者直接在 `Tag` 内使用 `Icon` 组件。 | ||
|
||
如果想控制 `Icon` 具体的位置,只能直接使用 `Icon` 组件,而非 `icon` 属性。 | ||
|
||
## en-US | ||
|
||
`Tag` components can contain an `Icon`. This is done by setting the `icon` property or placing an `Icon` component within the `Tag`. | ||
|
||
If you want specific control over the positioning and placement of the `Icon`, then that should be done by placing the `Icon` component within the `Tag` rather than using the `icon` property. | ||
|
||
```jsx | ||
import { Tag } from 'antd'; | ||
import { | ||
TwitterOutlined, | ||
YoutubeOutlined, | ||
FacebookOutlined, | ||
LinkedinOutlined, | ||
} from '@ant-design/icons'; | ||
|
||
ReactDOM.render( | ||
<div> | ||
<Tag icon={<TwitterOutlined />} color="#55acee"> | ||
</Tag> | ||
<Tag icon={<YoutubeOutlined />} color="#cd201f"> | ||
Youtube | ||
</Tag> | ||
<Tag icon={<FacebookOutlined />} color="#3b5999"> | ||
</Tag> | ||
<Tag icon={<LinkedinOutlined />} color="#55acee"> | ||
</Tag> | ||
</div>, | ||
mountNode, | ||
); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import CheckableTag from './CheckableTag'; | |
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; | ||
import { PresetColorTypes, PresetStatusColorTypes } from '../_util/colors'; | ||
import Wave from '../_util/wave'; | ||
import warning from '../_util/warning'; | ||
|
||
export { CheckableTagProps } from './CheckableTag'; | ||
|
||
|
@@ -18,6 +19,7 @@ export interface TagProps extends React.HTMLAttributes<HTMLSpanElement> { | |
visible?: boolean; | ||
onClose?: Function; | ||
style?: React.CSSProperties; | ||
icon?: React.ReactNode; | ||
} | ||
|
||
interface TagState { | ||
|
@@ -106,24 +108,39 @@ class Tag extends React.Component<TagProps, TagState> { | |
} | ||
|
||
renderTag = (configProps: ConfigConsumerProps) => { | ||
const { children, ...otherProps } = this.props; | ||
const { children, icon, ...otherProps } = this.props; | ||
const isNeedWave = | ||
'onClick' in otherProps || (children && (children as React.ReactElement<any>).type === 'a'); | ||
const tagProps = omit(otherProps, ['onClose', 'color', 'visible', 'closable', 'prefixCls']); | ||
warning( | ||
!(typeof icon === 'string' && icon.length > 2), | ||
'Tag', | ||
`\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`, | ||
); | ||
const iconNode = icon || null; | ||
const kids = iconNode ? ( | ||
<> | ||
{iconNode} | ||
<span>{children}</span> | ||
</> | ||
) : ( | ||
children | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So is this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, not sure what u mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @afc163 🔝 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this warning either, cause antd v3 never supported Tag[icon]. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that what you meant :) Fixed. Thought you somehow related to the rebase thing |
||
|
||
return isNeedWave ? ( | ||
<Wave> | ||
<span | ||
{...tagProps} | ||
className={this.getTagClassName(configProps)} | ||
style={this.getTagStyle()} | ||
> | ||
{children} | ||
{kids} | ||
{this.renderCloseIcon()} | ||
</span> | ||
</Wave> | ||
) : ( | ||
<span {...tagProps} className={this.getTagClassName(configProps)} style={this.getTagStyle()}> | ||
{children} | ||
{kids} | ||
{this.renderCloseIcon()} | ||
</span> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for reply in wrong line.