Skip to content

Commit 8c83d9e

Browse files
Merge pull request #2115 from iamfaran/feat/toast-notify
[Feat]: Toast / Notification Component
2 parents 6a300eb + 4741f03 commit 8c83d9e

File tree

14 files changed

+639
-102
lines changed

14 files changed

+639
-102
lines changed

client/packages/lowcoder/src/comps/controls/styleControlConstants.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,61 @@ export const ModalStyle = [
16121612
BACKGROUND_IMAGE_ORIGIN,
16131613
] as const;
16141614

1615+
1616+
export const NotificationStyle = [
1617+
getBackground("primarySurface"),
1618+
{
1619+
name: "color",
1620+
label: trans("color"),
1621+
depName: "background",
1622+
depType: DEP_TYPE.CONTRAST_TEXT,
1623+
transformer: contrastText,
1624+
},
1625+
{
1626+
name: "closeIconColor",
1627+
label: trans("toastComp.closeIconColor"),
1628+
depName: "background",
1629+
depType: DEP_TYPE.CONTRAST_TEXT,
1630+
transformer: contrastText,
1631+
},
1632+
{
1633+
name: "infoIconColor",
1634+
label: trans("toastComp.infoIconColor"),
1635+
color: "#1890ff",
1636+
},
1637+
{
1638+
name: "successIconColor",
1639+
label: trans("toastComp.successIconColor"),
1640+
color: "#52c41a",
1641+
},
1642+
{
1643+
name: "warningIconColor",
1644+
label: trans("toastComp.warningIconColor"),
1645+
color: "#faad14",
1646+
},
1647+
{
1648+
name: "errorIconColor",
1649+
label: trans("toastComp.errorIconColor"),
1650+
color: "#ff4d4f",
1651+
},
1652+
{
1653+
name: "progressColor",
1654+
label: trans("toastComp.progressColor"),
1655+
color: "#1890ff",
1656+
},
1657+
{
1658+
name: "progressBackground",
1659+
label: trans("toastComp.progressBackground"),
1660+
color: "#e8e8e8",
1661+
},
1662+
getStaticBorder("transparent"),
1663+
RADIUS,
1664+
BORDER_WIDTH,
1665+
BORDER_STYLE,
1666+
MARGIN,
1667+
PADDING,
1668+
] as const;
1669+
16151670
export const CascaderStyle = [
16161671
...getStaticBgBorderRadiusByBg(SURFACE_COLOR, "pc"),
16171672
TEXT,
@@ -2502,6 +2557,7 @@ export type ChildrenMultiSelectStyleType = StyleConfigType<
25022557
export type TabContainerStyleType = StyleConfigType<typeof TabContainerStyle>;
25032558
export type TabBodyStyleType = StyleConfigType<typeof TabBodyStyle>;
25042559
export type ModalStyleType = StyleConfigType<typeof ModalStyle>;
2560+
export type NotificationStyleType = StyleConfigType<typeof NotificationStyle>;
25052561
export type CascaderStyleType = StyleConfigType<typeof CascaderStyle>;
25062562
export type CheckboxStyleType = StyleConfigType<typeof CheckboxStyle>;
25072563
export type RadioStyleType = StyleConfigType<typeof RadioStyle>;

client/packages/lowcoder/src/comps/hooks/hookCompTypes.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ const HookCompConfig: Record<
6060
},
6161
utils: { category: "hide" },
6262
message: { category: "hide" },
63-
toast: { category: "hide" },
63+
toast: {
64+
category: "ui",
65+
singleton: false,
66+
},
6467
};
6568

6669
// Get hook component category

client/packages/lowcoder/src/comps/hooks/toastComp.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React from "react";
2+
import { Section, sectionNames } from "lowcoder-design";
3+
import { trans } from "i18n";
4+
5+
/**
6+
* Property view for toast component configuration
7+
*/
8+
export const ToastPropertyView = React.memo((props: { comp: any }) => {
9+
const { comp } = props;
10+
11+
return (
12+
<>
13+
<Section name={sectionNames.basic}>
14+
{comp.children.title.propertyView({
15+
label: trans("toastComp.title"),
16+
placeholder: trans("toastComp.titlePlaceholder"),
17+
})}
18+
{comp.children.description.propertyView({
19+
label: trans("toastComp.description"),
20+
placeholder: trans("toastComp.descriptionPlaceholder"),
21+
})}
22+
{comp.children.type.propertyView({
23+
label: trans("toastComp.type"),
24+
})}
25+
</Section>
26+
27+
<Section name={trans("toastComp.behavior")}>
28+
{comp.children.duration.propertyView({
29+
label: trans("toastComp.duration"),
30+
tooltip: trans("toastComp.durationTooltip"),
31+
placeholder: "4.5",
32+
})}
33+
{comp.children.placement.propertyView({
34+
label: trans("toastComp.placement"),
35+
})}
36+
{comp.children.dismissible.propertyView({
37+
label: trans("toastComp.dismissible"),
38+
})}
39+
{comp.children.showProgress.propertyView({
40+
label: trans("toastComp.showProgress"),
41+
tooltip: trans("toastComp.showProgressTooltip"),
42+
})}
43+
{comp.children.pauseOnHover.propertyView({
44+
label: trans("toastComp.pauseOnHover"),
45+
})}
46+
</Section>
47+
48+
<Section name={sectionNames.layout}>
49+
{comp.children.width.propertyView({
50+
label: trans("toastComp.width"),
51+
tooltip: trans("toastComp.widthTooltip"),
52+
placeholder: "384px or 100vw",
53+
})}
54+
{comp.children.progressHeight.propertyView({
55+
label: trans("toastComp.progressHeight"),
56+
tooltip: trans("toastComp.progressHeightTooltip"),
57+
placeholder: "4px",
58+
})}
59+
</Section>
60+
61+
<Section name={sectionNames.interaction}>
62+
{comp.children.onEvent.getPropertyView()}
63+
</Section>
64+
65+
<Section name={sectionNames.style}>
66+
{comp.children.style.getPropertyView()}
67+
</Section>
68+
</>
69+
);
70+
});
71+
72+
ToastPropertyView.displayName = "ToastPropertyView";
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useEffect, useId } from "react";
2+
import { NotificationStyleType } from "comps/controls/styleControlConstants";
3+
import { ToastGlobalStyle } from "./toastStyles";
4+
5+
/**
6+
* Toast runtime view - injects global CSS styles for the notification.
7+
*/
8+
export const ToastRuntimeView = React.memo((props: { comp: any }) => {
9+
const { comp } = props;
10+
const style = comp.children.style.getView() as NotificationStyleType;
11+
const width = comp.children.width.getView() as string;
12+
const progressHeight = comp.children.progressHeight.getView() as string;
13+
const instanceId = useId().replace(/:/g, '-');
14+
15+
// Store instance ID so the show() method can use it for the notification className
16+
useEffect(() => {
17+
comp.children.instanceId.dispatchChangeValueAction(instanceId);
18+
}, [comp, instanceId]);
19+
20+
return (
21+
<ToastGlobalStyle
22+
$instanceId={instanceId}
23+
$background={style.background}
24+
$textColor={style.color}
25+
$closeIconColor={style.closeIconColor}
26+
$infoIconColor={style.infoIconColor}
27+
$successIconColor={style.successIconColor}
28+
$warningIconColor={style.warningIconColor}
29+
$errorIconColor={style.errorIconColor}
30+
$progressColor={style.progressColor}
31+
$progressBackground={style.progressBackground}
32+
$progressHeight={progressHeight || undefined}
33+
$border={style.border}
34+
$borderWidth={style.borderWidth}
35+
$borderStyle={style.borderStyle}
36+
$radius={style.radius}
37+
$margin={style.margin}
38+
$padding={style.padding || '20px'}
39+
$width={width || undefined}
40+
/>
41+
);
42+
});
43+
44+
ToastRuntimeView.displayName = "ToastRuntimeView";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { ToastComp } from "./toastComp";
2+
export type { ToastType } from "./toastConstants";

0 commit comments

Comments
 (0)