Skip to content

Commit ef1f136

Browse files
feat: add showIcon to show default icon
1 parent ff7a733 commit ef1f136

2 files changed

Lines changed: 85 additions & 4 deletions

File tree

apps/demo/src/Views/Ui/components/Message.tsx

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
11
import { useTranslation } from "@dzangolab/react-i18n";
2-
import { Button, Message, Page } from "@dzangolab/react-ui";
2+
import { Button, Message, Page, TDataTable } from "@dzangolab/react-ui";
33
import { useNavigate } from "react-router-dom";
44

55
import { CodeBlock, Section } from "../../../components/Demo";
66

7+
const data = [
8+
{
9+
default: "false",
10+
description:
11+
"Displays a close icon if true, allowing the message to be dismissed.",
12+
prop: "enableClose",
13+
type: "boolean",
14+
},
15+
{
16+
default: "-",
17+
description: "Icon to display alongside the message.",
18+
prop: "icon",
19+
type: "string | ReactNode ",
20+
},
21+
{
22+
default: "-",
23+
description: "The message text to display in the component.",
24+
prop: "message",
25+
type: "string",
26+
},
27+
{
28+
default: "-",
29+
description: "Function to be called when the message is closed.",
30+
prop: "onClose",
31+
type: "() => void",
32+
},
33+
{
34+
default: "info",
35+
description:
36+
"Defines the styling severity of the message. Defaults to 'info'.",
37+
prop: "severity",
38+
type: `"info" | "success" | "warning" | "danger"`,
39+
},
40+
{
41+
default: "true",
42+
description:
43+
"Show default icon based on severity or custom icon if provided.",
44+
prop: "showIcon",
45+
type: "boolean",
46+
},
47+
];
48+
749
export const MessageDemo = () => {
850
const [t] = useTranslation("ui");
951
const navigate = useNavigate();
@@ -80,6 +122,30 @@ export const MessageDemo = () => {
80122
<Message message="Danger Message" severity="danger" />'
81123
/>
82124
</Section>
125+
<Section
126+
title={t("headers.propertiesValue", {
127+
value: "IButtonProperties",
128+
})}
129+
>
130+
<TDataTable
131+
columns={[
132+
{
133+
accessorKey: "prop",
134+
header: "Properties",
135+
},
136+
{
137+
accessorKey: "type",
138+
header: "Type",
139+
},
140+
{
141+
accessorKey: "description",
142+
header: "Description",
143+
},
144+
]}
145+
data={data}
146+
paginated={false}
147+
/>
148+
</Section>
83149
</Page>
84150
);
85151
};

packages/ui/src/Message/index.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { ReactNode, useState } from "react";
22

33
type MessageProperties = {
44
enableClose?: boolean;
5+
icon?: string | ReactNode;
56
message: string;
67
onClose?: () => void;
7-
icon?: string | ReactNode;
88
severity?: "info" | "success" | "warning" | "danger";
9+
showIcon?: boolean;
910
};
1011

1112
const Message = ({
@@ -14,9 +15,17 @@ const Message = ({
1415
message,
1516
icon,
1617
severity = "info",
18+
showIcon = true,
1719
}: MessageProperties) => {
1820
const [showMessage, setShowMessage] = useState(true);
1921

22+
const defaultSeverityIcons = {
23+
info: "pi pi-info-circle",
24+
success: "pi pi-check-circle",
25+
warning: "pi pi-exclamation-triangle",
26+
danger: "pi pi-times-circle",
27+
};
28+
2029
const handleClose = () => {
2130
setShowMessage(false);
2231
if (onClose) {
@@ -31,14 +40,20 @@ const Message = ({
3140
const renderIcon = () => {
3241
return (
3342
<span className="icon" data-testid="icon">
34-
{typeof icon === "string" ? <i className={icon} /> : icon}
43+
{!icon ? (
44+
<i className={defaultSeverityIcons[severity]} />
45+
) : typeof icon === "string" ? (
46+
<i className={icon} />
47+
) : (
48+
icon
49+
)}
3550
</span>
3651
);
3752
};
3853

3954
return (
4055
<div className={`message ${severity}`}>
41-
{icon && renderIcon()}
56+
{showIcon && renderIcon()}
4257
<span className="message-content">{message}</span>
4358
{enableClose && (
4459
<span className="close-message" onClick={handleClose}>

0 commit comments

Comments
 (0)