MCPcopy Create free account
hub / github.com/Roy3838/Observer / SensorDropdownButton

Function SensorDropdownButton

app/src/components/AgentCard/SensorModal.tsx:27–87  ·  view source on GitHub ↗
({
  icon: Icon,
  label,
  colorClass,
  agents,
  onSelect
}: {
  icon: React.ElementType;
  label: string;
  colorClass?: string;
  agents: { id: string; name: string }[];
  onSelect: (agentId: string) => void;
})

Source from the content-addressed store, hash-verified

25
26// Sensor Dropdown Button Component
27const SensorDropdownButton = ({
28 icon: Icon,
29 label,
30 colorClass,
31 agents,
32 onSelect
33}: {
34 icon: React.ElementType;
35 label: string;
36 colorClass?: string;
37 agents: { id: string; name: string }[];
38 onSelect: (agentId: string) => void;
39}) => {
40 const [isOpen, setIsOpen] = useState(false);
41 const dropdownRef = useRef<HTMLDivElement>(null);
42
43 // Close dropdown when clicking outside
44 useEffect(() => {
45 const handleClickOutside = (event: MouseEvent) => {
46 if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
47 setIsOpen(false);
48 }
49 };
50 if (isOpen) {
51 document.addEventListener('mousedown', handleClickOutside);
52 return () => document.removeEventListener('mousedown', handleClickOutside);
53 }
54 }, [isOpen]);
55
56 if (agents.length === 0) return null;
57
58 return (
59 <div ref={dropdownRef} className="relative flex-grow md:flex-grow-0">
60 <button
61 onClick={() => setIsOpen(!isOpen)}
62 className={`w-full flex items-center justify-center space-x-2 px-3 py-2 bg-gray-100 hover:bg-gray-200 rounded-lg transition-colors ${colorClass || 'text-gray-700'}`}
63 >
64 <Icon className="h-5 w-5" />
65 <span className="text-sm font-medium">{label}</span>
66 <ChevronDown className={`h-4 w-4 transition-transform ${isOpen ? 'rotate-180' : ''}`} />
67 </button>
68
69 {isOpen && (
70 <div className="absolute z-30 bottom-full mb-1 w-full min-w-[200px] max-h-60 bg-white border border-gray-300 rounded-md shadow-lg overflow-y-auto overscroll-contain" style={{ WebkitOverflowScrolling: 'touch' }}>
71 {agents.map((agent) => (
72 <button
73 key={agent.id}
74 onClick={() => {
75 onSelect(agent.id);
76 setIsOpen(false);
77 }}
78 className="w-full text-left px-3 py-2 text-sm hover:bg-gray-100 transition-colors"
79 >
80 {agent.name}
81 </button>
82 ))}
83 </div>
84 )}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected