An AI-powered search engine with a generative UI
TypeScript generative-aigenerative-uinextjsollamareactsearxngshadcn-uitailwindcsstavilytypescriptupstashvercel-ai-sdk
feat: Add slide animation for ArtifactPanel and adjust speed
Yoshiki Miura66d81df1c2e8
diff --git a/components/artifact/chat-artifact-container.tsx b/components/artifact/chat-artifact-container.tsxindex a44a4920..0fdd9d41 100644--- a/components/artifact/chat-artifact-container.tsx+++ b/components/artifact/chat-artifact-container.tsx@@ -6,7 +6,8 @@ import {ResizablePanelGroup} from '@/components/ui/resizable'import { useMediaQuery } from '@/lib/hooks/use-media-query'-import React from 'react'+import { cn } from '@/lib/utils'+import React, { useEffect, useState } from 'react'import { useArtifact } from './artifact-context'import { ArtifactDrawer } from './artifact-drawer'import { ArtifactPanel } from './artifact-panel'@@ -18,6 +19,27 @@ export function ChatArtifactContainer({}) {const { state } = useArtifact()const isMobile = useMediaQuery('(max-width: 767px)') // Below md breakpoint+ const [renderPanel, setRenderPanel] = useState(state.isOpen)+ const [isClosing, setIsClosing] = useState(false)++ useEffect(() => {+ let timer: NodeJS.Timeout+ if (state.isOpen) {+ setRenderPanel(true)+ setIsClosing(false)+ } else {+ if (renderPanel) {+ setIsClosing(true)+ timer = setTimeout(() => {+ setRenderPanel(false)+ setIsClosing(false)+ }, 200)+ }+ }+ return () => {+ clearTimeout(timer)+ }+ }, [state.isOpen, renderPanel])return (<div className="flex-1 min-h-0 flex">@@ -29,10 +51,16 @@ export function ChatArtifactContainer({><ResizablePanel className="min-w-0">{children}</ResizablePanel>- {state.isOpen && (+ {renderPanel && (<><ResizableHandle />- <ResizablePanel className="min-w-96 w-96" maxSize={50}>+ <ResizablePanel+ className={cn('min-w-96 w-96 overflow-hidden', {+ 'animate-slide-in-right': state.isOpen && !isClosing,+ 'animate-slide-out-right': isClosing+ })}+ maxSize={50}+ ><ArtifactPanel /></ResizablePanel></>diff --git a/tailwind.config.ts b/tailwind.config.tsindex e79cda35..6e203e70 100644--- a/tailwind.config.ts+++ b/tailwind.config.ts@@ -101,13 +101,23 @@ const config = {opacity: '1'},to: { height: '0', opacity: '0' }+ },+ 'slide-in-right': {+ from: { transform: 'translateX(100%)', opacity: '0' },+ to: { transform: 'translateX(0)', opacity: '1' }+ },+ 'slide-out-right': {+ from: { transform: 'translateX(0)', opacity: '1' },+ to: { transform: 'translateX(100%)', opacity: '0' }}},animation: {'accordion-down': 'accordion-down 0.2s ease-out','accordion-up': 'accordion-up 0.2s ease-out','collapse-down': 'collapse-down 0.1s ease-in-out',- 'collapse-up': 'collapse-up 0.1s ease-in-out'+ 'collapse-up': 'collapse-up 0.1s ease-in-out',+ 'slide-in-right': 'slide-in-right 0.2s ease-out',+ 'slide-out-right': 'slide-out-right 0.2s ease-out'},fontFamily: {sans: ['var(--font-sans)', ...fontFamily.sans]