Skip to content

Commit 7e4e7bd

Browse files
authored
Merge pull request #97 from gravity-ui/feat/navigation-logo-dark-light-theme
feat(navigation): add themed logo support in navigation
2 parents 420d0c3 + 6e6485d commit 7e4e7bd

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

src/containers/PageConstructor/__stories__/PageConstructor.stories.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default {
1313

1414
interface TemplateProps {
1515
items: HeaderBlockModel[];
16+
navigation?: NavigationData;
1617
}
1718

1819
const DefaultTemplate: Story<TemplateProps> = (args) => (
@@ -39,7 +40,7 @@ const NavigationTemplate: Story<TemplateProps> = (args) => (
3940
content={{
4041
blocks: args.items,
4142
}}
42-
navigation={data.navigation as NavigationData}
43+
navigation={args.navigation}
4344
/>
4445
);
4546

@@ -49,8 +50,12 @@ export const Navigation = NavigationTemplate.bind({});
4950

5051
interface PageConstructorStoryProps {
5152
items: HeaderBlockModel[];
53+
navigation?: NavigationData;
5254
}
5355

5456
Default.args = data.default.content as PageConstructorStoryProps;
5557
WithFootnotes.args = data.default.content as PageConstructorStoryProps;
56-
Navigation.args = data.default.content as PageConstructorStoryProps;
58+
Navigation.args = {
59+
items: data.default.content.items,
60+
navigation: data.navigation,
61+
} as PageConstructorStoryProps;

src/containers/PageConstructor/__stories__/data.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@
128128
"navigation": {
129129
"logo": {
130130
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg",
131-
"text": "Logo"
131+
"text": "Logo",
132+
"dark": {
133+
"text": "Logo Dark",
134+
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_dark.svg"
135+
},
136+
"light": {
137+
"text": "Logo Light"
138+
}
132139
},
133140
"header": {
134141
"leftItems": [
@@ -138,19 +145,23 @@
138145
"items": [
139146
{
140147
"text": "Lorem ipsum ",
141-
"url": "https://example.com"
148+
"url": "https://example.com",
149+
"type": "link"
142150
},
143151
{
144152
"text": "Dolor sit amet",
145-
"url": "https://example.com"
153+
"url": "https://example.com",
154+
"type": "link"
146155
},
147156
{
148157
"text": "Consectetur adipiscing",
149-
"url": "https://example.com"
158+
"url": "https://example.com",
159+
"type": "link"
150160
},
151161
{
152162
"text": "Ut enim ad minim ",
153-
"url": "https://example.com"
163+
"url": "https://example.com",
164+
"type": "link"
154165
}
155166
]
156167
},

src/models/navigation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {ThemeSupporting} from '../utils';
12
import {ImageProps, ButtonProps} from './constructor-items';
23

34
export enum NavigationItemType {
@@ -56,6 +57,8 @@ export interface NavigationLogoData {
5657
url?: string;
5758
}
5859

60+
export type ThemedNavigationLogoData = NavigationLogoData & ThemeSupporting<NavigationLogoData>;
61+
5962
export interface HeaderData {
6063
leftItems: NavigationItemModel[];
6164
rightItems?: NavigationItemModel[];
@@ -78,7 +81,7 @@ export interface FooterData {
7881
}
7982

8083
export interface NavigationData {
81-
logo: NavigationLogoData;
84+
logo: ThemedNavigationLogoData;
8285
header: HeaderData;
8386
footer?: FooterData;
8487
}

src/navigation/components/Header/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {MouseEvent, useCallback, useState} from 'react';
22

33
import {block} from '../../../utils';
4-
import {HeaderData, NavigationLogoData} from '../../../models';
4+
import {HeaderData, ThemedNavigationLogoData} from '../../../models';
55
import {Col, Grid, Row} from '../../../grid';
66
import OutsideClick from '../../../components/OutsideClick/OutsideClick';
77
import Control from '../../../components/Control/Control';
@@ -19,7 +19,7 @@ const b = block('header');
1919
const ICON_SIZE = 36;
2020

2121
export interface HeaderProps {
22-
logo: NavigationLogoData;
22+
logo: ThemedNavigationLogoData;
2323
data: HeaderData;
2424
}
2525

src/navigation/components/Logo/Logo.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
import React from 'react';
1+
import React, {useContext} from 'react';
22

3-
import {block} from '../../../utils';
4-
import {NavigationLogoData} from '../../../models';
3+
import {block, getThemedValue} from '../../../utils';
4+
import {ThemedNavigationLogoData} from '../../../models';
55
import RouterLink from '../../../components/RouterLink/RouterLink';
66
import {getMediaImage} from '../../../components/Media/Image/utils';
7+
import {ThemeValueContext} from '../../../context/theme/ThemeValueContext';
78
import {Image} from '../../../components';
89

910
import './Logo.scss';
1011

1112
const b = block('logo');
1213

13-
export interface LogoProps extends NavigationLogoData {
14+
export type LogoProps = ThemedNavigationLogoData & {
1415
className?: string;
15-
}
16+
};
1617

17-
const Logo: React.FC<LogoProps> = ({icon, text, className}) => {
18-
const imageData = getMediaImage(icon);
18+
const Logo: React.FC<LogoProps> = (props) => {
19+
const {themeValue: theme} = useContext(ThemeValueContext);
20+
const themedLogoProps = getThemedValue(props, theme) || props;
21+
const imageData = getMediaImage(themedLogoProps.icon || props.icon);
22+
const textData = themedLogoProps.text || props.text;
1923

2024
return (
21-
<RouterLink href="/" passHref>
22-
<div className={b(null, className)}>
25+
<RouterLink href={themedLogoProps.url || props.url || '/'} passHref>
26+
<div className={b(null, props.className)}>
2327
{imageData && <Image className={b('icon')} {...imageData} />}
24-
<span className={b('text')}>{text}</span>
28+
<span className={b('text')}>{textData}</span>
2529
</div>
2630
</RouterLink>
2731
);

0 commit comments

Comments
 (0)