fix: move AnimMode type to module scope, fix tsc -b build error

This commit is contained in:
Pouzor
2026-03-29 14:57:25 +02:00
parent 37cb97dca1
commit 95a3db34f1
+29 -16
View File
@@ -10,6 +10,14 @@ import { EDGE_DEFAULT_COLORS } from '@/utils/edgeColors'
const EDGE_TYPES = Object.entries(EDGE_TYPE_LABELS) as [EdgeType, string][] const EDGE_TYPES = Object.entries(EDGE_TYPE_LABELS) as [EdgeType, string][]
type AnimMode = 'none' | 'snake' | 'flow'
function toAnimMode(v: EdgeData['animated']): AnimMode {
if (v === true || v === 'snake') return 'snake'
if (v === 'flow') return 'flow'
return 'none'
}
interface EdgeModalProps { interface EdgeModalProps {
open: boolean open: boolean
onClose: () => void onClose: () => void
@@ -25,7 +33,7 @@ export function EdgeModal({ open, onClose, onSubmit, onDelete, initial, title =
const [vlanId, setVlanId] = useState(initial?.vlan_id?.toString() ?? '') const [vlanId, setVlanId] = useState(initial?.vlan_id?.toString() ?? '')
const [customColor, setCustomColor] = useState<string | undefined>(initial?.custom_color) const [customColor, setCustomColor] = useState<string | undefined>(initial?.custom_color)
const [pathStyle, setPathStyle] = useState<EdgePathStyle>(initial?.path_style ?? 'bezier') const [pathStyle, setPathStyle] = useState<EdgePathStyle>(initial?.path_style ?? 'bezier')
const [animated, setAnimated] = useState(initial?.animated ?? false) const [animation, setAnimation] = useState<AnimMode>(() => toAnimMode(initial?.animated))
const effectiveColor = customColor ?? EDGE_DEFAULT_COLORS[type] const effectiveColor = customColor ?? EDGE_DEFAULT_COLORS[type]
@@ -37,7 +45,7 @@ export function EdgeModal({ open, onClose, onSubmit, onDelete, initial, title =
vlan_id: type === 'vlan' && vlanId ? parseInt(vlanId) : undefined, vlan_id: type === 'vlan' && vlanId ? parseInt(vlanId) : undefined,
custom_color: customColor, custom_color: customColor,
path_style: pathStyle, path_style: pathStyle,
animated: animated || undefined, animated: animation !== 'none' ? animation : undefined,
}) })
onClose() onClose()
} }
@@ -115,20 +123,25 @@ export function EdgeModal({ open, onClose, onSubmit, onDelete, initial, title =
</div> </div>
</div> </div>
<div className="flex items-center justify-between"> <div className="flex flex-col gap-1.5">
<Label className="text-xs text-muted-foreground">Flow Animation</Label> <Label className="text-xs text-muted-foreground">Animation</Label>
<button <div className="flex rounded-md overflow-hidden border border-[#30363d]">
type="button" {(['none', 'snake', 'flow'] as AnimMode[]).map((mode, i) => (
onClick={() => setAnimated((a) => !a)} <button
className="relative w-9 h-5 rounded-full transition-colors focus:outline-none shrink-0" key={mode}
style={{ background: animated ? '#00d4ff' : '#30363d' }} type="button"
aria-pressed={animated} onClick={() => setAnimation(mode)}
> className="flex-1 py-1 text-xs capitalize transition-colors"
<span style={{
className="absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform" background: animation === mode ? '#00d4ff22' : '#21262d',
style={{ transform: animated ? 'translateX(16px)' : 'translateX(0)' }} color: animation === mode ? '#00d4ff' : '#8b949e',
/> borderRight: i < 2 ? '1px solid #30363d' : undefined,
</button> }}
>
{mode === 'none' ? 'None' : mode === 'snake' ? 'Snake' : 'Flow'}
</button>
))}
</div>
</div> </div>
<div className="flex flex-col gap-1.5"> <div className="flex flex-col gap-1.5">