Skip to content

Commit d133ebf

Browse files
author
berdysheva
committed
fix: icon props
1 parent b39ea57 commit d133ebf

File tree

6 files changed

+56
-37
lines changed

6 files changed

+56
-37
lines changed

src/components/navigation/components/Logo/Logo.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
display: flex;
66
align-items: center;
77

8-
font-weight: 500;
9-
@include text-size(header-2);
8+
font-weight: var(--yc-text-accent-font-weight);
9+
10+
@include heading4();
1011

1112
&__icon {
12-
width: 178px;
13+
display: flex;
1314
height: 36px;
1415
margin-right: $indentXXXS;
1516

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import block from 'bem-cn-lite';
33

4-
import {NavigationLogo} from '../../../../models/navigation';
5-
import {Image} from '../../../index';
4+
import {NavigationLogo} from '../../../../models';
65
import RouterLink from '../../../RouterLink/RouterLink';
6+
import {getMediaImage} from '../../../Media/Image/utils';
7+
import {Image} from '../../../index';
78

89
import './Logo.scss';
910

@@ -13,13 +14,17 @@ export interface LogoProps extends NavigationLogo {
1314
className?: string;
1415
}
1516

16-
const Logo: React.FC<LogoProps> = ({icon, text, className}) => (
17-
<RouterLink href="/" passHref>
18-
<div className={b(null, className)}>
19-
{icon && <Image className={b('icon')} src={icon} />}
20-
<span className={b('text')}>{text}</span>
21-
</div>
22-
</RouterLink>
23-
);
17+
const Logo: React.FC<LogoProps> = ({icon, text, className}) => {
18+
const imageData = getMediaImage(icon);
19+
20+
return (
21+
<RouterLink href="/" passHref>
22+
<div className={b(null, className)}>
23+
{imageData && <Image {...imageData} />}
24+
<span className={b('text')}>{text}</span>
25+
</div>
26+
</RouterLink>
27+
);
28+
};
2429

2530
export default Logo;

src/components/navigation/components/NavigationItem/NavigationItem.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import {
1313
} from '../../../../models/navigation';
1414
import {NavigationArrow} from '../../../../icons';
1515
import SocialIcon from '../SocialIcon/SocialIcon';
16+
import {getMediaImage} from '../../../Media/Image/utils';
1617

1718
import './NavigationItem.scss';
19+
import {ImageProps} from '../../../../models';
1820

1921
const b = block('navigation-item');
2022

@@ -33,9 +35,9 @@ export interface NavigationItemProps {
3335
isOpened?: boolean;
3436
}
3537

36-
const Content: React.FC<{text: string; icon?: string}> = ({text, icon}) => (
38+
const Content: React.FC<{text: string; icon?: ImageProps}> = ({text, icon}) => (
3739
<Fragment>
38-
{icon && <img className={b('icon')} src={icon} />}
40+
{icon && <img className={b('icon')} {...icon} />}
3941
<span className={b('text')}>{text}</span>
4042
</Fragment>
4143
);
@@ -47,29 +49,34 @@ const NavigationDropdown: React.FC<NavigationDropdownProps> = ({
4749
icon,
4850
isOpened,
4951
...props
50-
}) => (
51-
<span {...props}>
52-
<Content text={text} icon={icon} />
53-
<ToggleArrow
54-
className={b('dropdown')}
55-
size={12}
56-
type={'vertical'}
57-
iconType="navigation"
58-
open={isOpened}
59-
/>
60-
</span>
61-
);
52+
}) => {
53+
const iconData = icon && getMediaImage(icon);
54+
55+
return (
56+
<span {...props}>
57+
<Content text={text} icon={iconData} />
58+
<ToggleArrow
59+
className={b('dropdown')}
60+
size={12}
61+
type={'vertical'}
62+
iconType="navigation"
63+
open={isOpened}
64+
/>
65+
</span>
66+
);
67+
};
6268

6369
type NavigationLinkProps = NavigationItemProps & NavigationLinkItem;
6470

6571
const NavigationLink: React.FC<NavigationLinkProps> = (props) => {
6672
const {hostname} = useContext(LocationContext);
6773
const {url, text, icon, arrow, target, ...rest} = props;
6874
const linkExtraProps = getLinkProps(url, hostname, target);
75+
const iconData = icon && getMediaImage(icon);
6976

7077
const content = (
7178
<Fragment>
72-
<Content text={text} icon={icon} />
79+
<Content text={text} icon={iconData} />
7380
{arrow && <NavigationArrow className={b('arrow')} />}
7481
</Fragment>
7582
);

src/components/navigation/components/SocialIcon/SocialIcon.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import block from 'bem-cn-lite';
33

44
import {NavigationSocialItem} from '../../../../models/navigation';
55
import {Image} from '../../../index';
6+
import {getMediaImage} from '../../../Media/Image/utils';
67

78
import './SocialIcon.scss';
89

@@ -12,10 +13,14 @@ export interface NavigationSocialItemProps extends NavigationSocialItem {
1213
className?: string;
1314
}
1415

15-
const SocialIcon: React.FC<NavigationSocialItemProps> = ({icon, url, className}) => (
16-
<a href={url} target="_blank" rel="noopener noreferrer" className={b(null, className)}>
17-
<Image className={b('icon')} src={icon} />
18-
</a>
19-
);
16+
const SocialIcon: React.FC<NavigationSocialItemProps> = ({icon, url, className}) => {
17+
const iconData = getMediaImage(icon);
18+
19+
return (
20+
<a href={url} target="_blank" rel="noopener noreferrer" className={b(null, className)}>
21+
<Image className={b('icon')} {...iconData} />
22+
</a>
23+
);
24+
};
2025

2126
export default SocialIcon;

src/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './common';
44
export * from './components';
55
export * from './guards';
66
export * from './react';
7+
export * from './navigation';

src/models/navigation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ButtonProps} from '../components/Button/Button';
1+
import {ImageProps, ButtonProps} from './constructor-items';
22

33
export enum NavigationItemType {
44
Link = 'link',
@@ -9,7 +9,7 @@ export enum NavigationItemType {
99

1010
export interface NavigationItemBase {
1111
text: string;
12-
icon?: string;
12+
icon?: ImageProps;
1313
url?: string;
1414
}
1515

@@ -33,14 +33,14 @@ export interface NavigationDropdownItem extends NavigationItemBase {
3333

3434
export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
3535
type: NavigationItemType.Social;
36-
icon: string;
36+
icon: ImageProps;
3737
url: string;
3838
}
3939

4040
export type NavigationItem = NavigationLinkItem | NavigationButtonItem | NavigationDropdownItem;
4141

4242
export interface NavigationLogo extends Omit<NavigationItemBase, 'text'> {
43-
icon: string;
43+
icon: ImageProps;
4444
text?: string;
4545
}
4646

0 commit comments

Comments
 (0)