File size: 1,632 Bytes
ab9d59a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { useStore } from '@nanostores/react';
import { AnimatePresence, motion, type Variants } from 'framer-motion';
import { IconButton } from '~/components/ui/IconButton';
import { cubicEasingFn } from '~/utils/easings';
import { workspaceStore } from '../../lib/stores/workspace';

interface WorkspaceProps {
  chatStarted?: boolean;
}

const workspaceVariants = {
  closed: {
    width: 0,
    transition: {
      duration: 0.2,
      ease: cubicEasingFn,
    },
  },
  open: {
    width: '100%',
    transition: {
      duration: 0.5,
      type: 'spring',
    },
  },
} satisfies Variants;

export function Workspace({ chatStarted }: WorkspaceProps) {
  const showWorkspace = useStore(workspaceStore.showWorkspace);

  return (
    chatStarted && (
      <AnimatePresence>
        {showWorkspace && (
          <motion.div initial="closed" animate="open" exit="closed" variants={workspaceVariants}>
            <div className="fixed top-[calc(var(--header-height)+1.5rem)] bottom-6 w-[50vw] mr-4 z-0">
              <div className="bg-white border border-gray-200 shadow-sm rounded-lg overflow-hidden absolute inset-0 right-8">
                <header className="px-3 py-2 border-b border-gray-200">
                  <IconButton
                    icon="i-ph:x-circle"
                    className="ml-auto"
                    size="xxl"
                    onClick={() => {
                      workspaceStore.showWorkspace.set(false);
                    }}
                  />
                </header>
              </div>
            </div>
          </motion.div>
        )}
      </AnimatePresence>
    )
  );
}