@@ -11,6 +11,7 @@ import {
11
11
alias ,
12
12
} from './utils' ;
13
13
import warning from '../_util/warning' ;
14
+ import LocaleReceiver from '../locale-provider/LocaleReceiver' ;
14
15
import { getTwoToneColor , setTwoToneColor } from './twoTonePrimaryColor' ;
15
16
import { filterEmpty , getClass } from '../_util/props-util' ;
16
17
@@ -20,109 +21,146 @@ setTwoToneColor('#1890ff');
20
21
const defaultTheme = 'outlined' ;
21
22
let dangerousTheme ;
22
23
24
+ function renderIcon ( h , locale , context ) {
25
+ const { props, slots, listeners, data } = context ;
26
+ const {
27
+ // affect inner <svg>...</svg>
28
+ type,
29
+ component : Component ,
30
+ viewBox,
31
+ spin,
32
+ // other
33
+ theme, // default to outlined
34
+ twoToneColor,
35
+ rotate,
36
+ tabIndex,
37
+ } = props ;
38
+ const slotsMap = slots ( ) ;
39
+ let children = filterEmpty ( slotsMap . default ) ;
40
+ children = children . length === 0 ? undefined : children ;
41
+ warning (
42
+ Boolean ( type || Component || children ) ,
43
+ 'Icon should have `type` prop or `component` prop or `children`.' ,
44
+ ) ;
45
+
46
+ const classString = classNames ( {
47
+ ...getClass ( context ) ,
48
+ [ `anticon` ] : true ,
49
+ [ `anticon-${ type } ` ] : ! ! type ,
50
+ } ) ;
51
+
52
+ const svgClassString = classNames ( {
53
+ [ `anticon-spin` ] : ! ! spin || type === 'loading' ,
54
+ } ) ;
55
+
56
+ const svgStyle = rotate
57
+ ? {
58
+ msTransform : `rotate(${ rotate } deg)` ,
59
+ transform : `rotate(${ rotate } deg)` ,
60
+ }
61
+ : undefined ;
62
+
63
+ let innerNode ;
64
+
65
+ // component > children > type
66
+ if ( Component ) {
67
+ const innerSvgProps = {
68
+ attrs : {
69
+ ...svgBaseProps ,
70
+ style : svgStyle ,
71
+ viewBox,
72
+ } ,
73
+ class : svgClassString ,
74
+ } ;
75
+ if ( ! viewBox ) {
76
+ delete innerSvgProps . attrs . viewBox ;
77
+ }
78
+
79
+ innerNode = < Component { ...innerSvgProps } > { children } </ Component > ;
80
+ }
81
+ if ( children ) {
82
+ warning (
83
+ Boolean ( viewBox ) || ( children . length === 1 && children [ 0 ] . tag === 'use' ) ,
84
+ 'Make sure that you provide correct `viewBox`' +
85
+ ' prop (default `0 0 1024 1024`) to the icon.' ,
86
+ ) ;
87
+ const innerSvgProps = {
88
+ attrs : {
89
+ ...svgBaseProps ,
90
+ } ,
91
+ class : svgClassString ,
92
+ } ;
93
+ innerNode = (
94
+ < svg { ...innerSvgProps } viewBox = { viewBox } >
95
+ { children }
96
+ </ svg >
97
+ ) ;
98
+ }
99
+
100
+ if ( typeof type === 'string' ) {
101
+ let computedType = type ;
102
+ if ( theme ) {
103
+ const themeInName = getThemeFromTypeName ( type ) ;
104
+ warning (
105
+ ! themeInName || theme === themeInName ,
106
+ `The icon name '${ type } ' already specify a theme '${ themeInName } ',` +
107
+ ` the 'theme' prop '${ theme } ' will be ignored.` ,
108
+ ) ;
109
+ }
110
+ computedType = withThemeSuffix (
111
+ removeTypeTheme ( alias ( computedType ) ) ,
112
+ dangerousTheme || theme || defaultTheme ,
113
+ ) ;
114
+ innerNode = (
115
+ < VueIcon
116
+ class = { svgClassString }
117
+ type = { computedType }
118
+ primaryColor = { twoToneColor }
119
+ style = { svgStyle }
120
+ />
121
+ ) ;
122
+ }
123
+ let iconTabIndex = tabIndex ;
124
+ if ( iconTabIndex === undefined && ( 'click' in listeners ) ) {
125
+ iconTabIndex = - 1 ;
126
+ }
127
+ const { attrs, ...restDataProps } = data ;
128
+ // functional component not support nativeOn,https://github.com/vuejs/vue/issues/7526
129
+ const iProps = {
130
+ ...restDataProps ,
131
+ attrs : {
132
+ ...attrs ,
133
+ 'aria-label' : type && `${ locale . icon } : ${ type } ` ,
134
+ tabIndex : iconTabIndex ,
135
+ } ,
136
+ on : { ...listeners , ...data . nativeOn } ,
137
+ class : classString ,
138
+ staticClass : '' ,
139
+ } ;
140
+ return < i { ...iProps } > { innerNode } </ i > ;
141
+ }
142
+
23
143
const Icon = {
24
144
functional : true ,
25
145
name : 'AIcon' ,
26
146
props : {
147
+ tabIndex : PropTypes . number ,
27
148
type : PropTypes . string ,
28
149
component : PropTypes . any ,
29
150
viewBox : PropTypes . any ,
30
151
spin : PropTypes . bool . def ( false ) ,
152
+ rotate : PropTypes . number ,
31
153
theme : PropTypes . oneOf ( [ 'filled' , 'outlined' , 'twoTone' ] ) ,
32
154
twoToneColor : PropTypes . string ,
155
+ role : PropTypes . string ,
33
156
} ,
34
157
render ( h , context ) {
35
- const { props, slots, listeners, data } = context ;
36
- const {
37
- // affect inner <svg>...</svg>
38
- type,
39
- component : Component ,
40
- viewBox,
41
- spin,
42
- // other
43
- theme, // default to outlined
44
- twoToneColor,
45
- } = props ;
46
- const slotsMap = slots ( ) ;
47
- let children = filterEmpty ( slotsMap . default ) ;
48
- children = children . length === 0 ? undefined : children ;
49
- warning (
50
- Boolean ( type || Component || children ) ,
51
- 'Icon should have `type` prop or `component` prop or `children`.' ,
158
+ return (
159
+ < LocaleReceiver
160
+ componentName = "Icon"
161
+ scopedSlots = { { default : ( locale ) => renderIcon ( h , locale , context ) } }
162
+ />
52
163
) ;
53
-
54
- const classString = classNames ( {
55
- ...getClass ( context ) ,
56
- [ `anticon` ] : true ,
57
- [ `anticon-${ type } ` ] : ! ! type ,
58
- } ) ;
59
-
60
- const svgClassString = classNames ( {
61
- [ `anticon-spin` ] : ! ! spin || type === 'loading' ,
62
- } ) ;
63
-
64
- let innerNode ;
65
-
66
- // component > children > type
67
- if ( Component ) {
68
- const innerSvgProps = {
69
- attrs : {
70
- ...svgBaseProps ,
71
- viewBox,
72
- } ,
73
- class : svgClassString ,
74
- } ;
75
- if ( ! viewBox ) {
76
- delete innerSvgProps . attrs . viewBox ;
77
- }
78
-
79
- innerNode = < Component { ...innerSvgProps } > { children } </ Component > ;
80
- }
81
- if ( children ) {
82
- warning (
83
- Boolean ( viewBox ) || ( children . length === 1 && children [ 0 ] . tag === 'use' ) ,
84
- 'Make sure that you provide correct `viewBox`' +
85
- ' prop (default `0 0 1024 1024`) to the icon.' ,
86
- ) ;
87
- const innerSvgProps = {
88
- attrs : {
89
- ...svgBaseProps ,
90
- } ,
91
- class : svgClassString ,
92
- } ;
93
- innerNode = (
94
- < svg { ...innerSvgProps } viewBox = { viewBox } >
95
- { children }
96
- </ svg >
97
- ) ;
98
- }
99
-
100
- if ( typeof type === 'string' ) {
101
- let computedType = type ;
102
- if ( theme ) {
103
- const themeInName = getThemeFromTypeName ( type ) ;
104
- warning (
105
- ! themeInName || theme === themeInName ,
106
- `The icon name '${ type } ' already specify a theme '${ themeInName } ',` +
107
- ` the 'theme' prop '${ theme } ' will be ignored.` ,
108
- ) ;
109
- }
110
- computedType = withThemeSuffix (
111
- removeTypeTheme ( alias ( computedType ) ) ,
112
- dangerousTheme || theme || defaultTheme ,
113
- ) ;
114
- innerNode = (
115
- < VueIcon class = { svgClassString } type = { computedType } primaryColor = { twoToneColor } />
116
- ) ;
117
- }
118
- // functional component not support nativeOn,https://github.com/vuejs/vue/issues/7526
119
- const iProps = {
120
- ...data ,
121
- on : { ...listeners , ...data . nativeOn } ,
122
- class : classString ,
123
- staticClass : '' ,
124
- } ;
125
- return < i { ...iProps } > { innerNode } </ i > ;
126
164
} ,
127
165
} ;
128
166
0 commit comments