Skip to content

Commit

Permalink
Allow to toggle NotificationAlert text wrap (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
bayasdev authored Oct 22, 2024
1 parent 860db19 commit b492262
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface NotificationAlertConstruct {
variant?: NotificationVariant;
shadow?: boolean;
designMode?: AlertDesignMode;
wrapText?: boolean;
sx?: OverrideTheme;
}

Expand Down
39 changes: 29 additions & 10 deletions src/components/NotificationAlert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Index: FC<NotificationAlertPrp & HTMLAttributes<HTMLDivElement>> = ({
emphasisMode = "subtle",
variant = "information",
shadow = false,
wrapText = false,
isLoading,
id,
sx,
Expand Down Expand Up @@ -95,6 +96,33 @@ const Index: FC<NotificationAlertPrp & HTMLAttributes<HTMLDivElement>> = ({
},
});

const wrapTextStyles = useMemo(() => {
if (wrapText) {
return css({
"& .alertInitLine": {
"& .notificationTitle": {
"& .cardTitle": {
display: "-webkit-box",
WebkitLineClamp: 1,
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
},
},
"& .content": {
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
},
},
});
} else {
return {};
}
}, [wrapText]);

const baseStyle = css({
display: "flex",
width: "100%",
Expand Down Expand Up @@ -176,11 +204,6 @@ const Index: FC<NotificationAlertPrp & HTMLAttributes<HTMLDivElement>> = ({
overflowWrap: "break-word",
whiteSpace: "normal",
minWidth: 0,
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
},
},
"& .cardContent": {
Expand All @@ -192,11 +215,6 @@ const Index: FC<NotificationAlertPrp & HTMLAttributes<HTMLDivElement>> = ({
overflowWrap: "break-word",
whiteSpace: "normal",
minWidth: 0,
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
},
"& .actionCardMode": {
lineHeight: 1,
Expand All @@ -214,6 +232,7 @@ const Index: FC<NotificationAlertPrp & HTMLAttributes<HTMLDivElement>> = ({
baseStyle,
designMode === "banner" ? bannerStyle : cardStyle,
overrideThemes,
wrapTextStyles,
]}
className={"notification-alert"}
id={id}
Expand Down
7 changes: 6 additions & 1 deletion src/components/Notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ const Notifications: React.FC<NotificationsProps> = ({
return (
<div css={[notificationsContainerStyles(position)]} key={position}>
{notifications.map((notification) => {
const { children, shadow = true } = notification.options;
const {
children,
wrapText = true,
shadow = true,
} = notification.options;

const title = children ? notification.message : undefined;
const content = children || notification.message;
Expand All @@ -97,6 +101,7 @@ const Notifications: React.FC<NotificationsProps> = ({
onClose={() =>
NotificationManager.removeNotification(notification.id)
}
wrapText={wrapText}
shadow={shadow}
{...notification.options}
>
Expand Down

0 comments on commit b492262

Please sign in to comment.