mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-22 14:30:53 +08:00
feat(desktop): add open-with menu component for links
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d9ebf4c2f1
commit
029c2a3f8f
17
desktop/src/components/chat/OpenWithMenu.test.tsx
Normal file
17
desktop/src/components/chat/OpenWithMenu.test.tsx
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import '@testing-library/jest-dom'
|
||||||
|
import { fireEvent, render, screen } from '@testing-library/react'
|
||||||
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
|
import { OpenWithMenu } from './OpenWithMenu'
|
||||||
|
|
||||||
|
describe('OpenWithMenu', () => {
|
||||||
|
it('offers in-app and system browser choices', () => {
|
||||||
|
const onInApp = vi.fn(); const onSystem = vi.fn()
|
||||||
|
render(<OpenWithMenu url="https://example.com" onOpenInApp={onInApp} onOpenSystem={onSystem} />)
|
||||||
|
fireEvent.click(screen.getByLabelText('打开方式'))
|
||||||
|
fireEvent.click(screen.getByText('应用内浏览器'))
|
||||||
|
expect(onInApp).toHaveBeenCalledWith('https://example.com')
|
||||||
|
fireEvent.click(screen.getByLabelText('打开方式'))
|
||||||
|
fireEvent.click(screen.getByText('系统浏览器'))
|
||||||
|
expect(onSystem).toHaveBeenCalledWith('https://example.com')
|
||||||
|
})
|
||||||
|
})
|
||||||
21
desktop/src/components/chat/OpenWithMenu.tsx
Normal file
21
desktop/src/components/chat/OpenWithMenu.tsx
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import { ChevronDown } from 'lucide-react'
|
||||||
|
|
||||||
|
type Props = { url: string; onOpenInApp: (url: string) => void; onOpenSystem: (url: string) => void }
|
||||||
|
|
||||||
|
export function OpenWithMenu({ url, onOpenInApp, onOpenSystem }: Props) {
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
return (
|
||||||
|
<span className="relative inline-block">
|
||||||
|
<button aria-label="打开方式" onClick={() => setOpen((v) => !v)} className="inline-flex items-center gap-0.5 text-xs">
|
||||||
|
<ChevronDown size={12} />
|
||||||
|
</button>
|
||||||
|
{open && (
|
||||||
|
<div className="absolute z-10 mt-1 rounded-md border border-[var(--color-border)] bg-[var(--color-surface)] py-1 text-xs shadow">
|
||||||
|
<button className="block w-full px-3 py-1 text-left hover:bg-[var(--color-surface-hover)]" onClick={() => { setOpen(false); onOpenInApp(url) }}>应用内浏览器</button>
|
||||||
|
<button className="block w-full px-3 py-1 text-left hover:bg-[var(--color-surface-hover)]" onClick={() => { setOpen(false); onOpenSystem(url) }}>系统浏览器</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user