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.

2.6 KB
Raw Blame
import {
  SegmentedControl as KSegmentedControl,
  type SegmentedControlRootProps,
} from '@kobalte/core/segmented-control';
import { For, type JSX, splitProps } from 'solid-js';
import { cn } from '../utils/classname';

export type TabItem = {
  value: string;
  label: string | (() => JSX.Element);
};

export type TabsProps = {
  list: TabItem[];
  value?: string;
  defaultValue?: string;
  class?: string;
  itemClass?: string;
  labelClass?: string;
  fullWidth?: boolean;
} & Omit<SegmentedControlRootProps, 'defaultValue'>;

/**
 * Borderless tab switcher. No track chrome — a rounded pill slides behind
 * the active item.
 */
export const Tabs = (props: TabsProps) => {
  const [local, rootProps] = splitProps(props, [
    'list',
    'value',
    'defaultValue',
    'disabled',
    'class',
    'itemClass',
    'labelClass',
    'fullWidth',
  ]);

  return (
    <KSegmentedControl
      value={local.value}
      defaultValue={local.defaultValue ?? local.list[0]?.value}
      disabled={local.disabled}
      {...rootProps}
      class={cn(
        'relative inline-flex h-8 items-center',
        local.fullWidth && 'flex w-full',
        local.class
      )}
    >
      <KSegmentedControl.Indicator class="pointer-events-none absolute top-0 left-0 z-0 rounded-full border border-edge-frame bg-active transition-[transform,width,height] duration-50 motion-reduce:transition-none" />
      <For each={local.list}>
        {(item) => (
          <KSegmentedControl.Item
            value={item.value}
            disabled={local.disabled}
            class={cn(
              'relative z-1 inline-flex h-full min-w-0 items-center rounded-full',
              'has-focus-visible:ring-2 has-focus-visible:ring-inset has-focus-visible:ring-edge-focus data-disabled:pointer-events-none data-disabled:opacity-50',
              local.fullWidth && 'flex-1',
              local.itemClass
            )}
          >
            <KSegmentedControl.ItemInput class="pointer-events-none absolute inset-0" />
            <KSegmentedControl.ItemLabel
              class={cn(
                'flex h-8 items-center px-4 text-xs font-medium rounded-full select-none text-ink-extra-muted hover:text-ink data-checked:text-ink transition-colors duration-120 motion-reduce:transition-none',
                local.fullWidth && 'w-full justify-center',
                local.labelClass
              )}
            >
              {typeof item.label === 'function' ? item.label() : item.label}
            </KSegmentedControl.ItemLabel>
          </KSegmentedControl.Item>
        )}
      </For>
    </KSegmentedControl>
  );
};