Skip to content

Commit 7757ec1

Browse files
Juli Ovechkinaaeksandla
andauthored
feat: update header and navigation (#369)
* feat(Header): update indents (#368) * feat(navigation): add prop withBorder by default (#363) --------- Co-authored-by: Aleksandra Pleshcheva <[email protected]>
1 parent d14fbf3 commit 7757ec1

File tree

8 files changed

+187
-17
lines changed

8 files changed

+187
-17
lines changed

src/blocks/Header/Header.scss

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ $backgroundWidth: 1440px;
66

77
#{$block} {
88
position: relative;
9-
margin: $indentXS 0;
109

1110
&_full-width {
1211
--pc-border-radius: 0;
@@ -36,19 +35,19 @@ $backgroundWidth: 1440px;
3635
margin: $indentXS 0;
3736

3837
&_s {
39-
padding: $indentL 0;
38+
padding: $indentXL 0;
4039
}
4140

4241
&_m {
43-
padding: calc(#{$indentXXL} - #{$indentXS}) 0;
42+
padding: $indentXXL 0;
4443
}
4544

4645
&_l {
47-
padding: calc(#{$indentXXXL} - #{$indentXS}) 0;
46+
padding: $indentXXXL 0;
4847
}
4948

5049
&_xl {
51-
padding: calc(#{$indent4XL} - #{$indentXS}) 0;
50+
padding: $indent4XL 0;
5251
}
5352
}
5453

@@ -100,10 +99,10 @@ $backgroundWidth: 1440px;
10099
&__media {
101100
position: absolute;
102101
display: none;
103-
top: 0;
102+
top: $indentXS;
104103
right: 0;
105104
width: 50%;
106-
height: 100%;
105+
height: calc(100% - 2 * #{$indentXS});
107106
overflow: hidden;
108107
object-fit: cover;
109108

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@ export default {
1414

1515
const DefaultTemplate: Story<PageConstructorProps> = (args) => <PageConstructor {...args} />;
1616

17-
const NavigationTemplate: Story<PageConstructorProps> = (args) => <PageConstructor {...args} />;
18-
1917
const WithFullWidthBackgroundMediaTemplate: Story<PageConstructorProps> = (args) => (
2018
<PageConstructor {...args} />
2119
);
2220

2321
export const Default = DefaultTemplate.bind({});
24-
export const Navigation = NavigationTemplate.bind({});
22+
export const withNavigation = DefaultTemplate.bind({});
2523
export const WithFullWidthBackgroundMedia = WithFullWidthBackgroundMediaTemplate.bind({});
2624

2725
Default.args = data.default as PageConstructorProps;
28-
Navigation.args = {
26+
withNavigation.args = {
2927
content: {
3028
blocks: data.default.content.blocks,
3129
},

src/demo/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const BLOCKS = 'Blocks';
22
export const COMPONENTS = 'Components';
33
export const CONTAINERS = 'Containers';
4+
export const NAVIGATION = 'Navigation';
45
export const EDITOR = 'Editor(Beta)';
56
export const BUTTONS_LINKS = 'Links and buttons';
67
export const CARDS = 'Cards';

src/models/navigation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export interface HeaderData {
8585
leftItems: NavigationItemModel[];
8686
rightItems?: NavigationItemModel[];
8787
iconSize?: number;
88+
withBorder?: boolean;
8889
}
8990

9091
export interface FooterColumn {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
3+
import {Meta, Story} from '@storybook/react/types-6-0';
4+
5+
import {PageConstructor} from '../../containers/PageConstructor';
6+
import {NAVIGATION} from '../../demo/constants';
7+
import {NavigationData} from '../../models';
8+
9+
import data from './data.json';
10+
11+
export default {
12+
title: `${NAVIGATION}/Navigation`,
13+
component: PageConstructor,
14+
} as Meta;
15+
16+
const DefaultTemplate: Story<NavigationData> = (args) => <PageConstructor navigation={args} />;
17+
export const DefaultNavigation = DefaultTemplate.bind({});
18+
export const NavigationWithBorder = DefaultTemplate.bind({});
19+
20+
DefaultNavigation.args = data.navigation as NavigationData;
21+
22+
NavigationWithBorder.args = {
23+
...data.navigation,
24+
header: {
25+
...data.navigation.header,
26+
withBorder: true,
27+
},
28+
} as NavigationData;
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"navigation": {
3+
"logo": {
4+
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg",
5+
"text": "Logo",
6+
"dark": {
7+
"text": "Logo Dark",
8+
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_dark.svg"
9+
},
10+
"light": {
11+
"text": "Logo Light"
12+
}
13+
},
14+
"header": {
15+
"leftItems": [
16+
{
17+
"text": "Dropdown 1",
18+
"type": "dropdown",
19+
"items": [
20+
{
21+
"text": "Lorem ipsum",
22+
"url": "https://example.com",
23+
"type": "link"
24+
},
25+
{
26+
"text": "Dolor sit amet",
27+
"url": "https://example.com",
28+
"type": "link"
29+
},
30+
{
31+
"text": "Consectetur adipiscing",
32+
"url": "https://example.com",
33+
"type": "link"
34+
},
35+
{
36+
"text": "Ut enim ad minim ",
37+
"url": "https://example.com",
38+
"type": "link"
39+
}
40+
]
41+
},
42+
{
43+
"text": "Dropdown2",
44+
"type": "dropdown",
45+
"items": [
46+
{
47+
"text": "Lorem ipsum ",
48+
"url": "https://example.com"
49+
},
50+
{
51+
"text": "Dolor sit amet",
52+
"url": "https://example.com"
53+
},
54+
{
55+
"text": "Consectetur adipiscing",
56+
"url": "https://example.com"
57+
},
58+
{
59+
"text": "Ut enim ad minim ",
60+
"url": "https://example.com"
61+
}
62+
]
63+
},
64+
{
65+
"type": "link",
66+
"text": "Link with spaces",
67+
"url": "https://example.com",
68+
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_3_light.svg"
69+
},
70+
{
71+
"type": "link",
72+
"text": "Link with arrow",
73+
"url": "https://example.com",
74+
"arrow": true
75+
},
76+
{
77+
"type": "link",
78+
"text": "Link3",
79+
"url": "https://example.com"
80+
},
81+
{
82+
"type": "link",
83+
"text": "Link4",
84+
"url": "https://example.com"
85+
}
86+
],
87+
"rightItems": [
88+
{
89+
"type": "dropdown",
90+
"text": "Language",
91+
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_3_light.svg",
92+
"items": [
93+
{
94+
"text": "Russian",
95+
"url": "/ru",
96+
"type": "link"
97+
},
98+
{
99+
"text": "English",
100+
"url": "/",
101+
"type": "link"
102+
}
103+
]
104+
},
105+
{
106+
"type": "github-button",
107+
"text": "Star",
108+
"label": "Star @gravity-ui/page-constructor on GitHub",
109+
"url": "https://github.com/gravity-ui/page-constructor"
110+
},
111+
{
112+
"type": "link",
113+
"text": "Link",
114+
"url": "https://example.com",
115+
"icon": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_2_light.svg"
116+
},
117+
{
118+
"type": "button",
119+
"text": "Button",
120+
"url": "https://example.com",
121+
"theme": "pseudo"
122+
}
123+
]
124+
}
125+
}
126+
}

src/navigation/components/Header/Header.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ $block: '.#{$ns}header';
1717
height: var(--header-height);
1818

1919
background-color: var(--yc-color-base-background);
20-
box-shadow: inset 0 -1px 0 var(--yc-color-line-generic);
20+
21+
&_with-border {
22+
box-shadow: inset 0 -1px 0 var(--yc-color-line-generic);
23+
}
2124

2225
&__wrapper {
2326
display: flex;

src/navigation/components/Header/Header.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, {MouseEvent, useCallback, useMemo, useState} from 'react';
1+
import React, {MouseEvent, useCallback, useEffect, useMemo, useState} from 'react';
2+
3+
import _ from 'lodash';
24

35
import Control from '../../../components/Control/Control';
46
import OutsideClick from '../../../components/OutsideClick/OutsideClick';
@@ -68,9 +70,10 @@ const isDropdownItem = (item: NavigationItemModel): item is NavigationDropdownIt
6870
item.type === NavigationItemType.Dropdown;
6971

7072
export const Header: React.FC<HeaderProps> = ({data, logo}) => {
71-
const {leftItems, rightItems, iconSize = 20} = data;
73+
const {leftItems, rightItems, iconSize = 20, withBorder = false} = data;
7274
const [isSidebarOpened, setIsSidebarOpened] = useState(false);
73-
const [activeItemId, setactiveItemId] = useState<string | undefined>(undefined);
75+
const [activeItemId, setActiveItemId] = useState<string | undefined>(undefined);
76+
const [showBorder, setShowBorder] = useState(withBorder);
7477

7578
const getNavigationItemWithIconSize = useCallback(
7679
(item: NavigationItemModel) => {
@@ -99,7 +102,7 @@ export const Header: React.FC<HeaderProps> = ({data, logo}) => {
99102
);
100103

101104
const onActiveItemChange = useCallback((id?: string) => {
102-
setactiveItemId(id);
105+
setActiveItemId(id);
103106
}, []);
104107

105108
const hidePopup = useCallback(() => {
@@ -114,8 +117,19 @@ export const Header: React.FC<HeaderProps> = ({data, logo}) => {
114117
setIsSidebarOpened(false);
115118
}, []);
116119

120+
useEffect(() => {
121+
const showBorderOnScroll = () => {
122+
if (!showBorder) {
123+
setShowBorder(window.scrollY > 0);
124+
}
125+
};
126+
127+
window.addEventListener('scroll', _.debounce(showBorderOnScroll, 20), {passive: true});
128+
return () => window.removeEventListener('scroll', _.debounce(showBorderOnScroll, 20));
129+
});
130+
117131
return (
118-
<Grid className={b()}>
132+
<Grid className={b({'with-border': showBorder})}>
119133
<Row>
120134
<Col>
121135
<header className={b('wrapper')}>

0 commit comments

Comments
 (0)