@@ -61,7 +61,7 @@ module.exports = new Transformer({
61
61
plugins : [ '@svgr/plugin-svgo' , '@svgr/plugin-jsx' ]
62
62
} )
63
63
) . replace ( 'export default ForwardRef;' , '' ) ;
64
- let newFile = template ( asset , iconName , optimized ) ;
64
+ let newFile = template ( asset , optimized ) ;
65
65
return [ {
66
66
type : 'tsx' ,
67
67
content : newFile ,
@@ -72,65 +72,16 @@ module.exports = new Transformer({
72
72
}
73
73
} ) ;
74
74
75
- function template ( asset , iconName , svg ) {
76
- let importName = iconName
77
- . replace ( / ^ S 2 _ I c o n _ ( .* ?) _ \d + (?: x \d + ) ? _ N $ / , '$1' )
78
- . replace ( / ^ S 2 _ ( f i l l | l i n ) _ ( .+ ) _ ( .+ _ ) ? ( \d + ) $ / , ( m , name ) => name [ 0 ] . toUpperCase ( ) + name . slice ( 1 ) ) ;
79
- let iconRename = importName ;
80
- if ( / ^ [ 0 - 9 ] / . test ( importName ) ) {
81
- iconRename = '_' + importName ;
82
- }
75
+ function template ( asset , svg ) {
83
76
let normalizedPath = asset . filePath . replaceAll ( '\\' , '/' ) ;
84
77
let context = asset . pipeline === 'illustration' || normalizedPath . includes ( '@react-spectrum/s2/spectrum-illustrations' ) ? 'IllustrationContext' : 'IconContext' ;
85
78
return (
86
79
`
87
- import {IconProps, ${ context } , IconContextValue} from '${ normalizedPath . includes ( '@react-spectrum/s2' ) ? '~/src/Icon' : '@react-spectrum/s2' } ';
88
- import {SVGProps, useRef} from 'react';
89
- import {useContextProps} from 'react-aria-components';
90
- import {SkeletonWrapper, useSkeletonIcon} from '~/src/Skeleton';
80
+ import {createIcon, ${ context } } from '${ normalizedPath . includes ( '@react-spectrum/s2' ) ? '~/src/Icon' : '@react-spectrum/s2' } ';
91
81
92
82
${ svg . replace ( 'import { SVGProps } from "react";' , '' ) }
93
83
94
- export default function ${ iconRename } (props: IconProps) {
95
- let ref = useRef<SVGElement>(null);
96
- let ctx;
97
- // TODO: remove this default once we release RAC and use DEFAULT_SLOT.
98
- [ctx, ref] = useContextProps({slot: props.slot || 'icon'} as IconContextValue, ref, ${ context } );
99
- let {render, styles} = ctx;
100
- let {
101
- UNSAFE_className,
102
- UNSAFE_style,
103
- slot,
104
- 'aria-label': ariaLabel,
105
- 'aria-hidden': ariaHidden,
106
- ...otherProps
107
- } = props;
108
-
109
- if (!ariaHidden) {
110
- ariaHidden = undefined;
111
- }
112
-
113
- let svg = (
114
- <SkeletonWrapper>
115
- <ForwardRef
116
- {...otherProps}
117
- focusable={false}
118
- aria-label={ariaLabel}
119
- aria-hidden={ariaLabel ? (ariaHidden || undefined) : true}
120
- role="img"
121
- data-slot={slot}
122
- className={(UNSAFE_className ?? '') + ' ' + useSkeletonIcon(styles)}
123
- style={UNSAFE_style} />
124
- </SkeletonWrapper>
125
- );
126
-
127
- if (render) {
128
- return render(svg);
129
- }
130
-
131
- return svg;
132
- }
133
-
84
+ export default /*#__PURE__*/ createIcon(ForwardRef, ${ context } );
134
85
`
135
86
) ;
136
87
}
0 commit comments