mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
new getter & setter
This commit is contained in:
parent
73218926c3
commit
39ffee1fa5
@ -10,6 +10,31 @@ describe('Icon', () => {
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should support basic usage', () => {
|
||||
const wrapper = render(
|
||||
<div>
|
||||
<Icon type="home" />
|
||||
<Icon type="setting" theme="filled" />
|
||||
<Icon type="smile" theme="outlined" />
|
||||
<Icon type="sync" spin />
|
||||
<Icon type="loading" />
|
||||
</div>
|
||||
);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should support older usage', () => {
|
||||
const wrapper = render(
|
||||
<div>
|
||||
<Icon type="home-o" />
|
||||
<Icon type="setting-fill" />
|
||||
<Icon type="smile-o" />
|
||||
<Icon type="check-circle-twotone" />
|
||||
</div>
|
||||
);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should support two-tone icon', () => {
|
||||
const wrapper = render(
|
||||
<Icon type="check-circle" theme="two-tone" primaryColor="#f5222d" />
|
||||
@ -17,6 +42,25 @@ describe('Icon', () => {
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should support config global two-tone primary color', () => {
|
||||
const colors = Icon.getTwoToneColors();
|
||||
Icon.setTwoToneColors({
|
||||
primaryColor: '#1890ff',
|
||||
});
|
||||
const wrapper = render(
|
||||
<Icon type="check-circle" theme="two-tone" />
|
||||
);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
Icon.setTwoToneColors(colors);
|
||||
});
|
||||
|
||||
it('should give a warning when there is no primaryColor but secondaryColor', () => {
|
||||
const wrapper = render(
|
||||
<Icon type="check-circle" theme="two-tone" secondaryColor="#f5222d" />
|
||||
);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should support pass svg paths as children', () => {
|
||||
const wrapper = render(
|
||||
<Icon viewBox="0 0 24 24">
|
||||
|
@ -16,7 +16,9 @@ Specific them property `theme` to `two-tone` to render two-tone icons. You can a
|
||||
````jsx
|
||||
import { Icon } from 'antd';
|
||||
|
||||
Icon.setTwoTonePrimaryColor('#1890ff');
|
||||
Icon.setTwoToneColors({
|
||||
primaryColor: '#1890ff',
|
||||
});
|
||||
|
||||
ReactDOM.render(
|
||||
<div className="icons-list">
|
||||
|
@ -5,7 +5,7 @@ import ReactIcon from '@ant-design/icons-react';
|
||||
import createFromIconfontCN from './IconFont';
|
||||
import { svgBaseProps, withThemeSuffix } from './utils';
|
||||
import warning from '../_util/warning';
|
||||
import { setTwoTonePrimaryColor } from './setTwoTonePrimaryColor';
|
||||
import { getTwoToneColors, setTwoToneColors } from './twoTonePrimaryColor';
|
||||
|
||||
ReactIcon.add(...Object.keys(allIcons).map((key) => (allIcons as any)[key]));
|
||||
|
||||
@ -149,11 +149,13 @@ const Icon: React.SFC<IconProps> = (props) => {
|
||||
|
||||
export type IconType = typeof Icon & {
|
||||
createFromIconfontCN: typeof createFromIconfontCN;
|
||||
setTwoTonePrimaryColor: typeof setTwoTonePrimaryColor;
|
||||
getTwoToneColors: typeof getTwoToneColors;
|
||||
setTwoToneColors: typeof setTwoToneColors;
|
||||
};
|
||||
|
||||
Icon.displayName = 'Icon';
|
||||
(Icon as IconType).createFromIconfontCN = createFromIconfontCN;
|
||||
(Icon as IconType).setTwoTonePrimaryColor = setTwoTonePrimaryColor;
|
||||
(Icon as IconType).getTwoToneColors = getTwoToneColors;
|
||||
(Icon as IconType).setTwoToneColors = setTwoToneColors;
|
||||
|
||||
export default Icon as IconType;
|
||||
|
@ -1,5 +0,0 @@
|
||||
import ReactIcon from '@ant-design/icons-react';
|
||||
|
||||
export function setTwoTonePrimaryColor(primaryColor: string, secondaryColor?: string) {
|
||||
return ReactIcon.setTwoTonePrimaryColor(primaryColor, secondaryColor);
|
||||
}
|
9
components/icon/twoTonePrimaryColor.ts
Normal file
9
components/icon/twoTonePrimaryColor.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import ReactIcon, { TwoToneColorPalette, TwoToneColorPaletteSetter } from '@ant-design/icons-react';
|
||||
|
||||
export function setTwoToneColors(colors: TwoToneColorPaletteSetter): void {
|
||||
return ReactIcon.setTwoToneColors(colors);
|
||||
}
|
||||
|
||||
export function getTwoToneColors(): TwoToneColorPalette {
|
||||
return ReactIcon.getTwoToneColors();
|
||||
}
|
@ -40,7 +40,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "~1.0.0-alpha.5",
|
||||
"@ant-design/icons-react": "~1.0.0-alpha.2",
|
||||
"@ant-design/icons-react": "~1.0.0-alpha.6",
|
||||
"array-tree-filter": "^2.0.0",
|
||||
"babel-runtime": "6.x",
|
||||
"classnames": "~2.2.0",
|
||||
|
Loading…
Reference in New Issue
Block a user