A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.
TypeScript animationcartoonclip-studio-paintcollaborativedesktop-appdigital-paintingdrawing-appillustrationmangamultiplayeropen-sourcerusttaurithreejswebglwebtoon
import React, { useRef, useState } from 'react';
import { ArrowLeftRight, ChevronDown, Minus, X } from 'lucide-react';
import { CanvasColorMode } from '../../types/editor';
import { FocusHudPoint } from '../../types/workspace';
import { toolStoreActions, useToolStore, workspaceStoreActions } from '../../stores';
import { ColorWheel } from '../ColorWheel';
import { FocusGripDots, getFocusHudSurfaceStyle, useFocusHudDrag } from './focusHudUtils';
import { useI18n } from '../../i18n';
export interface FocusFloatingColorCardProps {
colorMode: CanvasColorMode;
leftHandedMode: boolean;
floatingOpacity: number;
isAutoFaded: boolean;
customPosition?: FocusHudPoint;
}
export const FocusFloatingColorCard: React.FC<FocusFloatingColorCardProps> = React.memo(
({ colorMode, leftHandedMode, floatingOpacity, isAutoFaded, customPosition }) => {
const { t } = useI18n();
const primaryColor = useToolStore((s) => s.primaryColor);
const secondaryColor = useToolStore((s) => s.secondaryColor);
const recentColors = useToolStore((s) => s.recentColors);
const isTransparentColor = useToolStore((s) => s.isTransparentColor);
const currentTool = useToolStore((s) => s.tool);
const [collapsed, setCollapsed] = useState(false);
const [activeTarget, setActiveTarget] = useState<'primary' | 'secondary'>('primary');
const cardRef = useRef<HTMLDivElement>(null);
const { isDragging, handleStartDrag, handleResetWidgetPosition } = useFocusHudDrag(
'colorWheel',
cardRef,
customPosition
);
const activeHex = (activeTarget === 'primary' ? primaryColor : secondaryColor).toUpperCase();
const isFixed = Boolean(customPosition);
const anchorSide = isFixed ? 'custom' : leftHandedMode ? 'left' : 'right';
const anchorClass = isFixed
? ''
: leftHandedMode
? 'absolute top-12 left-3'
: 'absolute top-12 right-3';
const surfaceStyle = getFocusHudSurfaceStyle(
floatingOpacity,
isAutoFaded,
isFixed
? {
position: 'fixed',
left: customPosition!.x,
top: customPosition!.y,
zIndex: isDragging ? 49 : 42,
}
: { zIndex: 42 }
);
return (
<section
ref={cardRef}
role="region"
aria-label={t('Focus Color Wheel')}
data-testid="focus-color-card"
data-anchor-side={anchorSide}
data-collapsed={String(collapsed)}
data-hud-blur={floatingOpacity < 0.98 ? 'true' : 'false'}
data-auto-faded={String(isAutoFaded)}
onPointerDown={(e) => e.stopPropagation()}
onWheel={(e) => e.stopPropagation()}
style={surfaceStyle}
className={`${anchorClass} w-[192px] rounded-ui-lg border shadow-ui-floating text-ui-primary transition-[opacity,border-color,box-shadow] duration-150 select-none ui-icon-stroke ${
isDragging ? 'border-ui-strong shadow-ui-popover' : 'border-ui-default'
}`}
>
{/* Draggable Compact Header */}
<div
data-testid="focus-color-card-drag-handle"
onPointerDown={handleStartDrag}
onDoubleClick={handleResetWidgetPosition}
title={t('Drag to move Color Wheel · Double-click to snap back')}
className={`group h-7 px-2 flex items-center justify-between gap-1.5 cursor-grab active:cursor-grabbing ${
collapsed ? '' : 'border-b border-ui-subtle'
}`}
>
<div className="flex items-center gap-1.5 min-w-0">
<FocusGripDots orientation="horizontal" />
<span
aria-hidden="true"
className="w-3 h-3 rounded-ui-xs border border-ui-strong shrink-0"
style={{ backgroundColor: primaryColor }}
/>
<span
data-testid="focus-color-hex-readout"
className="text-[10px] font-ui-mono tabular-nums text-ui-secondary truncate"
>
{activeHex}
</span>
</div>
<div className="flex items-center gap-0.5 shrink-0">
<button
type="button"
data-testid="focus-color-collapse-btn"
onClick={() => setCollapsed((v) => !v)}
aria-label={collapsed ? t('Expand Color Wheel') : t('Collapse Color Wheel')}
aria-expanded={!collapsed}
title={collapsed ? t('Expand Color Wheel') : t('Collapse Color Wheel')}
className="w-4 h-4 rounded-ui-xs flex items-center justify-center text-ui-muted hover:text-ui-primary hover:bg-ui-control-hover transition-colors cursor-pointer"
>
{collapsed ? <ChevronDown className="w-3 h-3" /> : <Minus className="w-3 h-3" />}
</button>
<button
type="button"
data-testid="focus-color-close-btn"
onClick={() => workspaceStoreActions.updateFocusHud({ showFloatingColorWheel: false })}
aria-label={t('Hide Floating Color Wheel')}
title={t('Hide Color Wheel in Focus Mode')}
className="w-4 h-4 rounded-ui-xs flex items-center justify-center text-ui-muted hover:text-ui-primary hover:bg-ui-control-hover transition-colors cursor-pointer"
>
<X className="w-3 h-3" />
</button>
</div>
</div>
{/* Wheel + Swatches + Recent Strip */}
{!collapsed && (
<div className="p-2 space-y-1.5">
<div className="w-[174px] h-[164px] mx-auto flex items-center justify-center">
<ColorWheel
primaryColor={primaryColor}
secondaryColor={secondaryColor}
onPrimaryColorChange={(color, commit) =>
toolStoreActions.setPrimaryColor(color, commit, colorMode)
}
onSecondaryColorChange={(color, commit) =>
toolStoreActions.setSecondaryColor(color, commit, colorMode)
}
onSwapColors={() => toolStoreActions.swapColors(colorMode)}
colorMode={colorMode}
currentTool={currentTool}
onSelectTool={(t) => toolStoreActions.selectTool(t)}
recentColors={recentColors}
containerWidth={174}
containerHeight={164}
activeTarget={activeTarget}
onActiveTargetChange={setActiveTarget}
hideHeader
/>
</div>
{/* Primary / Secondary Swatch Pair + Swap + Hex */}
<div className="pt-1.5 border-t border-ui-subtle flex items-center justify-between gap-1.5">
<div className="flex items-center gap-1.5">
<div className="relative w-7 h-6 shrink-0">
<button
type="button"
data-testid="focus-color-secondary-swatch"
onClick={() => setActiveTarget('secondary')}
title={t('Secondary Color: {color}', { color: secondaryColor })}
aria-label={t('Select Secondary Color')}
className={`absolute bottom-0 right-0 w-4 h-4 rounded-ui-xs cursor-pointer transition-shadow ${
activeTarget === 'secondary'
? 'ring-[1.5px] ring-ui-accent z-20'
: 'ring-1 ring-ui-strong z-10'
}`}
style={{ backgroundColor: secondaryColor }}
/>
<button
type="button"
data-testid="focus-color-primary-swatch"
onClick={() => setActiveTarget('primary')}
title={t('Primary Color: {color}', { color: primaryColor })}
aria-label={t('Select Primary Color')}
className={`absolute top-0 left-0 w-4 h-4 rounded-ui-xs cursor-pointer transition-shadow ${
activeTarget === 'primary' && !isTransparentColor
? 'ring-[1.5px] ring-ui-accent z-20'
: 'ring-1 ring-ui-strong z-10'
}`}
style={{ backgroundColor: primaryColor }}
/>
</div>
<button
type="button"
data-testid="focus-color-swap-btn"
onClick={() => toolStoreActions.swapColors(colorMode)}
title={t('Swap Primary & Secondary Colors (X)')}
aria-label={t('Swap Colors')}
className="w-5 h-5 rounded-ui-xs bg-ui-control hover:bg-ui-control-hover border border-ui-subtle flex items-center justify-center text-ui-muted hover:text-ui-primary transition-colors cursor-pointer"
>
<ArrowLeftRight className="w-3 h-3" />
</button>
</div>
{/* Mini Recent Swatches */}
<div className="flex items-center gap-1">
{recentColors.slice(0, 5).map((hex) => (
<button
key={hex}
type="button"
onClick={() => toolStoreActions.setPrimaryColor(hex, true, colorMode)}
title={hex.toUpperCase()}
aria-label={t('Pick recent color {color}', { color: hex })}
className="w-3.5 h-3.5 rounded-ui-xs border border-ui-default hover:border-ui-strong cursor-pointer shrink-0"
style={{ backgroundColor: hex }}
/>
))}
</div>
</div>
</div>
)}
</section>
);
}
);
FocusFloatingColorCard.displayName = 'FocusFloatingColorCard';