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
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.
45 changes: 43 additions & 2 deletions src/components/AsideHeader/__stories__/AsideHeader.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import {Xmark} from '@gravity-ui/icons';
import {Button, Flex, Icon, Text, spacing} from '@gravity-ui/uikit';
import type {Meta, StoryFn} from '@storybook/react';

Expand All @@ -8,7 +9,7 @@
import {PageLayout} from '../components/PageLayout/PageLayout';
import {PageLayoutAside} from '../components/PageLayout/PageLayoutAside';

import {AsideHeaderShowcase} from './AsideHeaderShowcase';
import {AsideHeaderShowcase, AsideHeaderShowcaseProps} from './AsideHeaderShowcase';
import {DEFAULT_LOGO, menuItemsClamped, menuItemsShowcase} from './moc';

import logoIcon from '../../../../.storybook/assets/logo.svg';
Expand Down Expand Up @@ -126,7 +127,9 @@
initialCompact: true,
};

const TopAlertTemplate: StoryFn = (args) => <AsideHeaderShowcase {...args} />;
const TopAlertTemplate: StoryFn<AsideHeaderShowcaseProps> = (args) => (
<AsideHeaderShowcase {...args} />
);
export const HeaderAlert = TopAlertTemplate.bind({});
HeaderAlert.args = {
topAlert: {
Expand All @@ -148,6 +151,44 @@
},
};

export const HeaderAlertCustom = TopAlertTemplate.bind({});
HeaderAlertCustom.args = {
topAlert: {
render: ({handleClose}) => (
<Flex
direction="row"
justifyContent="center"
alignItems="center"
gap={4}
style={{
position: 'relative',
padding: '8px',
background:
' linear-gradient(120deg, #191654, #43cea2 40%, #185a9d 70%, #f857a6 100%)',
}}
>
<Text variant="subheader-2" style={{color: 'var(--g-color-text-light-primary)'}}>
We&apos;ve got something new for you to try!
</Text>
<Button view="normal-contrast" size="m">
Try Now
</Button>
<Button view="outlined-contrast" size="m">
Learn More
</Button>
<Button
style={{position: 'absolute', right: '8px'}}
view="flat-contrast"
aria-label="Close"
onClick={handleClose}
>
<Icon data={Xmark} size={18} />
</Button>
</Flex>
),
},
};

const fallbackArgs = {
headerDecoration: true,
subheaderItemsCount: 2,
Expand Down Expand Up @@ -179,7 +220,7 @@
export const Fallback = FallbackTemplate.bind({});
Fallback.args = fallbackArgs;

/** @type {StoryFn} */

Check warning on line 223 in src/components/AsideHeader/__stories__/AsideHeader.stories.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Missing JSDoc @returns for function
export function LineClamp() {
const [compact, setCompact] = React.useState(false);
return (
Expand All @@ -204,7 +245,7 @@
menuItems={menuItemsShowcase}
logo={DEFAULT_LOGO}
onChangeCompact={setCompact}
collapseButtonWrapper={(defaultButton, {compact}) => (

Check warning on line 248 in src/components/AsideHeader/__stories__/AsideHeader.stories.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'compact' is already declared in the upper scope on line 239 column 12
<React.Fragment>
{defaultButton}
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
eventBroker,
} from '@gravity-ui/uikit';

import {AsideHeader, AsideHeaderProps, FooterItem, TopAlertProps} from '../..';
import {AsideHeader, AsideHeaderProps, FooterItem} from '../..';
import {ASIDE_HEADER_ICON_SIZE} from '../../constants';
import {OpenModalSubscriber} from '../../types';
import {OpenModalSubscriber, TopAlertProps} from '../../types';
import {cn} from '../../utils/cn';

import {menuItemsShowcase, text as placeholderText} from './moc';
Expand All @@ -36,7 +36,7 @@
Components = 'components',
}

interface AsideHeaderShowcaseProps {
export interface AsideHeaderShowcaseProps {
multipleTooltip?: boolean;
initialCompact?: boolean;
topAlert?: TopAlertProps;
Expand Down Expand Up @@ -72,7 +72,7 @@
const openModalCount = data?.meta?.layers?.filter(
({type}) => type === 'modal',
).length;
callback(openModalCount !== 0);

Check warning on line 75 in src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Expected return with your callback function
}
});
};
Expand Down Expand Up @@ -155,7 +155,7 @@
multipleTooltip={multipleTooltip}
openModalSubscriber={openModalSubscriber}
topAlert={topAlert}
renderFooter={({compact, asideRef}) => (

Check warning on line 158 in src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'compact' is already declared in the upper scope on line 62 column 12
<React.Fragment>
<FooterItem
compact={compact}
Expand Down Expand Up @@ -291,8 +291,8 @@
onChangeCompact={(v) => {
setCompact(v);
}}
onMenuMoreClick={() => console.log('onMenuMoreClick')}

Check warning on line 294 in src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
onAllPagesClick={() => console.log('onAllPagesClick')}

Check warning on line 295 in src/components/AsideHeader/__stories__/AsideHeaderShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
editMenuProps={{
enableSorting: true,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ test.describe('AsideHeader', () => {
await expectScreenshot();
});

test('render story: <HeaderAlertCustom>', async ({mount, expectScreenshot}) => {
await mount(<AsideHeaderStories.HeaderAlertCustom />, undefined, {
width: 1200,
height: 720,
});

await expectScreenshot();
});

test('render story: <MultipleTooltip>', async ({mount, expectScreenshot}) => {
await mount(<AsideHeaderStories.MultipleTooltip />, undefined, {
width: 1200,
Expand Down
2 changes: 2 additions & 0 deletions src/components/AsideHeader/types.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as React from 'react';

import {QAProps} from '@gravity-ui/uikit';

import {RenderContentType} from '../Content';
Expand Down
20 changes: 18 additions & 2 deletions src/components/TopAlert/TopAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export const TopAlert = ({alert, className, mobileView = false}: Props) => {

const handleClose = React.useCallback(() => {
setOpened(false);
alert?.onCloseTopAlert?.();

if (alert && 'onCloseTopAlert' in alert) {
alert.onCloseTopAlert?.();
}
}, [alert]);

React.useEffect(() => {
Expand All @@ -33,10 +36,23 @@ export const TopAlert = ({alert, className, mobileView = false}: Props) => {
}
}, [opened, updateTopSize]);

if (!alert || !alert.message) {
if (!alert) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems better to make message optional if the render is set.

}

const {render} = alert;

if (typeof render === 'function') {
return (
<div
ref={alertRef}
className={b('wrapper', {'with-bottom-border': !mobileView && opened}, className)}
>
{opened && render({handleClose})}
</div>
);
}

return (
<div
ref={alertRef}
Expand Down
9 changes: 8 additions & 1 deletion src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface LogoProps {
'aria-labelledby'?: string;
}

export interface TopAlertProps {
interface TopAlertBaseProps {
align?: AlertProps['align'];
message: AlertProps['message'];
title?: AlertProps['title'];
Expand All @@ -89,4 +89,11 @@ export interface TopAlertProps {
centered?: boolean;
dense?: boolean;
onCloseTopAlert?: () => void;
render?: never;
}

export type TopAlertProps =
| TopAlertBaseProps
| {
render: (params: {handleClose: () => void}) => React.ReactElement;
};
Loading