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

3.6 KB
Raw Blame
import { t } from 'i18next';
import { ReactNode, useId } from 'react';

import { cn } from '@/lib/utils';

import { adminSurface } from './admin-surface';

export function SettingsPanel({
  title,
  description,
  action,
  flush = false,
  className,
  children,
}: SettingsPanelProps) {
  const hasHeader = title !== undefined || action !== undefined;
  return (
    <section
      data-slot="settings-panel"
      className={cn(adminSurface.card, 'flex flex-col', className)}
    >
      {hasHeader && (
        <header
          className={cn(
            adminSurface.panelHeader,
            'flex justify-between gap-4 p-5',
            description ? 'items-start' : 'items-center',
          )}
        >
          <div className="flex min-w-0 flex-col gap-1">
            {title && (
              <h2 className="text-sm font-semibold text-gray-12">{title}</h2>
            )}
            {description && (
              <p className="text-sm text-gray-11">{description}</p>
            )}
          </div>
          {action && (
            <div className="flex shrink-0 items-center gap-2">{action}</div>
          )}
        </header>
      )}
      <div
        className={cn(
          'flex flex-col',
          flush
            ? cn(
                'divide-y *:last:rounded-b-xl',
                !hasHeader && '*:first:rounded-t-xl',
                adminSurface.divider,
              )
            : 'gap-4 p-5',
        )}
      >
        {children}
      </div>
    </section>
  );
}

export function SettingsRow({
  icon,
  media,
  title,
  description,
  children,
  below,
  className,
  ...rest
}: SettingsRowProps) {
  const id = useId();
  const titleId = `${id}-title`;
  const descriptionId = `${id}-description`;
  return (
    <div
      data-slot="settings-row"
      role="group"
      aria-labelledby={titleId}
      aria-describedby={description ? descriptionId : undefined}
      className={cn('flex flex-col gap-4 px-5 py-4', className)}
      {...rest}
    >
      <div className="flex flex-wrap items-center gap-4">
        <div
          className={cn(
            'flex min-w-0 flex-1 items-center gap-4',
            media || icon ? 'basis-68' : 'basis-56',
          )}
        >
          {media && <div className="flex shrink-0 items-center">{media}</div>}
          {icon && (
            <div className="flex size-9 shrink-0 items-center justify-center rounded-lg border bg-gray-3 text-gray-12 [&_svg:not([class*='size-'])]:size-4">
              {icon}
            </div>
          )}
          <div className="flex min-w-0 flex-1 flex-col gap-1">
            <div
              id={titleId}
              className="flex flex-wrap items-center gap-x-2 gap-y-1 text-sm font-medium text-gray-12"
            >
              {title}
            </div>
            {description && (
              <div id={descriptionId} className="text-sm text-gray-11">
                {description}
              </div>
            )}
          </div>
        </div>
        {children && (
          <div className="ml-auto flex max-w-full shrink-0 items-center gap-2">
            {children}
          </div>
        )}
      </div>
      {below}
    </div>
  );
}

export function DangerZone({ children }: { children: ReactNode }) {
  return (
    <SettingsPanel title={t('Danger zone')} flush>
      {children}
    </SettingsPanel>
  );
}

type SettingsPanelProps = {
  title?: ReactNode;
  description?: ReactNode;
  action?: ReactNode;
  flush?: boolean;
  className?: string;
  children: ReactNode;
};

type SettingsRowProps = Omit<React.ComponentProps<'div'>, 'title'> & {
  icon?: ReactNode;
  media?: ReactNode;
  title: ReactNode;
  description?: ReactNode;
  below?: ReactNode;
};