Skip to content
Open
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
107 changes: 59 additions & 48 deletions packages/main/src/components/MessageView/MessageView.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link } from '@ui5/webcomponents-react';
import { useRef } from 'react';
import { MessageItem } from './MessageItem';
import { MessageView } from './index.js';
import { Dialog } from '../../webComponents/Dialog/index.js';

describe('MessageView', () => {
it('default & grouped', () => {
Expand Down Expand Up @@ -80,54 +81,64 @@ describe('MessageView', () => {
getAllTextsVisible();
});

it('select & nav back', () => {
const select = cy.spy().as('select');
const TestComp = () => {
const ref = useRef(null);
return (
<>
<button
onClick={() => {
ref.current.navigateBack();
}}
>
nav back
</button>
<MessageView onItemSelect={select} ref={ref} showDetailsPageHeader>
<MessageItem titleText="Error" type={ValueState.Negative} groupName="Group1">
Error Message
</MessageItem>
<MessageItem titleText="Warning" type={ValueState.Critical} groupName="Group1">
Warning
</MessageItem>
<MessageItem titleText="Success" type={ValueState.Positive}>
Success
</MessageItem>
<MessageItem titleText="Information" type={ValueState.Information}>
Information Message
</MessageItem>
<MessageItem titleText="None" type={ValueState.None} groupName="Group2">
None
</MessageItem>
</MessageView>
</>
);
};
cy.mount(<TestComp />);
cy.findByText('Error').click();
cy.findAllByText('Error').should('have.length', 1);
cy.findByText('Error Message').should('be.visible');
cy.get('[ui5-button]').click();
cy.findAllByText('Error').should('have.length', 1);
cy.findByText('Error Message').should('not.exist');
cy.get('@select').should('have.been.calledOnce');
cy.findByText('Information').click();
cy.findAllByText('Information').should('have.length', 1);
cy.findByText('Information Message').should('be.visible');
cy.findByText('nav back').click();
cy.findAllByText('Information').should('have.length', 1);
cy.findByText('Information Message').should('not.exist');
cy.get('@select').should('have.been.calledTwice');
[false, true].forEach((inDialog) => {
['ltr', 'rtl'].forEach((dir) => {
it(`select & nav back ${inDialog ? 'in Dialog' : ''} (${dir})`, () => {
const select = cy.spy().as('select');
const TestComp = () => {
const ref = useRef(null);
const Parent = inDialog ? Dialog : 'div';
return (
<Parent dir={dir} open style={{ width: '400px' }}>
<button
slot="header"
onClick={() => {
ref.current.navigateBack();
}}
>
nav back
</button>
<MessageView onItemSelect={select} ref={ref} showDetailsPageHeader={!inDialog}>
<MessageItem titleText="Error" type={ValueState.Negative} groupName="Group1">
Error Message
</MessageItem>
<MessageItem titleText="Warning" type={ValueState.Critical} groupName="Group1">
Warning
</MessageItem>
<MessageItem titleText="Success" type={ValueState.Positive}>
Success
</MessageItem>
<MessageItem titleText="Information" type={ValueState.Information}>
Information Message
</MessageItem>
<MessageItem titleText="None" type={ValueState.None} groupName="Group2">
None
</MessageItem>
</MessageView>
</Parent>
);
};
cy.mount(<TestComp />);
cy.findByText('Error').click();
cy.findAllByText('Error').should('have.length', 1);
cy.findByText('Error Message').should('be.visible');
if (inDialog) {
cy.findByText('nav back').click();
} else {
cy.get('[ui5-button]').click();
}
cy.findAllByText('Error').should('have.length', 1);
cy.findByText('Error Message').should('not.exist');
cy.get('@select').should('have.been.calledOnce');
cy.findByText('Information').click();
cy.findAllByText('Information').should('have.length', 1);
cy.findByText('Information Message').should('be.visible');
cy.findByText('nav back').click();
cy.findAllByText('Information').should('have.length', 1);
cy.findByText('Information Message').should('not.exist');
cy.get('@select').should('have.been.calledTwice');
});
});
});

it('one/no message-type/item', () => {
Expand Down
18 changes: 13 additions & 5 deletions packages/main/src/components/MessageView/MessageView.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@
> * {
width: 100%;
flex-shrink: 0;
transition: transform 200ms ease-in-out;
transition:
transform 200ms ease-in-out,
opacity 300ms ease-in-out;
}
}

.showDetails {
> * {
transform: translateX(-100%);
}
.container[data-with-animation='false'] > * {
transition: none;
}

.showDetails > * {
transform: translateX(-100%);
}

:dir(rtl) .showDetails > * {
transform: translateX(100%);
}

.button {
Expand Down
22 changes: 19 additions & 3 deletions packages/main/src/components/MessageView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ButtonDesign from '@ui5/webcomponents/dist/types/ButtonDesign.js';
import ListSeparator from '@ui5/webcomponents/dist/types/ListSeparator.js';
import TitleLevel from '@ui5/webcomponents/dist/types/TitleLevel.js';
import WrappingType from '@ui5/webcomponents/dist/types/WrappingType.js';
import { getAnimationMode } from '@ui5/webcomponents-base/dist/config/AnimationMode.js';
import ValueState from '@ui5/webcomponents-base/dist/types/ValueState.js';
import announce from '@ui5/webcomponents-base/dist/util/InvisibleMessage.js';
import iconSlimArrowLeft from '@ui5/webcomponents-icons/dist/slim-arrow-left.js';
Expand Down Expand Up @@ -64,6 +65,8 @@ export interface MessageViewPropTypes extends CommonProps {
onItemSelect?: ListPropTypes['onItemClick'];
}

const withAnimation = getAnimationMode() !== 'none';

export const resolveMessageTypes = (children: ReactElement<MessageItemPropTypes>[]) => {
return (children ?? [])
.map((message) => message?.props?.type)
Expand Down Expand Up @@ -193,13 +196,22 @@ const MessageView = forwardRef<MessageViewDomRef, MessageViewPropTypes>((props,

const outerClasses = clsx(classNames.container, className, selectedMessage && classNames.showDetails);
return (
<div ref={componentRef} {...rest} className={outerClasses} onTransitionEnd={handleTransitionEnd}>
<div
ref={componentRef}
{...rest}
className={outerClasses}
onTransitionEnd={handleTransitionEnd}
data-with-animation={`${withAnimation}`}
>
<MessageViewContext.Provider
value={{
selectMessage: setSelectedMessage,
}}
>
<div style={{ visibility: selectedMessage ? 'hidden' : 'visible' }} className={classNames.messagesContainer}>
<div
style={{ visibility: selectedMessage ? 'hidden' : 'visible', opacity: selectedMessage ? 0.3 : 1 }}
className={classNames.messagesContainer}
>
{!selectedMessage && (
<>
{filledTypes > 1 && (
Expand Down Expand Up @@ -257,7 +269,11 @@ const MessageView = forwardRef<MessageViewDomRef, MessageViewPropTypes>((props,
</>
)}
</div>
<div className={classNames.detailsContainer} data-component-name="MessageViewDetailsContainer">
<div
className={classNames.detailsContainer}
style={{ opacity: selectedMessage ? 1 : 0.3 }}
data-component-name="MessageViewDetailsContainer"
>
{childrenArray.length > 0 ? (
<>
{showDetailsPageHeader && selectedMessage && (
Expand Down
Loading