Skip to content

Commit 4efc509

Browse files
committed
feat: update icon
1 parent 1fffe0d commit 4efc509

File tree

13 files changed

+154
-253
lines changed

13 files changed

+154
-253
lines changed

build/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
dev: {
3-
componentName: 'grid', // dev components
3+
componentName: 'icon', // dev components
44
},
55
};

components/icon/__tests__/__snapshots__/index.test.js.snap

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
exports[`Icon \`component\` prop can access to svg defs if has children 1`] = `
44
<i class="my-home-icon anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
5-
<title>Cool Home</title>
6-
<path d="'M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z'"></path>
5+
<defs>
6+
<linearGradient id="gradient">
7+
<stop offset="20%" stopColor="#39F"></stop>
8+
<stop offset="90%" stopColor="#F3F"></stop>
9+
</linearGradient>
10+
</defs>
711
</svg></i>
812
`;
913

@@ -58,9 +62,9 @@ exports[`Icon should support pass svg paths as children 1`] = `
5862
`;
5963

6064
exports[`Icon should support svg vue component 1`] = `
61-
<i class="my-home-icon anticon"><svg width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
65+
<i class="my-home-icon anticon"><svg viewBox="0 0 24 24" width="1em" height="1em" fill="currentColor" aria-hidden="true" focusable="false" class="">
6266
<title>Cool Home</title>
63-
<path d="'M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z'"></path>
67+
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"></path>
6468
</svg></i>
6569
`;
6670

components/icon/__tests__/index.test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import Icon from '..';
33
import VueIcon from '@ant-design/icons-vue';
44
import { getThemeFromTypeName, withThemeSuffix } from '../utils';
55
import { cloneElement } from '../../_util/vnode';
6+
import mountTest from '../../../tests/shared/mountTest';
67

78
describe('Icon', () => {
9+
mountTest(Icon);
10+
811
it('should render to a <i class="xxx"><svg>...</svg></i>', () => {
912
const wrapper = mount({
1013
render() {
@@ -119,7 +122,7 @@ describe('Icon', () => {
119122
return <Icon type="clock-circle-o" theme="outlined" />;
120123
},
121124
});
122-
expect(errorSpy).not.toBeCalled();
125+
expect(errorSpy).not.toHaveBeenCalled();
123126
});
124127

125128
it('warns', () => {
@@ -129,7 +132,7 @@ describe('Icon', () => {
129132
},
130133
});
131134
expect(errorSpy).toBeCalledWith(
132-
"Warning: The icon name 'clock-circle-o' already specify a theme 'outlined', the 'theme' prop 'filled' will be ignored.",
135+
"Warning: [antdv: Icon] The icon name 'clock-circle-o' already specify a theme 'outlined', the 'theme' prop 'filled' will be ignored.",
133136
);
134137
});
135138
});

components/icon/demo/index.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ const md = {
1313
## 设计师专属
1414
安装 [Kitchen Sketch 插件 �](https://kitchen.alipay.com),就可以一键拖拽使用 Ant Design 和 Iconfont 的海量图标,还可以关联自有项目。
1515
## 图标列表
16-
> 点击图标即可复制代码。
17-
新版图标可能略有缺失,我们还在持续补充中。
1816
`,
1917
us: `# Icon
2018
Semantic vector graphics.
2119
## List of icons
22-
> Click the icon and copy the code.
23-
We are still adding two-tone icons right now.
2420
`,
2521
};
2622
export default {

components/icon/demo/two-tone.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<us>
77
#### Two-tone icon and colorful icon
8-
Specific them property `theme` to `twoTone` to render two-tone icons. You can also set the primary color.
8+
Specify the property `theme` to `twoTone` to render two-tone icons. You can also set the primary color.
99
</us>
1010

1111
```tpl

components/icon/index.en-US.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@
44
| --- | --- | --- | --- |
55
| type | Type of the ant design icon | string | - |
66
| style | Style properties of icon, like `fontSize` and `color` | CSSProperties | - |
7-
| theme | Theme of the ant design icon | 'filled' \| 'outlined' \| 'twoTone' | 'outlined' |
7+
| theme | Theme variant of the icon | 'filled' \| 'outlined' \| 'twoTone' | 'outlined' |
88
| spin | Rotate icon with animation | boolean | false |
99
| rotate | Rotate degrees (added in 1.4.0, not working in IE9) | number | - |
1010
| component | The component used for the root node. This will override the **`type`** property. | ComponentType<CustomIconComponentProps\> | - |
1111
| twoToneColor | Only support the two-tone icon. Specific the primary color. | string (hex color) | - |
1212

13+
> Note: icon rendering priority of the Icon component is component > children > type. When props is passed, the higher priority item will work, and the lower priority item will be invalid.
14+
1315
### SVG icons
1416

15-
We introduced SVG icons in `1.2.0` version replacing font icons which brings benefits below:
17+
We introduced SVG icons in version `1.2.0`, replacing font icons. This has the following benefits:
1618

17-
- Complete offline usage of icon, no dependency of CDN font icon file and no more empty square during downloading than no need to deploy icon font files locally either.
18-
- Much more display accuracy in lower-level screens.
19-
- Support multiple colors for icon.
20-
- No need to change built-in icons with overriding styles by providing more props in component.
19+
- Complete offline usage of icons, without dependency on a CDN-hosted font icon file (No more empty square during downloading and no need to deploy icon font files locally either!)
20+
- Much more display accuracy on lower-resolution screens
21+
- The ability to choose icon color
22+
- No need to change built-in icons with overriding styles by providing more props in component
2123

22-
More discussion of SVG icon reference to [#10353](https://github.com/ant-design/ant-design/issues/10353).
24+
More discussion of SVG icon reference at [#10353](https://github.com/ant-design/ant-design/issues/10353).
2325

24-
> ⚠️ About the extra bundle size brought by all SVG icons we imported in 1.2.0, we will provide new API to allow developers importing icons as your need, you can trace [#12011](https://github.com/ant-design/ant-design/issues/12011) for further progress.
26+
> ⚠️ Given the extra bundle size caused by all SVG icons imported in 1.2.0, we will provide a new API to allow developers to import icons as needed, you can track [#12011](https://github.com/ant-design/ant-design/issues/12011) for updates.
27+
>
28+
> While you wait, you can use [webpack plugin](https://github.com/Beven91/webpack-ant-icon-loader) from the community to chunk the icon file.
2529
26-
The properties `theme`, `component` and `twoToneColor` are added in `1.2.0`. The best practice is to pass the property `theme` to every `<Icon />` components.
30+
The properties `theme`, `component` and `twoToneColor` were added in `1.2.0`. The best practice is to pass the property `theme` to every `<Icon />` component.
2731

2832
```html
2933
<a-icon type="star" theme="filled" />

components/icon/index.js

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function renderIcon(h, locale, context) {
4141
children = children.length === 0 ? undefined : children;
4242
warning(
4343
Boolean(type || Component || children),
44+
'Icon',
4445
'Icon should have `type` prop or `component` prop or `children`.',
4546
);
4647

@@ -61,68 +62,71 @@ function renderIcon(h, locale, context) {
6162
}
6263
: undefined;
6364

64-
let innerNode;
65+
const innerSvgProps = {
66+
attrs: {
67+
...svgBaseProps,
68+
viewBox,
69+
},
70+
class: svgClassString,
71+
style: svgStyle,
72+
};
73+
if (!viewBox) {
74+
delete innerSvgProps.attrs.viewBox;
75+
}
6576

66-
// component > children > type
67-
if (Component) {
68-
const innerSvgProps = {
69-
attrs: {
70-
...svgBaseProps,
71-
viewBox,
72-
},
73-
class: svgClassString,
74-
style: svgStyle,
75-
};
76-
if (!viewBox) {
77-
delete innerSvgProps.attrs.viewBox;
77+
const renderInnerNode = () => {
78+
// component > children > type
79+
if (Component) {
80+
return <Component {...innerSvgProps}>{children}</Component>;
81+
}
82+
if (children) {
83+
warning(
84+
Boolean(viewBox) || (children.length === 1 && children[0].tag === 'use'),
85+
'Icon',
86+
'Make sure that you provide correct `viewBox`' +
87+
' prop (default `0 0 1024 1024`) to the icon.',
88+
);
89+
const innerSvgProps = {
90+
attrs: {
91+
...svgBaseProps,
92+
},
93+
class: svgClassString,
94+
style: svgStyle,
95+
};
96+
return (
97+
<svg {...innerSvgProps} viewBox={viewBox}>
98+
{children}
99+
</svg>
100+
);
78101
}
79102

80-
innerNode = <Component {...innerSvgProps}>{children}</Component>;
81-
}
82-
if (children) {
83-
warning(
84-
Boolean(viewBox) || (children.length === 1 && children[0].tag === 'use'),
85-
'Make sure that you provide correct `viewBox`' +
86-
' prop (default `0 0 1024 1024`) to the icon.',
87-
);
88-
const innerSvgProps = {
89-
attrs: {
90-
...svgBaseProps,
91-
},
92-
class: svgClassString,
93-
style: svgStyle,
94-
};
95-
innerNode = (
96-
<svg {...innerSvgProps} viewBox={viewBox}>
97-
{children}
98-
</svg>
99-
);
100-
}
103+
if (typeof type === 'string') {
104+
let computedType = type;
105+
if (theme) {
106+
const themeInName = getThemeFromTypeName(type);
107+
warning(
108+
!themeInName || theme === themeInName,
109+
'Icon',
110+
`The icon name '${type}' already specify a theme '${themeInName}',` +
111+
` the 'theme' prop '${theme}' will be ignored.`,
112+
);
113+
}
114+
computedType = withThemeSuffix(
115+
removeTypeTheme(alias(computedType)),
116+
dangerousTheme || theme || defaultTheme,
117+
);
101118

102-
if (typeof type === 'string') {
103-
let computedType = type;
104-
if (theme) {
105-
const themeInName = getThemeFromTypeName(type);
106-
warning(
107-
!themeInName || theme === themeInName,
108-
`The icon name '${type}' already specify a theme '${themeInName}',` +
109-
` the 'theme' prop '${theme}' will be ignored.`,
119+
return (
120+
<VueIcon
121+
focusable="false"
122+
class={svgClassString}
123+
type={computedType}
124+
primaryColor={twoToneColor}
125+
style={svgStyle}
126+
/>
110127
);
111128
}
112-
computedType = withThemeSuffix(
113-
removeTypeTheme(alias(computedType)),
114-
dangerousTheme || theme || defaultTheme,
115-
);
116-
innerNode = (
117-
<VueIcon
118-
focusable="false"
119-
class={svgClassString}
120-
type={computedType}
121-
primaryColor={twoToneColor}
122-
style={svgStyle}
123-
/>
124-
);
125-
}
129+
};
126130
let iconTabIndex = tabIndex;
127131
if (iconTabIndex === undefined && 'click' in listeners) {
128132
iconTabIndex = -1;
@@ -140,7 +144,7 @@ function renderIcon(h, locale, context) {
140144
class: classString,
141145
staticClass: '',
142146
};
143-
return <i {...iProps}>{innerNode}</i>;
147+
return <i {...iProps}>{renderInnerNode()}</i>;
144148
}
145149

146150
const Icon = {

components/icon/index.zh-CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
| component | 控制如何渲染图标,通常是一个渲染根标签为 `<svg>``Vue` 组件,**会使 `type` 属性失效** | ComponentType<CustomIconComponentProps\> | - |
1111
| twoToneColor | 仅适用双色图标。设置双色图标的主要颜色 | string (十六进制颜色) | - |
1212

13+
> 注意:Icon 组件中图标渲染的优先级为 component > children > type, 传入 props 时,优先级高的直接生效,优先级低的则失效。
14+
1315
### SVG 图标
1416

1517
`1.2.0` 之后,我们使用了 SVG 图标替换了原先的 font 图标,从而带来了以下优势:
@@ -21,7 +23,7 @@
2123

2224
更多讨论可参考:[#10353](https://github.com/ant-design/ant-design/issues/10353)
2325

24-
> ⚠️ 1.2.0 之后我们全量引入了所有图标,导致 antd 默认的包体积有一定增加,我们会在不远的未来增加新的 API 来实现图标的按需使用,更多相关讨论可关注:[#12011](https://github.com/ant-design/ant-design/issues/12011)
26+
> ⚠️ 1.2.0 之后我们全量引入了所有图标,导致 antd 默认的包体积有一定增加,我们会在不远的未来增加新的 API 来实现图标的按需使用,更多相关讨论可关注:[#12011](https://github.com/ant-design/ant-design/issues/12011)在此之前,你可以通过来自社区同学的 [webpack 插件](https://github.com/Beven91/webpack-ant-icon-loader)将图标文件拆分。
2527
2628
其中 `theme`, `component`, `twoToneColor``1.2.x` 版本新增加的属性。最佳实践是给使用的 `<Icon />` 组件传入属性 `theme` 以明确图标的主题风格。例如:
2729

components/icon/utils.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,36 @@ export function withThemeSuffix(type, theme) {
4242
} else if (theme === 'twoTone') {
4343
result += '-twotone';
4444
} else {
45-
warning(false, `This icon '${type}' has unknown theme '${theme}'`);
45+
warning(false, 'Icon', `This icon '${type}' has unknown theme '${theme}'`);
4646
}
4747
return result;
4848
}
4949

5050
// For alias or compatibility
5151
export function alias(type) {
52+
let newType = type;
5253
switch (type) {
5354
case 'cross':
54-
return 'close';
55+
newType = 'close';
56+
break;
57+
// https://github.com/ant-design/ant-design/issues/13007
58+
case 'interation':
59+
newType = 'interaction';
60+
break;
61+
// https://github.com/ant-design/ant-design/issues/16810
62+
case 'canlendar':
63+
newType = 'calendar';
64+
break;
65+
// https://github.com/ant-design/ant-design/issues/17448
66+
case 'colum-height':
67+
newType = 'column-height';
68+
break;
5569
default:
5670
}
57-
return type;
71+
warning(
72+
newType === type,
73+
'Icon',
74+
`Icon '${type}' was a typo and is now deprecated, please use '${newType}' instead.`,
75+
);
76+
return newType;
5877
}

site/theme/template/IconDisplay/CopyableIcon.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
</li>
1414
</template>
1515
<script>
16+
import Badge from '@/components/badge';
17+
import '@/components/badge/style';
1618
export default {
19+
components: {
20+
'a-badge': Badge,
21+
},
1722
props: ['type', 'isNew', 'theme', 'justCopied'],
1823
data() {
1924
const { type, theme } = this;

0 commit comments

Comments
 (0)