Skip to content

Commit

Permalink
fixup! feat: navigation dropdown refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
niktverd committed Jul 4, 2023
1 parent 9c3e3fd commit 79dc2bc
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $block: '.#{$ns}mobile-navigation';
border-bottom-left-radius: $borderRadius;
background-color: var(--yc-color-base-background);
box-shadow: 0 3px 10px var(--yc-color-sfx-shadow);
max-height: calc(100vh - 2 * var(--header-height));
overflow-y: scroll;

scrollbar-width: none;
Expand Down
55 changes: 7 additions & 48 deletions src/navigation/components/MobileNavigation/MobileNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,22 @@ import Foldable from '../../../components/Foldable/Foldable';
import {NavigationItemModel} from '../../../models';
import {block} from '../../../utils';
import {ItemColumnName} from '../../constants';
import {getItemClickHandler} from '../../utils';
import NavigationItem from '../NavigationItem/NavigationItem';

import {
MobileNavigationItem,
MobileNavigationItemProps,
} from './components/MobileNavigationItem/MobileNavigationItem';

import './MobileNavigation.scss';

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

interface MobileNavigationItemProps extends Pick<MobileNavigationProps, 'onActiveItemChange'> {
item: NavigationItemModel;
column: ItemColumnName;
index: number;
isOpened?: boolean;
activeItemId?: string;
hidePopup: () => void;
}

const MobileNavigationItem = ({
item,
index,
isOpened,
activeItemId,
onActiveItemChange,
column,
hidePopup,
}: MobileNavigationItemProps) => {
const id = `${column}-${index}`;
const isActive = id === activeItemId;

const onClick = getItemClickHandler({
column,
index,
activeItemId,
onActiveItemChange,
});

return (
<NavigationItem
key={index}
className={b('rows-item')}
data={item}
onClick={onClick}
isActive={isActive}
isOpened={isOpened}
hidePopup={hidePopup}
isTopLevel={true}
isMobile={true}
/>
);
};

export interface MobileNavigationProps {
export interface MobileNavigationProps
extends Pick<MobileNavigationItemProps, 'onActiveItemChange'> {
className?: string;
isOpened?: boolean;
topItems?: NavigationItemModel[];
bottomItems?: NavigationItemModel[];
activeItemId?: string;
onActiveItemChange: (id?: string) => void;
hidePopup: () => void;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@import '../../../../../../styles/variables';

$block: '.#{$ns}mobile-navigation-item';

#{$block} {
&__rows-item {
&:not(:last-child) {
margin-bottom: $indentSM;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';

import {NavigationItemModel} from '../../../../../models';
import {block} from '../../../../../utils';
import {ItemColumnName} from '../../../../constants';
import {getItemClickHandler} from '../../../../utils';
import NavigationItem from '../../../NavigationItem/NavigationItem';

import './MobileNavigationItem.scss';

const b = block('mobile-navigation-item');

export interface MobileNavigationItemProps {
item: NavigationItemModel;
column: ItemColumnName;
index: number;
isOpened?: boolean;
activeItemId?: string;
hidePopup: () => void;
onActiveItemChange: (id?: string) => void;
}

export const MobileNavigationItem = ({
item,
index,
activeItemId,
onActiveItemChange,
column,
hidePopup,
}: MobileNavigationItemProps) => {
const id = `${column}-${index}`;
const isActive = id === activeItemId;
const isOpened = isActive;

const onClick = getItemClickHandler({
column,
index,
activeItemId,
onActiveItemChange,
});

return (
<NavigationItem
key={index}
className={b('rows-item')}
data={item}
onClick={onClick}
isActive={isActive}
isOpened={isOpened}
hidePopup={hidePopup}
isMobile={true}
/>
);
};

0 comments on commit 79dc2bc

Please sign in to comment.