Skip to content

Commit

Permalink
Related #4602 - For Messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ulasturann committed Aug 4, 2023
1 parent f8cba94 commit f3b0573
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 63 deletions.
42 changes: 0 additions & 42 deletions components/lib/messages/Messages.css

This file was deleted.

6 changes: 4 additions & 2 deletions components/lib/messages/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MessagesBase } from './MessagesBase';
import { UIMessage } from './UIMessage';
import { mergeProps } from '../utils/Utils';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';

let messageIdx = 0;

Expand All @@ -23,6 +24,8 @@ export const Messages = React.memo(

const ptCallbacks = MessagesBase.setMetaData(metaData);

useHandleStyle(MessagesBase.css.styles, ptCallbacks.isUnstyled, { name: 'messages' });

const show = (messageInfo) => {
if (messageInfo) {
setMessagesState((prev) => assignIdentifiers(prev, messageInfo, true));
Expand Down Expand Up @@ -87,7 +90,6 @@ export const Messages = React.memo(
const rootProps = mergeProps(
{
id: props.id,
ref: elementRef,
className: props.className,
style: props.style
},
Expand All @@ -96,7 +98,7 @@ export const Messages = React.memo(
);

return (
<div {...rootProps}>
<div ref={elementRef} {...rootProps}>
<TransitionGroup>
{messagesState &&
messagesState.map((message, index) => {
Expand Down
65 changes: 65 additions & 0 deletions components/lib/messages/MessagesBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,65 @@
import { ComponentBase } from '../componentbase/ComponentBase';
import { classNames } from '../utils/Utils';

const styles = `
.p-message-wrapper {
display: flex;
align-items: center;
}
.p-message-close {
display: flex;
align-items: center;
justify-content: center;
}
.p-message-close.p-link {
margin-left: auto;
overflow: hidden;
position: relative;
}
.p-message-enter {
opacity: 0;
}
.p-message-enter-active {
opacity: 1;
transition: opacity .3s;
}
.p-message-exit {
opacity: 1;
max-height: 1000px;
}
.p-message-exit-active {
opacity: 0;
max-height: 0;
margin: 0;
overflow: hidden;
transition: max-height .3s cubic-bezier(0, 1, 0, 1), opacity .3s, margin .3s;
}
.p-message-exit-active .p-message-close {
display: none;
}
`;

const classes = {
uimessage: {
root: ({ severity }) =>
classNames('p-message p-component', {
[`p-message-${severity}`]: severity
}),
wrapper: 'p-message-wrapper',
detail: 'p-message-detail',
summary: 'p-message-summary',
icon: 'p-message-icon',
buttonicon: 'p-message-close-icon',
button: 'p-message-close p-link'
}
};

export const MessagesBase = ComponentBase.extend({
defaultProps: {
Expand All @@ -10,5 +71,9 @@ export const MessagesBase = ComponentBase.extend({
onRemove: null,
onClick: null,
children: undefined
},
css: {
classes,
styles
}
});
27 changes: 9 additions & 18 deletions components/lib/messages/UIMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const UIMessage = React.memo(
const {
message: messageInfo,
metaData: parentMetaData,
ptCallbacks: { ptm, ptmo },
ptCallbacks: { ptm, ptmo, cx },
index
} = props;
const { severity, content, summary, detail, closable, life, sticky, className: _className, style, contentClassName: _contentClassName, contentStyle, icon: _icon, closeIcon: _closeIcon, pt } = messageInfo.message;
Expand Down Expand Up @@ -47,10 +47,10 @@ export const UIMessage = React.memo(
if (closable !== false) {
const ariaLabel = localeOption('close');

const iconProps = { className: 'p-message-close-icon', 'aria-hidden': true };
const buttonIconProps = mergeProps(
{
className: iconProps
className: cx('uimessage.buttonicon'),
'aria-hidden': true
},
ptm('buttonicon', parentParams),
ptmo(pt, 'buttonicon', params)
Expand All @@ -62,7 +62,7 @@ export const UIMessage = React.memo(
const buttonProps = mergeProps(
{
type: 'button',
className: 'p-message-close p-link',
className: cx('uimessage.button'),
'aria-label': ariaLabel,
onClick: onClose
},
Expand All @@ -83,10 +83,9 @@ export const UIMessage = React.memo(

const createMessage = () => {
if (props.message) {
const iconClassName = 'p-message-icon';
const iconProps = mergeProps(
{
className: iconClassName
className: cx('uimessage.icon')
},
ptm('icon', parentParams),
ptmo(pt, 'icon', params)
Expand Down Expand Up @@ -117,15 +116,15 @@ export const UIMessage = React.memo(

const summaryProps = mergeProps(
{
className: 'p-message-summary'
className: cx('uimessage.summary')
},
ptm('summary', parentParams),
ptmo(pt, 'summary', params)
);

const detailProps = mergeProps(
{
className: 'p-message-detail'
className: cx('uimessage.detail')
},
ptm('detail', parentParams),
ptmo(pt, 'detail', params)
Expand All @@ -145,20 +144,12 @@ export const UIMessage = React.memo(
return null;
};

const className = classNames(
'p-message p-component',
{
[`p-message-${severity}`]: severity
},
_className
);
const contentClassName = classNames('p-message-wrapper', _contentClassName);
const closeIcon = createCloseIcon();
const message = createMessage();

const wrapperProps = mergeProps(
{
className: contentClassName,
className: classNames(_contentClassName, cx('uimessage.wrapper')),
style: contentStyle
},
ptm('wrapper', parentParams),
Expand All @@ -168,7 +159,7 @@ export const UIMessage = React.memo(
const rootProps = mergeProps(
{
ref,
className,
className: classNames(_className, cx('uimessage.root', { severity })),
style,
onClick
},
Expand Down
5 changes: 5 additions & 0 deletions components/lib/messages/messages.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export interface MessagesMessage {
* @type {MessagesPassThroughOptions}
*/
pt?: MessagesPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}

/**
Expand Down
1 change: 0 additions & 1 deletion styles/primereact.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@import "../components/lib/iconbase/IconBase.css";
@import "../components/lib/datatable/DataTable.css";
@import "../components/lib/toast/Toast.css";
@import "../components/lib/messages/Messages.css";
@import "../components/lib/tooltip/Tooltip.css";
@import "../components/lib/treetable/TreeTable.css";
@import "../components/lib/ripple/Ripple.css";
Expand Down

0 comments on commit f3b0573

Please sign in to comment.