File size: 2,348 Bytes
baa4c21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { useStore } from '@nanostores/react';
import useViewport from '~/lib/hooks';
import { chatStore } from '~/lib/stores/chat';
import { workbenchStore } from '~/lib/stores/workbench';
import { classNames } from '~/utils/classNames';

interface HeaderActionButtonsProps {}

export function HeaderActionButtons({}: HeaderActionButtonsProps) {
  const showWorkbench = useStore(workbenchStore.showWorkbench);
  const { showChat } = useStore(chatStore);

  const isSmallViewport = useViewport(1024);

  const canHideChat = showWorkbench || !showChat;

  return (
    <div className="flex">

      <div className="flex border border-bolt-elements-borderColor rounded-md overflow-hidden">

        <Button

          active={showChat}

          disabled={!canHideChat || isSmallViewport} // expand button is disabled on mobile as it's not needed

          onClick={() => {

            if (canHideChat) {

              chatStore.setKey('showChat', !showChat);

            }

          }}

        >

          <div className="i-bolt:chat text-sm" />

        </Button>

        <div className="w-[1px] bg-bolt-elements-borderColor" />

        <Button

          active={showWorkbench}

          onClick={() => {

            if (showWorkbench && !showChat) {

              chatStore.setKey('showChat', true);

            }



            workbenchStore.showWorkbench.set(!showWorkbench);

          }}

        >

          <div className="i-ph:code-bold" />

        </Button>

      </div>

    </div>
  );
}

interface ButtonProps {
  active?: boolean;
  disabled?: boolean;
  children?: any;
  onClick?: VoidFunction;
}

function Button({ active = false, disabled = false, children, onClick }: ButtonProps) {
  return (
    <button

      className={classNames('flex items-center p-1.5', {

        'bg-bolt-elements-item-backgroundDefault hover:bg-bolt-elements-item-backgroundActive text-bolt-elements-textTertiary hover:text-bolt-elements-textPrimary':

          !active,

        'bg-bolt-elements-item-backgroundAccent text-bolt-elements-item-contentAccent': active && !disabled,

        'bg-bolt-elements-item-backgroundDefault text-alpha-gray-20 dark:text-alpha-white-20 cursor-not-allowed':

          disabled,

      })}

      onClick={onClick}

    >

      {children}

    </button>
  );
}