import { Button } from "../../ui"; import React, { useMemo } from "react"; import { useDarkMode } from "../../flow-editor/DarkModeContext"; import { cn } from "../../lib/utils"; export type SelectionTypeInput = { type: "input"; pinId: string; }; export type SelectionTypeOutput = { type: "output"; pinId: string; }; export type SelectionTypeInstances = { type: "instances"; ids: string[]; }; export type SelectionTypeConnections = { type: "connections"; ids: string[]; }; export type SelectionType = | SelectionTypeInput | SelectionTypeOutput | SelectionTypeInstances | SelectionTypeConnections; export interface SelectionIndicatorProps { selection: SelectionType | undefined; onCenter: () => void; onGroup: () => void; onDelete: (ids: string[]) => void; } export const SelectionIndicator: React.FC = ( props ) => { const { selection, onCenter, onGroup, onDelete } = props; const dark = useDarkMode(); if (!selection) { return null; } const inner = useMemo(() => { switch (selection.type) { case "input": return ( "{selection.pinId}" input selected ); case "output": return ( "{selection.pinId}" output selected ); case "instances": return ( {selection.ids.length} instance {selection.ids.length > 1 ? "s" : ""} selected ); case "connections": return ( {selection.ids.length} connection {selection.ids.length > 1 ? "s" : ""} selected ); } }, [selection]); const onDeleteClick = () => { switch (selection.type) { case "instances": onDelete(selection.ids); break; case "connections": onDelete(selection.ids); break; } }; const actions = { center: ( ), group: ( ), delete: ( ), }; const actionsMap = { instances: [actions.center, actions.group, actions.delete], connections: [actions.delete], input: [actions.center], output: [actions.center], }; return (
{inner}
{actionsMap[selection.type]}
); };