()
| 60 | } |
| 61 | |
| 62 | export function useCopyImport() { |
| 63 | let [copiedId, setCopiedId] = useState<string | null>(null); |
| 64 | let timeout = useRef<ReturnType<typeof setTimeout> | null>(null); |
| 65 | |
| 66 | useEffect(() => { |
| 67 | return () => { |
| 68 | if (timeout.current) { |
| 69 | clearTimeout(timeout.current); |
| 70 | } |
| 71 | }; |
| 72 | }, []); |
| 73 | |
| 74 | let handleCopyImport = useCallback((id: string) => { |
| 75 | if (timeout.current) { |
| 76 | clearTimeout(timeout.current); |
| 77 | } |
| 78 | // Use underscore prefix for names starting with a number (invalid JS identifier) |
| 79 | let importName = id.replace(/^(\d)/, '_$1'); |
| 80 | navigator.clipboard |
| 81 | .writeText(`import ${importName} from '@react-spectrum/s2/icons/${id}';`) |
| 82 | .then(() => { |
| 83 | setCopiedId(id); |
| 84 | timeout.current = setTimeout(() => setCopiedId(null), 2000); |
| 85 | }) |
| 86 | .catch(() => { |
| 87 | ToastQueue.negative('Failed to copy import statement.'); |
| 88 | }); |
| 89 | }, []); |
| 90 | |
| 91 | return {copiedId, handleCopyImport}; |
| 92 | } |
| 93 | |
| 94 | interface IconListBoxProps { |
| 95 | items: typeof iconList; |
no outgoing calls
no test coverage detected