Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

2.6 KB
Raw Blame
import React from 'react';
import { ChevronDown, ChevronRight } from 'lucide-react';

export interface SectionDisclosureProps {
  title: string;
  open: boolean;
  onToggle: () => void;
  /** Optional compact right-side value or status indicator (e.g., "96%", "Pigment"). */
  summary?: React.ReactNode;
  summaryTone?: 'default' | 'accent' | 'success' | 'muted';
  /** Show top hairline divider (default: true). */
  divider?: boolean;
  dense?: boolean;
  children: React.ReactNode;
  className?: string;
  bodyClassName?: string;
  'data-testid'?: string;
}

const SUMMARY_TONE_CLASSES = {
  default: 'text-ui-primary',
  accent: 'text-ui-accent',
  success: 'text-ui-success',
  muted: 'text-ui-muted',
} as const;

const SectionDisclosureInner: React.FC<SectionDisclosureProps> = ({
  title,
  open,
  onToggle,
  summary,
  summaryTone = 'default',
  divider = true,
  dense = false,
  children,
  className = '',
  bodyClassName = '',
  'data-testid': dataTestId,
}) => (
  <div
    data-testid={dataTestId}
    data-open={open ? 'true' : 'false'}
    className={`bg-ui-panel ${divider ? 'border-t border-ui-subtle first:border-t-0' : ''} ${className}`}
  >
    <button
      type="button"
      aria-expanded={open}
      onClick={onToggle}
      className={`ui-icon-stroke w-full flex items-center justify-between gap-2 text-left transition-colors cursor-pointer select-none focus:outline-none focus-visible:bg-ui-control-hover ${
        dense ? 'px-2 py-1.5' : 'px-2.5 py-1.5'
      } ${
        open
          ? 'text-ui-primary hover:bg-ui-control-hover/65'
          : 'text-ui-secondary hover:text-ui-primary hover:bg-ui-control-hover/65'
      }`}
    >
      <span className="flex items-center gap-1 min-w-0">
        {open ? (
          <ChevronDown className="w-3 h-3 text-ui-icon-muted shrink-0" />
        ) : (
          <ChevronRight className="w-3 h-3 text-ui-icon-muted shrink-0" />
        )}
        <span className="text-[10.5px] font-medium tracking-[0.02em] truncate">
          {title}
        </span>
      </span>

      {summary !== undefined && summary !== null && (
        <span
          className={`font-ui-mono tabular-nums text-[10px] shrink-0 ${SUMMARY_TONE_CLASSES[summaryTone]}`}
        >
          {summary}
        </span>
      )}
    </button>

    {open && (
      <div
        className={`${
          dense ? 'px-2 pb-2 pt-1 space-y-2' : 'px-2.5 pb-2.5 pt-1 space-y-2'
        } ${bodyClassName}`}
      >
        {children}
      </div>
    )}
  </div>
);

export const SectionDisclosure = React.memo(SectionDisclosureInner);
SectionDisclosure.displayName = 'SectionDisclosure';