Spaces:
Running
Running
Download src/components/RowOverflowMenu.tsx from zelk12/ShareGPT_Dialogue_Studio: direct link, hf CLI and curl.
- Browser
- Download file 3.07 kB
-
https://huggingface.co/spaces/zelk12/ShareGPT_Dialogue_Studio/resolve/main/src/components/RowOverflowMenu.tsx
- Command line
-
hf download hf://spaces/zelk12/ShareGPT_Dialogue_Studio/src/components/RowOverflowMenu.tsx
-
curl -L -o RowOverflowMenu.tsx https://huggingface.co/spaces/zelk12/ShareGPT_Dialogue_Studio/resolve/main/src/components/RowOverflowMenu.tsx
3.07 kB
| import React, { useRef, useState } from 'react'; | |
| import { MoreHorizontal } from 'lucide-react'; | |
| import { FloatingPopover } from './FloatingPopover'; | |
| export interface RowOverflowAction { | |
| id?: string; | |
| label: string; | |
| icon: React.ReactNode; | |
| onClick: () => void; | |
| danger?: boolean; | |
| disabled?: boolean; | |
| title?: string; | |
| } | |
| interface RowOverflowMenuProps { | |
| id?: string; | |
| actions: RowOverflowAction[]; | |
| triggerTitle?: string; | |
| buttonClassName?: string; | |
| iconClassName?: string; | |
| zIndexClass?: string; | |
| } | |
| export const RowOverflowMenu: React.FC<RowOverflowMenuProps> = ({ | |
| id, | |
| actions, | |
| triggerTitle = 'Ещё действия', | |
| buttonClassName = 'p-1 rounded-md text-stone-500 dark:text-stone-400 hover:text-stone-900 dark:hover:text-stone-100 hover:bg-stone-100 dark:hover:bg-stone-800 transition-colors', | |
| iconClassName = 'w-3.5 h-3.5', | |
| zIndexClass = 'z-[100]', | |
| }) => { | |
| const [isOpen, setIsOpen] = useState(false); | |
| const triggerRef = useRef<HTMLButtonElement>(null); | |
| if (actions.length === 0) return null; | |
| return ( | |
| <> | |
| <button | |
| ref={triggerRef} | |
| id={id} | |
| type="button" | |
| onClick={(e) => { | |
| e.stopPropagation(); | |
| setIsOpen((v) => !v); | |
| }} | |
| className={buttonClassName} | |
| title={triggerTitle} | |
| aria-expanded={isOpen} | |
| aria-haspopup="menu" | |
| > | |
| <MoreHorizontal className={iconClassName} /> | |
| </button> | |
| <FloatingPopover | |
| isOpen={isOpen} | |
| onClose={() => setIsOpen(false)} | |
| triggerRef={triggerRef} | |
| align="right" | |
| direction="down" | |
| minWidth={195} | |
| maxWidth={260} | |
| zIndexClass={zIndexClass} | |
| className="text-xs" | |
| > | |
| <div | |
| className="p-1.5 space-y-0.5" | |
| role="menu" | |
| onClick={(e) => e.stopPropagation()} | |
| > | |
| {actions.map((action, idx) => ( | |
| <button | |
| key={action.id || `${action.label}-${idx}`} | |
| id={action.id} | |
| type="button" | |
| disabled={action.disabled} | |
| title={action.title || action.label} | |
| onClick={(e) => { | |
| e.stopPropagation(); | |
| if (action.disabled) return; | |
| setIsOpen(false); | |
| action.onClick(); | |
| }} | |
| className={`w-full px-2.5 py-2 rounded-lg text-left flex items-center gap-2 transition-colors ${ | |
| action.disabled | |
| ? 'opacity-40 cursor-not-allowed text-stone-400 dark:text-stone-600' | |
| : action.danger | |
| ? 'text-rose-700 dark:text-rose-400 hover:bg-rose-50 dark:hover:bg-rose-950/50' | |
| : 'text-stone-700 dark:text-stone-200 hover:bg-stone-100 dark:hover:bg-stone-800' | |
| }`} | |
| role="menuitem" | |
| > | |
| <span className="shrink-0">{action.icon}</span> | |
| <span className="truncate font-medium">{action.label}</span> | |
| </button> | |
| ))} | |
| </div> | |
| </FloatingPopover> | |
| </> | |
| ); | |
| }; | |