Skip to content

Commit

Permalink
feat: navigation dropdown refactoring (#392)
Browse files Browse the repository at this point in the history
* feat: navigation dropdown refactoring
  • Loading branch information
niktverd authored Jul 25, 2023
1 parent b449e43 commit 9f47dbe
Show file tree
Hide file tree
Showing 27 changed files with 548 additions and 626 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useHeightCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useHeightCalculator: (
useEffect(() => {
const handleResize = _.debounce(calculateContainerHeight, recalculateOnResizeDelay);

calculateContainerHeight();
handleResize();

window.addEventListener('resize', handleResize, {passive: true});
return () => {
Expand Down
6 changes: 3 additions & 3 deletions src/models/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export interface NavigationButtonItem extends ButtonProps {
export interface NavigationDropdownItem extends NavigationItemBase {
type: NavigationItemType.Dropdown;
items: NavigationLinkItem[];
hidePopup: () => void;
isActive: boolean;
}

export interface NavigationSocialItem extends Omit<NavigationItemBase, 'text'> {
Expand All @@ -69,9 +71,7 @@ export type NavigationItemData =
| NavigationLinkItem
| NavigationButtonItem
| NavigationSocialItem
| DropdownItemData;

export type DropdownItemData = Omit<NavigationDropdownItem, 'items'>;
| NavigationDropdownItem;

export interface NavigationLogoData {
icon: ImageProps;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
@import '../../../../styles/variables';
@import '../../../../styles/mixins';

$block: '.#{$ns}header';
$block: '.#{$ns}desktop-navigation';

#{$block} {
$root: &;

position: sticky;
z-index: 98;
top: 0;

display: flex;
justify-content: center;
align-items: center;

height: var(--header-height);

background-color: var(--yc-color-base-background);

&_with-border {
box-shadow: inset 0 -1px 0 var(--yc-color-line-generic);
}

&__wrapper {
display: flex;
justify-content: space-between;
Expand Down Expand Up @@ -76,11 +58,26 @@ $block: '.#{$ns}header';
margin-right: $indentM;
}

&__buttons {
&__button {
margin-top: 0;
}

&__logo {
margin: 0 $indentM 0 0;

cursor: pointer;
}

&__buttons,
&__links {
display: flex;
align-items: center;
@include desktop-only();

@include reset-list-style();
}

&__buttons {
@include desktop-only();

& > * {
&:not(:last-child) {
Expand All @@ -89,22 +86,18 @@ $block: '.#{$ns}header';
}
}

&__buttons-item {
&__links {
position: relative;

&:not(:last-child) {
margin-right: $indentS;
}
}

&__button {
margin-top: 0;
@include text-size(body-2);
}

&__logo {
margin: 0 $indentM 0 0;
&__item {
position: relative;

cursor: pointer;
&:not(:last-child) {
margin-right: $indentS;
}
}

@media (max-width: map-get($gridBreakpoints, 'md') - 1) {
Expand Down
64 changes: 64 additions & 0 deletions src/navigation/components/DesktopNavigation/DesktopNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';

import _ from 'lodash';

import OverflowScroller from '../../../components/OverflowScroller/OverflowScroller';
import {block} from '../../../utils';
import {DesktopNavigationProps, ItemColumnName, NavigationLayout} from '../../models';
import Logo from '../Logo/Logo';
import {MobileMenuButton} from '../MobileMenuButton/MobileMenuButton';
import {NavigationList} from '../NavigationList/NavigationList';

import './DesktopNavigation.scss';

const b = block('desktop-navigation');

const DesktopNavigation: React.FC<DesktopNavigationProps> = ({
logo,
leftItemsWithIconSize,
rightItemsWithIconSize,
isSidebarOpened,
onSidebarOpenedChange,
onActiveItemChange,
activeItemId,
}) => (
<div className={b('wrapper')}>
{logo && (
<div className={b('left')}>
<Logo {...logo} className={b('logo')} />
</div>
)}
<div className={b('navigation-container')}>
<OverflowScroller className={b('navigation')} onScrollStart={onActiveItemChange}>
<NavigationList
items={leftItemsWithIconSize}
onActiveItemChange={onActiveItemChange}
className={b('links')}
itemClassName={b('item')}
column={ItemColumnName.Left}
activeItemId={activeItemId}
menuLayout={NavigationLayout.Desktop}
/>
</OverflowScroller>
</div>
<div className={b('right')}>
<MobileMenuButton
isSidebarOpened={isSidebarOpened}
onSidebarOpenedChange={onSidebarOpenedChange}
/>
{rightItemsWithIconSize && (
<NavigationList
onActiveItemChange={onActiveItemChange}
column={ItemColumnName.Right}
items={rightItemsWithIconSize}
activeItemId={activeItemId}
className={b('buttons')}
itemClassName={b('item')}
menuLayout={NavigationLayout.Desktop}
/>
)}
</div>
</div>
);

export default DesktopNavigation;
188 changes: 0 additions & 188 deletions src/navigation/components/Header/Header.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import '../../../../styles/mixins';

$block: '.#{$ns}mobile-menu-button';

#{$block} {
@include add-specificity(&) {
@include mobile-tablet-only();
}
}
Loading

0 comments on commit 9f47dbe

Please sign in to comment.