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: UI5 toast component #3111

Merged
merged 2 commits into from
Aug 9, 2024
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
36 changes: 12 additions & 24 deletions src/shared/contexts/NotificationContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MessageStrip } from '@ui5/webcomponents-react';
import { createContext, useContext, useState } from 'react';
import { Toast, ToastDomRef } from '@ui5/webcomponents-react';
import { createContext, useContext, useRef, useState } from 'react';
import {
ErrorModal,
ErrorModalProps,
Expand All @@ -23,28 +23,23 @@ type NotificationContextArgs = {

export const NotificationContext = createContext<NotificationContextArgs>({
isOpen: false,
notifySuccess: props => {},
notifyError: props => {},
notifySuccess: () => {},
notifyError: () => {},
});

export const NotificationProvider = ({
children,
defaultVisibilityTime = 5000,
defaultVisibilityTime = 3000,
}: NotificationContextProps) => {
const [toastProps, setToastProps] = useState<ToastProps | null>();
const [errorProps, setErrorProps] = useState<ErrorModalProps | null>();

const toast = useRef<ToastDomRef | null>(null);

const methods = {
notifySuccess: function(
notificationProps: ToastProps,
visibilityTime: number = defaultVisibilityTime,
) {
if (visibilityTime !== 0) {
setTimeout(() => {
setToastProps(null);
}, visibilityTime);
}
notifySuccess: function(notificationProps: ToastProps) {
setToastProps(notificationProps);
toast.current?.show();
},
notifyError: function(notificationProps: Omit<ErrorModalProps, 'close'>) {
setErrorProps({
Expand All @@ -61,16 +56,9 @@ export const NotificationProvider = ({
...methods,
}}
>
{toastProps && (
<div
className="message-toast--wrapper"
onClick={() => setToastProps(null)}
>
<MessageStrip hideIcon hideCloseButton>
{toastProps.content}
</MessageStrip>
</div>
)}
<Toast ref={toast} duration={defaultVisibilityTime}>
{toastProps?.content}
</Toast>
{errorProps &&
createPortal(<ErrorModal {...errorProps} />, document.body)}
{children}
Expand Down
10 changes: 0 additions & 10 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,6 @@ ui5-tabcontainer::part(content) {
font-style: normal;
}

.message-toast--wrapper {
position: fixed;
transition: all ease-in-out 0.4s;
z-index: 1100;
cursor: pointer;
left: 50vw;
transform: translateX(-50%);
bottom: 50px;
}

.flexwrap {
display: flex;
flex-wrap: wrap;
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ Cypress.Commands.add(
cy.contains('ui5-link', resourceName).should('be.visible');
}

cy.contains('ui5-message-strip', /created/).should('not.exist');

cy.get('ui5-button[data-testid="delete"]').click();

if (confirmationEnabled) {
Expand All @@ -201,7 +199,7 @@ Cypress.Commands.add(
.click();

if (deletedVisible) {
cy.contains('ui5-message-strip', /deleted/).should('be.visible');
cy.contains('ui5-toast', /deleted/).should('be.visible');
}

if (clearSearch) {
Expand Down
Loading