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

Fixed #3196: Message: Override Icon using icon attribute #3214

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions components/doc/messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,12 @@ messages.current.show({ life: 5000, severity: 'error', summary: 'Error Message',
<td>null</td>
<td>Style class of the element.</td>
</tr>
<tr>
<td>icon</td>
<td>string</td>
<td>null</td>
<td>Customize icon class of icon attributes</td>
</tr>
<tr>
<td>style</td>
<td>string</td>
Expand Down Expand Up @@ -714,6 +720,12 @@ messages.current.show({ life: 5000, severity: 'error', summary: 'Error Message',
<td>null</td>
<td>Unique identifier of the element.</td>
</tr>
<tr>
<td>icon</td>
<td>string</td>
<td>null</td>
<td>Customize icon class of icon attributes</td>
</tr>
<tr>
<td>className</td>
<td>string</td>
Expand Down
23 changes: 16 additions & 7 deletions components/lib/message/Message.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import * as React from 'react';
import { classNames, ObjectUtils } from '../utils/Utils';
import { classNames, IconUtils, ObjectUtils } from '../utils/Utils';

export const Message = React.memo(
React.forwardRef((props, ref) => {
const elementRef = React.useRef(null);

const createIcon = () => {
return IconUtils.getJSXIcon(props.icon, { ...props.iconProps });
};

const createContent = () => {
if (props.content) {
return ObjectUtils.getJSXElement(props.content, props);
}

const text = ObjectUtils.getJSXElement(props.text, props);
const icon = classNames('p-inline-message-icon pi', {
'pi-info-circle': props.severity === 'info',
'pi-exclamation-triangle': props.severity === 'warn',
'pi-times-circle': props.severity === 'error',
'pi-check': props.severity === 'success'
'': props.severity === 'info',
'': props.severity === 'warn',
'': props.severity === 'error',
'': props.severity === 'success'
});

return (
Expand Down Expand Up @@ -44,9 +48,11 @@ export const Message = React.memo(
props.className
);
const content = createContent();
const icon = createIcon();

return (
<div id={props.id} ref={elementRef} className={className} style={props.style} {...otherProps} role="alert" aria-live="polite">
{icon}
{content}
</div>
);
Expand All @@ -60,6 +66,9 @@ Message.defaultProps = {
className: null,
style: null,
text: null,
severity: 'info',
content: null
severity: null,
content: null,
icon: 'pi pi-info-circle',
iconProps: null,
iconPos: 'left'
};
3 changes: 3 additions & 0 deletions components/lib/message/message.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { IconType } from '../utils';

type MessageSeverityType = 'success' | 'info' | 'warn' | 'error';

Expand All @@ -11,6 +12,8 @@ export interface MessageProps extends Omit<React.DetailedHTMLProps<React.HTMLAtt
severity?: MessageSeverityType;
content?: MessageContentType;
children?: React.ReactNode;
icon?: IconType<MessageProps>;
iconProps?: React.HTMLAttributes<HTMLSpanElement>;
}

export declare class Message extends React.Component<MessageProps, any> {
Expand Down
8 changes: 4 additions & 4 deletions pages/messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const MessagesDemo = () => {

useEffect(() => {
msgs1.current.show([
{ severity: 'success', summary: 'Success', detail: 'Message Content', sticky: true },
{ severity: 'success', icon: 'pi pi-apple', summary: 'Success', detail: 'Message Content', sticky: true },
{ severity: 'info', summary: 'Info', detail: 'Message Content', sticky: true },
{ severity: 'warn', summary: 'Warning', detail: 'Message Content', sticky: true },
{ severity: 'error', summary: 'Error', detail: 'Message Content', sticky: true }
Expand Down Expand Up @@ -82,13 +82,13 @@ const MessagesDemo = () => {
<Message severity="info" text="Message Content" />
</div>
<div className="col-12 md:col-3">
<Message severity="success" text="Message Content" />
<Message severity="success" icon="pi pi-check" text="Message Content" />
</div>
<div className="col-12 md:col-3">
<Message severity="warn" text="Message Content" />
<Message severity="warn" icon="pi pi-exclamation-triangle" text="Message Content" />
</div>
<div className="col-12 md:col-3">
<Message severity="error" text="Message Content" />
<Message severity="error" icon="pi pi-times-circle" text="Message Content" />
</div>
</div>

Expand Down