@@ -180,41 +180,43 @@ export type IconProps = {
180180 *
181181 */
182182type SvgIconProps = IconProps & {
183- iconColor : string | null ;
183+ iconColor ? : string | null ;
184184} ;
185185
186186/**
187187 *
188188 */
189- const SvgIcon = forwardRef (
189+ export const SvgIcon = forwardRef (
190190 ( props : SvgIconProps , ref : ForwardedRef < SVGSVGElement | null > ) => {
191191 const {
192192 className = '' ,
193193 category : category_ = 'utility' ,
194194 icon : icon_ ,
195- iconColor,
195+ iconColor = null ,
196196 size = '' ,
197197 align,
198198 textColor = 'default' ,
199199 style,
200200 ...rprops
201201 } = props ;
202202 const { assetRoot = getAssetRoot ( ) } = useContext ( ComponentSettingsContext ) ;
203- const iconClassNames = classnames (
204- 'react-slds-icon' ,
205- {
206- 'slds-icon' : ! / s l d s - b u t t o n _ _ i c o n / . test ( className ) ,
207- [ `slds-icon_${ size } ` ] : / ^ ( x x - s m a l l | x - s m a l l | s m a l l | m e d i u m | l a r g e ) $ / . test (
208- size
209- ) ,
210- [ `slds-icon-text-${ textColor ?? 'default' } ` ] :
211- / ^ ( d e f a u l t | s u c c e s s | w a r n i n g | e r r o r | l i g h t ) $ / . test ( textColor ?? '' ) &&
212- ! iconColor ,
213- 'slds-m-left_x-small' : align === 'right' ,
214- 'slds-m-right_x-small' : align === 'left' ,
215- } ,
216- className
217- ) ;
203+
204+ const inIcon = ! / s l d s - b u t t o n _ _ i c o n / . test ( className ) ;
205+ const iconOnlyClassNames = classnames ( 'react-slds-icon' , 'slds-icon' , {
206+ [ `slds-icon_${ size } ` ] : / ^ ( x x - s m a l l | x - s m a l l | s m a l l | m e d i u m | l a r g e ) $ / . test (
207+ size
208+ ) ,
209+ [ `slds-icon-text-${ textColor ?? 'default' } ` ] :
210+ / ^ ( d e f a u l t | s u c c e s s | w a r n i n g | e r r o r | l i g h t ) $ / . test ( textColor ?? '' ) &&
211+ ! iconColor ,
212+ 'slds-m-left_x-small' : align === 'right' ,
213+ 'slds-m-right_x-small' : align === 'left' ,
214+ } ) ;
215+
216+ const iconClassNames = classnames ( className , {
217+ [ iconOnlyClassNames ] : inIcon ,
218+ } ) ;
219+
218220 // icon and category prop should not include chars other than alphanumerics, underscore, and hyphen
219221 const icon = ( icon_ ?? '' ) . replace ( / [ ^ \w - ] / g, '' ) ;
220222 const category = ( category_ ?? '' ) . replace ( / [ ^ \w - ] / g, '' ) ;
@@ -233,32 +235,6 @@ const SvgIcon = forwardRef(
233235 }
234236) ;
235237
236- export const SvgButtonIcon = (
237- props : {
238- className ?: string ;
239- category ?: IconCategory ;
240- icon : string ;
241- } & SVGAttributes < SVGElement >
242- ) => {
243- const {
244- className = '' ,
245- category : category_ = 'utility' ,
246- icon : icon_ ,
247- style,
248- ...rprops
249- } = props ;
250- const { assetRoot = getAssetRoot ( ) } = useContext ( ComponentSettingsContext ) ;
251-
252- // icon and category prop should not include chars other than alphanumerics, underscore, and hyphen
253- const icon = ( icon_ ?? '' ) . replace ( / [ ^ \w - ] / g, '' ) ;
254- const category = ( category_ ?? '' ) . replace ( / [ ^ \w - ] / g, '' ) ;
255- const iconUrl = `${ assetRoot } /icons/${ category } -sprite/svg/symbols.svg#${ icon } ` ;
256- return (
257- < svg className = { className } aria-hidden style = { style } { ...rprops } >
258- < use xlinkHref = { iconUrl } />
259- </ svg >
260- ) ;
261- } ;
262238/**
263239 *
264240 */
0 commit comments