@@ -21,7 +21,7 @@ import {
21
21
} from 'react' ;
22
22
import { Unstyled } from '@storybook/addon-docs/blocks' ;
23
23
import * as iconComponents from '@sumup-oss/icons' ;
24
- import type { IconComponentType } from '@sumup-oss/icons' ;
24
+ import { getIconURL , type IconComponentType } from '@sumup-oss/icons' ;
25
25
import type { IconsManifest } from '@sumup-oss/icons' ;
26
26
import iconsManifest from '@sumup-oss/icons/manifest.json' ;
27
27
import { Badge } from '../../packages/circuit-ui/components/Badge/Badge.js' ;
@@ -38,7 +38,7 @@ import { clsx } from '../../packages/circuit-ui/styles/clsx.js';
38
38
import { utilClasses } from '../../packages/circuit-ui/styles/utility.js' ;
39
39
import { slugify } from '../slugify.js' ;
40
40
import classes from './Icons.module.css' ;
41
-
41
+ import ReactIcon from '../public/images/react.svg' ;
42
42
function groupBy (
43
43
icons : IconsManifest [ 'icons' ] ,
44
44
key : 'name' | 'category' | 'size' ,
@@ -218,21 +218,50 @@ function Icon({
218
218
} ) ;
219
219
} ;
220
220
221
+ const copyIconReactName = ( ) => {
222
+ const reactName = getComponentName ( icon . name ) ;
223
+ navigator . clipboard
224
+ . writeText ( reactName )
225
+ . then ( ( ) => {
226
+ setToast ( {
227
+ variant : 'success' ,
228
+ body : `Copied the ${ icon . name } icon's React name to the clipboard.` ,
229
+ } ) ;
230
+ } )
231
+ . catch ( ( error ) => {
232
+ console . error ( error ) ;
233
+ setToast ( {
234
+ variant : 'danger' ,
235
+ body : `Failed to copy the ${ icon . name } icon's React name to the clipboard.` ,
236
+ } ) ;
237
+ } ) ;
238
+ } ;
239
+
221
240
return (
222
241
< div className = { classes . wrapper } >
223
242
< div className = { clsx ( classes [ 'icon-wrapper' ] , classes [ scale ] ) } >
224
- < Icon
225
- aria-labelledby = { id }
226
- size = { icon . size }
227
- className = { classes . icon }
228
- style = { {
229
- color,
230
- backgroundColor :
231
- color === 'var(--cui-fg-on-strong)'
232
- ? 'var(--cui-bg-strong)'
233
- : 'var(--cui-bg-normal)' ,
234
- } }
235
- />
243
+ { icon . skipComponentFile ? (
244
+ < img
245
+ src = { getIconURL ( icon . name ) }
246
+ aria-labelledby = { id }
247
+ alt = { icon . name }
248
+ height = { 14 }
249
+ width = { 18 }
250
+ />
251
+ ) : (
252
+ < Icon
253
+ aria-labelledby = { id }
254
+ size = { icon . size }
255
+ className = { classes . icon }
256
+ style = { {
257
+ color,
258
+ backgroundColor :
259
+ color === 'var(--cui-fg-on-strong)'
260
+ ? 'var(--cui-bg-strong)'
261
+ : 'var(--cui-bg-normal)' ,
262
+ } }
263
+ />
264
+ ) }
236
265
</ div >
237
266
< span id = { id } className = { classes . label } >
238
267
{ icon . name }
@@ -254,17 +283,28 @@ function Icon({
254
283
) }
255
284
/>
256
285
) }
257
- { navigator . clipboard && (
258
- < IconButton
259
- variant = "tertiary"
260
- size = "s"
261
- icon = { iconComponents . Link }
262
- className = { classes . copy }
263
- onClick = { copyIconURL }
264
- >
265
- Copy URL
266
- </ IconButton >
267
- ) }
286
+ < div className = { classes . actions } >
287
+ { navigator . clipboard && (
288
+ < IconButton
289
+ variant = "tertiary"
290
+ size = "s"
291
+ icon = { iconComponents . Link }
292
+ onClick = { copyIconURL }
293
+ >
294
+ Copy URL
295
+ </ IconButton >
296
+ ) }
297
+ { ! icon . skipComponentFile && (
298
+ < IconButton
299
+ variant = "tertiary"
300
+ size = "s"
301
+ icon = { ( ) => < img src = { ReactIcon } alt = "React Logo" /> }
302
+ onClick = { copyIconReactName }
303
+ >
304
+ Copy React component name
305
+ </ IconButton >
306
+ ) }
307
+ </ div >
268
308
</ div >
269
309
) ;
270
310
}
0 commit comments