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[soup]: return to traditional tabs (#2375)

Peter Chinmanaf7a17ff9c86
diff --git a/js/app/packages/app/component/command/CommandMenu.tsx b/js/app/packages/app/component/command/CommandMenu.tsx
index c8dc613fbf..155183ff98 100644
--- a/js/app/packages/app/component/command/CommandMenu.tsx
+++ b/js/app/packages/app/component/command/CommandMenu.tsx
@@ -7,7 +7,7 @@ import {
import { getActiveCommandsFromScope } from '@core/hotkey/getCommands';
import { runCommand } from '@core/hotkey/utils';
import { Dialog } from '@kobalte/core/dialog';
-import { Tabs } from '@kobalte/core/tabs';
+import { Tabs } from '@core/component/Tabs';
import { registerHotkey, useHotkeyDOMScope } from 'core/hotkey/hotkeys';
import {
createEffect,
@@ -598,38 +598,20 @@ function CommandMenuFooter(props: {
}
function CategoryFilterTabs() {
+ const list = CATEGORIES.map((c) => ({ value: c.id, label: c.label }));
+
return (
- <Tabs
- value={CommandState.categoryFilter()}
- onChange={(value) => {
- if (value) {
- CommandState.setCategoryFilter(value as CategoryFilter);
- CommandState.setSelectedIndex(0);
- }
- }}
- >
- <Tabs.List class="p-1.5 border-b border-edge-muted/50">
- <div class="text-sm rounded-xs overflow-clip border border-edge-muted inline-block">
- <div class="flex">
- <For each={CATEGORIES}>
- {(category) => (
- <Tabs.Trigger
- value={category.id}
- class={cn(
- 'border-r-1 border-edge-muted last:border-r-0',
- 'relative text-ink-muted/70 px-2.5 py-1 text-xs font-medium block hover:bg-ink/6 hover:text-ink',
- CommandState.categoryFilter() === category.id &&
- 'text-ink bg-edge/50'
- )}
- tabIndex={-1}
- >
- {category.label}
- </Tabs.Trigger>
- )}
- </For>
- </div>
- </div>
- </Tabs.List>
- </Tabs>
+ <div class="px-1.5 py-1.5 border-b border-edge-muted/50">
+ <Tabs
+ list={list}
+ value={CommandState.categoryFilter()}
+ onChange={(value) => {
+ if (value) {
+ CommandState.setCategoryFilter(value as CategoryFilter);
+ CommandState.setSelectedIndex(0);
+ }
+ }}
+ />
+ </div>
);
}
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
index b794465cb5..48f871e9ec 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-create-button.tsx
@@ -85,7 +85,7 @@ export const SoupViewCreateButton = () => {
<Button
variant="secondary"
size="sm"
- class="rounded-xs whitespace-nowrap px-2"
+ class="rounded-xs whitespace-nowrap px-2 text-ink-muted hover:text-ink"
onClick={() => handleSelect(options()[0])}
>
<CreateOptionIcon id={options()[0].id} />
@@ -98,7 +98,7 @@ export const SoupViewCreateButton = () => {
as={Button}
variant="secondary"
size="sm"
- class="rounded-xs whitespace-nowrap px-2"
+ class="rounded-xs whitespace-nowrap px-2 text-ink-muted hover:text-ink"
>
<span>Create</span>
<ChevronDownIcon class="size-3" />
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx
index f78ea7f0d1..5a0f4de25b 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view-tabs.tsx
@@ -9,10 +9,7 @@ import { useSoupView } from '@app/component/next-soup/soup-view/soup-view-contex
import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';
import { isListViewID, type ListView } from '@app/constants/list-views';
import { useUserContext } from '@core/context/user';
-import {
- SegmentedControl,
- type SegmentedControlItem,
-} from '@core/component/SegmentedControl';
+import { Tabs, type TabItem } from '@core/component/Tabs';
import {
batch,
createEffect,
@@ -29,8 +26,6 @@ import ChevronDownIcon from '@icon/regular/caret-down.svg';
import { hapticImpact } from '@core/mobile/haptics';
import { cn } from '@ui/utils/classname';
-type TabItem = SegmentedControlItem;
-
/** Views that have tab definitions. Shared between VIEW_TAB_LISTS and VIEW_TAB_PRESETS. */
export type TabbedListView = Extract<
ListView,
@@ -150,14 +145,12 @@ const ViewTabs = (props: { view: TabbedListView }) => {
const list = () => VIEW_TAB_LISTS[props.view];
return (
- <div>
- <SegmentedControl
- list={list()}
- value={activeTab()}
- defaultValue={VIEW_TAB_PRESETS[props.view].default}
- onChange={(value) => applyTabPreset(props.view, value)}
- />
- </div>
+ <Tabs
+ list={list()}
+ value={activeTab()}
+ defaultValue={VIEW_TAB_PRESETS[props.view].default}
+ onChange={(value) => applyTabPreset(props.view, value)}
+ />
);
};
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index 56128e137f..8e165ce06e 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -248,7 +248,7 @@ export const SoupView = (props: SoupViewProps) => {
})}
>
<Show when={!isMobile()}>
- <h1 class="font-medium text-ink-muted select-none text-sm shrink-0">
+ <h1 class="font-semibold text-ink select-none text-sm shrink-0">
{props.viewName}
</h1>
</Show>
@@ -259,6 +259,7 @@ export const SoupView = (props: SoupViewProps) => {
priority={1}
expanded={<SoupViewTabs />}
collapsed={<CollapsedSoupViewTabs />}
+ containerClass="h-full"
/>
</Show>
<Show when={!isMobile()}>
diff --git a/js/app/packages/app/component/split-layout/components/CollapsibleHeaderItem.tsx b/js/app/packages/app/component/split-layout/components/CollapsibleHeaderItem.tsx
index 9bd854d26c..0662b980cb 100644
--- a/js/app/packages/app/component/split-layout/components/CollapsibleHeaderItem.tsx
+++ b/js/app/packages/app/component/split-layout/components/CollapsibleHeaderItem.tsx
@@ -1,5 +1,6 @@
import { createSignal, type JSX, Show } from 'solid-js';
import { useRegisterCollapsibleHeaderItem } from '../layoutUtils';
+import { cn } from '@ui/utils/classname';
type CollapsibleHeaderItemProps = {
id: string;
@@ -7,6 +8,7 @@ type CollapsibleHeaderItemProps = {
expanded: JSX.Element;
collapsed: JSX.Element;
onCollapsedChange?: (isCollapsed: boolean) => void;
+ containerClass?: string;
};
export function CollapsibleHeaderItem(props: CollapsibleHeaderItemProps) {
@@ -26,12 +28,18 @@ export function CollapsibleHeaderItem(props: CollapsibleHeaderItemProps) {
return (
<>
<Show when={!isCollapsed()}>
- <div ref={setExpandedRef} class="flex items-center">
+ <div
+ ref={setExpandedRef}
+ class={cn('flex items-center', props.containerClass)}
+ >
{props.expanded}
</div>
</Show>
<Show when={isCollapsed()}>
- <div ref={setCollapsedRef} class="flex items-center">
+ <div
+ ref={setCollapsedRef}
+ class={cn('flex items-center', props.containerClass)}
+ >
{props.collapsed}
</div>
</Show>
diff --git a/js/app/packages/block-channel/component/Top.tsx b/js/app/packages/block-channel/component/Top.tsx
index 32ce764099..1f7c57d95f 100644
--- a/js/app/packages/block-channel/component/Top.tsx
+++ b/js/app/packages/block-channel/component/Top.tsx
@@ -33,10 +33,7 @@ import { isChannelAdminOrOwner } from '@queries/channel/derived';
import { useChannelModals } from './ModalsProvider';
import { ParticipantManagerButton } from './ParticipantManager';
import { useAnalytics } from '@app/component/analytics-context';
-import {
- SegmentedControl,
- type SegmentedControlItem,
-} from '@core/component/SegmentedControl';
+import { Tabs, type TabItem } from '@core/component/Tabs';
import type { ChannelTabId } from '@channel/Channel/channel-tabs';
type TopIconProps = {
@@ -73,7 +70,7 @@ type TopProps = {
type ChannelTopLeftProps = TopProps & {
lockRename?: boolean;
- tabs?: readonly SegmentedControlItem[];
+ tabs?: readonly TabItem[];
activeTab?: ChannelTabId;
onTabChange?: (value: ChannelTabId) => void;
};
@@ -101,8 +98,8 @@ export function ChannelTopLeft(props: ChannelTopLeftProps) {
/>
</div>
<Show when={props.tabs && props.activeTab && props.onTabChange}>
- <div class="ph-no-capture min-w-0 shrink-0">
- <SegmentedControl
+ <div class="ph-no-capture min-w-0 shrink-0 h-full">
+ <Tabs
list={[...(props.tabs ?? [])]}
value={props.activeTab}
onChange={(value) => props.onTabChange?.(value as ChannelTabId)}
diff --git a/js/app/packages/core/component/Tabs.tsx b/js/app/packages/core/component/Tabs.tsx
new file mode 100644
index 0000000000..1a6494aa23
--- /dev/null
+++ b/js/app/packages/core/component/Tabs.tsx
@@ -0,0 +1,93 @@
+import {
+ SegmentedControl as KSegmentedControl,
+ type SegmentedControlRootProps,
+} from '@kobalte/core/segmented-control';
+import { createEffect, createSignal, For, splitProps } from 'solid-js';
+import { cn } from '@ui/utils/classname';
+
+export type TabItem = {
+ value: string;
+ label: string;
+};
+
+export const Tabs = (
+ props: {
+ list: TabItem[];
+ value?: string;
+ defaultValue?: string;
+ } & Omit<SegmentedControlRootProps, 'defaultValue'>
+) => {
+ const [local, rootProps] = splitProps(props, [
+ 'list',
+ 'value',
+ 'defaultValue',
+ 'disabled',
+ ]);
+
+ let listRef!: HTMLDivElement;
+ const itemRefs: HTMLElement[] = [];
+
+ const [indicatorStyle, setIndicatorStyle] = createSignal({
+ left: 0,
+ width: 0,
+ });
+
+ const updateIndicatorPosition = (element: HTMLElement) => {
+ if (!listRef || !element) return;
+ const listRect = listRef.getBoundingClientRect();
+ const tabRect = element.getBoundingClientRect();
+ setIndicatorStyle({
+ left: tabRect.left - listRect.left + listRef.scrollLeft,
+ width: tabRect.width,
+ });
+ };
+
+ createEffect(() => {
+ const val = local.value ?? local.defaultValue ?? local.list[0]?.value;
+ const idx = local.list.findIndex((t) => t.value === val);
+ if (idx >= 0 && itemRefs[idx]) updateIndicatorPosition(itemRefs[idx]);
+ });
+
+ return (
+ <KSegmentedControl
+ value={local.value}
+ defaultValue={local.defaultValue ?? local.list[0]?.value}
+ disabled={local.disabled}
+ {...rootProps}
+ class="h-full"
+ >
+ <div ref={listRef} class="relative flex items-center h-full">
+ <For each={local.list}>
+ {(item, i) => (
+ <KSegmentedControl.Item
+ value={item.value}
+ disabled={local.disabled}
+ ref={(el) => {
+ itemRefs[i()] = el;
+ }}
+ >
+ <KSegmentedControl.ItemInput class="absolute inset-0 pointer-events-none" />
+ <KSegmentedControl.ItemLabel
+ class={cn(
+ 'flex items-center px-2 py-1 text-sm font-medium',
+ 'text-ink-extra-muted',
+ 'data-[checked]:text-accent hover:text-accent'
+ )}
+ onPointerDown={() => rootProps.onChange?.(item.value)}
+ >
+ {item.label}
+ </KSegmentedControl.ItemLabel>
+ </KSegmentedControl.Item>
+ )}
+ </For>
+ <div
+ class="absolute bottom-0 h-[1px] bg-accent transition-[left,width] duration-150 pointer-events-none"
+ style={{
+ left: `${indicatorStyle().left}px`,
+ width: `${indicatorStyle().width}px`,
+ }}
+ />
+ </div>
+ </KSegmentedControl>
+ );
+};