Skip to content

Commit 3932e1f

Browse files
committed
chatbot popover
1 parent 4997361 commit 3932e1f

File tree

3 files changed

+88
-44
lines changed

3 files changed

+88
-44
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@leafygreen-ui/password-input": "^3.0.13",
5858
"@leafygreen-ui/pipeline": "^7.0.14",
5959
"@leafygreen-ui/polymorphic": "^2.0.9",
60+
"@leafygreen-ui/popover": "^13.0.11",
6061
"@leafygreen-ui/radio-box-group": "^14.0.10",
6162
"@leafygreen-ui/radio-group": "^12.0.12",
6263
"@leafygreen-ui/search-input": "^5.0.14",

src/app/template.tsx

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ import IconButton from '@leafygreen-ui/icon-button';
2828
import Icon from '@leafygreen-ui/icon';
2929
import { ChatbotComponent } from '@/components/chatbot';
3030

31+
const DRAWER_WIDTH = 432;
32+
3133
export default function Template({ children }: { children: React.ReactNode }) {
3234
const { darkMode } = useDarkMode();
33-
const [isDrawerOpen, setDrawerOpen] = useState(true);
3435

3536
const [isMobile] = useMediaQuery(['(max-width: 640px)'], {
3637
fallback: [false],
@@ -47,43 +48,39 @@ export default function Template({ children }: { children: React.ReactNode }) {
4748
: color.light.background.primary.default};
4849
`}
4950
>
50-
<TempDrawerLayout open={isDrawerOpen} setOpen={setDrawerOpen}>
51-
<SideNavigation />
51+
<SideNavigation />
5252

53-
<div
54-
className={css`
55-
width: 100%;
56-
padding-top: ${spacing[400]}px;
57-
padding-right: ${spacing[400]}px;
58-
display: flex;
59-
justify-content: flex-end;
60-
gap: ${spacing[150]}px;
61-
`}
62-
>
63-
<UserMenu />
64-
<IconButton onClick={() => setDrawerOpen(!isDrawerOpen)}>
65-
<Icon glyph="Sparkle" />
66-
</IconButton>
67-
<DarkModeToggle />
68-
</div>
53+
<div
54+
className={css`
55+
width: 100%;
56+
padding-top: ${spacing[400]}px;
57+
padding-right: ${spacing[400]}px;
58+
display: flex;
59+
justify-content: flex-end;
60+
gap: ${spacing[150]}px;
61+
`}
62+
>
63+
<UserMenu />
64+
<DarkModeToggle />
65+
</div>
6966

70-
<div
71-
className={cx(
72-
css`
73-
height: 100%;
74-
margin-left: ${isMobile
75-
? 0
76-
: `${SIDE_NAV_WIDTH}px`}; // SideNav override}))}
77-
padding-left: ${spacing[1000]}px;
78-
padding-right: ${spacing[1000]}px;
79-
padding-top: ${spacing[1600]}px;
80-
`,
81-
)}
82-
>
83-
{children}
84-
<Footer />
85-
</div>
86-
</TempDrawerLayout>
67+
<div
68+
className={cx(
69+
css`
70+
height: 100%;
71+
margin-left: ${isMobile
72+
? 0
73+
: `${SIDE_NAV_WIDTH}px`}; // SideNav override}))}
74+
padding-left: ${spacing[1000]}px;
75+
padding-right: ${spacing[1000]}px;
76+
padding-top: ${spacing[1600]}px;
77+
`,
78+
)}
79+
>
80+
{children}
81+
<ChatbotComponent />
82+
<Footer />
83+
</div>
8784
</div>
8885
);
8986
}
@@ -111,7 +108,7 @@ const TempDrawerLayout = ({
111108
`,
112109
{
113110
[css`
114-
grid-template-columns: auto 384px;
111+
grid-template-columns: auto ${DRAWER_WIDTH}px;
115112
`]: open,
116113
},
117114
)}

src/components/chatbot/index.tsx

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
1+
import Button, { Variant } from '@leafygreen-ui/button';
2+
import Popover from '@leafygreen-ui/popover';
13
import { css } from '@leafygreen-ui/emotion';
4+
import Icon from '@leafygreen-ui/icon';
25
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider';
3-
import Chatbot, { ChatWindow } from 'mongodb-chatbot-ui';
6+
import Chatbot, {
7+
ChatWindow,
8+
FloatingActionButtonTrigger,
9+
} from 'mongodb-chatbot-ui';
10+
import { useRef, useState } from 'react';
11+
import Card from '@leafygreen-ui/card';
12+
import { spacing } from '@leafygreen-ui/tokens';
413

514
export const ChatbotComponent = () => {
6-
const { darkMode } = useDarkMode();
715
const endpoint = process.env.NEXT_PUBLIC_CHATBOT_ENDPOINT;
16+
const { darkMode } = useDarkMode();
17+
const fabRef = useRef<HTMLButtonElement>(null);
18+
19+
const [isOpen, setIsOpen] = useState(false);
20+
const handleFABClick = () => {
21+
setIsOpen(prev => !prev);
22+
};
823

924
return endpoint ? (
1025
<Chatbot darkMode={darkMode} serverBaseUrl={endpoint}>
11-
<ChatWindow
26+
<Button
27+
ref={fabRef}
28+
onClick={handleFABClick}
29+
variant={Variant.BaseGreen}
30+
size="large"
31+
leftGlyph={<Icon glyph="Sparkle" size="large" />}
1232
className={css`
13-
height: 100%;
33+
position: fixed;
34+
bottom: 24px;
35+
right: 24px;
1436
`}
15-
initialMessageText="Welcome to LeafyGreen AI. What can I help you with?"
16-
// initialMessageSuggestedPrompts={suggestedPrompts}
17-
/>
37+
>
38+
{/* <span>Chat with LeafyGreen AI</span> */}
39+
</Button>
40+
41+
<Popover
42+
active={isOpen}
43+
refEl={fabRef}
44+
spacing={spacing[200]}
45+
align={'bottom'}
46+
justify={'end'}
47+
className={css`
48+
min-width: 33vw;
49+
max-width: 50vw;
50+
/* max-height: 50vh; */
51+
`}
52+
>
53+
<ChatWindow
54+
className={css`
55+
height: 100%;
56+
width: 100%;
57+
`}
58+
windowTitle="LeafyGreen AI"
59+
60+
// initialMessageText="Welcome to LeafyGreen AI. What can I help you with?"
61+
// initialMessageSuggestedPrompts={suggestedPrompts}
62+
/>
63+
</Popover>
1864
</Chatbot>
1965
) : null;
2066
};

0 commit comments

Comments
 (0)