@dashx/react 0.2.3 → 0.3.0
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 +1 -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.d.ts +38 -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 +13 -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 +1 -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.d.ts +38 -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 +13 -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 +1 -0
- package/src/hooks/use-in-app-chat.ts +254 -0
- package/src/providers/DashXProvider.tsx +74 -7
- package/src/widgets/InAppChat.tsx +165 -0
- package/src/widgets/InAppChatButton.tsx +59 -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,165 @@
|
|
|
1
|
+
import * as ScrollArea from '@radix-ui/react-scroll-area';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
|
+
import { Send, X } from 'lucide-react';
|
|
4
|
+
import type { KeyboardEvent } from 'react';
|
|
5
|
+
|
|
6
|
+
import { Button, Flex, Heading, Popover, Text, TextArea, Theme } from '../components';
|
|
7
|
+
import { cn } from '../utils/cn.js';
|
|
8
|
+
import useAutoScroll from '../hooks/use-auto-scroll.js';
|
|
9
|
+
import useInAppChat, {
|
|
10
|
+
type InAppChatMessage,
|
|
11
|
+
type UseInAppChatHookProps,
|
|
12
|
+
type UseInAppChatHookResponse,
|
|
13
|
+
} from '../hooks/use-in-app-chat.js';
|
|
14
|
+
|
|
15
|
+
type InAppChatProps = UseInAppChatHookResponse & {
|
|
16
|
+
withChatHeader?: boolean;
|
|
17
|
+
withPopoverClose?: boolean;
|
|
18
|
+
borderless?: boolean;
|
|
19
|
+
title?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const messageText = (message: InAppChatMessage): string => {
|
|
23
|
+
const content = message.renderedContent;
|
|
24
|
+
if (typeof content === 'string') return content;
|
|
25
|
+
return content?.text ?? '';
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const isOutgoing = (message: InAppChatMessage): boolean => message.aiRole?.toUpperCase() === 'USER';
|
|
29
|
+
|
|
30
|
+
const InAppChat = ({
|
|
31
|
+
messages,
|
|
32
|
+
isLoading,
|
|
33
|
+
error,
|
|
34
|
+
sendMessage,
|
|
35
|
+
withChatHeader = false,
|
|
36
|
+
withPopoverClose = false,
|
|
37
|
+
borderless = false,
|
|
38
|
+
title = 'Chat',
|
|
39
|
+
}: InAppChatProps) => {
|
|
40
|
+
const [inputValue, setInputValue] = useState('');
|
|
41
|
+
const { scrollAreaRef, scrollToBottom } = useAutoScroll();
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
setTimeout(() => scrollToBottom({ smooth: true }), 0);
|
|
45
|
+
}, [messages.length, scrollToBottom]);
|
|
46
|
+
|
|
47
|
+
const handleSubmit = () => {
|
|
48
|
+
if (!inputValue.trim()) return;
|
|
49
|
+
// `sendMessage` is synchronous: it returns true the instant the message is
|
|
50
|
+
// optimistically queued (network send runs in the background). Clear the
|
|
51
|
+
// composer right away on success so a fast second Enter can't re-send the same
|
|
52
|
+
// text as a duplicate; on false (chat not ready) keep the visitor's text.
|
|
53
|
+
if (sendMessage(inputValue)) setInputValue('');
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
|
57
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
handleSubmit();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Theme asChild>
|
|
65
|
+
<Flex direction="column" className={cn('h-full', !borderless && 'border border-gray-400/40')}>
|
|
66
|
+
{withChatHeader && (
|
|
67
|
+
<Flex align="center" justify="between" className="border-b border-b-gray-400/40 px-6 py-4">
|
|
68
|
+
<Heading size={3}>{title}</Heading>
|
|
69
|
+
{withPopoverClose && (
|
|
70
|
+
<Popover.Close>
|
|
71
|
+
<Button shape="square" roundness="full" variant="ghost" mode="subtle" inset="right">
|
|
72
|
+
<X />
|
|
73
|
+
</Button>
|
|
74
|
+
</Popover.Close>
|
|
75
|
+
)}
|
|
76
|
+
</Flex>
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
<Flex direction="column" className="grow overflow-auto bg-gray-50">
|
|
80
|
+
<ScrollArea.Root ref={scrollAreaRef} className="h-full grow-1 p-6">
|
|
81
|
+
<ScrollArea.Viewport className="h-full">
|
|
82
|
+
<Flex direction="column" gap={3}>
|
|
83
|
+
{messages.map((message) => (
|
|
84
|
+
<div
|
|
85
|
+
key={message.externalUid || message.id}
|
|
86
|
+
className={cn(
|
|
87
|
+
'max-w-[80%] rounded-lg py-2 px-3',
|
|
88
|
+
isOutgoing(message)
|
|
89
|
+
? 'bg-accent-600 ml-auto items-end text-white'
|
|
90
|
+
: 'bg-gray-200 mr-auto items-start text-gray-900',
|
|
91
|
+
)}
|
|
92
|
+
>
|
|
93
|
+
<Text as="p" size={2}>{messageText(message)}</Text>
|
|
94
|
+
</div>
|
|
95
|
+
))}
|
|
96
|
+
|
|
97
|
+
{isLoading && (
|
|
98
|
+
<Text as="p" size={2} className="mr-auto text-gray-500">
|
|
99
|
+
Loading…
|
|
100
|
+
</Text>
|
|
101
|
+
)}
|
|
102
|
+
|
|
103
|
+
{error && (
|
|
104
|
+
<Text
|
|
105
|
+
as="p"
|
|
106
|
+
size={2}
|
|
107
|
+
className="bg-negative-100 text-negative-900 mx-auto rounded-lg py-2 px-3"
|
|
108
|
+
>
|
|
109
|
+
{error}
|
|
110
|
+
</Text>
|
|
111
|
+
)}
|
|
112
|
+
</Flex>
|
|
113
|
+
</ScrollArea.Viewport>
|
|
114
|
+
<ScrollArea.Scrollbar orientation="vertical" className="w-1 bg-gray-200 opacity-50">
|
|
115
|
+
<ScrollArea.Thumb className="flex-1 rounded-2xl bg-gray-400" />
|
|
116
|
+
</ScrollArea.Scrollbar>
|
|
117
|
+
<ScrollArea.Corner />
|
|
118
|
+
</ScrollArea.Root>
|
|
119
|
+
</Flex>
|
|
120
|
+
|
|
121
|
+
<div className="shrink-0 grow-0 border-t border-t-gray-400/40">
|
|
122
|
+
<Flex gap={2} align="end" className="w-full">
|
|
123
|
+
<div className="w-full [&_textarea]:!border-none [&_textarea]:!outline-none">
|
|
124
|
+
<TextArea
|
|
125
|
+
aria-label="message"
|
|
126
|
+
size="extralarge"
|
|
127
|
+
placeholder="Type a message…"
|
|
128
|
+
value={inputValue}
|
|
129
|
+
onKeyDown={handleKeyDown}
|
|
130
|
+
onChange={(text) => setInputValue(text)}
|
|
131
|
+
roundness="none"
|
|
132
|
+
autogrow
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
<div className="mr-[7px] mb-[7px]">
|
|
136
|
+
<Button
|
|
137
|
+
shape="square"
|
|
138
|
+
roundness="full"
|
|
139
|
+
variant="fill"
|
|
140
|
+
size="medium"
|
|
141
|
+
onPress={handleSubmit}
|
|
142
|
+
isDisabled={!inputValue.trim()}
|
|
143
|
+
>
|
|
144
|
+
<Send size={20} />
|
|
145
|
+
</Button>
|
|
146
|
+
</div>
|
|
147
|
+
</Flex>
|
|
148
|
+
</div>
|
|
149
|
+
</Flex>
|
|
150
|
+
</Theme>
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
type InAppChatWrapperProps = Omit<InAppChatProps, keyof UseInAppChatHookResponse> & UseInAppChatHookProps;
|
|
155
|
+
|
|
156
|
+
const InAppChatWrapper = ({ identityId, idempotencyKey, initialMessage, ...props }: InAppChatWrapperProps) => {
|
|
157
|
+
const chat = useInAppChat({ identityId, idempotencyKey, initialMessage });
|
|
158
|
+
return <InAppChat {...chat} {...props} />;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export type { InAppChatProps, InAppChatWrapperProps };
|
|
162
|
+
|
|
163
|
+
export { InAppChat };
|
|
164
|
+
|
|
165
|
+
export default InAppChatWrapper;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import React 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
|
+
|
|
7
|
+
type LauncherPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
8
|
+
|
|
9
|
+
type InAppChatButtonProps = InAppChatWrapperProps & {
|
|
10
|
+
/** Where the floating launcher sits on screen. Defaults to `bottom-right`. */
|
|
11
|
+
position?: LauncherPosition,
|
|
12
|
+
/** Theme overrides for the launcher + chat surface (accent color, mode, roundness, …). */
|
|
13
|
+
theme?: ThemeProps,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Full, non-interpolated class strings so Tailwind can detect them.
|
|
17
|
+
const POSITION_CLASS: Record<LauncherPosition, string> = {
|
|
18
|
+
'bottom-right': 'right-4 bottom-4',
|
|
19
|
+
'bottom-left': 'left-4 bottom-4',
|
|
20
|
+
'top-right': 'right-4 top-4',
|
|
21
|
+
'top-left': 'left-4 top-4',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const InAppChatButton = ({
|
|
25
|
+
identityId,
|
|
26
|
+
idempotencyKey,
|
|
27
|
+
position = 'bottom-right',
|
|
28
|
+
theme,
|
|
29
|
+
...props
|
|
30
|
+
}: InAppChatButtonProps) => (
|
|
31
|
+
<Theme {...theme}>
|
|
32
|
+
<Flex className={`fixed z-50 ${POSITION_CLASS[position]}`}>
|
|
33
|
+
<Popover.Root>
|
|
34
|
+
<Popover.Trigger>
|
|
35
|
+
<Button shape="square" roundness="full" variant="fill" size="large">
|
|
36
|
+
<MessageCircle />
|
|
37
|
+
</Button>
|
|
38
|
+
</Popover.Trigger>
|
|
39
|
+
{/* Radix unmounts Content while closed, so the chat hook (start →
|
|
40
|
+
subscribe → fetch) runs only once the visitor opens the launcher —
|
|
41
|
+
no empty conversation is created on page load. */}
|
|
42
|
+
<Popover.Content spacing="large" width="350px" height="450px">
|
|
43
|
+
<InAppChat
|
|
44
|
+
identityId={identityId}
|
|
45
|
+
idempotencyKey={idempotencyKey}
|
|
46
|
+
borderless
|
|
47
|
+
withChatHeader
|
|
48
|
+
withPopoverClose
|
|
49
|
+
{...props}
|
|
50
|
+
/>
|
|
51
|
+
</Popover.Content>
|
|
52
|
+
</Popover.Root>
|
|
53
|
+
</Flex>
|
|
54
|
+
</Theme>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export type { InAppChatButtonProps };
|
|
58
|
+
|
|
59
|
+
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,I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AgB,KAChC,KACA,OAAC,QAAK,KAAM,EAAG,QAAQ,WACpB,kCAAmBA,EAAa,OAAQ,IAAI,IAAM,EACrD,GACF,KACA,QAAC,UAAQ,KAAR,CACC,oBAAC,UAAQ,QAAR,CACC,mBAAC,UACC,MAAM,SACN,QAAQ,QACR,UAAU,OACV,KAAMA,EAAa,OAAS,SAAW,WACvC,QAAS,IAAM,CACTA,EAAa,OACfH,EAAyBG,EAAa,EAAE,EAExCJ,EAAuBI,EAAa,EAAE,CAE1C,EAEC,SAAAA,EAAa,UAAS,OAAC,aAAS,KAAK,OAAC,SAAK,EAC9C,EACF,KACA,OAAC,UAAQ,QAAR,CACC,QAASA,EAAa,OAAS,iBAAmB,eACpD,GACF,GACF,GAhCSA,EAAa,EAiCxB,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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Popover", "Text", "Theme", "Tooltip", "Inbox", "Mail", "MailOpen", "X", "NotificationBell", "markNotificationAsRead", "markNotificationAsUnread", "notifications", "unreadNotificationsCount", "notification", "NotificationBell_default"]
|
|
7
|
-
}
|