File tree Expand file tree Collapse file tree 2 files changed +26
-14
lines changed
Expand file tree Collapse file tree 2 files changed +26
-14
lines changed Original file line number Diff line number Diff line change 1- import React , { useContext } from 'react' ;
1+ import React , { Fragment , useContext } from 'react' ;
22
33import { Image , Title } from '../../components' ;
44import { LocationContext } from '../../context/locationContext' ;
@@ -9,23 +9,36 @@ import './Icons.scss';
99
1010const b = block ( 'icons-block' ) ;
1111
12+ const getItemContent = ( item : IconsBlockProps [ 'items' ] [ number ] ) => (
13+ < Fragment >
14+ < Image className = { b ( 'image' ) } src = { item . src } />
15+ < p className = { b ( 'text' ) } > { item . text } </ p >
16+ </ Fragment >
17+ ) ;
18+
1219const Icons = ( { title, size = 's' , items} : IconsBlockProps ) => {
1320 const { hostname} = useContext ( LocationContext ) ;
1421
1522 return (
1623 < div className = { b ( { size} ) } >
1724 { title && < Title className = { b ( 'header' ) } title = { title } colSizes = { { all : 12 } } /> }
18- { items . map ( ( item ) => (
19- < a
20- className = { b ( 'item' ) }
21- key = { item . url }
22- href = { item . url }
23- { ...getLinkProps ( item . url , hostname ) }
24- >
25- < Image className = { b ( 'image' ) } src = { item . src } />
26- < p className = { b ( 'text' ) } > { item . text } </ p >
27- </ a >
28- ) ) }
25+ { items . map ( ( item ) => {
26+ const itemContent = getItemContent ( item ) ;
27+ return item . url ? (
28+ < a
29+ className = { b ( 'item' ) }
30+ key = { item . url }
31+ href = { item . url }
32+ { ...getLinkProps ( item . url , hostname ) }
33+ >
34+ { itemContent }
35+ </ a >
36+ ) : (
37+ < div className = { b ( 'item' ) } key = { item . url } >
38+ { itemContent }
39+ </ div >
40+ ) ;
41+ } ) }
2942 </ div >
3043 ) ;
3144} ;
Original file line number Diff line number Diff line change 55 "items" : [
66 {
77 "src" : " https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icons-link_1_64.svg" ,
8- "text" : " Lorem ipsum dolor sit amet" ,
9- "url" : " #"
8+ "text" : " Lorem ipsum dolor sit amet"
109 },
1110 {
1211 "src" : " https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icons-link_2_64.svg" ,
You can’t perform that action at this time.
0 commit comments