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

fix(Toast): fix overflows #1079

Merged
merged 1 commit into from
Nov 9, 2023
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/components/Toaster/Toast/Toast.scss
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ $block: '.#{variables.$ns}toast';
width: 100%;
height: 100%;
min-height: var(--g-text-body-2-line-height);
min-width: 0;
grid-template-columns: 100%;

&:before {
content: '';
Expand Down
1 change: 1 addition & 0 deletions src/components/Toaster/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function renderActions({actions, onClose}: RenderActionsProps) {
type="button"
size={'l'}
view={view}
width="auto"
>
{label}
</Button>
Expand Down
14 changes: 8 additions & 6 deletions src/components/Toaster/__stories__/Toaster.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import type {ComponentMeta, ComponentStory} from '@storybook/react';
import type {Meta, StoryObj} from '@storybook/react';

import type {ButtonView} from '../../Button';
import {ToasterProvider} from '../Provider/ToasterProvider';
Expand Down Expand Up @@ -85,9 +85,11 @@ export default {
);
},
],
} as ComponentMeta<typeof Toast>;
} as Meta<typeof Toast>;

const DefaultTemplate: ComponentStory<typeof Toast & typeof ToasterDemo> = (args) => (
<ToasterDemo {...args} />
);
export const Default = DefaultTemplate.bind({});
type Story = StoryObj<typeof Toast & typeof ToasterDemo>;

export const Default: Story = {
args: {},
render: (props) => <ToasterDemo {...props} />,
};
34 changes: 32 additions & 2 deletions src/components/Toaster/__stories__/ToasterShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {faker} from '@faker-js/faker/locale/en';
import {CircleCheck, CircleInfo, TriangleExclamation} from '@gravity-ui/icons';

import {ToasterComponent, useToaster} from '..';
import type {ToastProps} from '..';
import type {ToastAction, ToastProps} from '..';
import {Button} from '../../Button';
import type {ButtonView} from '../../Button';
import {Icon} from '../../Icon';
Expand Down Expand Up @@ -75,6 +75,7 @@ export const ToasterDemo = ({
type?: ToastProps['type'];
className?: string;
content?: React.ReactNode;
actions?: ToastAction[];
}): ToastProps {
let content: React.ReactNode = null;
let title;
Expand Down Expand Up @@ -108,7 +109,7 @@ export const ToasterDemo = ({
...action,
view: index === 0 ? action1View : action2View,
}))
: undefined,
: extra.actions,
};
}

Expand Down Expand Up @@ -220,6 +221,28 @@ export const ToasterDemo = ({
setState((state) => ({...state, lastToastName: toastProps.name}));
};

const createToastLongContent = () => {
const toastProps = getToastProps({
name: 'overflow',
type: 'error',
title: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.',
content:
'Excepturi cumque dicta, et a repellat culpa totam minus vero, error ducimus nesciunt? Dicta soluta earum sapiente explicabo commodi pariatur nulla eius?',
actions: [
{
label: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.',
onClick: () => {
console.log('Lorem ipsum dolor sit amet consectetur adipisicing elit.');
},
},
],
});

toaster.add(toastProps);

setState((state) => ({...state, lastToastName: toastProps.name}));
};

const createDynamicallyUpdatingToast = () => {
const toastProps = getToastProps({
name: 'UpdatingToast',
Expand Down Expand Up @@ -305,6 +328,12 @@ export const ToasterDemo = ({
</Button>
);

const toastWithLongContent = (
<Button view="outlined" size="l" onClick={createToastLongContent} style={btnStyle}>
Create toast with long content
</Button>
);

const dynamicallyUpdatingToast = (
<Button size="l" onClick={createDynamicallyUpdatingToast} style={btnStyle}>
Create dynamically updating toast
Expand Down Expand Up @@ -333,6 +362,7 @@ export const ToasterDemo = ({
<p>{warningToastBtn}</p>
<p>{errorToastBtn}</p>
<p>{customToastBtn}</p>
<p>{toastWithLongContent}</p>
<p>{dynamicallyUpdatingToast}</p>
<p>{overrideToastBtn}</p>
<p>{clearBtn}</p>
Expand Down
Loading