Skip to content

Commit

Permalink
feat: add line-clamp at MobileHeader's TopAlert; fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
benax-se committed Nov 13, 2024
1 parent 817f3b9 commit 304b454
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
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 @@ -28,7 +28,7 @@ const Layout = ({compact, className, children, topAlert}: PageLayoutProps) => {
>
{topAlert && (
<Suspense fallback={null}>
<TopAlert className={b('top-alert')} alert={topAlert} withBottomBorder />
<TopAlert className={b('top-alert')} alert={topAlert} />
</Suspense>
)}
<div className={b('pane-container')}>{children}</div>
Expand Down
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
2 changes: 1 addition & 1 deletion src/components/MobileHeader/MobileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const MobileHeader = React.forwardRef<HTMLDivElement, MobileHeaderProps>(
<div className={b('top')}>
{topAlert && (
<Suspense fallback={null}>
<TopAlert alert={topAlert} />
<TopAlert alert={topAlert} mobileView />
</Suspense>
)}
<header className={b('header')} style={{height: size}}>
Expand Down
18 changes: 13 additions & 5 deletions src/components/TopAlert/TopAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {Alert} from '@gravity-ui/uikit';
import {Alert, Text} from '@gravity-ui/uikit';

import {TopAlertProps} from '../types';
import {block} from '../utils/cn';
Expand All @@ -14,10 +14,10 @@ const b = block('top-alert');
type Props = {
alert?: TopAlertProps;
className?: string;
withBottomBorder?: boolean;
mobileView?: boolean;
};

export const TopAlert = ({alert, className, withBottomBorder = false}: Props) => {
export const TopAlert = ({alert, className, mobileView = false}: Props) => {
const {alertRef, updateTopSize} = useTopAlertHeight({alert});

const [opened, setOpened] = React.useState(true);
Expand All @@ -40,7 +40,7 @@ export const TopAlert = ({alert, className, withBottomBorder = false}: Props) =>
return (
<div
ref={alertRef}
className={b('wrapper', {'with-bottom-border': withBottomBorder && opened}, className)}
className={b('wrapper', {'with-bottom-border': !mobileView && opened}, className)}
>
{opened && (
<Alert
Expand All @@ -55,7 +55,15 @@ export const TopAlert = ({alert, className, withBottomBorder = false}: Props) =>
view={alert.view}
icon={alert.icon}
title={alert.title}
message={alert.message}
message={
mobileView ? (
<Text ellipsisLines={5} variant="body-2">
{alert.message}
</Text>
) : (
alert.message
)
}
actions={alert.actions}
onClose={alert.closable ? handleClose : undefined}
/>
Expand Down
1 change: 1 addition & 0 deletions src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface LogoProps {
}

export interface TopAlertProps {
align?: AlertProps['align'];
message: AlertProps['message'];
title?: AlertProps['title'];
icon?: AlertProps['icon'];
Expand Down

0 comments on commit 304b454

Please sign in to comment.