(props: { zen?: boolean; go?: boolean; hideGetStarted?: boolean })
| 36 | } |
| 37 | |
| 38 | export function Header(props: { zen?: boolean; go?: boolean; hideGetStarted?: boolean }) { |
| 39 | const navigate = useNavigate() |
| 40 | const i18n = useI18n() |
| 41 | const language = useLanguage() |
| 42 | |
| 43 | const [store, setStore] = createStore({ |
| 44 | mobileMenuOpen: false, |
| 45 | contextMenuOpen: false, |
| 46 | contextMenuPosition: { x: 0, y: 0 }, |
| 47 | }) |
| 48 | |
| 49 | createEffect(() => { |
| 50 | const handleClickOutside = () => { |
| 51 | setStore("contextMenuOpen", false) |
| 52 | } |
| 53 | |
| 54 | const handleContextMenu = (event: MouseEvent) => { |
| 55 | event.preventDefault() |
| 56 | setStore("contextMenuOpen", false) |
| 57 | } |
| 58 | |
| 59 | const handleKeyDown = (event: KeyboardEvent) => { |
| 60 | if (event.key === "Escape") { |
| 61 | setStore("contextMenuOpen", false) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (store.contextMenuOpen) { |
| 66 | document.addEventListener("click", handleClickOutside) |
| 67 | document.addEventListener("contextmenu", handleContextMenu) |
| 68 | document.addEventListener("keydown", handleKeyDown) |
| 69 | onCleanup(() => { |
| 70 | document.removeEventListener("click", handleClickOutside) |
| 71 | document.removeEventListener("contextmenu", handleContextMenu) |
| 72 | document.removeEventListener("keydown", handleKeyDown) |
| 73 | }) |
| 74 | } |
| 75 | }) |
| 76 | |
| 77 | const handleLogoContextMenu = (event: MouseEvent) => { |
| 78 | event.preventDefault() |
| 79 | const logoElement = (event.currentTarget as HTMLElement).querySelector("a") |
| 80 | if (logoElement) { |
| 81 | const rect = logoElement.getBoundingClientRect() |
| 82 | setStore("contextMenuPosition", { |
| 83 | x: rect.left - 16, |
| 84 | y: rect.bottom + 8, |
| 85 | }) |
| 86 | } |
| 87 | setStore("contextMenuOpen", true) |
| 88 | } |
| 89 | |
| 90 | const copyWordmarkToClipboard = async () => { |
| 91 | try { |
| 92 | const isDark = isDarkMode() |
| 93 | const wordmarkSvgPath = isDark ? copyWordmarkSvgDark : copyWordmarkSvgLight |
| 94 | const wordmarkSvg = await fetchSvgContent(wordmarkSvgPath) |
| 95 | await navigator.clipboard.writeText(wordmarkSvg) |
nothing calls this directly
no test coverage detected