Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

955 B
Raw Blame
import { cn } from '@/lib/utils';

const toTitleCase = (str: string) => {
  return str
    .toLowerCase()
    .split(' ')
    .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
    .join(' ');
};
export type ShortcutProps = {
  //can't name it key because it conflicts with the key prop of the component
  shortcutKey: string;
  withCtrl?: boolean;
  withShift?: boolean;
};

export const Shortcut = ({
  shortcutKey,
  withCtrl,
  withShift,
  className,
}: ShortcutProps & { className?: string }) => {
  const isMac = /(Mac)/i.test(navigator.userAgent);
  const isEscape = shortcutKey?.toLocaleLowerCase() === 'esc';
  return (
    <span
      className={cn('grow text-xs tracking-widest text-gray-11', className)}
    >
      {!isEscape && withCtrl && (isMac ? '⌘' : 'Ctrl')}
      {!isEscape && withShift && 'Shift'}
      {!isEscape && (withCtrl || withShift) && ' + '}
      {shortcutKey && toTitleCase(shortcutKey)}
    </span>
  );
};