Skip to content

Commit f59ae1a

Browse files
authored
fix: fix logo router link rendering (#669)
1 parent 1a8bf2c commit f59ae1a

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

src/models/navigation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface NavigationLogoData {
8282
icon: ImageProps;
8383
text?: string;
8484
url?: string;
85+
urlTitle?: string;
8586
}
8687

8788
export type ThemedNavigationLogoData = NavigationLogoData & ThemeSupporting<NavigationLogoData>;

src/navigation/__stories__/data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"logo": {
44
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg",
55
"text": "Logo",
6+
"urlTitle": "Title",
67
"dark": {
78
"text": "Logo Dark",
89
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_dark.svg"

src/navigation/components/Logo/Logo.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ $block: '.#{$ns}logo';
66
#{$block} {
77
display: flex;
88
align-items: center;
9+
text-decoration: none;
910

1011
&__icon {
1112
display: flex;

src/navigation/components/Logo/Logo.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import React from 'react';
1+
import React, {Fragment, useContext} from 'react';
22

33
import {Image} from '../../../components';
44
import {getMediaImage} from '../../../components/Media/Image/utils';
55
import RouterLink from '../../../components/RouterLink/RouterLink';
6+
import {LocationContext} from '../../../context/locationContext';
67
import {useTheme} from '../../../context/theme';
78
import {ThemedNavigationLogoData} from '../../../models';
8-
import {block, getThemedValue} from '../../../utils';
9+
import {block, getLinkProps, getThemedValue} from '../../../utils';
910

1011
import './Logo.scss';
1112

@@ -16,17 +17,35 @@ export type LogoProps = ThemedNavigationLogoData & {
1617
};
1718

1819
const Logo: React.FC<LogoProps> = (props) => {
20+
const {hostname, Link} = useContext(LocationContext);
1921
const theme = useTheme();
2022
const themedLogoProps = getThemedValue(props, theme) || props;
2123
const imageData = getMediaImage(themedLogoProps.icon || props.icon);
2224
const textData = themedLogoProps.text || props.text;
25+
const url = themedLogoProps.url || props.url || '/';
26+
const urlTitle = themedLogoProps.urlTitle || props.urlTitle || textData;
27+
const linkExtraProps = getLinkProps(url, hostname);
28+
const content = (
29+
<Fragment>
30+
{imageData && <Image className={b('icon')} {...imageData} />}
31+
<span className={b('text')}>{textData}</span>
32+
</Fragment>
33+
);
2334

2435
return (
25-
<RouterLink href={themedLogoProps.url || props.url || '/'} passHref>
26-
<div className={b(null, props.className)}>
27-
{imageData && <Image className={b('icon')} {...imageData} />}
28-
<span className={b('text')}>{textData}</span>
29-
</div>
36+
<RouterLink href={url} passHref>
37+
{Link ? (
38+
<span className={b(null, props.className)}>{content}</span>
39+
) : (
40+
<a
41+
className={b(null, props.className)}
42+
href={url}
43+
title={urlTitle}
44+
{...linkExtraProps}
45+
>
46+
{content}
47+
</a>
48+
)}
3049
</RouterLink>
3150
);
3251
};

0 commit comments

Comments
 (0)