Skip to content

Commit

Permalink
Refactor #4602 - for Message
Browse files Browse the repository at this point in the history
  • Loading branch information
habubey committed Jul 6, 2023
1 parent dd95b2e commit 7712c0b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
15 changes: 0 additions & 15 deletions components/lib/message/Message.css

This file was deleted.

31 changes: 11 additions & 20 deletions components/lib/message/Message.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as React from 'react';
import { classNames, IconUtils, ObjectUtils, mergeProps } from '../utils/Utils';
import { MessageBase } from './MessageBase';
import { PrimeReactContext } from '../api/Api';
import { useStyle } from '../hooks/Hooks';
import { CheckIcon } from '../icons/check';
import { ExclamationTriangleIcon } from '../icons/exclamationtriangle';
import { InfoCircleIcon } from '../icons/infocircle';
import { TimesCircleIcon } from '../icons/timescircle';
import { CheckIcon } from '../icons/check';
import { PrimeReactContext } from '../api/Api';
import { IconUtils, ObjectUtils, mergeProps } from '../utils/Utils';
import { MessageBase } from './MessageBase';

export const Message = React.memo(
React.forwardRef((inProps, ref) => {
Expand All @@ -14,7 +15,9 @@ export const Message = React.memo(

const elementRef = React.useRef(null);

const { ptm } = MessageBase.setMetaData({
useStyle(MessageBase.css.styles, { name: 'primereact_message_style' });

const { ptm, cx } = MessageBase.setMetaData({
props
});

Expand All @@ -24,11 +27,10 @@ export const Message = React.memo(
}

const text = ObjectUtils.getJSXElement(props.text, props);
let iconClassName = 'p-inline-message-icon';

const iconProps = mergeProps(
{
className: iconClassName
className: cx('icon')
},
ptm('icon')
);
Expand Down Expand Up @@ -58,7 +60,7 @@ export const Message = React.memo(

const textProps = mergeProps(
{
className: 'p-inline-message-text'
className: cx('text')
},
ptm('text')
);
Expand All @@ -76,24 +78,13 @@ export const Message = React.memo(
getElement: () => elementRef.current
}));

const className = classNames(
'p-inline-message p-component',
{
'p-inline-message-info': props.severity === 'info',
'p-inline-message-warn': props.severity === 'warn',
'p-inline-message-error': props.severity === 'error',
'p-inline-message-success': props.severity === 'success',
'p-inline-message-icon-only': !props.text
},
props.className
);
const content = createContent();

const rootProps = mergeProps(
{
id: props.id,
ref: elementRef,
className,
className: cx('root'),
style: props.style,
role: 'alert',
'aria-live': 'polite'
Expand Down
36 changes: 36 additions & 0 deletions components/lib/message/MessageBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentBase } from '../componentbase/ComponentBase';
import { classNames } from '../utils/utils';

export const MessageBase = ComponentBase.extend({
defaultProps: {
Expand All @@ -11,5 +12,40 @@ export const MessageBase = ComponentBase.extend({
severity: 'info',
content: null,
children: undefined
},
css: {
classes: {
root: ({ props }) =>
classNames(
'p-inline-message p-component',
{
'p-inline-message-info': props.severity === 'info',
'p-inline-message-warn': props.severity === 'warn',
'p-inline-message-error': props.severity === 'error',
'p-inline-message-success': props.severity === 'success',
'p-inline-message-icon-only': !props.text
},
props.className
),
icon: 'p-inline-message-icon',
text: 'p-inline-message-text'
},
styles: `
.p-inline-message {
display: inline-flex;
align-items: center;
justify-content: center;
vertical-align: top;
}
.p-inline-message-icon-only .p-inline-message-text {
visibility: hidden;
width: 0;
}
.p-fluid .p-inline-message {
display: flex;
}
`
}
});
5 changes: 5 additions & 0 deletions components/lib/message/message.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export interface MessageProps extends Omit<React.DetailedHTMLProps<React.HTMLAtt
* @type {MessagePassThroughOptions}
*/
pt?: MessagePassThroughOptions;
/**
* 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 @@ -29,7 +29,6 @@
@import "../components/lib/menu/Menu.css";
@import "../components/lib/megamenu/MegaMenu.css";
@import "../components/lib/menubar/Menubar.css";
@import "../components/lib/message/Message.css";
@import "../components/lib/messages/Messages.css";
@import "../components/lib/multiselect/MultiSelect.css";
@import "../components/lib/orderlist/OrderList.css";
Expand Down

0 comments on commit 7712c0b

Please sign in to comment.