From 2205fde429bf0efce7500e3282c331186415d780 Mon Sep 17 00:00:00 2001 From: Galina Teklyuk <54212063+lunaticenslaved@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:51:03 +0300 Subject: [PATCH] fix(Toast): fix overflows (#1079) --- src/components/Toaster/Toast/Toast.scss | 2 ++ src/components/Toaster/Toast/Toast.tsx | 1 + .../Toaster/__stories__/Toaster.stories.tsx | 14 ++++---- .../Toaster/__stories__/ToasterShowcase.tsx | 34 +++++++++++++++++-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/components/Toaster/Toast/Toast.scss b/src/components/Toaster/Toast/Toast.scss index e6560cba09..69ffcf6787 100644 --- a/src/components/Toaster/Toast/Toast.scss +++ b/src/components/Toaster/Toast/Toast.scss @@ -92,6 +92,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: ''; diff --git a/src/components/Toaster/Toast/Toast.tsx b/src/components/Toaster/Toast/Toast.tsx index 633d2bf06f..f5a82ee6ec 100644 --- a/src/components/Toaster/Toast/Toast.tsx +++ b/src/components/Toaster/Toast/Toast.tsx @@ -57,6 +57,7 @@ function renderActions({actions, onClose}: RenderActionsProps) { type="button" size={'l'} view={view} + width="auto" > {label} diff --git a/src/components/Toaster/__stories__/Toaster.stories.tsx b/src/components/Toaster/__stories__/Toaster.stories.tsx index 16da9bc985..4403a62a94 100644 --- a/src/components/Toaster/__stories__/Toaster.stories.tsx +++ b/src/components/Toaster/__stories__/Toaster.stories.tsx @@ -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'; @@ -85,9 +85,11 @@ export default { ); }, ], -} as ComponentMeta; +} as Meta; -const DefaultTemplate: ComponentStory = (args) => ( - -); -export const Default = DefaultTemplate.bind({}); +type Story = StoryObj; + +export const Default: Story = { + args: {}, + render: (props) => , +}; diff --git a/src/components/Toaster/__stories__/ToasterShowcase.tsx b/src/components/Toaster/__stories__/ToasterShowcase.tsx index 6e32654982..98dfc4988f 100644 --- a/src/components/Toaster/__stories__/ToasterShowcase.tsx +++ b/src/components/Toaster/__stories__/ToasterShowcase.tsx @@ -4,7 +4,7 @@ import {faker} from '@faker-js/faker/locale/en'; import {CircleCheck, CircleInfo, Thunderbolt, 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'; @@ -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; @@ -108,7 +109,7 @@ export const ToasterDemo = ({ ...action, view: index === 0 ? action1View : action2View, })) - : undefined, + : extra.actions, }; } @@ -232,6 +233,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', @@ -324,6 +347,12 @@ export const ToasterDemo = ({ ); + const toastWithLongContent = ( + + ); + const dynamicallyUpdatingToast = (