Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add top alert to MobileHeader component #335

Merged
merged 5 commits into from
Dec 9, 2024
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
39 changes: 7 additions & 32 deletions src/components/AsideHeader/AsideHeader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

$block: '.#{variables.$ns}aside-header';

.g-root {
--gn-aside-top-panel-height: 0px;
}

#{$block} {
$class: &;
--gn-aside-header-min-width: 56px;
Expand All @@ -24,7 +20,7 @@ $block: '.#{variables.$ns}aside-header';

&__aside {
position: sticky;
top: var(--gn-aside-top-panel-height);
top: var(--gn-top-alert-height, 0);
left: 0;
height: 100vh;
width: inherit;
Expand All @@ -35,8 +31,8 @@ $block: '.#{variables.$ns}aside-header';
var(--gn-aside-header-background-color, var(--_--background-color))
);
z-index: var(--gn-aside-header-z-index, 100);
max-height: calc(100vh - var(--gn-aside-top-panel-height));
margin-top: var(--gn-aside-top-panel-height);
max-height: calc(100vh - var(--gn-top-alert-height, 0));
margin-top: var(--gn-top-alert-height, 0);

box-sizing: border-box;

Expand Down Expand Up @@ -205,9 +201,9 @@ $block: '.#{variables.$ns}aside-header';
&__panels {
z-index: var(--gn-aside-header-panel-z-index, 98);
position: fixed;
inset: var(--gn-aside-top-panel-height) 0 0;
inset: var(--gn-top-alert-height, 0) 0 0;
overflow: auto;
max-height: calc(100vh - var(--gn-aside-top-panel-height));
max-height: calc(100vh - var(--gn-top-alert-height, 0));
}

&__panel {
Expand All @@ -222,38 +218,17 @@ $block: '.#{variables.$ns}aside-header';
flex-direction: row;
}

&__pane-top-divider {
height: 1px;
background-color: var(
--gn-aside-header-divider-horizontal-color,
var(--_--horizontal-divider-line-color)
);
margin-top: -1px;
}

&__pane-top {
&__top-alert {
position: fixed;
z-index: var(--gn-aside-header-pane-top-z-index, 98);
top: 0;
background: var(--g-color-base-background);
width: 100%;
}

&__pane-top-alert {
&_centered {
display: flex;
justify-content: space-around;
}

&_dense {
padding-top: var(--g-spacing-2);
padding-bottom: var(--g-spacing-2);
}
}

&__content {
width: calc(100% - var(--gn-aside-header-size));
z-index: var(--gn-aside-header-content-z-index, 95);
margin-top: var(--gn-aside-top-panel-height);
margin-top: var(--gn-top-alert-height, 0);
}
}
4 changes: 2 additions & 2 deletions src/components/AsideHeader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const Aside: FC = () => {

Top Alert can be useful for displaying important information that users need to know. This alert is often appeared in all pages like call to action or warning.

You can customize the inner content, make alert closeable if necessary. For reading top alert height see value from CSS variable `--gn-aside-top-panel-height`.
You can customize the inner content, make alert closeable if necessary. For reading top alert height see value from CSS variable `--gn-top-alert-height`.

| Name | Description | Type | Default |
| :-------------- | :----------------------------------------------------------------- | :------------------------------------------------------------------------------------------------: | :---------: |
Expand All @@ -199,7 +199,7 @@ You can customize the inner content, make alert closeable if necessary. For read
| `--gn-aside-header-expanded-background-color` | Expanded navigation background color | `--g-color-base-background` |
| `--gn-aside-header-divider-horizontal-color` | All horizontal divider line color | `--g-color-line-generic` |
| `--gn-aside-header-divider-vertical-color` | Vertical divider line color between `AsideHeader` and content | `--g-color-line-generic` |
| `--gn-aside-top-panel-height` | **Read only**.`AsideHeader` top alert height | 0px |
| `--gn-top-alert-height` | **Read only**.`AsideHeader` top alert height | 0px |
| `--gn-aside-header-padding-top` | Navigation top padding. May be helpful when logo and subheader items hide | |
| Item | | |
| `--gn-aside-header-general-item-icon-color` | Icon color for Subheader and Footer items | `--g-color-text-primary` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
eventBroker,
} from '@gravity-ui/uikit';

import {AsideHeader, AsideHeaderTopAlertProps, FooterItem} from '../..';
import {AsideHeader, FooterItem, TopAlertProps} from '../..';
import {ASIDE_HEADER_ICON_SIZE} from '../../constants';
import {MenuItem, OpenModalSubscriber} from '../../types';
import {cn} from '../../utils/cn';
Expand Down Expand Up @@ -39,7 +39,7 @@ enum Panel {
interface AsideHeaderShowcaseProps {
multipleTooltip?: boolean;
initialCompact?: boolean;
topAlert?: AsideHeaderTopAlertProps;
topAlert?: TopAlertProps;
customBackground?: React.ReactNode;
customBackgroundClassName?: string;
headerDecoration?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {b} from '../../utils';

import '../../AsideHeader.scss';

const TopPanel = React.lazy(() =>
import('../TopPanel').then((module) => ({default: module.TopPanel})),
const TopAlert = React.lazy(() =>
import('../../../TopAlert').then((module) => ({default: module.TopAlert})),
);

export interface PageLayoutProps extends PropsWithChildren<LayoutProps> {}
Expand All @@ -28,7 +28,7 @@ const Layout = ({compact, className, children, topAlert}: PageLayoutProps) => {
>
{topAlert && (
<Suspense fallback={null}>
<TopPanel topAlert={topAlert} />
<TopAlert className={b('top-alert')} alert={topAlert} />
</Suspense>
)}
<div className={b('pane-container')}>{children}</div>
Expand Down
57 changes: 0 additions & 57 deletions src/components/AsideHeader/components/TopPanel.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/AsideHeader/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export {FirstPanel} from './FirstPanel';
export {TopPanel} from './TopPanel';
12 changes: 3 additions & 9 deletions src/components/AsideHeader/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ import {QAProps} from '@gravity-ui/uikit';

import {RenderContentType} from '../Content';
import {DrawerItemProps} from '../Drawer/Drawer';
import {
AsideHeaderTopAlertProps,
LogoProps,
MenuItem,
OpenModalSubscriber,
SubheaderMenuItem,
} from '../types';
import {LogoProps, MenuItem, OpenModalSubscriber, SubheaderMenuItem, TopAlertProps} from '../types';

import {AsideHeaderContextType} from './AsideHeaderContext';

export interface LayoutProps {
compact: boolean;
className?: string;
topAlert?: AsideHeaderTopAlertProps;
topAlert?: TopAlertProps;
}

export interface AsideHeaderGeneralProps extends QAProps {
Expand All @@ -25,7 +19,7 @@ export interface AsideHeaderGeneralProps extends QAProps {
collapseTitle?: string;
expandTitle?: string;
menuMoreTitle?: string;
topAlert?: AsideHeaderTopAlertProps;
topAlert?: TopAlertProps;
customBackground?: React.ReactNode;
customBackgroundClassName?: string;
hideCollapseButton?: boolean;
Expand Down
63 changes: 0 additions & 63 deletions src/components/AsideHeader/useAsideHeaderTopPanel.tsx

This file was deleted.

9 changes: 6 additions & 3 deletions src/components/MobileHeader/MobileHeader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ $block: '.#{variables.$ns}mobile-header';

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

&__header {
background-color: var(--g-color-base-background);
border-bottom: 1px solid var(--g-color-line-generic);
&__top {
position: sticky;
top: 0;
background-color: var(--g-color-base-background);
}

&__header {
border-bottom: 1px solid var(--g-color-line-generic);
padding: 0 10px;
box-sizing: border-box;
display: flex;
Expand Down
41 changes: 27 additions & 14 deletions src/components/MobileHeader/MobileHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import React, {Suspense, useCallback, useEffect, useMemo, useState} from 'react';

import {useForwardRef} from '../../hooks/useForwardRef';
import {Content, RenderContentType} from '../Content';
import {Drawer, DrawerItem, DrawerItemProps} from '../Drawer/Drawer';
import {MobileLogo} from '../MobileLogo';
import {LogoProps} from '../types';
import {LogoProps, TopAlertProps} from '../types';
import {block} from '../utils/cn';

import {Burger} from './Burger/Burger';
Expand All @@ -25,6 +25,10 @@ import {MobileHeaderEvent, MobileHeaderEventOptions, MobileMenuItem} from './typ

import './MobileHeader.scss';

const TopAlert = React.lazy(() =>
import('../TopAlert').then((module) => ({default: module.TopAlert})),
);

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

type PanelName = DrawerItemProps['id'] | null;
Expand All @@ -44,6 +48,7 @@ export interface MobileHeaderProps {
burgerCloseTitle?: string;
burgerOpenTitle?: string;
panelItems?: PanelItem[];
topAlert?: TopAlertProps;
renderContent?: RenderContentType;
sideItemRenderContent?: RenderContentType;
onEvent?: (itemName: string, eventName: MobileHeaderEvent) => void;
Expand All @@ -67,6 +72,7 @@ export const MobileHeader = React.forwardRef<HTMLDivElement, MobileHeaderProps>(
className,
contentClassName,
overlapPanel,
topAlert,
},
ref,
): React.ReactElement => {
Expand Down Expand Up @@ -261,24 +267,31 @@ export const MobileHeader = React.forwardRef<HTMLDivElement, MobileHeaderProps>(

return (
<div className={b({compact}, className)} ref={targetRef}>
<header className={b('header')} style={{height: size}}>
<Burger
opened={visiblePanel === burgerPanelItem.id}
onClick={() => onPanelToggle(BURGER_PANEL_ITEM_ID)}
className={b('burger')}
closeTitle={burgerCloseTitle}
openTitle={burgerOpenTitle}
/>
<MobileLogo {...logo} compact={compact} onClick={onLogoClick} />
<div className={b('top')}>
{topAlert && (
Lunory marked this conversation as resolved.
Show resolved Hide resolved
<Suspense fallback={null}>
<TopAlert alert={topAlert} mobileView />
</Suspense>
)}
<header className={b('header')} style={{height: size}}>
<Burger
opened={visiblePanel === burgerPanelItem.id}
onClick={() => onPanelToggle(BURGER_PANEL_ITEM_ID)}
className={b('burger')}
closeTitle={burgerCloseTitle}
openTitle={burgerOpenTitle}
/>
<MobileLogo {...logo} compact={compact} onClick={onLogoClick} />

<div className={b('side-item')}>{sideItemRenderContent?.({size})}</div>
</header>
<div className={b('side-item')}>{sideItemRenderContent?.({size})}</div>
</header>
</div>

<Drawer
className={b('panels')}
onVeilClick={onCloseDrawer}
onEscape={onCloseDrawer}
style={{top: size}}
style={{top: `calc(${size}px + var(--gn-top-alert-height, 0)`}}
>
{[burgerPanelItem, ...panelItems].map((item) => (
<DrawerItem
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading