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.

feat(sidebar): hotkey tooltips for links, replace <a> with <btn> (#1974)

Seamus63c73432efa1
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsx
index 3a1e605b12..423435128a 100644
--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx
+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx
@@ -27,7 +27,7 @@ import { useSettingsState } from '@core/constant/SettingsState';
import type { ValidHotkey } from '@core/hotkey/types';
import { registerHotkey } from '@core/hotkey/hotkeys';
import { GO_TO_COMMAND_SCOPE, GO_TO_LEADER_KEY } from '@app/constants/hotkeys';
-import { ROUTER_BASE } from '@app/constants/routerBase';
+
import { TOKENS } from '@core/hotkey/tokens';
import { Hotkey } from '@core/component/Hotkey';
@@ -272,6 +272,7 @@ export const AppSidebar = (props: AppSidebarProps) => {
<Button
class="flex items-center justify-start text-sm gap-2 cursor-default w-full rounded-xs py-1"
variant="ghost"
+ tooltipPlacement="right"
tooltip={
<LabelAndHotKey
label="Create new"
@@ -292,6 +293,7 @@ export const AppSidebar = (props: AppSidebarProps) => {
<Button
class="flex items-center justify-start text-sm gap-2 cursor-default w-full rounded-xs py-1"
variant="ghost"
+ tooltipPlacement="right"
tooltip={
<LabelAndHotKey
label="Command palette"
@@ -312,11 +314,12 @@ export const AppSidebar = (props: AppSidebarProps) => {
<Button
class="flex items-center justify-start text-sm gap-2 cursor-default w-full rounded-xs py-1"
variant="ghost"
+ tooltipPlacement="right"
onClick={toggleSettings}
tooltip={
<LabelAndHotKey
label="Settings"
- hotkeyToken="global.toggleSettings"
+ hotkeyToken={TOKENS.global.toggleSettings}
/>
}
>
@@ -360,14 +363,24 @@ const SidebarLink = (props: SidebarLinkProps) => {
return (
<Button
- as="a"
+ as="button"
draggable={false}
variant="ghost"
class={cn(
'flex items-center justify-start text-sm gap-2 cursor-default w-full rounded-xs py-1',
isActive() && 'bg-ink/7 not-disabled:hover:bg-ink/15 text-ink'
)}
- href={`${ROUTER_BASE}/component${props.href}`}
+ tooltipPlacement="right"
+ tooltip={
+ <LabelAndHotKey
+ label={`Go to ${props.label}`}
+ hotkeySequence={
+ props.standaloneHotkey
+ ? [{ shortcut: props.hotkey }]
+ : [{ shortcut: GO_TO_LEADER_KEY }, { shortcut: props.hotkey }]
+ }
+ />
+ }
onMouseEnter={() => setIsHovering(true)}
onMouseLeave={() => setIsHovering(false)}
onClick={(e) => {
diff --git a/js/app/packages/core/component/Tooltip.tsx b/js/app/packages/core/component/Tooltip.tsx
index 772890284d..6267b01eba 100644
--- a/js/app/packages/core/component/Tooltip.tsx
+++ b/js/app/packages/core/component/Tooltip.tsx
@@ -1,7 +1,8 @@
import type { HotkeyToken } from '@core/hotkey/tokens';
import CorvuTooltip, { type FloatingOptions } from '@corvu/tooltip';
import type { Placement } from '@floating-ui/dom';
-import { type JSX, mergeProps, type ParentProps, Show } from 'solid-js';
+import { cn } from '@ui/utils/classname';
+import { For, type JSX, mergeProps, type ParentProps, Show } from 'solid-js';
import { Hotkey } from './Hotkey';
const TOOLTIP_DELAY = 250;
@@ -104,19 +105,54 @@ export const NullTooltip = (props: ParentProps<{}>) => {
);
};
+export type HotkeySequenceStep = {
+ token?: HotkeyToken;
+ shortcut?: string;
+};
+
export type LabelAndHotKeyProps = {
label: string;
hotkeyToken?: HotkeyToken;
shortcut?: string;
+ hotkeySequence?: HotkeySequenceStep[];
};
export function LabelAndHotKey(props: LabelAndHotKeyProps) {
+ const hasSingleHotkey = () =>
+ !props.hotkeySequence && (!!props.hotkeyToken || !!props.shortcut);
+ const hasSequence = () =>
+ !!props.hotkeySequence && props.hotkeySequence.length > 0;
+ const hasPadding = () => !hasSingleHotkey() && !hasSequence();
+
return (
<div
- class={`flex flex-row items-center space-x-2 ${props.hotkeyToken || props.shortcut ? 'px-0' : 'px-1'}`}
+ class={cn(
+ 'flex flex-row items-center space-x-2',
+ hasPadding() ? 'px-1' : 'px-0'
+ )}
>
<div class="text-xs capitalize">{props.label}</div>
- <Show when={props.hotkeyToken || props.shortcut}>
+ <Show when={hasSequence()}>
+ <div class="flex items-center gap-1 ml-auto">
+ <For each={props.hotkeySequence}>
+ {(step, ndx) => (
+ <>
+ <div class="text-[0.625rem] rounded-sm border border-edge-muted px-1.5 py-0.25">
+ <Hotkey
+ token={step.token}
+ shortcut={step.shortcut}
+ class="flex gap-1"
+ />
+ </div>
+ <Show when={ndx() < (props.hotkeySequence ?? []).length - 1}>
+ <span class="text-ink-extra-muted">then</span>
+ </Show>
+ </>
+ )}
+ </For>
+ </div>
+ </Show>
+ <Show when={hasSingleHotkey()}>
<div class="text-[0.625rem] rounded-sm ml-auto border border-edge-muted px-1.5 py-0.25">
{props.hotkeyToken
? Hotkey({ token: props.hotkeyToken, class: 'flex gap-1' })
diff --git a/js/app/packages/ui/components/Button.tsx b/js/app/packages/ui/components/Button.tsx
index 304f2a021e..84cb3ff85a 100644
--- a/js/app/packages/ui/components/Button.tsx
+++ b/js/app/packages/ui/components/Button.tsx
@@ -1,8 +1,9 @@
import { Button as KButton, type ButtonRootProps } from '@kobalte/core/button';
import type { PolymorphicProps } from '@kobalte/core/polymorphic';
import { cn } from '@ui/utils/classname';
-import { Tooltip } from 'core/component/Tooltip';
-import { type JSX, splitProps, type ValidComponent } from 'solid-js';
+import CorvuTooltip from '@corvu/tooltip';
+import type { Placement } from '@floating-ui/dom';
+import { type JSX, Show, splitProps, type ValidComponent } from 'solid-js';
export type ButtonVariant =
| 'primary'
@@ -22,6 +23,7 @@ export type ButtonProps<T extends ValidComponent = 'button'> = PolymorphicProps<
variant?: ButtonVariant;
size?: ButtonSize;
tooltip?: JSX.Element;
+ tooltipPlacement?: Placement;
class?: string;
children?: JSX.Element;
};
@@ -51,6 +53,16 @@ const sizeStyles: Record<ButtonSize, string> = {
'icon-lg': 'p-2 size-11 [&_svg]:size-7',
};
+const TOOLTIP_DELAY = 250;
+
+const TOOLTIP_FLOATING_OPTIONS = {
+ offset: 12,
+ flip: true,
+ shift: { padding: 16 },
+ size: { padding: 16, fitViewPort: true },
+ boundary: 'viewport' as const,
+};
+
/**
* ### The basic button component. When in doubt, use Button.
*
@@ -60,6 +72,7 @@ const sizeStyles: Record<ButtonSize, string> = {
* @param props.variant - primary, secondary, tertiary, destructive, ghost (default), link, or accent.
* @param props.size - sm, md (default), lg, icon-sm, icon-md, or icon-lg.
* @param props.tooltip - Optional tooltip content to display when hovering over the button.
+ * @param props.tooltipPlacement - Placement of the tooltip (default: "bottom"). Accepts any Floating UI placement string.
* @param props.as - Override the rendered element (e.g. `"a"` or a router `<Link>` component).
*
* @example
@@ -92,31 +105,52 @@ export const Button = <T extends ValidComponent = 'button'>(
'class',
'children',
'tooltip',
+ 'tooltipPlacement',
]);
const variant = () => local.variant ?? 'ghost';
const size = () => local.size ?? 'md';
- function MaybeWrapInTooltip(wrapProps: { children: JSX.Element }) {
- if (!local.tooltip) return wrapProps.children;
- return <Tooltip tooltip={local.tooltip}>{wrapProps.children}</Tooltip>;
- }
+ const cls = () =>
+ cn(
+ 'relative inline-flex items-center justify-center font-medium leading-none border border-transparent',
+ 'data-[disabled]:cursor-not-allowed',
+ 'touch:min-h-11 touch:min-w-11 touch:[&_svg]:size-6',
+ variantStyles[variant()],
+ sizeStyles[size()],
+ local.class
+ );
return (
- <MaybeWrapInTooltip>
- <KButton
- class={cn(
- 'relative inline-flex items-center justify-center font-medium leading-none border border-transparent',
- 'data-[disabled]:cursor-not-allowed',
- 'touch:min-h-11 touch:min-w-11 touch:[&_svg]:size-6',
- variantStyles[variant()],
- sizeStyles[size()],
- local.class
- )}
- {...others}
+ <Show
+ when={local.tooltip}
+ fallback={
+ <KButton class={cls()} {...others}>
+ {local.children}
+ </KButton>
+ }
+ >
+ <CorvuTooltip
+ placement={local.tooltipPlacement ?? 'bottom'}
+ floatingOptions={TOOLTIP_FLOATING_OPTIONS}
+ group="tooltip-single-group"
+ openDelay={TOOLTIP_DELAY}
+ closeDelay={TOOLTIP_DELAY}
>
- {local.children}
- </KButton>
- </MaybeWrapInTooltip>
+ <CorvuTooltip.Trigger as={KButton} class={cls()} {...others}>
+ {local.children}
+ </CorvuTooltip.Trigger>
+ <CorvuTooltip.Portal>
+ <CorvuTooltip.Content
+ class="z-tool-tip"
+ style={{ 'max-width': 'calc(100vw - 32px)' }}
+ >
+ <div class="flex items-center justify-center bg-panel p-1.5 text-ink-muted text-xs wrap-break-word rounded-sm border border-edge-muted shadow-md shadow-[#000]/5">
+ {local.tooltip}
+ </div>
+ </CorvuTooltip.Content>
+ </CorvuTooltip.Portal>
+ </CorvuTooltip>
+ </Show>
);
};