@@ -61,7 +61,7 @@ module.exports = new Transformer({
6161 plugins : [ '@svgr/plugin-svgo' , '@svgr/plugin-jsx' ]
6262 } )
6363 ) . replace ( 'export default ForwardRef;' , '' ) ;
64- let newFile = template ( asset , iconName , optimized ) ;
64+ let newFile = template ( asset , optimized ) ;
6565 return [ {
6666 type : 'tsx' ,
6767 content : newFile ,
@@ -72,65 +72,16 @@ module.exports = new Transformer({
7272 }
7373} ) ;
7474
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 ) {
8376 let normalizedPath = asset . filePath . replaceAll ( '\\' , '/' ) ;
8477 let context = asset . pipeline === 'illustration' || normalizedPath . includes ( '@react-spectrum/s2/spectrum-illustrations' ) ? 'IllustrationContext' : 'IconContext' ;
8578 return (
8679`
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' } ';
9181
9282${ svg . replace ( 'import { SVGProps } from "react";' , '' ) }
9383
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 } );
13485`
13586 ) ;
13687}
0 commit comments