Skip to content

Commit cacbce4

Browse files
Merge pull request #59 from KeyValueSoftwareSystems/dev
v1.1.0
2 parents c6520ce + 56af9b6 commit cacbce4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+17132
-6871
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
browser: true,
44
es2021: true
55
},
6-
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
6+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:storybook/recommended'],
77
overrides: [
88
{
99
env: {

.storybook/main.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { StorybookConfig } from "@storybook/react-webpack5";
2+
3+
const config: StorybookConfig = {
4+
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
5+
addons: [
6+
"@storybook/addon-links",
7+
"@storybook/addon-essentials",
8+
"@storybook/addon-onboarding",
9+
"@storybook/addon-interactions",
10+
],
11+
framework: {
12+
name: "@storybook/react-webpack5",
13+
options: {
14+
builder: {
15+
useSWC: true,
16+
},
17+
},
18+
},
19+
docs: {
20+
autodocs: "tag",
21+
},
22+
};
23+
export default config;

.storybook/preview.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Preview } from "@storybook/react";
2+
3+
const preview: Preview = {
4+
parameters: {
5+
actions: { argTypesRegex: "^on[A-Z].*" },
6+
controls: {
7+
matchers: {
8+
color: /(background|color)$/i,
9+
date: /Date$/i,
10+
},
11+
},
12+
},
13+
};
14+
15+
export default preview;

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [0.0.1] - 2024-03-26
5+
## 1.1.0
6+
This is an update to the package.
67

78
### Added
8-
9-
- React UI kit for managing and displaying in-app notification
9+
- Added support for custom delete icon and a flag to toggle the visibility of the delete icon.
10+
- Added functionality to display thumbnail URL previews for media content
11+
- Exposed Avatar click property.
12+
- Implemented specific error code mapping.
13+
- Enhanced style and theme customizations.

README.md

Lines changed: 35 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ Below are optional props available for the inbox component:
5858
Prop | Description | Type | Default value |
5959
--- | --- | --- | --- |
6060
theme | Object for custom themes | Theme | {} |
61+
customStyles | Object for custom styling | CustomStyle | {} |
6162
loadMoreLabel | Text shown on the load more component | string | "Load More" |
6263
hideBadge | Toggle to hide or show the badge | boolean | false |
6364
darkMode | Toggle to enable dark mode | boolean | false |
6465
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
6566
windowViewOnly | Toggle to enable fit-to-screen window or modal view | boolean | false |
6667
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: '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 } |
69-
customNotificationCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
70-
onNotificationCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
68+
headerProps | 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. | HeaderProps| { title: 'Notifications', <br>hideHeader: false,<br> hideClearAll: false, <br>customHeader: null } |
69+
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> hideMediaThumbnail - Toggle to hide or show thumbnail image<br> disableAutoMarkAsRead - Toggle to disable or enable the markAsReadById functionality on card click.<br> deleteIcon - Custom delete icon <br> onAvatarClick - Custom click handler for avatar <br> onMediaThumbnailClick - Custom click handler for media thumbnail | CardProps | { hideDelete: false,<br> hideAvatar: false,<br> disableAutoMarkAsRead: false, <br> hideMediaThumbnail: false, <br>deleteIcon: null, <br> onAvatarClick: ()=>null,<br> onMediaThumbnailClick: () => null } |
70+
customCard | Function for rendering custom notification cards | (notification)=> JSX Element | null |
71+
onCardClick | Custom click handler for notification cards | (notification)=> void | ()=>null |
7172
listEmptyComponent | Custom component for empty notification list | JSX Element | null |
7273
customFooter | Custom footer component | JSX Element | null |
7374
customLoader | Custom loader component | JSX Element | null |
@@ -88,9 +89,6 @@ type Theme = {
8889
};
8990

9091
type ThemeProps = {
91-
notificationIcon?: {
92-
size?: number,
93-
},
9492
colors?: {
9593
primaryColor?: string,
9694
textColor?: string,
@@ -108,25 +106,22 @@ type ThemeProps = {
108106
color?: string,
109107
textColor?: string,
110108
},
111-
window?: {
112-
borderColor?: string,
113-
},
114109
windowHeader?: {
115110
background?: string,
116111
titleColor?: string,
117112
headerActionColor?: string,
118-
borderColor?: string,
119113
},
120114
windowContainer?: {
121115
background?: string,
122116
},
123-
notificationCard?: {
117+
customCard?: {
124118
borderColor?: string,
125119
background?: string,
126120
titleColor?: string,
121+
subtitleColor?: string,
127122
descriptionColor?: string,
128123
},
129-
loadMoreButton: {
124+
loadMoreButton?: {
130125
color?: string,
131126
background?: string,
132127
},
@@ -153,17 +148,21 @@ Please note that the badgeStyle, window shadow and border props are only applica
153148
titleFontWeight?:TextStyle["fontWeight"],
154149
titleSize?: number,
155150
titlePadding?: number,
151+
borderWidth?: string,
156152
},
157153
windowContainer?: {
158154
padding?: number,
159155
contentHeight?: DimensionValue,
160156
},
161-
notificationCard?: {
157+
customCard?: {
162158
padding?: number,
163159
borderWidth?: number,
164160
avatarSize?: number,
165161
titleFontWeight?: TextStyle["fontWeight"],
166162
titleSize?: number,
163+
subtitleFontWeight?: TextStyle['fontWeight'],
164+
subtitleSize?: number,
165+
descriptionFontWeight?: TextStyle['fontWeight'],
167166
descriptionSize?: number,
168167
dateSize?: number,
169168
},
@@ -174,36 +173,40 @@ Please note that the badgeStyle, window shadow and border props are only applica
174173
badgeStyle?: {
175174
size?: number,
176175
textSize?: number,
177-
top?: number;
178-
left?: number
176+
top?: number,
177+
right?: number
179178
},
180179
deleteIcon?:{
181180
size?: number
182-
}
183-
dateIcon?:{
181+
},
182+
timerIcon?:{
184183
size?: number
185-
}
184+
},
186185
clearAllIcon?:{
187186
size?: number
188-
}
187+
},
189188
}
190189
```
191190

192191
#### CardProps
193192

194193
```js
195194
type CardProps = {
196-
hideDelete?: boolean;
195+
hideDelete?: boolean,
197196
hideAvatar?: boolean,
197+
hideMediaThumbnail?: boolean,
198198
disableAutoMarkAsRead?: boolean,
199+
deleteIcon?: JSX.Element,
200+
onAvatarClick?: () => void,
201+
onMediaThumbnailClick?: () => void,
199202
};
200203
```
201204

202205
#### InboxHeaderProps
203206

204207
```js
205208
type InboxHeaderProps = {
206-
title?: string;
209+
title?: string,
207210
hideHeader?: boolean,
208211
hideClearAll?: boolean,
209212
customHeader?: JSX.Element | null,
@@ -219,31 +222,11 @@ import { useSiren } from "@sirenapp/react-inbox";
219222

220223
function MyComponent() {
221224
const {
222-
markAsRead,
223-
deleteNotification,
224-
markAllNotificationsAsReadByDate,
225-
clearAllNotificationByDate,
226-
markNotificationsAsViewed,
225+
markAsReadById,
227226
} = useSiren();
228227

229228
function handleMarkAsRead(id) {
230-
markAsRead(id);
231-
}
232-
233-
function handleDeleteNotification(id) {
234-
deleteNotification(id);
235-
}
236-
237-
function handleMarkAllNotificationsAsReadByDate(untilDate) {
238-
markNotificationsAsReadByDate(untilDate);
239-
}
240-
241-
function handleClearAllNotificationByDate(untilDate) {
242-
deleteNotificationsByDate(untilDate);
243-
}
244-
245-
function handleMarkNotificationsAsViewed(untilDate) {
246-
markNotificationsAsViewed(untilDate);
229+
markAsReadById(id);
247230
}
248231

249232
return {
@@ -256,24 +239,12 @@ function MyComponent() {
256239

257240
Functions | Parameters | Type | Description |
258241
----------|------------|-------|------------|
259-
markNotificationsAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
260-
markAsRead | id | string | Set read status of a notification to true |
261-
deleteNotification | id | string | Delete a notification by id |
262-
deleteNotificationsByDate | startDate | ISO date string | Delete all notifications until given date |
263-
markNotificationsAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |
264-
265-
## 5. Error codes
266-
267-
Given below are all possible error codes thrown by sdk.
242+
markAsReadByDate | startDate | ISO date string | Sets the read status of notifications to true until the given date |
243+
markAsReadById | id | string | Set read status of a notification to true |
244+
deleteById | id | string | Delete a notification by id |
245+
deleteByDate | startDate | ISO date string | Delete all notifications until given date |
246+
markAllAsViewed | startDate | ISO date string |Sets the viewed status of notifications to true until the given date |
268247

269-
Error code | Description |
270-
------------------------- | ------------------------------------------------------------------|
271-
INVALID_TOKEN | The token passed in the provider is invalid |
272-
INVALID_RECIPIENT_ID | The recipient id passed in the provider is invalid |
273-
TOKEN_VERIFICATION_FAILED | Verification of the given tokens has failed |
274-
GENERIC_API_ERROR | Occurrence of an unexpected api error |
275-
OUTSIDE_SIREN_CONTEXT | Attempting to invoke the functions outside the siren inbox context|
276-
MISSING_PARAMETER | The required parameter is missing |
277248

278249
## Example
279250

@@ -302,7 +273,7 @@ export function MyContainer(): React.JSX.Element {
302273
return (
303274
<div>
304275
<SirenInbox
305-
inboxHeaderProps={
276+
headerProps={
306277
title: "Notifications",
307278
hideHeader: false
308279
}
@@ -311,6 +282,8 @@ export function MyContainer(): React.JSX.Element {
311282
hideDelete: false,
312283
hideAvatar: false,
313284
disableAutoMarkAsRead: false,
285+
deleteIcon: null,
286+
onAvatarClick: () => null,
314287
}}
315288
/>
316289
</div>

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"react": "^18.2.0",
77
"react-dom": "^18.2.0",
88
"react-scripts": "^5.0.1",
9-
"@sirenapp/react-inbox": "^1.0.0"
9+
"@sirenapp/react-inbox": "^1.1.0"
1010
},
1111
"scripts": {
1212
"dev": "PORT=9902 react-scripts start",

example/src/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const App: React.FC = () => {
3737
const [showCustomNotificationCard, setShowCustomNotificationCard] =
3838
useState(false);
3939

40-
const { markNotificationsAsReadByDate } = useSiren();
40+
const { markAsReadByDate } = useSiren();
4141

4242
const renderListEmpty = () => {
4343
return (
@@ -84,7 +84,7 @@ const App: React.FC = () => {
8484
<div style={{ color: "#fff", fontWeight: "600" }}>Siren</div>
8585
</div>
8686
<div>
87-
<div style={{ color: "#fff", fontWeight: "600" }} onClick={() => markNotificationsAsReadByDate(String(new Date().getTime()))}>Mark allAsRead</div>
87+
<div style={{ color: "#fff", fontWeight: "600" }} onClick={() => markAsReadByDate(String(new Date().getTime()))}>Mark allAsRead</div>
8888
</div>
8989
</div>
9090
);
@@ -249,24 +249,24 @@ const App: React.FC = () => {
249249
return (
250250
<div>
251251
<SirenInbox
252-
inboxHeaderProps={{
252+
headerProps={{
253253
title:"Siren Notifications",
254254
hideHeader: hideHeader,
255255
customHeader: showCustomHeader ? renderCustomHeader() : undefined
256256
}}
257257
darkMode={sdkDarkModeEnabled}
258-
cardProps={{ hideAvatar: hideAvatar, showMedia: true }}
258+
cardProps={{ hideAvatar: hideAvatar, onAvatarClick: () => console.log('avatar click') }}
259259
theme={windowThemes[windowThemeIndex]}
260260
customFooter={showCustomFooter ? renderCustomFooter() : undefined}
261261
listEmptyComponent={
262262
showCustomEmptyComponent ? renderListEmpty() : undefined
263263
}
264-
customNotificationCard={
264+
customCard={
265265
showCustomNotificationCard
266266
? (notification: any) => renderCustomNotificationCard(notification)
267267
: undefined
268268
}
269-
onNotificationCardClick={() => {
269+
onCardClick={() => {
270270
console.log("click on notification");
271271
}}
272272
onError={(error: any) => {

0 commit comments

Comments
 (0)