@dashx/react 0.2.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/cjs/hooks/index.d.ts +3 -0
- package/dist/cjs/hooks/index.js +1 -1
- package/dist/cjs/hooks/index.js.map +3 -3
- package/dist/cjs/hooks/use-in-app-chat-notifications.d.ts +27 -0
- package/dist/cjs/hooks/use-in-app-chat-notifications.js +2 -0
- package/dist/cjs/hooks/use-in-app-chat-notifications.js.map +7 -0
- package/dist/cjs/hooks/use-in-app-chat.d.ts +41 -0
- package/dist/cjs/hooks/use-in-app-chat.js +2 -0
- package/dist/cjs/hooks/use-in-app-chat.js.map +7 -0
- package/dist/cjs/providers/DashXProvider.d.ts +15 -1
- package/dist/cjs/providers/DashXProvider.js +1 -1
- package/dist/cjs/providers/DashXProvider.js.map +3 -3
- package/dist/cjs/widgets/InAppChat.d.ts +16 -0
- package/dist/cjs/widgets/InAppChat.js +2 -0
- package/dist/cjs/widgets/InAppChat.js.map +7 -0
- package/dist/cjs/widgets/InAppChatButton.d.ts +12 -0
- package/dist/cjs/widgets/InAppChatButton.js +2 -0
- package/dist/cjs/widgets/InAppChatButton.js.map +7 -0
- package/dist/cjs/widgets/index.d.ts +2 -0
- package/dist/cjs/widgets/index.js +1 -1
- package/dist/cjs/widgets/index.js.map +3 -3
- package/dist/esm/hooks/index.d.ts +3 -0
- package/dist/esm/hooks/index.js +1 -1
- package/dist/esm/hooks/index.js.map +2 -2
- package/dist/esm/hooks/use-in-app-chat-notifications.d.ts +27 -0
- package/dist/esm/hooks/use-in-app-chat-notifications.js +2 -0
- package/dist/esm/hooks/use-in-app-chat-notifications.js.map +7 -0
- package/dist/esm/hooks/use-in-app-chat.d.ts +41 -0
- package/dist/esm/hooks/use-in-app-chat.js +2 -0
- package/dist/esm/hooks/use-in-app-chat.js.map +7 -0
- package/dist/esm/providers/DashXProvider.d.ts +15 -1
- package/dist/esm/providers/DashXProvider.js +1 -1
- package/dist/esm/providers/DashXProvider.js.map +3 -3
- package/dist/esm/widgets/InAppChat.d.ts +16 -0
- package/dist/esm/widgets/InAppChat.js +2 -0
- package/dist/esm/widgets/InAppChat.js.map +7 -0
- package/dist/esm/widgets/InAppChatButton.d.ts +12 -0
- package/dist/esm/widgets/InAppChatButton.js +2 -0
- package/dist/esm/widgets/InAppChatButton.js.map +7 -0
- package/dist/esm/widgets/index.d.ts +2 -0
- package/dist/esm/widgets/index.js +1 -1
- package/dist/esm/widgets/index.js.map +2 -2
- package/package.json +2 -2
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-in-app-chat-notifications.ts +117 -0
- package/src/hooks/use-in-app-chat.ts +281 -0
- package/src/providers/DashXProvider.tsx +74 -7
- package/src/widgets/InAppChat.tsx +193 -0
- package/src/widgets/InAppChatButton.tsx +103 -0
- package/src/widgets/index.ts +2 -0
- package/styles.css +6 -0
- package/dist/cjs/widgets/NotificationBell.d.ts +0 -2
- package/dist/cjs/widgets/NotificationBell.js +0 -2
- package/dist/cjs/widgets/NotificationBell.js.map +0 -7
- package/dist/esm/widgets/NotificationBell.d.ts +0 -2
- package/dist/esm/widgets/NotificationBell.js +0 -2
- package/dist/esm/widgets/NotificationBell.js.map +0 -7
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React, { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { MessageCircle } from 'lucide-react';
|
|
3
|
+
|
|
4
|
+
import { Button, Flex, Popover, Theme, type ThemeProps } from '../components';
|
|
5
|
+
import { InAppChat, type InAppChatWrapperProps } from './InAppChat.js';
|
|
6
|
+
import useInAppChat from '../hooks/use-in-app-chat.js';
|
|
7
|
+
import useInAppChatNotifications from '../hooks/use-in-app-chat-notifications.js';
|
|
8
|
+
|
|
9
|
+
type LauncherPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
10
|
+
|
|
11
|
+
type InAppChatButtonProps = InAppChatWrapperProps & {
|
|
12
|
+
/** Where the floating launcher sits on screen. Defaults to `bottom-right`. */
|
|
13
|
+
position?: LauncherPosition,
|
|
14
|
+
/** Theme overrides for the launcher + chat surface (accent color, mode, roundness, …). */
|
|
15
|
+
theme?: ThemeProps,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Full, non-interpolated class strings so Tailwind can detect them.
|
|
19
|
+
const POSITION_CLASS: Record<LauncherPosition, string> = {
|
|
20
|
+
'bottom-right': 'right-4 bottom-4',
|
|
21
|
+
'bottom-left': 'left-4 bottom-4',
|
|
22
|
+
'top-right': 'right-4 top-4',
|
|
23
|
+
'top-left': 'left-4 top-4',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const InAppChatButton = ({
|
|
27
|
+
identityId,
|
|
28
|
+
idempotencyKey,
|
|
29
|
+
initialMessage,
|
|
30
|
+
notifications = true,
|
|
31
|
+
position = 'bottom-right',
|
|
32
|
+
theme,
|
|
33
|
+
...props
|
|
34
|
+
}: InAppChatButtonProps) => {
|
|
35
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
36
|
+
|
|
37
|
+
// Latch: once the launcher has been opened, keep the chat hook active so its
|
|
38
|
+
// channel subscription persists while the panel is closed — that's what lets
|
|
39
|
+
// us notify on replies that land while the panel is shut. Before the first
|
|
40
|
+
// open the hook is idle, so no conversation is created on page load.
|
|
41
|
+
const hasOpenedRef = useRef(false);
|
|
42
|
+
if (isOpen) hasOpenedRef.current = true;
|
|
43
|
+
const enabled = hasOpenedRef.current;
|
|
44
|
+
|
|
45
|
+
const open = useCallback(() => setIsOpen(true), []);
|
|
46
|
+
|
|
47
|
+
const { handleInboundMessage, requestPermissionOnOpen } = useInAppChatNotifications({
|
|
48
|
+
isOpen,
|
|
49
|
+
enabled: notifications !== false,
|
|
50
|
+
options: typeof notifications === 'object' ? notifications : undefined,
|
|
51
|
+
onActivate: open,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Request notification permission inside the open gesture (synchronously), so
|
|
55
|
+
// the prompt runs within the browser's transient user activation — requesting
|
|
56
|
+
// from an effect after the click unwinds is ignored on some browsers.
|
|
57
|
+
const handleOpenChange = useCallback(
|
|
58
|
+
(nextOpen: boolean) => {
|
|
59
|
+
if (nextOpen) requestPermissionOnOpen();
|
|
60
|
+
setIsOpen(nextOpen);
|
|
61
|
+
},
|
|
62
|
+
[requestPermissionOnOpen],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const chat = useInAppChat({
|
|
66
|
+
identityId,
|
|
67
|
+
idempotencyKey,
|
|
68
|
+
initialMessage,
|
|
69
|
+
enabled,
|
|
70
|
+
onInboundMessage: handleInboundMessage,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Theme {...theme}>
|
|
75
|
+
<Flex className={`fixed z-50 ${POSITION_CLASS[position]}`}>
|
|
76
|
+
<Popover.Root open={isOpen} onOpenChange={handleOpenChange}>
|
|
77
|
+
<Popover.Trigger>
|
|
78
|
+
<Button shape="square" roundness="full" variant="fill" size="large">
|
|
79
|
+
<MessageCircle />
|
|
80
|
+
</Button>
|
|
81
|
+
</Popover.Trigger>
|
|
82
|
+
{/* The chat hook lives at the launcher level (above the popover) so its
|
|
83
|
+
subscription survives the panel closing — required to notify on
|
|
84
|
+
replies that arrive while the panel is shut. It activates lazily on
|
|
85
|
+
first open, so no empty conversation is created on page load. */}
|
|
86
|
+
<Popover.Content spacing="large" width="350px" height="450px">
|
|
87
|
+
<InAppChat
|
|
88
|
+
{...chat}
|
|
89
|
+
borderless
|
|
90
|
+
withChatHeader
|
|
91
|
+
withPopoverClose
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
</Popover.Content>
|
|
95
|
+
</Popover.Root>
|
|
96
|
+
</Flex>
|
|
97
|
+
</Theme>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type { InAppChatButtonProps };
|
|
102
|
+
|
|
103
|
+
export default InAppChatButton;
|
package/src/widgets/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as Chat } from './Chat.js';
|
|
2
2
|
export { default as ChatPopover } from './ChatPopover.js';
|
|
3
|
+
export { default as InAppChat } from './InAppChat.js';
|
|
4
|
+
export { default as InAppChatButton } from './InAppChatButton.js';
|
|
3
5
|
export { default as MessageBell } from './MessageBell.js';
|
|
4
6
|
export { default as Preference } from './Preference.js';
|
|
5
7
|
export { default as Preferences } from './Preferences.js';
|
package/styles.css
CHANGED
|
@@ -155,6 +155,9 @@ button, input:where([type='button'], [type='reset'], [type='submit']), ::file-se
|
|
|
155
155
|
.relative {
|
|
156
156
|
position: relative;
|
|
157
157
|
}
|
|
158
|
+
.top-4 {
|
|
159
|
+
top: var(--spacing-4);
|
|
160
|
+
}
|
|
158
161
|
.top-\[0\] {
|
|
159
162
|
top: 0;
|
|
160
163
|
}
|
|
@@ -529,6 +532,9 @@ button, input:where([type='button'], [type='reset'], [type='submit']), ::file-se
|
|
|
529
532
|
.bg-accent-500 {
|
|
530
533
|
background-color: var(--color-accent-500);
|
|
531
534
|
}
|
|
535
|
+
.bg-accent-600 {
|
|
536
|
+
background-color: var(--color-accent-600);
|
|
537
|
+
}
|
|
532
538
|
.bg-bg {
|
|
533
539
|
background-color: var(--color-bg);
|
|
534
540
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(a,r)=>{for(var n in r)l(a,n,{get:r[n],enumerable:!0})},T=(a,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of u(r))!c.call(a,o)&&o!==n&&l(a,o,{get:()=>r[o],enumerable:!(s=g(r,o))||s.enumerable});return a};var h=a=>T(l({},"__esModule",{value:!0}),a);var f={};m(f,{default:()=>x});module.exports=h(f);var t=require("react/jsx-runtime"),d=require("date-fns"),p=require("../hooks/index.js"),e=require("../components"),i=require("../icons/index.js");const v=()=>{let{markNotificationAsRead:a,markNotificationAsUnread:r,notifications:n,unreadNotificationsCount:s}=(0,p.useInApp)();return(0,t.jsx)(e.Theme,{children:(0,t.jsxs)(e.Popover.Root,{children:[(0,t.jsxs)(e.Tooltip.Root,{children:[(0,t.jsx)(e.Tooltip.Trigger,{children:(0,t.jsx)(e.Popover.Trigger,{children:(0,t.jsx)(e.Button,{shape:"square",roundness:"full",variant:s?"fill":"ghost",children:(0,t.jsx)(i.Inbox,{})})})}),(0,t.jsx)(e.Tooltip.Content,{content:"Notification"})]}),(0,t.jsxs)(e.Popover.Content,{spacing:"large",width:"350px",height:"450px",children:[(0,t.jsx)(e.Popover.Header,{asChild:!0,children:(0,t.jsxs)(e.Flex,{justify:"between",align:"center",children:[(0,t.jsx)(e.Heading,{size:3,children:"Notifications"}),(0,t.jsx)(e.Popover.Close,{children:(0,t.jsx)(e.Button,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:(0,t.jsx)(i.X,{})})})]})}),(0,t.jsx)(e.Popover.Body,{children:(0,t.jsxs)(e.Flex,{direction:"column",gap:1,children:[n.length===0&&(0,t.jsx)(e.Flex,{justify:"center",align:"center",children:(0,t.jsx)(e.Text,{variant:"tertiary",size:2,children:"No notifications yet."})}),n.map(o=>(0,t.jsx)(e.Card,{children:(0,t.jsxs)(e.Flex,{align:"center",gap:4,justify:"between",children:[(0,t.jsxs)(e.Flex,{direction:"column",gap:1,children:[(0,t.jsx)(e.Text,{as:"p",variant:"secondary",weight:"semibold",size:2,children:o.renderedContent.body}),(0,t.jsx)(e.Text,{size:1,variant:"tertiary",children:(0,d.intlFormatDistance)(o.sentAt,new Date)})]}),(0,t.jsxs)(e.Tooltip.Root,{children:[(0,t.jsx)(e.Tooltip.Trigger,{children:(0,t.jsx)(e.Button,{shape:"square",variant:"ghost",roundness:"full",mode:o.readAt?"subtle":"distinct",onPress:()=>{o.readAt?r(o.id):a(o.id)},children:o.readAt?(0,t.jsx)(i.MailOpen,{}):(0,t.jsx)(i.Mail,{})})}),(0,t.jsx)(e.Tooltip.Content,{content:o.readAt?"Mark as unread":"Mark as read"})]})]})},o.id))]})}),(0,t.jsx)(e.Popover.Footer,{asChild:!0,children:(0,t.jsx)(e.Text,{as:"p",align:"center",color:"accent",variant:"tertiary",size:1,children:"Powered by DashX"})})]})]})})};var x=v;
|
|
2
|
-
//# sourceMappingURL=NotificationBell.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/widgets/NotificationBell.tsx"],
|
|
4
|
-
"sourcesContent": ["import { intlFormatDistance } from 'date-fns';\n\nimport { useInApp } from '../hooks/index.js';\nimport { Button, Card, Flex, Heading, Popover, Text, Theme, Tooltip } from '../components';\nimport { Inbox, Mail, MailOpen, X } from '../icons/index.js';\n\nconst NotificationBell = () => {\n let {\n markNotificationAsRead,\n markNotificationAsUnread,\n notifications,\n unreadNotificationsCount,\n } = useInApp();\n\n return (\n <Theme>\n <Popover.Root>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Popover.Trigger>\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant={unreadNotificationsCount ? 'fill' : 'ghost'}\n >\n <Inbox />\n </Button>\n </Popover.Trigger>\n </Tooltip.Trigger>\n <Tooltip.Content content=\"Notification\" />\n </Tooltip.Root>\n <Popover.Content spacing=\"large\" width=\"350px\" height=\"450px\">\n <Popover.Header asChild>\n <Flex justify=\"between\" align=\"center\">\n <Heading size={3}>Notifications</Heading>\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n </Flex>\n </Popover.Header>\n <Popover.Body>\n <Flex direction=\"column\" gap={1}>\n {notifications.length === 0 && (\n <Flex justify=\"center\" align=\"center\">\n <Text variant=\"tertiary\" size={2}>\n No notifications yet.\n </Text>\n </Flex>\n )}\n {notifications.map((notification) => (\n <Card key={notification.id}>\n <Flex align=\"center\" gap={4} justify=\"between\">\n <Flex direction=\"column\" gap={1}>\n <Text as=\"p\" variant=\"secondary\" weight=\"semibold\" size={2}>\n {notification.renderedContent.body}\n </Text>\n <Text size={1} variant=\"tertiary\">\n {intlFormatDistance(notification.sentAt, new Date())}\n </Text>\n </Flex>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Button\n shape=\"square\"\n variant=\"ghost\"\n roundness=\"full\"\n mode={notification.readAt ? 'subtle' : 'distinct'}\n onPress={() => {\n if (notification.readAt) {\n markNotificationAsUnread(notification.id);\n } else {\n markNotificationAsRead(notification.id);\n }\n }}\n >\n {notification.readAt ? <MailOpen /> : <Mail />}\n </Button>\n </Tooltip.Trigger>\n <Tooltip.Content\n content={notification.readAt ? 'Mark as unread' : 'Mark as read'}\n />\n </Tooltip.Root>\n </Flex>\n </Card>\n ))}\n </Flex>\n </Popover.Body>\n <Popover.Footer asChild>\n <Text as=\"p\" align=\"center\" color=\"accent\" variant=\"tertiary\" size={1}>\n Powered by DashX\n </Text>\n </Popover.Footer>\n </Popover.Content>\n </Popover.Root>\n </Theme>\n );\n};\n\nexport default NotificationBell;\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAiBQ,IAAAI,EAAA,6BAjBRC,EAAmC,oBAEnCC,EAAyB,6BACzBC,EAA2E,yBAC3EC,EAAyC,6BAEzC,MAAMC,EAAmB,IAAM,CAC7B,GAAI,CACF,uBAAAC,EACA,yBAAAC,EACA,cAAAC,EACA,yBAAAC,CACF,KAAI,YAAS,EAEb,SACE,OAAC,SACC,oBAAC,UAAQ,KAAR,CACC,qBAAC,UAAQ,KAAR,CACC,oBAAC,UAAQ,QAAR,CACC,mBAAC,UAAQ,QAAR,CACC,mBAAC,UACC,MAAM,SACN,UAAU,OACV,QAASA,EAA2B,OAAS,QAE7C,mBAAC,UAAM,EACT,EACF,EACF,KACA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CxB,CACD,GACH,EACF,KACA,OAAC,UAAQ,OAAR,CAAe,QAAO,GACrB,mBAAC,QAAK,GAAG,IAAI,MAAM,SAAS,MAAM,SAAS,QAAQ,WAAW,KAAM,EAAG,4BAEvE,EACF,GACF,GACF,EACF,CAEJ,EAEA,IAAOZ,EAAQO",
|
|
6
|
-
"names": ["NotificationBell_exports", "__export", "NotificationBell_default", "__toCommonJS", "import_jsx_runtime", "import_date_fns", "import_hooks", "import_components", "import_icons", "NotificationBell", "markNotificationAsRead", "markNotificationAsUnread", "notifications", "unreadNotificationsCount", "notification"]
|
|
7
|
-
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{jsx as e,jsxs as o}from"react/jsx-runtime";import{intlFormatDistance as u}from"date-fns";import{useInApp as c}from"../hooks/index.js";import{Button as s,Card as m,Flex as i,Heading as T,Popover as r,Text as n,Theme as h,Tooltip as a}from"../components";import{Inbox as v,Mail as x,MailOpen as f,X as y}from"../icons/index.js";const C=()=>{let{markNotificationAsRead:d,markNotificationAsUnread:p,notifications:l,unreadNotificationsCount:g}=c();return e(h,{children:o(r.Root,{children:[o(a.Root,{children:[e(a.Trigger,{children:e(r.Trigger,{children:e(s,{shape:"square",roundness:"full",variant:g?"fill":"ghost",children:e(v,{})})})}),e(a.Content,{content:"Notification"})]}),o(r.Content,{spacing:"large",width:"350px",height:"450px",children:[e(r.Header,{asChild:!0,children:o(i,{justify:"between",align:"center",children:[e(T,{size:3,children:"Notifications"}),e(r.Close,{children:e(s,{shape:"square",roundness:"full",variant:"ghost",mode:"subtle",inset:"right",children:e(y,{})})})]})}),e(r.Body,{children:o(i,{direction:"column",gap:1,children:[l.length===0&&e(i,{justify:"center",align:"center",children:e(n,{variant:"tertiary",size:2,children:"No notifications yet."})}),l.map(t=>e(m,{children:o(i,{align:"center",gap:4,justify:"between",children:[o(i,{direction:"column",gap:1,children:[e(n,{as:"p",variant:"secondary",weight:"semibold",size:2,children:t.renderedContent.body}),e(n,{size:1,variant:"tertiary",children:u(t.sentAt,new Date)})]}),o(a.Root,{children:[e(a.Trigger,{children:e(s,{shape:"square",variant:"ghost",roundness:"full",mode:t.readAt?"subtle":"distinct",onPress:()=>{t.readAt?p(t.id):d(t.id)},children:t.readAt?e(f,{}):e(x,{})})}),e(a.Content,{content:t.readAt?"Mark as unread":"Mark as read"})]})]})},t.id))]})}),e(r.Footer,{asChild:!0,children:e(n,{as:"p",align:"center",color:"accent",variant:"tertiary",size:1,children:"Powered by DashX"})})]})]})})};var B=C;export{B as default};
|
|
2
|
-
//# sourceMappingURL=NotificationBell.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/widgets/NotificationBell.tsx"],
|
|
4
|
-
"sourcesContent": ["import { intlFormatDistance } from 'date-fns';\n\nimport { useInApp } from '../hooks/index.js';\nimport { Button, Card, Flex, Heading, Popover, Text, Theme, Tooltip } from '../components';\nimport { Inbox, Mail, MailOpen, X } from '../icons/index.js';\n\nconst NotificationBell = () => {\n let {\n markNotificationAsRead,\n markNotificationAsUnread,\n notifications,\n unreadNotificationsCount,\n } = useInApp();\n\n return (\n <Theme>\n <Popover.Root>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Popover.Trigger>\n <Button\n shape=\"square\"\n roundness=\"full\"\n variant={unreadNotificationsCount ? 'fill' : 'ghost'}\n >\n <Inbox />\n </Button>\n </Popover.Trigger>\n </Tooltip.Trigger>\n <Tooltip.Content content=\"Notification\" />\n </Tooltip.Root>\n <Popover.Content spacing=\"large\" width=\"350px\" height=\"450px\">\n <Popover.Header asChild>\n <Flex justify=\"between\" align=\"center\">\n <Heading size={3}>Notifications</Heading>\n <Popover.Close>\n <Button shape=\"square\" roundness=\"full\" variant=\"ghost\" mode=\"subtle\" inset=\"right\">\n <X />\n </Button>\n </Popover.Close>\n </Flex>\n </Popover.Header>\n <Popover.Body>\n <Flex direction=\"column\" gap={1}>\n {notifications.length === 0 && (\n <Flex justify=\"center\" align=\"center\">\n <Text variant=\"tertiary\" size={2}>\n No notifications yet.\n </Text>\n </Flex>\n )}\n {notifications.map((notification) => (\n <Card key={notification.id}>\n <Flex align=\"center\" gap={4} justify=\"between\">\n <Flex direction=\"column\" gap={1}>\n <Text as=\"p\" variant=\"secondary\" weight=\"semibold\" size={2}>\n {notification.renderedContent.body}\n </Text>\n <Text size={1} variant=\"tertiary\">\n {intlFormatDistance(notification.sentAt, new Date())}\n </Text>\n </Flex>\n <Tooltip.Root>\n <Tooltip.Trigger>\n <Button\n shape=\"square\"\n variant=\"ghost\"\n roundness=\"full\"\n mode={notification.readAt ? 'subtle' : 'distinct'}\n onPress={() => {\n if (notification.readAt) {\n markNotificationAsUnread(notification.id);\n } else {\n markNotificationAsRead(notification.id);\n }\n }}\n >\n {notification.readAt ? <MailOpen /> : <Mail />}\n </Button>\n </Tooltip.Trigger>\n <Tooltip.Content\n content={notification.readAt ? 'Mark as unread' : 'Mark as read'}\n />\n </Tooltip.Root>\n </Flex>\n </Card>\n ))}\n </Flex>\n </Popover.Body>\n <Popover.Footer asChild>\n <Text as=\"p\" align=\"center\" color=\"accent\" variant=\"tertiary\" size={1}>\n Powered by DashX\n </Text>\n </Popover.Footer>\n </Popover.Content>\n </Popover.Root>\n </Theme>\n );\n};\n\nexport default NotificationBell;\n"],
|
|
5
|
-
"mappings": "AAiBQ,OAQQ,OAAAA,EARR,QAAAC,MAAA,oBAjBR,OAAS,sBAAAC,MAA0B,WAEnC,OAAS,YAAAC,MAAgB,oBACzB,OAAS,UAAAC,EAAQ,QAAAC,EAAM,QAAAC,EAAM,WAAAC,EAAS,WAAAC,EAAS,QAAAC,EAAM,SAAAC,EAAO,WAAAC,MAAe,gBAC3E,OAAS,SAAAC,EAAO,QAAAC,EAAM,YAAAC,EAAU,KAAAC,MAAS,oBAEzC,MAAMC,EAAmB,IAAM,CAC7B,GAAI,CACF,uBAAAC,EACA,yBAAAC,EACA,cAAAC,EACA,yBAAAC,CACF,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AG,QAAQ,WACpB,SAAAP,EAAmBmB,EAAa,OAAQ,IAAI,IAAM,EACrD,GACF,EACApB,EAACU,EAAQ,KAAR,CACC,UAAAX,EAACW,EAAQ,QAAR,CACC,SAAAX,EAACI,EAAA,CACC,MAAM,SACN,QAAQ,QACR,UAAU,OACV,KAAMiB,EAAa,OAAS,SAAW,WACvC,QAAS,IAAM,CACTA,EAAa,OACfH,EAAyBG,EAAa,EAAE,EAExCJ,EAAuBI,EAAa,EAAE,CAE1C,EAEC,SAAAA,EAAa,OAASrB,EAACc,EAAA,EAAS,EAAKd,EAACa,EAAA,EAAK,EAC9C,EACF,EACAb,EAACW,EAAQ,QAAR,CACC,QAASU,EAAa,OAAS,iBAAmB,eACpD,GACF,GACF,GAhCSA,EAAa,EAiCxB,CACD,GACH,EACF,EACArB,EAACQ,EAAQ,OAAR,CAAe,QAAO,GACrB,SAAAR,EAACS,EAAA,CAAK,GAAG,IAAI,MAAM,SAAS,MAAM,SAAS,QAAQ,WAAW,KAAM,EAAG,4BAEvE,EACF,GACF,GACF,EACF,CAEJ,EAEA,IAAOa,EAAQN",
|
|
6
|
-
"names": ["jsx", "jsxs", "intlFormatDistance", "useInApp", "Button", "Card", "Flex", "Heading", "Popover", "Text", "Theme", "Tooltip", "Inbox", "Mail", "MailOpen", "X", "NotificationBell", "markNotificationAsRead", "markNotificationAsUnread", "notifications", "unreadNotificationsCount", "notification", "NotificationBell_default"]
|
|
7
|
-
}
|