Skip to content

Commit e249b08

Browse files
committed
refactor: icon to normal component #1947
1 parent ff9f408 commit e249b08

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

components/icon/index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import warning from '../_util/warning';
1414
import LocaleReceiver from '../locale-provider/LocaleReceiver';
1515
import { getTwoToneColor, setTwoToneColor } from './twoTonePrimaryColor';
16-
import { filterEmpty, getClass } from '../_util/props-util';
16+
import { filterEmpty, getListeners } from '../_util/props-util';
1717
import Base from '../base';
1818

1919
// Initial setting
@@ -23,7 +23,8 @@ const defaultTheme = 'outlined';
2323
let dangerousTheme;
2424

2525
function renderIcon(h, locale, context) {
26-
const { props, slots, listeners, data } = context;
26+
const { $props: props, $slots } = context;
27+
const listeners = getListeners(context);
2728
const {
2829
// affect inner <svg>...</svg>
2930
type,
@@ -36,8 +37,7 @@ function renderIcon(h, locale, context) {
3637
rotate,
3738
tabIndex,
3839
} = props;
39-
const slotsMap = slots();
40-
let children = filterEmpty(slotsMap.default);
40+
let children = filterEmpty($slots.default);
4141
children = children.length === 0 ? undefined : children;
4242
warning(
4343
Boolean(type || Component || children),
@@ -46,7 +46,6 @@ function renderIcon(h, locale, context) {
4646
);
4747

4848
const classString = classNames({
49-
...getClass(context),
5049
[`anticon`]: true,
5150
[`anticon-${type}`]: !!type,
5251
});
@@ -131,24 +130,20 @@ function renderIcon(h, locale, context) {
131130
if (iconTabIndex === undefined && 'click' in listeners) {
132131
iconTabIndex = -1;
133132
}
134-
const { attrs, ...restDataProps } = data;
135133
// functional component not support nativeOn,https://github.com/vuejs/vue/issues/7526
136134
const iProps = {
137-
...restDataProps,
138135
attrs: {
139-
...attrs,
140136
'aria-label': type && `${locale.icon}: ${type}`,
141137
tabIndex: iconTabIndex,
142138
},
143-
on: { ...listeners, ...data.nativeOn },
139+
on: listeners,
144140
class: classString,
145141
staticClass: '',
146142
};
147143
return <i {...iProps}>{renderInnerNode()}</i>;
148144
}
149145

150146
const Icon = {
151-
functional: true,
152147
name: 'AIcon',
153148
props: {
154149
tabIndex: PropTypes.number,
@@ -161,11 +156,11 @@ const Icon = {
161156
twoToneColor: PropTypes.string,
162157
role: PropTypes.string,
163158
},
164-
render(h, context) {
159+
render(h) {
165160
return (
166161
<LocaleReceiver
167162
componentName="Icon"
168-
scopedSlots={{ default: locale => renderIcon(h, locale, context) }}
163+
scopedSlots={{ default: locale => renderIcon(h, locale, this) }}
169164
/>
170165
);
171166
},

0 commit comments

Comments
 (0)