Skip to content

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

6.8 KB
Raw Blame
import React from 'react';
import {
  Paintbrush,
  Sliders,
  ChevronDown,
  Settings,
  BookOpen,
  Blend,
} from 'lucide-react';
import { ToolType, BrushSettings } from '../types/editor';
import { useI18n } from '../i18n';

interface ModernPropertyBarProps {
  tool: ToolType;
  brushSettings: BrushSettings;
  onUpdateBrushSettings: (newSettings: Partial<BrushSettings>) => void;
  onToggleBrushEditor: () => void;
  onOpenPresets?: () => void;
  isBrushEditorOpen?: boolean;
}

const BLEND_MODES = [
  { value: 'source-over', label: 'Normal' },
  { value: 'multiply', label: 'Multiply' },
  { value: 'screen', label: 'Screen' },
  { value: 'overlay', label: 'Overlay' },
  { value: 'darken', label: 'Darken' },
  { value: 'lighten', label: 'Lighten' },
  { value: 'color-dodge', label: 'Color Dodge' },
  { value: 'color-burn', label: 'Color Burn' },
];

export const ModernPropertyBar: React.FC<ModernPropertyBarProps> = ({
  tool: _tool,
  brushSettings,
  onUpdateBrushSettings,
  onToggleBrushEditor,
  onOpenPresets,
  isBrushEditorOpen = false,
}) => {
  const { t, tc, td } = useI18n();
  const currentSize = Math.round(brushSettings.size);
  const currentOpacity = Math.round((brushSettings.opacity ?? 1) * 100);
  const currentFlow = Math.round((brushSettings.flow ?? 1) * 100);
  const brushDisplayName = td(brushSettings.brushName || (brushSettings.preset as string) || 'Brush');

  return (
    <div className="h-9 px-3 flex items-center justify-between text-xs select-none z-20 shrink-0 bg-ui-panel border-b border-ui-subtle text-ui-primary">
      {/* Left controls */}
      <div className="flex items-center space-x-2">
        {/* Presets Button */}
        <button
          onClick={onOpenPresets || onToggleBrushEditor}
          title={t('Browse Brush Presets')}
          className="flex items-center space-x-1 px-2.5 py-1 rounded-ui-sm bg-ui-control hover:bg-ui-control-hover border border-ui-subtle text-ui-secondary hover:text-ui-primary transition-colors cursor-pointer text-xs"
        >
          <BookOpen className="w-3.5 h-3.5 text-ui-icon-muted" />
          <span>{t('Presets')}</span>
        </button>

        {/* Active Brush Preset Pill */}
        <button
          onClick={onToggleBrushEditor}
          title={t('Current Brush Preset (Click to Toggle Editor)')}
          className={`flex items-center space-x-1.5 px-2.5 py-1 rounded-ui-sm border text-xs transition-colors cursor-pointer ${
            isBrushEditorOpen
              ? 'bg-ui-control-active border-ui-default text-ui-primary'
              : 'bg-ui-control hover:bg-ui-control-hover border-ui-subtle text-ui-primary'
          }`}
        >
          <Paintbrush className="w-3.5 h-3.5 text-ui-icon" />
          <span className="font-medium max-w-[140px] truncate">{brushDisplayName}</span>
          <ChevronDown className="w-3 h-3 text-ui-muted" />
        </button>

        {/* Brush Editor Button */}
        <button
          onClick={onToggleBrushEditor}
          title={t('Toggle Detailed Brush Settings & Dynamics')}
          className={`flex items-center space-x-1 px-2.5 py-1 rounded-ui-sm border text-xs transition-colors cursor-pointer ${
            isBrushEditorOpen
              ? 'bg-ui-accent-subtle text-ui-accent border-ui-accent-border'
              : 'bg-ui-control hover:bg-ui-control-hover border-ui-subtle text-ui-secondary hover:text-ui-primary'
          }`}
        >
          <Sliders className="w-3.5 h-3.5" />
          <span>{t('Brush Editor')}</span>
        </button>

        <span className="text-ui-disabled">|</span>

        {/* Mode Dropdown */}
        <div className="flex items-center space-x-1.5 bg-ui-input border border-ui-subtle rounded-ui-sm px-2 py-0.5">
          <Blend className="w-3.5 h-3.5 text-ui-muted" />
          <span className="text-[11px] text-ui-muted">{t('Mode:')}</span>
          <select
            defaultValue="source-over"
            className="bg-transparent text-ui-primary text-xs font-medium outline-none cursor-pointer pr-1"
            title={t('Brush Blending Mode')}
          >
            {BLEND_MODES.map((bm) => (
              <option key={bm.value} value={bm.value} className="bg-ui-elevated text-ui-primary">
                {tc('blendMode', bm.label)}
              </option>
            ))}
          </select>
        </div>

        {/* Size Input */}
        <div className="flex items-center space-x-1 bg-ui-input border border-ui-subtle rounded-ui-sm px-2 py-0.5">
          <span className="text-[11px] text-ui-muted">{t('Size:')}</span>
          <input
            type="number"
            min={1}
            max={500}
            value={currentSize}
            onChange={(e) => onUpdateBrushSettings({ size: Math.max(1, Math.min(500, Number(e.target.value))) })}
            className="w-11 bg-transparent text-ui-primary text-xs font-ui-mono tabular-nums outline-none text-right"
          />
          <span className="text-[11px] text-ui-muted font-ui-mono">px</span>
        </div>

        {/* Opacity Input */}
        <div className="flex items-center space-x-1 bg-ui-input border border-ui-subtle rounded-ui-sm px-2 py-0.5">
          <span className="text-[11px] text-ui-muted">{t('Opacity:')}</span>
          <input
            type="number"
            min={1}
            max={100}
            value={currentOpacity}
            onChange={(e) =>
              onUpdateBrushSettings({
                opacity: Math.max(0.01, Math.min(1, Number(e.target.value) / 100)),
              })
            }
            className="w-9 bg-transparent text-ui-primary text-xs font-ui-mono tabular-nums outline-none text-right"
          />
          <span className="text-[11px] text-ui-muted font-ui-mono">%</span>
        </div>

        {/* Flow Input */}
        <div className="flex items-center space-x-1 bg-ui-input border border-ui-subtle rounded-ui-sm px-2 py-0.5">
          <span className="text-[11px] text-ui-muted">{t('Flow:')}</span>
          <input
            type="number"
            min={1}
            max={100}
            value={currentFlow}
            onChange={(e) =>
              onUpdateBrushSettings({
                flow: Math.max(0.01, Math.min(1, Number(e.target.value) / 100)),
              })
            }
            className="w-9 bg-transparent text-ui-primary text-xs font-ui-mono tabular-nums outline-none text-right"
          />
          <span className="text-[11px] text-ui-muted font-ui-mono">%</span>
        </div>
      </div>

      {/* Right controls: Tool settings cog */}
      <div className="flex items-center space-x-1.5">
        <button
          onClick={onToggleBrushEditor}
          title={t('Tool Options & Presets')}
          className="p-1 rounded-ui-sm text-ui-muted hover:text-ui-primary hover:bg-ui-control-hover transition-colors cursor-pointer"
        >
          <Settings className="w-3.5 h-3.5" />
        </button>
      </div>
    </div>
  );
};