Skip to content

Commit 7e1e523

Browse files
authored
feat: Add a new property to hide the delete button and display a skeleton loader without avatar if hideAvatar is enabled
1 parent 8cd55bf commit 7e1e523

File tree

7 files changed

+65
-36
lines changed

7 files changed

+65
-36
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ darkMode | Toggle to enable dark mode | boolean | false |
6464
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
6565
windowViewOnly | Toggle to enable fit-to-screen window or modal view | boolean | false |
6666
notificationIcon | Option to use custom notification Icon | JSX Element | null |
67-
inboxHeaderProps | Props for customizing the header.<br> title - Title of the notification inbox<br> hideHeader - Toggle to hide or show the header section.<br> hideClearAll - Toggle to hide or show the clear all button.<br> customHeader - Custom header component. | InboxHeaderProps| { title: '', hideHeader: false, hideClearAll: false, customHeader: null } |
68-
cardProps | Props for customizing the notification cards..<br> hideAvatar - Toggle to hide or show the avatar.<br> disableAutoMarkAsRead - Toggle to disable or enable the markAsRead functionality on card click | CardProps | { hideAvatar: false, disableAutoMarkAsRead: false } |
67+
inboxHeaderProps | Props for customizing the header.<br> title - Title of the notification inbox<br> hideHeader - Toggle to hide or show the header section.<br> hideClearAll - Toggle to hide or show the clear all button.<br> customHeader - Custom header component. | InboxHeaderProps| { title: 'Notifications', <br>hideHeader: false,<br> hideClearAll: false, <br>customHeader: null } |
68+
cardProps | Props for customizing the notification cards. <br>hideDelete - Toggle to hide or show delete icon<br> hideAvatar - Toggle to hide or show the avatar.<br> disableAutoMarkAsRead - Toggle to disable or enable the markAsRead functionality on card click | CardProps | { hideDelete: false,<br> hideAvatar: false,<br> disableAutoMarkAsRead: false } |
6969
customNotificationCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
7070
onNotificationCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
7171
listEmptyComponent | Custom component for empty notification list | JSX Element | null |
@@ -193,6 +193,7 @@ Please note that the badgeStyle, window shadow and border props are only applica
193193

194194
```js
195195
type CardProps = {
196+
hideDelete?: boolean;
196197
hideAvatar?: boolean,
197198
disableAutoMarkAsRead?: boolean,
198199
};
@@ -301,10 +302,13 @@ export function MyContainer(): React.JSX.Element {
301302
return (
302303
<div>
303304
<SirenInbox
304-
title="Notifications"
305-
hideHeader={false}
305+
inboxHeaderProps={
306+
title: "Notifications",
307+
hideHeader: false
308+
}
306309
darkMode={false}
307310
cardProps={{
311+
hideDelete: false,
308312
hideAvatar: false,
309313
disableAutoMarkAsRead: false,
310314
}}

src/components/Card.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const Card: FC<NotificationCardProps> = ({
5252
}) => {
5353
const { id, createdAt, message, isRead } = notification;
5454
const { avatar, header, subHeader, body } = message;
55-
const { hideAvatar, disableAutoMarkAsRead } = cardProps ?? {};
55+
const { hideAvatar, hideDelete, disableAutoMarkAsRead } = cardProps ?? {};
5656
const {
5757
markAsRead
5858
} = useSiren();
@@ -125,16 +125,18 @@ const Card: FC<NotificationCardProps> = ({
125125
</div>
126126
</div>
127127
</div>
128-
<div
129-
data-testid={`delete-${notification.id}`}
130-
className="siren-sdk-delete-button"
131-
onClick={onDelete}
132-
>
133-
<CloseIcon
134-
color={styles?.deleteIcon.color}
135-
size={styles.deleteIcon.size}
136-
/>
137-
</div>
128+
{!hideDelete && (
129+
<div
130+
data-testid={`delete-${notification.id}`}
131+
className="siren-sdk-delete-button"
132+
onClick={onDelete}
133+
>
134+
<CloseIcon
135+
color={styles?.deleteIcon.color}
136+
size={styles.deleteIcon.size}
137+
/>
138+
</div>
139+
)}
138140
</div>
139141
);
140142
};

src/components/Loader.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import React from "react";
1+
import React, { type FC } from "react";
22

33
import "../styles/loader.css";
4-
import type { SirenStyleProps } from "../types";
4+
import type { LoaderProps } from "../types";
55

6-
const Loader = ({styles}: {styles: SirenStyleProps}) => {
6+
const Loader : FC<LoaderProps> = ({
7+
hideAvatar,
8+
styles,
9+
10+
}) => {
711
return (
812
<div className="siren-sdk-skeleton-container">
9-
<div className="siren-sdk-skeleton-grid">
10-
<div className="siren-sdk-skeleton-avatar siren-sdk-skeleton" style={styles.loader} />
13+
<div className={`${!hideAvatar ? 'siren-sdk-skeleton-grid-with-avatar' : 'siren-sdk-skeleton-grid-without-avatar' }`}>
14+
{!hideAvatar && (<div className="siren-sdk-skeleton-avatar siren-sdk-skeleton" style={styles.loader} />)}
1115
<div className="siren-sdk-skeleton-head siren-sdk-skeleton" style={styles.loader} />
1216
<div className="siren-sdk-skeleton-subtitle siren-sdk-skeleton" style={styles.loader} />
1317
<div className="siren-sdk-skeleton-body siren-sdk-skeleton" style={styles.loader}/>

src/components/SirenPanel.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,22 @@ const SirenPanel: FC<SirenPanelProps> = ({
315315
};
316316

317317
const renderList = () => {
318-
if (isLoading && isEmptyArray(notifications))
318+
if (isLoading && isEmptyArray(notifications)) {
319+
const hideAvatar = cardProps?.hideAvatar || false;
320+
319321
return (
320322
<div className="siren-sdk-list-loader-container">
321-
{customLoader || (
322-
<>
323-
<AnimatedLoader styles={styles} />
324-
<AnimatedLoader styles={styles} />
325-
<AnimatedLoader styles={styles} />
326-
<AnimatedLoader styles={styles} />
327-
<AnimatedLoader styles={styles} />
328-
</>
329-
)}
323+
{customLoader ||
324+
<>
325+
<AnimatedLoader styles={styles} hideAvatar={hideAvatar}/>
326+
<AnimatedLoader styles={styles} hideAvatar={hideAvatar}/>
327+
<AnimatedLoader styles={styles} hideAvatar={hideAvatar}/>
328+
<AnimatedLoader styles={styles} hideAvatar={hideAvatar}/>
329+
<AnimatedLoader styles={styles} hideAvatar={hideAvatar}/>
330+
</>}
330331
</div>
331332
);
333+
}
332334

333335
if (error)
334336
return (

src/styles/loader.css

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
}
1717

18-
.siren-sdk-skeleton-grid {
18+
.siren-sdk-skeleton-grid-with-avatar {
1919
display: grid;
2020
grid-template-columns: 70px 10px auto auto auto auto 25px;
2121
grid-template-areas:
@@ -26,6 +26,17 @@
2626
gap:8px ;
2727
}
2828

29+
.siren-sdk-skeleton-grid-without-avatar {
30+
display: grid;
31+
grid-template-columns: 10px auto auto auto auto 25px;
32+
grid-template-areas:
33+
'header header header header header close'
34+
'subheader subheader subheader subheader subheader close'
35+
'body body body body body close'
36+
'icon footer footer footer footer close';
37+
gap:8px ;
38+
}
39+
2940
.siren-sdk-skeleton-head {
3041
grid-area: header;
3142
height: 20px;

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type SirenProps = SirenInboxProps &
5050
export type CardProps = {
5151
hideAvatar?: boolean;
5252
showMedia?: boolean;
53+
hideDelete?: boolean;
5354
disableAutoMarkAsRead?: boolean;
5455
};
5556

@@ -101,6 +102,11 @@ export type HeaderProps = {
101102
handleClearAllNotification: () => void;
102103
};
103104

105+
export type LoaderProps = {
106+
styles: SirenStyleProps;
107+
hideAvatar: boolean;
108+
}
109+
104110
type BadgeType = "none" | "dot" | "default";
105111

106112
export type Theme = {

tests/components/__snapshots__/sirenPanel.spec.tsx.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exports[`matches snapshot 1`] = `
6060
class="siren-sdk-skeleton-container"
6161
>
6262
<div
63-
class="siren-sdk-skeleton-grid"
63+
class="siren-sdk-skeleton-grid-with-avatar"
6464
>
6565
<div
6666
class="siren-sdk-skeleton-avatar siren-sdk-skeleton"
@@ -96,7 +96,7 @@ exports[`matches snapshot 1`] = `
9696
class="siren-sdk-skeleton-container"
9797
>
9898
<div
99-
class="siren-sdk-skeleton-grid"
99+
class="siren-sdk-skeleton-grid-with-avatar"
100100
>
101101
<div
102102
class="siren-sdk-skeleton-avatar siren-sdk-skeleton"
@@ -132,7 +132,7 @@ exports[`matches snapshot 1`] = `
132132
class="siren-sdk-skeleton-container"
133133
>
134134
<div
135-
class="siren-sdk-skeleton-grid"
135+
class="siren-sdk-skeleton-grid-with-avatar"
136136
>
137137
<div
138138
class="siren-sdk-skeleton-avatar siren-sdk-skeleton"
@@ -168,7 +168,7 @@ exports[`matches snapshot 1`] = `
168168
class="siren-sdk-skeleton-container"
169169
>
170170
<div
171-
class="siren-sdk-skeleton-grid"
171+
class="siren-sdk-skeleton-grid-with-avatar"
172172
>
173173
<div
174174
class="siren-sdk-skeleton-avatar siren-sdk-skeleton"
@@ -204,7 +204,7 @@ exports[`matches snapshot 1`] = `
204204
class="siren-sdk-skeleton-container"
205205
>
206206
<div
207-
class="siren-sdk-skeleton-grid"
207+
class="siren-sdk-skeleton-grid-with-avatar"
208208
>
209209
<div
210210
class="siren-sdk-skeleton-avatar siren-sdk-skeleton"

0 commit comments

Comments
 (0)