Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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.
46 changes: 44 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,45 @@
},
};

export const HeaderAlertCustom = TopAlertTemplate.bind({});
HeaderAlertCustom.args = {
topAlert: {
message: "We've got something new for you to try!",
render: ({message, 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)'}}>
{message}
</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 +221,7 @@
export const Fallback = FallbackTemplate.bind({});
Fallback.args = fallbackArgs;

/** @type {StoryFn} */

Check warning on line 224 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 +246,7 @@
menuItems={menuItemsShowcase}
logo={DEFAULT_LOGO}
onChangeCompact={setCompact}
collapseButtonWrapper={(defaultButton, {compact}) => (

Check warning on line 249 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 240 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
6 changes: 6 additions & 0 deletions src/components/TopAlert/TopAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export const TopAlert = ({alert, className, mobileView = false}: Props) => {
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, ...restProps} = alert;

if (typeof render === 'function') {
return <div ref={alertRef}>{opened && render({...restProps, handleClose})}</div>;
}

return (
<div
ref={alertRef}
Expand Down
6 changes: 5 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 @@ -90,3 +90,7 @@ export interface TopAlertProps {
dense?: boolean;
onCloseTopAlert?: () => void;
}

export interface TopAlertProps extends TopAlertBaseProps {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The updated TopAlertProps interface still requires message, yet the component explicitly supports a render function that can render arbitrary content. Making message mandatory in the type system forces callers who only want a custom renderer to pass meaningless placeholder text to satisfy the compiler. This should be modeled as a union or by making message optional when render is provided.

render?: (params: TopAlertBaseProps & {handleClose: () => void}) => React.ReactElement;
}
Loading