Skip to content

Commit 2da5cdf

Browse files
feat: Add prop to hide badge in icon
1 parent 6b2c71e commit 2da5cdf

File tree

8 files changed

+3765
-1182
lines changed

8 files changed

+3765
-1182
lines changed

src/components/NotificationIcon.vue

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@
55
data-testid="notification-icon-container"
66
>
77
<slot name="notification-icon">
8-
<BellIcon :stroke=" darkMode
9-
? COLORS.dark.notificationIcon
10-
: COLORS.light.notificationIcon" />
8+
<BellIcon
9+
:stroke="
10+
darkMode
11+
? COLORS.dark.notificationIcon
12+
: COLORS.light.notificationIcon
13+
"
14+
/>
1115
</slot>
1216
<div
17+
v-if="!hideBadge"
1318
class="siren-sdk-notificationIcon-badge-container"
1419
:style="
1520
badgeType === BadgeType.DEFAULT && unViewedCount > 0
1621
? styles.badgeStyle
1722
: {
1823
width: 0,
1924
height: 0,
20-
overflow: 'hidden'
25+
overflow: 'hidden',
2126
}
2227
"
2328
>
@@ -29,8 +34,7 @@
2934
</template>
3035

3136
<script setup lang="ts">
32-
import type {
33-
Ref } from 'vue';
37+
import type { Ref } from 'vue';
3438
import {
3539
defineProps,
3640
inject,
@@ -39,20 +43,27 @@ import {
3943
ref,
4044
watch
4145
} from 'vue';
42-
import PubSub from 'pubsub-js';
4346
import type { Siren } from 'test_notification';
47+
import PubSub from 'pubsub-js';
4448
4549
import type { SirenStyleProps } from '../types';
46-
import { BadgeType, EventType, eventTypes, events, COLORS } from '../utils/constants';
50+
import {
51+
BadgeType,
52+
EventType,
53+
eventTypes,
54+
events,
55+
COLORS
56+
} from '../utils/constants';
4757
import BellIcon from './BellIcon.vue';
4858
4959
import '../styles/icon.css';
5060
51-
defineProps<{
61+
const props = defineProps<{
5262
handleNotification: (event: any) => void;
5363
badgeType: BadgeType;
5464
darkMode: boolean;
5565
styles: SirenStyleProps;
66+
hideBadge: boolean;
5667
}>();
5768
5869
const siren: Ref<Siren> = inject('siren') as Ref<Siren>;
@@ -93,20 +104,21 @@ const getUnViewedCount = async (): Promise<void> => {
93104
};
94105
95106
onMounted(() => {
96-
PubSub.subscribe(
97-
events.NOTIFICATION_COUNT_EVENT,
98-
notificationCountSubscriber
99-
);
107+
if (!props.hideBadge)
108+
PubSub.subscribe(
109+
events.NOTIFICATION_COUNT_EVENT,
110+
notificationCountSubscriber
111+
);
100112
});
101113
102114
onMounted(() => {
103-
startRealTimeDataFetch();
115+
if (!props.hideBadge) startRealTimeDataFetch();
104116
});
105117
106118
watch(
107119
() => siren.value,
108120
() => {
109-
getUnViewedCount();
121+
if (!props.hideBadge) getUnViewedCount();
110122
},
111123
{ immediate: true }
112124
);

src/components/SirenInbox.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div v-if="!windowViewOnly" ref="iconRef" data-testid="siren-inbox-icon">
44
<NotificationIcon :handleNotification="handleNotification"
55
:badgeType="showNotifications ? BadgeType.NONE : BadgeType.DEFAULT"
6-
:darkMode="darkMode" :styles="styles" />
6+
:darkMode="darkMode" :styles="styles" :hideBadge="hideBadge" />
77
</div>
88
<div v-if="showNotifications || windowViewOnly" :style="{
99
...styles.container,

src/components/SirenPanel.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ onMounted(() => {
320320
onBeforeUnmount(() => {
321321
cleanUp();
322322
notificationsContent.value = [];
323-
restartNotificationCountFetch();
323+
if (!props.hideBadge) restartNotificationCountFetch();
324324
handleMarkNotificationsAsViewed(new Date().toISOString());
325325
});
326326
@@ -356,7 +356,7 @@ watch(
356356
[() => siren.value, () => verificationStatus.value],
357357
() => {
358358
if (siren.value && verificationStatus.value !== VerificationStatus.PENDING) {
359-
siren.value?.stopRealTimeFetch(EventType.UNVIEWED_COUNT);
359+
if (!props.hideBadge) siren.value?.stopRealTimeFetch(EventType.UNVIEWED_COUNT);
360360
fetchNotifications(true);
361361
}
362362
if (!siren.value && isLoading.value) {

stories/NotificationIcon.stories.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const meta = {
2626
badgeType: BadgeType.DEFAULT,
2727
darkMode: false,
2828
handleNotification: () => {},
29-
styles: applyTheme({}, ThemeMode.LIGHT, {})
29+
styles: applyTheme({}, ThemeMode.LIGHT, {}),
30+
hideBadge: false
3031
}
3132
} satisfies Meta<typeof NotificationIcon>;
3233

0 commit comments

Comments
 (0)