From de43eb05d2e43ab31effce3dcca62ad91a556b26 Mon Sep 17 00:00:00 2001
From: Elizabeth Hunt <me@liz.coffee>
Date: Sun, 5 Oct 2025 16:42:02 -0700
Subject: Init

---
 src/components/toolbar/ToolbarItem.tsx | 57 ++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 src/components/toolbar/ToolbarItem.tsx

(limited to 'src/components/toolbar/ToolbarItem.tsx')

diff --git a/src/components/toolbar/ToolbarItem.tsx b/src/components/toolbar/ToolbarItem.tsx
new file mode 100644
index 0000000..76bd615
--- /dev/null
+++ b/src/components/toolbar/ToolbarItem.tsx
@@ -0,0 +1,57 @@
+import React, { useState } from 'react';
+
+export interface ToolbarItemProps {
+    children: React.ReactNode;
+    renderContent?: (onClose: () => void) => React.ReactNode;
+    onClick?: () => void;
+    disabled?: boolean;
+}
+
+export const ToolbarItem: React.FC<ToolbarItemProps> = ({
+    children,
+    renderContent,
+    onClick,
+    disabled = false,
+}) => {
+    const [isOpen, setIsOpen] = useState(false);
+    const [isFading, setIsFading] = useState(false);
+
+    const handleClose = () => {
+        setIsFading(true);
+        setTimeout(() => {
+            setIsOpen(false);
+            setIsFading(false);
+        }, 200);
+    };
+
+    const handleToggle = (e: React.MouseEvent) => {
+        e.stopPropagation();
+        if (disabled) return;
+
+        if (renderContent) {
+            if (isOpen) {
+                handleClose();
+            } else {
+                setIsOpen(true);
+            }
+        }
+
+        onClick?.();
+    };
+
+    return (
+        <div className={`toolbar-item ${disabled ? 'disabled' : ''}`} onClick={handleToggle}>
+            <div className='toolbar-item-content'>
+                {children}
+            </div>
+            {renderContent && isOpen && !disabled && (
+                <div
+                    className={`toolbar-item-content-panel ${isFading ? 'fading' : ''}`}
+                    onClick={(e) => e.stopPropagation()}
+                >
+                    {renderContent(handleClose)}
+                </div>
+            )}
+        </div>
+    );
+};
-- 
cgit v1.2.3-70-g09d2

