Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

1.6 KB
Raw Blame
import { isMobile } from '@core/mobile/isMobile';
import { fireAndForget } from '@core/util/fireAndForget';
import { cn, SendButton } from '@ui';
import { type JSX, splitProps } from 'solid-js';
import { useInput, useInputCommands } from './context';
import { hasSendableInputContent } from './utils/sendable-content';

export type SendActionProps = JSX.ButtonHTMLAttributes<HTMLButtonElement> & {
  /** Custom tooltip label. Defaults to "Send message". */
  tooltip?: string;
};

export function SendAction(props: SendActionProps) {
  const input = useInput();
  const commands = useInputCommands();
  const [local, rest] = splitProps(props, [
    'class',
    'disabled',
    'tooltip',
    'hidden',
  ]);
  const isBlockedByPending = () => !!input().hasPendingAttachments;
  const isBlockedByEmptyInput = () => !hasSendableInputContent(input());
  const isDisabled = () =>
    !!local.disabled || isBlockedByPending() || isBlockedByEmptyInput();

  const tooltipText = () => local.tooltip ?? 'Send message';

  return (
    <SendButton
      appearance="composer"
      tooltip={{ content: tooltipText(), shortcut: 'enter' }}
      aria-label={tooltipText()}
      data-input-action="send"
      pending={isBlockedByPending()}
      disabled={isDisabled()}
      hidden={isMobile() && isBlockedByEmptyInput()}
      // Full-frame mobile/tablet: pill rounding to match the dock/accessory islands.
      class={cn('touch:rounded-full', local.class)}
      onPointerDown={(event) => event.preventDefault()}
      onMouseDown={(event) => event.preventDefault()}
      onClick={() => fireAndForget(commands.send(), 'channel-input')}
      {...rest}
    />
  );
}