Skip to content

Commit 1225017

Browse files
committed
Add animation to dialog
1 parent ac3d076 commit 1225017

2 files changed

Lines changed: 61 additions & 28 deletions

File tree

src/app/components/Chat/ConversationPanel.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,28 @@ const ConversationPanel: FC<Props> = (props) => {
106106
<WebAccessCheckbox botId={props.botId} />
107107
<div className="flex flex-row items-center gap-3">
108108
<Tooltip content={t('Share conversation')}>
109-
<img src={shareIcon} className="w-5 h-5 cursor-pointer" onClick={openShareDialog} />
109+
<motion.img
110+
src={shareIcon}
111+
className="w-5 h-5 cursor-pointer"
112+
onClick={openShareDialog}
113+
whileHover={{ scale: 1.1 }}
114+
/>
110115
</Tooltip>
111116
<Tooltip content={t('Clear conversation')}>
112-
<img
117+
<motion.img
113118
src={clearIcon}
114119
className={cx('w-5 h-5', props.generating ? 'cursor-not-allowed' : 'cursor-pointer')}
115120
onClick={resetConversation}
121+
whileHover={{ scale: 1.1 }}
116122
/>
117123
</Tooltip>
118124
<Tooltip content={t('View history')}>
119-
<img src={historyIcon} className="w-5 h-5 cursor-pointer" onClick={openHistoryDialog} />
125+
<motion.img
126+
src={historyIcon}
127+
className="w-5 h-5 cursor-pointer"
128+
onClick={openHistoryDialog}
129+
whileHover={{ scale: 1.1 }}
130+
/>
120131
</Tooltip>
121132
</div>
122133
</div>
@@ -139,10 +150,10 @@ const ConversationPanel: FC<Props> = (props) => {
139150
/>
140151
</div>
141152
</div>
142-
{showHistory && <HistoryDialog botId={props.botId} open={true} onClose={() => setShowHistory(false)} />}
143153
{showShareDialog && (
144154
<ShareDialog open={true} onClose={() => setShowShareDialog(false)} messages={props.messages} />
145155
)}
156+
{showHistory && <HistoryDialog botId={props.botId} open={true} onClose={() => setShowHistory(false)} />}
146157
</ConversationContext.Provider>
147158
)
148159
}

src/app/components/Dialog.tsx

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Dialog as HeadlessDialog } from '@headlessui/react'
2-
import { cx } from '~/utils'
3-
import { FC, PropsWithChildren } from 'react'
1+
import { Dialog as HeadlessDialog, Transition } from '@headlessui/react'
2+
import { FC, Fragment, PropsWithChildren } from 'react'
43
import closeIcon from '~/assets/icons/close.svg'
4+
import { cx } from '~/utils'
55

66
interface Props {
77
title: string
@@ -13,29 +13,51 @@ interface Props {
1313

1414
const Dialog: FC<PropsWithChildren<Props>> = (props) => {
1515
return (
16-
<HeadlessDialog open={props.open} onClose={props.onClose} className="relative z-50">
17-
<div className="fixed inset-0 bg-black/30" aria-hidden="true" />
18-
<div className="fixed inset-0 flex items-center justify-center max-h-screen m-5">
19-
<HeadlessDialog.Panel
20-
className={cx(
21-
'mx-auto rounded-3xl bg-primary-background shadow-2xl max-h-full overflow-hidden flex flex-col',
22-
props.className,
23-
)}
16+
<Transition.Root show={props.open} as={Fragment}>
17+
<HeadlessDialog as="div" onClose={props.onClose} className="relative z-50">
18+
<Transition.Child
19+
as={Fragment}
20+
enter="ease-out duration-200"
21+
enterFrom="opacity-0"
22+
enterTo="opacity-100"
23+
leave="ease-in duration-200"
24+
leaveFrom="opacity-100"
25+
leaveTo="opacity-0"
2426
>
25-
<HeadlessDialog.Title
26-
className={cx(
27-
!props.borderless && 'border-b',
28-
'border-solid border-primary-border flex flex-row justify-center items-center py-4 px-5',
29-
)}
27+
<div className="fixed inset-0 bg-black/30 bg-opacity-75 transition-opacity" />
28+
</Transition.Child>
29+
<div className="fixed inset-0 flex items-center justify-center max-h-screen m-5">
30+
<Transition.Child
31+
as={Fragment}
32+
enter="ease-out duration-300"
33+
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
34+
enterTo="opacity-100 translate-y-0 sm:scale-100"
35+
leave="ease-in duration-200"
36+
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
37+
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
3038
>
31-
<span className="ml-auto" />
32-
<span className="font-bold text-primary-text text-base">{props.title}</span>
33-
<img src={closeIcon} className="w-4 h-4 ml-auto mr-[10px] cursor-pointer" onClick={props.onClose} />
34-
</HeadlessDialog.Title>
35-
{props.children}
36-
</HeadlessDialog.Panel>
37-
</div>
38-
</HeadlessDialog>
39+
<HeadlessDialog.Panel
40+
className={cx(
41+
'mx-auto rounded-3xl bg-primary-background shadow-2xl max-h-full overflow-hidden flex flex-col',
42+
props.className,
43+
)}
44+
>
45+
<HeadlessDialog.Title
46+
className={cx(
47+
!props.borderless && 'border-b',
48+
'border-solid border-primary-border flex flex-row justify-center items-center py-4 px-5',
49+
)}
50+
>
51+
<span className="ml-auto" />
52+
<span className="font-bold text-primary-text text-base">{props.title}</span>
53+
<img src={closeIcon} className="w-4 h-4 ml-auto mr-[10px] cursor-pointer" onClick={props.onClose} />
54+
</HeadlessDialog.Title>
55+
{props.children}
56+
</HeadlessDialog.Panel>
57+
</Transition.Child>
58+
</div>
59+
</HeadlessDialog>
60+
</Transition.Root>
3961
)
4062
}
4163

0 commit comments

Comments
 (0)