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(ui): add ButtonGroup, update common topbar buttons (#3195)

Seamus5f66c02d5873
diff --git a/js/app/packages/app/component/ChatWithAgentButton.tsx b/js/app/packages/app/component/ChatWithAgentButton.tsx
index cc46d5d86c..79018db7b3 100644
--- a/js/app/packages/app/component/ChatWithAgentButton.tsx
+++ b/js/app/packages/app/component/ChatWithAgentButton.tsx
@@ -2,10 +2,10 @@ import { globalSplitManager } from '@app/signal/splitLayout';
import type { Attachment } from '@core/component/AI/types';
import { storeChatStateImmediate } from '@core/component/AI/util/storage';
import { toast } from '@core/component/Toast/Toast';
-import { Tooltip } from '@core/component/Tooltip';
import { createChat } from '@core/util/create';
import { AnimatedStarIcon } from '@macro-icons/wide/animating/star';
import { ChannelType } from '@service-cognition/generated/schemas/channelType';
+import { Button } from '@ui';
import { createSignal } from 'solid-js';
import { match } from 'ts-pattern';
@@ -88,20 +88,18 @@ export function ChatWithAgentButton(props: { entity: ChatWithAgentEntity }) {
const [hovering, setHovering] = createSignal(false);
return (
- <Tooltip tooltip="Chat with Agent">
- <div class="border border-edge-muted flex ml-1 items-stretch rounded-xs">
- <button
- class="h-7 px-2 flex items-center gap-1 text-xs hover:bg-hover hover-transition-bg"
- onMouseEnter={() => setHovering(true)}
- onMouseLeave={() => setHovering(false)}
- onClick={() => openChatWithAgent(props.entity)}
- >
- <div class="size-4">
- <AnimatedStarIcon triggerAnimation={hovering()} />
- </div>
- <span class="text-ink">Chat</span>
- </button>
- </div>
- </Tooltip>
+ <Button
+ tooltip="Chat with Agent"
+ variant="base"
+ size="sm"
+ onMouseEnter={() => setHovering(true)}
+ onMouseLeave={() => setHovering(false)}
+ onClick={() => openChatWithAgent(props.entity)}
+ depth={3}
+ class="bg-panel shadow shadow-drop-shadow"
+ >
+ <AnimatedStarIcon triggerAnimation={hovering()} />
+ <span class="text-xs">Chat</span>
+ </Button>
);
}
diff --git a/js/app/packages/app/component/split-layout/components/SplitToolbar.tsx b/js/app/packages/app/component/split-layout/components/SplitToolbar.tsx
index 9d38cb39a2..e9a9d1b6fe 100644
--- a/js/app/packages/app/component/split-layout/components/SplitToolbar.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitToolbar.tsx
@@ -46,20 +46,20 @@ export function SplitToolbar(props: { ref: Setter<HTMLDivElement | null> }) {
<div
class={cn(
'relative w-full flex items-center justify-between shrink-0',
- hasContent() && 'min-h-10.25 border-b border-edge-muted',
+ hasContent() && 'min-h-10 border-b border-edge-muted',
preview() && 'hidden'
)}
data-split-toolbar
ref={props.ref}
>
<div
- class="flex-1 h-full flex items-center gap-0.5 px-1"
+ class="flex-1 h-full flex items-center gap-0.5 px-2"
ref={(ref) => {
panel.layoutRefs.toolbarLeft = ref;
}}
/>
<div
- class="flex h-full items-center gap-0.5 px-1.25"
+ class="flex h-full items-center gap-0.5 px-2"
ref={(ref) => {
panel.layoutRefs.toolbarRight = ref;
}}
diff --git a/js/app/packages/block-md/component/DispatchAgentMenu.tsx b/js/app/packages/block-md/component/DispatchAgentMenu.tsx
index b2262a4044..6bc19ba455 100644
--- a/js/app/packages/block-md/component/DispatchAgentMenu.tsx
+++ b/js/app/packages/block-md/component/DispatchAgentMenu.tsx
@@ -19,7 +19,7 @@ import { storageServiceClient } from '@service-storage/client';
import type { CommentThread } from '@service-storage/generated/schemas/commentThread';
import { createCallback } from '@solid-primitives/rootless';
import { makePersisted } from '@solid-primitives/storage';
-import { Button } from '@ui';
+import { Button, ButtonGroup } from '@ui';
import { type Component, createSignal, For, type JSX } from 'solid-js';
import { Dynamic } from 'solid-js/web';
import {
@@ -191,29 +191,23 @@ export function DispatchAgentButton() {
return (
<DropdownMenu open={open()} onOpenChange={setOpen}>
- <div class="border border-edge-muted flex ml-1 items-stretch rounded-xs">
- <Button
- onClick={handlePrimaryClick}
- tooltip={lastUsed().name}
- variant="ghost"
- size="icon-sm"
- class="p-1"
- >
+ <ButtonGroup
+ variant="base"
+ size="icon-sm"
+ depth={3}
+ class="mx-1 bg-panel"
+ >
+ <Button onClick={handlePrimaryClick} tooltip={lastUsed().name}>
<Dynamic
component={lastUsed().buttonIcon ?? lastUsed().icon}
- class="size-3.5"
+ class="size-3!"
/>
</Button>
- <div class="w-px bg-edge-muted" />
- <DropdownMenu.Trigger
- as={Button}
- variant="ghost"
- size="icon-sm"
- class="p-1"
- >
- <CaretDown class="size-3" />
+ <ButtonGroup.Divider />
+ <DropdownMenu.Trigger as={Button} class="p-1">
+ <CaretDown class="size-3.5!" />
</DropdownMenu.Trigger>
- </div>
+ </ButtonGroup>
<DropdownMenu.Portal>
<DropdownMenuContent>
<MenuItem
diff --git a/js/app/packages/core/component/NotificationsModal.tsx b/js/app/packages/core/component/NotificationsModal.tsx
index 2eb6fe191c..8c410de52a 100644
--- a/js/app/packages/core/component/NotificationsModal.tsx
+++ b/js/app/packages/core/component/NotificationsModal.tsx
@@ -29,7 +29,7 @@ export function NotificationsButton(props: {
() => notifications().filter((n) => !n.viewed_at).length
);
return (
- <div class="relative" tabIndex={-1}>
+ <div class="relative p-0 flex" tabIndex={-1}>
<Button
class={cn(
'px-1',
diff --git a/js/app/packages/core/component/ReferencesModal.tsx b/js/app/packages/core/component/ReferencesModal.tsx
index 693f2d743d..255b0b829b 100644
--- a/js/app/packages/core/component/ReferencesModal.tsx
+++ b/js/app/packages/core/component/ReferencesModal.tsx
@@ -6,6 +6,7 @@ import Quotes from '@icon/regular/quotes.svg';
import BracketLeft from '@macro-icons/macro-group-bracket-left.svg';
import { commsServiceClient } from '@service-comms/client';
import type { ItemType } from '@service-storage/client';
+import { Button } from '@ui';
import { createResource, Suspense } from 'solid-js';
import { References } from './References';
import { Tooltip } from './Tooltip';
@@ -21,40 +22,17 @@ export function ReferencesButton(props: {
onOpenChange?: (open: boolean) => void;
}) {
const drawerControl = useDrawerControl(REFERENCES_DRAWER_ID);
- const [referenceCount] = createResource(
- () => props.documentId,
- async (id) => {
- const entityType = props.entityType ?? 'document';
- const response = await commsServiceClient.attachmentReferences({
- entity_type: entityType,
- entity_id: id,
- });
- if (isErr(response)) {
- console.error(response);
- return 0;
- }
- return response[1].references.length;
- }
- );
return (
- <Tooltip tooltip={'View References'}>
- <div
- class="flex items-center gap-1 py-1 font-mono text-xs text-ink-disabled hover:bg-hover relative"
- tabIndex={0}
- onClick={() => {
- props.onOpenChange?.(!drawerControl.isOpen());
- drawerControl.toggle();
- }}
- role="button"
- >
- <BracketLeft class="h-4 w-2 text-edge" />
- <Quotes class="size-4 text-ink" />
- <Suspense fallback={<div class="text-xs">0</div>}>
- <span class="text-xs">{referenceCount() ?? ''}</span>
- </Suspense>
- <BracketLeft class="h-4 w-2 rotate-180 text-edge" />
- </div>
- </Tooltip>
+ <Button
+ size="icon-sm"
+ variant="ghost"
+ onClick={() => {
+ props.onOpenChange?.(!drawerControl.isOpen());
+ drawerControl.toggle();
+ }}
+ >
+ <Quotes />
+ </Button>
);
}
diff --git a/js/app/packages/core/component/TopBar/ShareButton.tsx b/js/app/packages/core/component/TopBar/ShareButton.tsx
index b673ea30e8..157b692bb4 100644
--- a/js/app/packages/core/component/TopBar/ShareButton.tsx
+++ b/js/app/packages/core/component/TopBar/ShareButton.tsx
@@ -45,13 +45,13 @@ import CheckIcon from '@icon/bold/check-bold.svg';
import IconX from '@icon/bold/x-bold.svg';
import ChevronDownIcon from '@icon/regular/caret-down.svg';
import IconLink from '@icon/regular/link.svg';
+import IconShared from '@icon/regular/share.svg';
import { Dialog } from '@kobalte/core/dialog';
import { DropdownMenu } from '@kobalte/core/dropdown-menu';
import IconComment from '@macro-icons/wide/comment.svg';
import WideCopy from '@macro-icons/wide/copy.svg';
import IconEdit from '@macro-icons/wide/edit.svg';
import IconEye from '@macro-icons/wide/eye.svg';
-import IconShared from '@macro-icons/wide/share.svg';
import UserCircle from '@macro-icons/wide/user-circle.svg';
import WideUsers from '@macro-icons/wide/users.svg';
import { cognitionApiServiceClient } from '@service-cognition/client';
@@ -65,7 +65,7 @@ import type { AccessLevel } from '@service-storage/generated/schemas/accessLevel
import type { SharePermissionV2ChannelSharePermissions } from '@service-storage/generated/schemas/sharePermissionV2ChannelSharePermissions';
import { createCallback } from '@solid-primitives/rootless';
import { useNavigate } from '@solidjs/router';
-import { Button, cn, Panel } from '@ui';
+import { Button, ButtonGroup, cn, Panel } from '@ui';
import {
type Accessor,
createContext,
@@ -1255,7 +1255,7 @@ export function ShareTrigger(props: { copyLink?: () => void }) {
});
return (
- <div class="border border-edge-muted flex ml-1 items-stretch rounded-xs">
+ <ButtonGroup variant="base" size="sm" class="ml-1 bg-panel" depth={3}>
<Tooltip
tooltip={
<div>
@@ -1276,8 +1276,7 @@ export function ShareTrigger(props: { copyLink?: () => void }) {
</div>
}
>
- <button
- class="text-xs hover:bg-hover text-ink px-2 flex items-center gap-1 h-full"
+ <Button
onClick={() => {
if (!isAuthenticated()) {
openLoginModal();
@@ -1287,23 +1286,21 @@ export function ShareTrigger(props: { copyLink?: () => void }) {
}
}}
>
- <IconShared class="size-3.5" />
+ <IconShared />
Share
- </button>
+ </Button>
</Tooltip>
- <div class="w-px bg-edge-muted" />
+ <ButtonGroup.Divider />
<Button
tooltip="Copy Share Link"
- onClick={ShareLinkAction().action}
- variant="ghost"
size="icon-sm"
- class="p-1"
+ onClick={ShareLinkAction().action}
>
- <Dynamic component={ShareLinkAction().icon} />
+ <Dynamic component={ShareLinkAction().icon} class="size-3.5!" />
</Button>
- </div>
+ </ButtonGroup>
);
}
diff --git a/js/app/packages/ui/components/Button.tsx b/js/app/packages/ui/components/Button.tsx
index cabb5a4703..d758f836c0 100644
--- a/js/app/packages/ui/components/Button.tsx
+++ b/js/app/packages/ui/components/Button.tsx
@@ -3,6 +3,7 @@ import { type ComponentProps, type JSX, Show, splitProps } from 'solid-js';
import type { Placement } from '@floating-ui/dom';
import CorvuTooltip from '@corvu/tooltip';
import { cn } from '../utils/classname';
+import { useButtonGroupContext } from './ButtonGroup';
import { Layer } from './Layer';
export type ButtonProps = ButtonRootProps<'button'> & ComponentProps<'button'> & {
@@ -16,9 +17,9 @@ export type ButtonProps = ButtonRootProps<'button'> & ComponentProps<'button'> &
class?: string;
};
-type ButtonSize = 'sm' | 'icon-sm' | 'md' | 'icon-md' | 'lg' | 'icon-lg';
+export type ButtonSize = 'sm' | 'icon-sm' | 'md' | 'icon-md' | 'lg' | 'icon-lg';
-type ButtonVariant = 'ghost' | 'base' | 'active' | 'danger';
+export type ButtonVariant = 'ghost' | 'base' | 'active' | 'danger';
const variantStyles: Record<ButtonVariant, string> = {
danger: 'bg-transparent text-failure border border-failure/50 not-disabled:hover:bg-failure/10 not-disabled:active:bg-failure/20 disabled:opacity-30 ',
@@ -28,12 +29,12 @@ const variantStyles: Record<ButtonVariant, string> = {
};
const sizeStyles: Record<ButtonSize, string> = {
- 'lg': ' p-2.5 [&_svg]:size-5 gap-2 text-base',
- 'md': ' p-2 gap-1.5 text-sm ', /* scuffed */
- 'sm': 'h-6 px-2 [&_svg]:size-4 gap-1 text-xs ',
- 'icon-lg': 'size-11 p-2 [&_svg]:size-7 ', /* unused */
- 'icon-md': 'size-9 p-1.5 [&_svg]:size-6 ',
- 'icon-sm': 'size-6 p-1 [&_svg]:size-4 ',
+ 'lg': ' p-2.5 [&_:where(svg)]:size-5 gap-2 text-base',
+ 'md': ' p-2 gap-1.5 text-sm ', /* scuffed */
+ 'sm': 'h-6 px-2 [&_:where(svg)]:size-4 gap-1 text-xs ',
+ 'icon-lg': 'size-11 p-2 [&_:where(svg)]:size-7 ', /* unused */
+ 'icon-md': 'size-9 p-1.5 [&_:where(svg)]:size-6 ',
+ 'icon-sm': 'size-6 p-1 [&_:where(svg)]:size-4 ',
};
export const Button = (props: ButtonProps) => {
@@ -47,22 +48,24 @@ export const Button = (props: ButtonProps) => {
'size',
]);
+ const group = useButtonGroupContext();
+
const cls = () =>
cn(
'relative inline-flex items-center justify-center font-medium leading-none border border-transparent rounded-sm whitespace-nowrap',
{ 'touch:min-h-9 touch:min-w-9 touch:[&_svg]:size-6': !(props.noTouchResize) },
'outline-none focus-visible:bg-active',
'data-disabled:cursor-not-allowed',
- variantStyles[local.variant ?? 'ghost'],
- sizeStyles[local.size ?? 'md'],
+ variantStyles[local.variant ?? group?.variant ?? 'ghost'],
+ sizeStyles[local.size ?? group?.size ?? 'md'],
local.class
);
return (
- <Layer depth={local.depth ?? 0}>
+ <Layer depth={local.depth ?? group?.depth ?? 0}>
<Show
fallback={
- <KobalteButton class={cls()} {...others}>
+ <KobalteButton class={cls()} data-button {...others}>
{local.children}
</KobalteButton>
}
@@ -80,7 +83,7 @@ export const Button = (props: ButtonProps) => {
closeDelay={250}
openDelay={250}
>
- <CorvuTooltip.Trigger as={KobalteButton} class={cls()} {...others}>
+ <CorvuTooltip.Trigger as={KobalteButton} class={cls()} data-button {...others}>
{local.children}
</CorvuTooltip.Trigger>
<CorvuTooltip.Portal>
diff --git a/js/app/packages/ui/components/ButtonGroup.tsx b/js/app/packages/ui/components/ButtonGroup.tsx
new file mode 100644
index 0000000000..e379254016
--- /dev/null
+++ b/js/app/packages/ui/components/ButtonGroup.tsx
@@ -0,0 +1,126 @@
+import { type JSX, createContext, useContext } from 'solid-js';
+import type { ButtonSize, ButtonVariant } from './Button';
+import { cn } from '../utils/classname';
+import { Layer } from './Layer';
+
+type ButtonGroupOrientation = 'horizontal' | 'vertical';
+
+type ButtonGroupContextValue = {
+ depth?: 0 | 1 | 2 | 3 | 4 | 5;
+ variant?: ButtonVariant;
+ size?: ButtonSize;
+ orientation: ButtonGroupOrientation;
+};
+
+const ButtonGroupContext = createContext<ButtonGroupContextValue | undefined>(undefined);
+
+export const useButtonGroupContext = () => useContext(ButtonGroupContext);
+
+type ButtonGroupProps = {
+ depth?: 0 | 1 | 2 | 3 | 4 | 5;
+ variant?: ButtonVariant;
+ size?: ButtonSize;
+ orientation?: ButtonGroupOrientation;
+ class?: string;
+ children?: JSX.Element;
+};
+
+const groupVariantStyles: Record<ButtonVariant, string> = {
+ danger: 'border border-failure/50 ',
+ base: 'border border-edge-muted ',
+ active: 'border border-accent-ink ',
+ ghost: ' ',
+};
+
+const dividerVariantStyles: Record<ButtonVariant, string> = {
+ danger: 'bg-failure/50',
+ base: 'bg-edge-muted',
+ active: 'bg-accent-ink',
+ ghost: 'bg-edge-muted',
+};
+
+/* explicit cross-axis size so the group's outer box matches a standalone
+ Button of the same size (border-box absorbs the 1px outer border) */
+const groupHorizontalSize: Record<ButtonSize, string> = {
+ 'lg': '',
+ 'md': '',
+ 'sm': 'h-6',
+ 'icon-lg': 'h-11',
+ 'icon-md': 'h-9',
+ 'icon-sm': 'h-6',
+};
+
+const groupVerticalSize: Record<ButtonSize, string> = {
+ 'lg': '',
+ 'md': '',
+ 'sm': '',
+ 'icon-lg': 'w-11',
+ 'icon-md': 'w-9',
+ 'icon-sm': 'w-6',
+};
+
+export const ButtonGroup = (props: ButtonGroupProps) => {
+ const orientation = () => props.orientation ?? 'horizontal';
+ const variant = () => props.variant ?? 'ghost';
+ const sizeClass = () => {
+ if (!props.size) return '';
+ return orientation() === 'horizontal'
+ ? groupHorizontalSize[props.size]
+ : groupVerticalSize[props.size];
+ };
+
+ const ctx: ButtonGroupContextValue = {
+ get depth() { return props.depth; },
+ get variant() { return props.variant; },
+ get size() { return props.size; },
+ get orientation() { return orientation(); },
+ };
+
+ return (
+ <ButtonGroupContext.Provider value={ctx}>
+ <Layer depth={props.depth ?? 0}>
+ <div
+ role="group"
+ data-orientation={orientation()}
+ class={cn(
+ 'inline-flex overflow-hidden rounded-sm',
+ 'data-[orientation=horizontal]:flex-row items-center',
+ 'data-[orientation=vertical]:flex-col justify-center',
+ /* strip per-button rounding + borders so the group owns the frame */
+ '[&_[data-button]]:rounded-none',
+ '[&_[data-button]]:border-0',
+ sizeClass(),
+ groupVariantStyles[variant()],
+ props.class
+ )}
+ >
+ {props.children}
+ </div>
+ </Layer>
+ </ButtonGroupContext.Provider>
+ );
+};
+
+type DividerProps = { class?: string };
+
+const Divider = (props: DividerProps) => {
+ const group = useButtonGroupContext();
+ const orientation = () => group?.orientation ?? 'horizontal';
+ const variant = () => group?.variant ?? 'base';
+ return (
+ <div
+ role="separator"
+ aria-orientation={orientation()}
+ data-orientation={orientation()}
+ class={cn(
+ 'shrink-0 self-stretch',
+ 'data-[orientation=horizontal]:w-px',
+ 'data-[orientation=vertical]:h-px',
+ dividerVariantStyles[variant()],
+ props.class
+ )}
+ />
+ );
+};
+
+ButtonGroup.Divider = Divider;
diff --git a/js/app/packages/ui/index.ts b/js/app/packages/ui/index.ts
index 9178d58e45..91ea90e341 100644
--- a/js/app/packages/ui/index.ts
+++ b/js/app/packages/ui/index.ts
@@ -7,6 +7,7 @@ export { Keyboard } from './components/Keyboard';
export { Surface } from './components/Surface';
export { Dialog } from './components/Dialog';
export { Button } from './components/Button';
+export { ButtonGroup } from './components/ButtonGroup';
export { Hotkey } from './components/Hotkey';
export { Scroll } from './components/Scroll';
export { Panel } from './components/Panel';
@@ -14,7 +15,7 @@ export { Layer } from './components/Layer';
/* types */
export type { AvatarSize, AvatarProps, AvatarGroupSize, AvatarGroupProps } from './components/Avatar';
-export type { ButtonProps } from './components/Button';
+export type { ButtonProps, ButtonSize, ButtonVariant } from './components/Button';
export type { DialogProps } from './components/Dialog';
/* utils */