-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathDropIndicators.tsx
More file actions
114 lines (104 loc) · 3.18 KB
/
Copy pathDropIndicators.tsx
File metadata and controls
114 lines (104 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'use client';
/**
* Shared Drop Indicator Components
*
* Reusable visual feedback components for drag-and-drop operations.
* Used by both LayersTree and CenterCanvas for consistent drop indicators.
*/
import { cn } from '@/lib/utils';
export type DropPosition = 'above' | 'below' | 'inside';
interface DropLineIndicatorProps {
/** Position of the line relative to the target element */
position: 'above' | 'below';
/** Left offset in pixels (for tree indentation) */
offsetLeft?: number;
/** Additional class names */
className?: string;
}
/**
* Horizontal line indicator for inserting before/after a sibling element.
* Shows a blue line with a circular endpoint.
*/
export function DropLineIndicator({
position,
offsetLeft = 0,
className
}: DropLineIndicatorProps) {
return (
<div
className={cn(
'absolute left-0 right-0 h-[1.5px] z-50 bg-primary',
'animate-in fade-in duration-100',
position === 'above' ? '-top-[0.75px]' : '-bottom-[0.75px]',
className
)}
style={{ marginLeft: `${offsetLeft}px` }}
>
{/* Circular endpoint */}
<div className="absolute -bottom-[3px] -left-[5.5px] size-2 rounded-full border-[1.5px] bg-neutral-950 border-primary" />
</div>
);
}
interface DropContainerIndicatorProps {
/** Optional label to show (e.g., "Add in Section") */
label?: string;
/** Whether to show as dashed border (for canvas) or solid (for tree) */
variant?: 'dashed' | 'solid';
/** Additional class names */
className?: string;
}
/**
* Container highlight indicator for dropping inside an element.
* Shows a background fill for canvas drops, border for tree drops.
*/
export function DropContainerIndicator({
label,
variant = 'solid',
className
}: DropContainerIndicatorProps) {
return (
<>
<div
className={cn(
'absolute inset-0 z-40 pointer-events-none',
'animate-in fade-in duration-100',
// Canvas variant: blue background fill
variant === 'dashed' && 'bg-primary/15',
// Tree variant: solid border
variant === 'solid' && 'border-[1.5px] rounded-lg border-primary',
className
)}
/>
{label && (
<div className="absolute -top-6 left-0 bg-primary text-primary-foreground text-xs px-2 py-0.5 rounded z-50 whitespace-nowrap font-medium animate-in fade-in slide-in-from-top-1 duration-100">
{label}
</div>
)}
</>
);
}
interface DropIndicatorProps {
/** Current drop position */
position: DropPosition;
/** Left offset for line indicators (tree indentation) */
offsetLeft?: number;
/** Label for container indicators */
label?: string;
/** Variant for container indicator */
variant?: 'dashed' | 'solid';
}
/**
* Combined drop indicator that renders the appropriate indicator based on position.
* Convenience component for common use cases.
*/
export function DropIndicator({
position,
offsetLeft = 0,
label,
variant = 'solid'
}: DropIndicatorProps) {
if (position === 'inside') {
return <DropContainerIndicator label={label} variant={variant} />;
}
return <DropLineIndicator position={position} offsetLeft={offsetLeft} />;
}