Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.5 KB
Raw Blame
import { ActionIcon } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
import { Maximize2Icon, Minimize2Icon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { useChatInputStore } from '@/features/ChatInput/store';
import { usePermission } from '@/hooks/usePermission';

import { composerHoverMarker } from '../markers.stylex';

const styles = stylex.create({
  revealOnComposerHover: {
    opacity: {
      default: null,
      [stylex.when.ancestor(':not(:hover)', composerHoverMarker)]: 0,
      [stylex.when.ancestor(':hover', composerHoverMarker)]: 1,
    },
  },
});

const ExpandButton = memo(() => {
  const { t } = useTranslation('editor');
  const [expand, setExpand, editor] = useChatInputStore((s) => [s.expand, s.setExpand, s.editor]);
  const { allowed: canUseChatInputAction, reason } = usePermission('create_content');
  return (
    <ActionIcon
      className={stylex.props(styles.revealOnComposerHover).className}
      disabled={!canUseChatInputAction}
      icon={expand ? Minimize2Icon : Maximize2Icon}
      size={{ blockSize: 32, size: 16, strokeWidth: 2.3 }}
      style={{
        zIndex: 10,
      }}
      title={
        canUseChatInputAction ? t(expand ? 'actions.expand.off' : 'actions.expand.on') : reason
      }
      onClick={() => {
        if (!canUseChatInputAction) return;
        setExpand?.(!expand);
        editor?.focus();
      }}
    />
  );
});

ExpandButton.displayName = 'ExpandButton';

export default ExpandButton;