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

Ensure stable references in useNotification hook #1055

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 20 additions & 26 deletions src/components/NotificationAlert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,26 @@ 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",
},
const wrapTextStyles = css({
"& .alertInitLine": {
"& .notificationTitle": {
"& .cardTitle": {
display: "-webkit-box",
WebkitLineClamp: 1,
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
},
});
} else {
return {};
}
}, [wrapText]);
},
"& .content": {
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: "vertical",
overflow: "hidden",
textOverflow: "ellipsis",
},
},
});

const baseStyle = css({
display: "flex",
Expand Down Expand Up @@ -231,8 +225,8 @@ const Index: FC<NotificationAlertPrp & HTMLAttributes<HTMLDivElement>> = ({
css={[
baseStyle,
designMode === "banner" ? bannerStyle : cardStyle,
...(wrapText ? [wrapTextStyles] : []),
overrideThemes,
wrapTextStyles,
]}
className={"notification-alert"}
id={id}
Expand Down
16 changes: 14 additions & 2 deletions src/components/Notifications/Notifications.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { useCallback } from "react";
import { useCallback, useMemo } from "react";

import NotificationManager from "./NotificationManager";
import { NotificationOptions } from "./Notifications.types";
Expand Down Expand Up @@ -59,5 +59,17 @@ export const useNotification = () => {
NotificationManager.clearNotifications();
}, []);

return { success, danger, warning, information, neutral, clear };
const notification = useMemo(
() => ({
success,
danger,
warning,
information,
neutral,
clear,
}),
[success, danger, warning, information, neutral, clear],
);

return notification;
};
Loading