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.7 KB
Raw Blame
import { cn } from '@ui/utils/classname';
import { createSignal, type JSX, Show } from 'solid-js';
import { CopySubjectButton } from './copy-subject-button';

function lastWordCluster(title: string): { lead: string; last: string } {
  const i = title.lastIndexOf(' ');
  if (i === -1) return { lead: '', last: title };
  return { lead: title.slice(0, i + 1), last: title.slice(i + 1) };
}

export function EmailThreadTitle(props: {
  title: string;
  onCopy?: (subject: string) => void | boolean | Promise<void | boolean>;
  copyReveal?: 'hover' | 'always';
  /** Replaces the Copy subject button after the last word. */
  trailing?: JSX.Element;
  class?: string;
}) {
  const [titleHovered, setTitleHovered] = createSignal(false);
  const cluster = () => lastWordCluster(props.title);
  const copyHidden = () => props.copyReveal === 'hover' && !titleHovered();

  return (
    <h1
      class={cn(
        'ph-no-capture block w-full max-w-full min-w-0 text-pretty font-semibold tracking-tight text-ink select-text cursor-text wrap-break-word leading-snug',
        props.class
      )}
      onMouseEnter={() => setTitleHovered(true)}
      onMouseLeave={() => setTitleHovered(false)}
    >
      {cluster().lead}
      <span class={cn('select-text', cluster().lead && 'whitespace-nowrap')}>
        {cluster().last}
        <Show
          when={props.trailing}
          fallback={
            <CopySubjectButton
              subject={props.title}
              onCopy={props.onCopy}
              class={cn(
                'ml-1.5 select-none text-inherit transition-opacity duration-150 ease',
                copyHidden() ? 'opacity-0' : 'opacity-100'
              )}
            />
          }
        >
          {props.trailing}
        </Show>
      </span>
    </h1>
  );
}