Skip to content

Commit e3eac97

Browse files
committed
fix + add more styling customizations for toast component
1 parent 8fda444 commit e3eac97

3 files changed

Lines changed: 53 additions & 14 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,11 @@ export const NotificationStyle = [
16091609
transformer: contrastText,
16101610
},
16111611
getStaticBorder("transparent"),
1612+
RADIUS,
1613+
BORDER_WIDTH,
1614+
BORDER_STYLE,
1615+
MARGIN,
1616+
PADDING,
16121617
] as const;
16131618

16141619
export const CascaderStyle = [

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

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,32 @@ import { stateComp } from "comps/generators/simpleGenerators";
1818
import { isEqual } from "lodash";
1919
import { createGlobalStyle } from "styled-components";
2020

21-
// Dynamic global styles for toast notifications - scoped by unique instance ID
22-
// Using high specificity selectors to override Ant Design's default styles
21+
2322
const ToastGlobalStyle = createGlobalStyle<{
2423
$instanceId: string;
2524
$background?: string;
2625
$textColor?: string;
2726
$border?: string;
27+
$borderWidth?: string;
28+
$borderStyle?: string;
29+
$radius?: string;
30+
$margin?: string;
31+
$padding?: string;
32+
$width?: string;
2833
}>`
29-
.ant-notification .ant-notification-notice-wrapper .ant-notification-notice.lowcoder-toast-${props => props.$instanceId} {
34+
.ant-notification .ant-notification-notice-wrapper:has(.lowcoder-toast-${props => props.$instanceId}) {
3035
background: ${props => props.$background || 'inherit'};
31-
border: ${props => props.$border && props.$border !== 'transparent'
32-
? `1px solid ${props.$border}`
33-
: 'none'};
36+
border-color: ${props => props.$border || 'transparent'};
37+
border-width: ${props => props.$borderWidth || '0'};
38+
border-style: ${props => props.$borderStyle || 'solid'};
39+
border-radius: ${props => props.$radius || '8px'};
40+
${props => props.$margin ? `margin: ${props.$margin};` : ''}
41+
${props => props.$width ? `width: ${props.$width};` : ''}
42+
${props => props.$padding ? `padding: ${props.$padding};` : ''}
43+
44+
.ant-notification-notice {
45+
background: transparent;
46+
}
3447
3548
.ant-notification-notice-message,
3649
.ant-notification-notice-description {
@@ -47,21 +60,18 @@ const toastTypeOptions = [
4760
{ label: trans("toastComp.typeError"), value: "error" },
4861
] as const;
4962

50-
// Placement options for notification position
5163
const placementOptions = [
5264
{ label: trans("toastComp.placementTopLeft"), value: "topLeft" },
5365
{ label: trans("toastComp.placementTopRight"), value: "topRight" },
5466
{ label: trans("toastComp.placementBottomLeft"), value: "bottomLeft" },
5567
{ label: trans("toastComp.placementBottomRight"), value: "bottomRight" },
5668
] as const;
5769

58-
// Event options for toast
5970
const ToastEventOptions = [
6071
{ label: trans("toastComp.click"), value: "click", description: trans("toastComp.clickDesc") },
6172
{ label: trans("toastComp.close"), value: "close", description: trans("toastComp.closeDesc") },
6273
] as const;
6374

64-
// Method parameters for programmatic API
6575
const showParams: ParamsConfig = [
6676
{ name: "text", type: "string" },
6777
{ name: "options", type: "JSON" },
@@ -87,6 +97,9 @@ const childrenMap = {
8797
showProgress: withDefault(BoolControl, false),
8898
pauseOnHover: withDefault(BoolControl, true),
8999

100+
// Layout
101+
width: withDefault(StringControl, ""),
102+
90103
// Event handlers
91104
onEvent: eventHandlerControl(ToastEventOptions),
92105

@@ -96,6 +109,11 @@ const childrenMap = {
96109
background: "",
97110
color: "",
98111
border: "",
112+
radius: "",
113+
borderWidth: "",
114+
borderStyle: "",
115+
margin: "",
116+
padding: "",
99117
}),
100118

101119
// Internal state for tracking visibility
@@ -242,6 +260,14 @@ const ToastPropertyView = React.memo((props: { comp: any }) => {
242260
})}
243261
</Section>
244262

263+
<Section name={sectionNames.layout}>
264+
{comp.children.width.propertyView({
265+
label: trans("toastComp.width"),
266+
tooltip: trans("toastComp.widthTooltip"),
267+
placeholder: "384",
268+
})}
269+
</Section>
270+
245271
<Section name={sectionNames.interaction}>
246272
{comp.children.onEvent.getPropertyView()}
247273
</Section>
@@ -256,14 +282,12 @@ const ToastPropertyView = React.memo((props: { comp: any }) => {
256282
ToastPropertyView.displayName = "ToastPropertyView";
257283

258284
/**
259-
* Toast runtime view:
260-
* - Resolves theme-dependent style values and stores them in `resolvedStyle`
261-
* - Generates unique instance ID for scoped styling
262-
* - Injects global styles scoped to this toast instance
285+
* Toast runtime view
263286
*/
264287
const ToastRuntimeView = React.memo((props: { comp: any }) => {
265288
const { comp } = props;
266289
const style = comp.children.style.getView() as NotificationStyleType;
290+
const width = comp.children.width.getView() as string;
267291
const instanceId = useId().replace(/:/g, '-');
268292

269293
// Store instance ID and resolved styles
@@ -284,6 +308,12 @@ const ToastRuntimeView = React.memo((props: { comp: any }) => {
284308
$background={style.background}
285309
$textColor={style.color}
286310
$border={style.border}
311+
$borderWidth={style.borderWidth}
312+
$borderStyle={style.borderStyle}
313+
$radius={style.radius}
314+
$margin={style.margin}
315+
$padding={style.padding || '20px'}
316+
$width={width ? `${width}px` : undefined}
287317
/>
288318
);
289319
});
@@ -307,6 +337,7 @@ let ToastCompWithExposing = withExposingConfigs(ToastCompBase, [
307337
new NameConfig("type", trans("toastComp.typeDesc")),
308338
new NameConfig("duration", trans("toastComp.durationDesc")),
309339
new NameConfig("placement", trans("toastComp.placementDesc")),
340+
new NameConfig("width", trans("toastComp.widthDesc")),
310341
]);
311342

312343
// Add method exposing

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,8 @@ export const en = {
32993299
"showProgressTooltip": "Display a progress bar indicating time until auto-close",
33003300
"pauseOnHover": "Pause on Hover",
33013301
"behavior": "Behavior",
3302+
"width": "Width",
3303+
"widthTooltip": "Width of the notification in pixels. Example: 384",
33023304

33033305
// Type options
33043306
"typeInfo": "Info",
@@ -3324,7 +3326,8 @@ export const en = {
33243326
"descriptionDesc": "The configured description of the notification",
33253327
"typeDesc": "The configured type (info, success, warning, error)",
33263328
"durationDesc": "The configured duration in seconds",
3327-
"placementDesc": "The configured placement position"
3329+
"placementDesc": "The configured placement position",
3330+
"widthDesc": "The configured width of the notification"
33283331
},
33293332
"themeComp": {
33303333
"switchTo": "Switch Theme"

0 commit comments

Comments
 (0)