diff --git a/components/icon/demo/two-tone.md b/components/icon/demo/two-tone.md index 4ab6bde67e..6dd4b9913a 100644 --- a/components/icon/demo/two-tone.md +++ b/components/icon/demo/two-tone.md @@ -20,7 +20,7 @@ ReactDOM.render(
- +
, mountNode ); diff --git a/components/icon/index.en-US.md b/components/icon/index.en-US.md index 26eb6a834d..265c9b23b8 100644 --- a/components/icon/index.en-US.md +++ b/components/icon/index.en-US.md @@ -29,8 +29,7 @@ ReactDOM.render(, mountNode); | svgClassName | Define extra class name for the SVG element | string | - | | spin | Rotate icon with animation | boolean | false | | component | The component used for the root node. This will override the **`type`** property. | ComponentType | - | -| primaryColor | Only support the two-tone icon. Specific the primary color. | string (hex color) | - | -| secondaryColor | Only support the two-tone icon. Specific the secondary color. | string (hex color) | - | +| twoToneColor | Only support the two-tone icon. Specific the primary color. | string (hex color) | - | All the icons will render to ``. You can still set `style` and `className` for size and color of icons. diff --git a/components/icon/index.tsx b/components/icon/index.tsx index 3e94604aba..296c2ed791 100755 --- a/components/icon/index.tsx +++ b/components/icon/index.tsx @@ -5,13 +5,11 @@ import ReactIcon from '@ant-design/icons-react'; import createFromIconfontCN from './IconFont'; import { svgBaseProps, withThemeSuffix } from './utils'; import warning from '../_util/warning'; -import { getTwoToneColors, setTwoToneColors } from './twoTonePrimaryColor'; +import { getTwoToneColor, setTwoToneColor } from './twoTonePrimaryColor'; // Initial setting ReactIcon.add(...Object.keys(allIcons).map((key) => (allIcons as any)[key])); -ReactIcon.setTwoToneColors({ - primaryColor: '#1890ff', -}); +setTwoToneColor('#1890ff'); export interface CustomIconComponentProps { width: string | number; @@ -32,8 +30,7 @@ export interface IconProps { title?: string; onClick?: React.MouseEventHandler; component?: React.ComponentType; - primaryColor?: string; - secondaryColor?: string; + twoToneColor?: string; viewBox?: string; spin?: boolean; style?: React.CSSProperties; @@ -62,9 +59,8 @@ const Icon: React.SFC = (props) => { children, // other - theme, - primaryColor, - secondaryColor, + theme, // default to outlined + twoToneColor, } = props; warning( @@ -127,20 +123,18 @@ const Icon: React.SFC = (props) => { if (theme) { computedType = withThemeSuffix(type, theme); } - if (secondaryColor) { - warning( - Boolean(!primaryColor), - `two-tone icon should be provided with the property 'primaryColor' at least.`, - ); - } + // default outlined + const computedType = withThemeSuffix( + getTypeWithoutTheme(type), + theme || 'outlined', + ); return ( ); @@ -153,13 +147,13 @@ const Icon: React.SFC = (props) => { export type IconType = typeof Icon & { createFromIconfontCN: typeof createFromIconfontCN; - getTwoToneColors: typeof getTwoToneColors; - setTwoToneColors: typeof setTwoToneColors; + getTwoToneColor: typeof getTwoToneColor; + setTwoToneColor: typeof setTwoToneColor; }; Icon.displayName = 'Icon'; (Icon as IconType).createFromIconfontCN = createFromIconfontCN; -(Icon as IconType).getTwoToneColors = getTwoToneColors; -(Icon as IconType).setTwoToneColors = setTwoToneColors; +(Icon as IconType).getTwoToneColor = getTwoToneColor; +(Icon as IconType).setTwoToneColor = setTwoToneColor; export default Icon as IconType; diff --git a/components/icon/index.zh-CN.md b/components/icon/index.zh-CN.md index e42348b3a8..19f1f093e5 100644 --- a/components/icon/index.zh-CN.md +++ b/components/icon/index.zh-CN.md @@ -34,8 +34,7 @@ ReactDOM.render(, mountNode); | svgClassName | 为图标本身``标签设置额外的类名 | string | - | | spin | 是否有旋转动画 | boolean | false | | component | 控制如何渲染图标,通常是一个渲染根标签为 `` 的 `React` 组件,**会使 `type` 属性失效** | ComponentType | - | -| primaryColor | 仅适用双色图标。设置双色图标的主要颜色。 | string (十六进制颜色) | - | -| secondaryColor | 仅适用双色图标。设置双色图标的次要颜色。 | string (十六进制颜色) | - | +| twoToneColor | 仅适用双色图标。设置双色图标的主要颜色。 | string (十六进制颜色) | - | 所有的图标都会以 `` 标签渲染,可以使用 `style` 和 `className` 设置图标的大小和单色图标的颜色。例如: diff --git a/components/icon/twoTonePrimaryColor.ts b/components/icon/twoTonePrimaryColor.ts index 556fa03c8d..7e9e93fe3d 100644 --- a/components/icon/twoTonePrimaryColor.ts +++ b/components/icon/twoTonePrimaryColor.ts @@ -1,9 +1,12 @@ -import ReactIcon, { TwoToneColorPalette, TwoToneColorPaletteSetter } from '@ant-design/icons-react'; +import ReactIcon from '@ant-design/icons-react'; -export function setTwoToneColors(colors: TwoToneColorPaletteSetter): void { - return ReactIcon.setTwoToneColors(colors); +export function setTwoToneColor(primaryColor: string): void { + return ReactIcon.setTwoToneColors({ + primaryColor, + }); } -export function getTwoToneColors(): TwoToneColorPalette { - return ReactIcon.getTwoToneColors(); +export function getTwoToneColor(): string { + const colors = ReactIcon.getTwoToneColors(); + return colors.primaryColor; }