Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/models/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface NavigationItemBase {
text: string;
icon?: ImageProps;
url?: string;
iconSize?: number;
}

export enum NavigationGithubButtonIcon {
Expand Down Expand Up @@ -82,6 +83,7 @@ export type ThemedNavigationLogoData = NavigationLogoData & ThemeSupporting<Navi
export interface HeaderData {
leftItems: NavigationItemModel[];
rightItems?: NavigationItemModel[];
iconSize?: number;
}

export interface FooterColumn {
Expand Down
38 changes: 32 additions & 6 deletions src/navigation/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React, {MouseEvent, useCallback, useState} from 'react';
import React, {MouseEvent, useCallback, useMemo, useState} from 'react';

import _ from 'lodash';

import Control from '../../../components/Control/Control';
import OutsideClick from '../../../components/OutsideClick/OutsideClick';
import {Col, Grid, Row} from '../../../grid';
import {NavigationClose, NavigationOpen} from '../../../icons';
import {HeaderData, ThemedNavigationLogoData} from '../../../models';
import {
HeaderData,
NavigationItemBase,
NavigationItemModel,
ThemedNavigationLogoData,
} from '../../../models';
import {block} from '../../../utils';
import {ItemColumnName} from '../../constants';
import Logo from '../Logo/Logo';
Expand Down Expand Up @@ -52,11 +57,32 @@ const MobileMenuButton: React.FC<MobileMenuButtonProps> = ({
);
};

const iconSizeKey: keyof NavigationItemBase = 'iconSize';

export const Header: React.FC<HeaderProps> = ({data, logo}) => {
const {leftItems, rightItems} = data;
const {leftItems, rightItems, iconSize = 20} = data;
const [isSidebarOpened, setIsSidebarOpened] = useState(false);
const [activeItemId, setactiveItemId] = useState<string | undefined>(undefined);

const getNavigationItemWithIconSize = useCallback(
(item: NavigationItemModel) => {
if (!(iconSizeKey in item)) {
return {...item, iconSize};
}
return item;
},
[iconSize],
);

const leftItemsWithIconSize = useMemo(
() => leftItems.map(getNavigationItemWithIconSize),
[getNavigationItemWithIconSize, leftItems],
);
const rightItemsWithIconSize = useMemo(
() => rightItems?.map(getNavigationItemWithIconSize),
[getNavigationItemWithIconSize, rightItems],
);

const onActiveItemChange = useCallback((id?: string) => {
setactiveItemId(id);
}, []);
Expand Down Expand Up @@ -86,7 +112,7 @@ export const Header: React.FC<HeaderProps> = ({data, logo}) => {
<div className={b('navigation-container')}>
<Navigation
className={b('navigation')}
links={leftItems}
links={leftItemsWithIconSize}
activeItemId={activeItemId}
onActiveItemChange={onActiveItemChange}
/>
Expand All @@ -96,9 +122,9 @@ export const Header: React.FC<HeaderProps> = ({data, logo}) => {
isSidebarOpened={isSidebarOpened}
onSidebarOpenedChange={onSidebarOpenedChange}
/>
{rightItems && (
{rightItemsWithIconSize && (
<ul className={b('buttons')}>
{rightItems.map((button, index) => (
{rightItemsWithIconSize.map((button, index) => (
<NavigationListItem
key={index}
className={b('buttons-item')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const NavigationDropdown: React.FC<NavigationDropdownProps> = ({
onClick,
}) => {
const anchorRef = useRef<HTMLElement>(null);
const {text, icon, items, ...popupProps} = data;
const {text, icon, items, iconSize, ...popupProps} = data;

return (
<Fragment>
Expand All @@ -29,7 +29,7 @@ const NavigationDropdown: React.FC<NavigationDropdownProps> = ({
ref={anchorRef}
onClick={onClick}
isOpened={isActive}
data={{text, type: NavigationItemType.Dropdown, icon}}
data={{text, type: NavigationItemType.Dropdown, icon, iconSize}}
/>
<NavigationPopup
open={isActive}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ $block: '.#{$ns}content-wrapper';
#{$block} {
&__icon {
display: flex;
width: 20px;
height: 20px;
margin-right: $indentXXXS;
margin-right: $navigationIconIndent;

object-fit: cover;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {Fragment} from 'react';
import React, {Fragment, useMemo} from 'react';

import {Image} from '../../../../../components';
import {ImageProps} from '../../../../../models';
Expand All @@ -8,9 +8,24 @@ import './ContentWrapper.scss';

const b = block('content-wrapper');

export const ContentWrapper: React.FC<{text: string; icon?: ImageProps}> = ({text, icon}) => (
<Fragment>
{icon && typeof icon !== 'string' && <Image className={b('icon')} {...icon} />}
<span className={b('text')}>{text}</span>
</Fragment>
);
interface ContentWrapperProps {
text: string;
icon?: ImageProps;
iconSize?: number;
}

export const ContentWrapper: React.FC<ContentWrapperProps> = ({text, icon, iconSize}) => {
const iconSizeStyle = useMemo(
() => (iconSize ? {height: `${iconSize}px`, width: `${iconSize}px`} : {}),
[iconSize],
);

return (
<Fragment>
{icon && typeof icon !== 'string' && (
<Image className={b('icon')} {...icon} style={iconSizeStyle} />
)}
<span className={b('text')}>{text}</span>
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const TOGGLE_ARROW_SIZE = 12;
type NavigationDropdownProps = NavigationItemProps & DropdownItemData;

export const NavigationDropdown = React.forwardRef<HTMLElement, NavigationDropdownProps>(
({text, icon, isOpened, className, ...props}, ref) => {
({text, icon, isOpened, className, iconSize, ...props}, ref) => {
const iconData = icon && getMediaImage(icon);

return (
<span ref={ref} {...props} className={b(null, className)}>
<ContentWrapper text={text} icon={iconData} />
<ContentWrapper text={text} icon={iconData} iconSize={iconSize} />
<ToggleArrow
className={b('arrow')}
size={TOGGLE_ARROW_SIZE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ type NavigationLinkProps = NavigationItemProps & NavigationLinkItem;

export const NavigationLink: React.FC<NavigationLinkProps> = (props) => {
const {hostname, Link} = useContext(LocationContext);
const {url, text, icon, arrow, target, className, ...rest} = props;
const {url, text, icon, arrow, target, className, iconSize, ...rest} = props;
const linkExtraProps = getLinkProps(url, hostname, target);
const iconData = icon && getMediaImage(icon);

const classes = b(null, className);
const content = (
<Fragment>
<ContentWrapper text={text} icon={iconData} />
<ContentWrapper text={text} icon={iconData} iconSize={iconSize} />
{arrow && <NavigationArrow className={b('arrow')} />}
</Fragment>
);
Expand Down
6 changes: 6 additions & 0 deletions src/navigation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const NavigationItemBaseProps = {
type: 'string',
pattern: urlPattern,
},
iconSize: {
type: 'number',
},
};

const NavigationItemBaseLinkProps = omit(NavigationItemBaseProps, ['url']);
Expand Down Expand Up @@ -96,5 +99,8 @@ export const NavigationHeaderProps = {
properties: {
leftItems: NavigationItemProps,
rightItems: NavigationItemProps,
iconSize: {
type: 'number',
},
},
};
2 changes: 2 additions & 0 deletions styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ $contentMargin: $indentM;
$contentLiftIndent: $indentXL;
$contentLiftIndentMobile: $indentM;

$navigationIconIndent: 6px;

//slider
$sliderArrowSize: 42px;
$headerSliderLargeBreakpoint: 1410px;
Expand Down