Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: docsearch integration #2392

Merged
merged 6 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/formbricks-com/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ NEXT_PUBLIC_FORMBRICKS_COM_DOCS_FEEDBACK_SURVEY_ID=

# Strapi API Key
STRAPI_API_KEY=

NEXT_PUBLIC_DOCSEARCH_APP_ID=
NEXT_PUBLIC_DOCSEARCH_API_KEY=
NEXT_PUBLIC_DOCSEARCH_INDEX_NAME=
10 changes: 7 additions & 3 deletions apps/formbricks-com/components/docs/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use client";

import { FooterLogo } from "@/components/shared/Logo";
import { Search } from "@/components/shared/Search";
import clsx from "clsx";
import { motion, useScroll, useTransform } from "framer-motion";
import Link from "next/link";
import { forwardRef } from "react";

import { Button } from "./Button";
import { MobileNavigation, useIsInsideMobileNavigation, useMobileNavigationStore } from "./MobileNavigation";
import { MobileSearch, Search } from "./Search";
import { ThemeToggle } from "./ThemeToggle";

function TopLevelNavItem({ href, children }: { href: string; children: React.ReactNode }) {
Expand Down Expand Up @@ -57,7 +57,9 @@ export const Header = forwardRef<React.ElementRef<"div">, { className?: string }
(isInsideMobileNavigation || !mobileNavIsOpen) && "bg-slate-900/7.5 dark:bg-white/7.5"
)}
/>
<Search />
<div className="hidden md:block">
<Search />
</div>
<div className="flex items-center gap-5 lg:hidden">
<MobileNavigation />
<Link href="/" aria-label="Home">
Expand All @@ -75,7 +77,9 @@ export const Header = forwardRef<React.ElementRef<"div">, { className?: string }
</nav>
<div className="hidden md:block md:h-5 md:w-px md:bg-slate-900/10 md:dark:bg-white/15" />
<div className="flex gap-4">
<MobileSearch />
<div className="block md:hidden">
<Search />
</div>
<ThemeToggle />
</div>
<div className="hidden min-[416px]:contents">
Expand Down
41 changes: 38 additions & 3 deletions apps/formbricks-com/components/shared/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "@docsearch/css";
import { DocSearchModal, useDocSearchKeyboardEvents } from "@docsearch/react";
import { useTheme } from "next-themes";
import Link from "next/link";
import Router from "next/router";
import { useCallback, useEffect, useState } from "react";
import { createPortal } from "react-dom";

Expand Down Expand Up @@ -28,6 +29,9 @@ function SearchIcon(props: any) {
}

export function Search() {
let { resolvedTheme } = useTheme();
let isLightMode = resolvedTheme === "light";

let [isOpen, setIsOpen] = useState(false);
let [modifierKey, setModifierKey] = useState<string>();

Expand All @@ -47,9 +51,40 @@ export function Search() {

return (
<>
<style>
{`
:root {
--docsearch-primary-color: ${isLightMode ? "#00C4B8" : "#1F7066"};
--docsearch-modal-background: ${isLightMode ? "#FFFFFF" : "#121212"};
--docsearch-text-color: ${isLightMode ? "#121212" : "#FFFFFF"};
--docsearch-hit-background: ${isLightMode ? "#FFFFFF" : "#282828"};
--docsearch-footer-background: ${isLightMode ? "#D8F6F4" : "#121212"};
--docsearch-searchbox-focus-background: ${isLightMode ? "#D8F6F4" : "#121212"};
--docsearch-modal-shadow: ${isLightMode ? "inset 1px 1px 0 0 hsla(0,0%,100%,0.5), 0 3px 8px 0 #D8F6F4" : "inset 1px 1px 0 0 hsla(0,0%,100%,0.5), 0 3px 8px 0 #808080"}';
}
.DocSearch-Hit-title {
color: #000000;
}
.DocSearch-Modal {
margin: 16rem auto auto;
}
[type='search']:focus {
--tw-ring-color: none;
}
.DocSearch-Button-Container {
width: 200px !important;
}
.DocSearch-Hit-Container {
color: var(--color-text-primary);
}
.DocSearch-Input {
outline: none;
}
`}
</style>
<button
type="button"
className="group flex h-6 w-6 items-center justify-center sm:justify-start md:h-auto md:w-60 md:flex-none md:rounded-lg md:py-2.5 md:pl-4 md:pr-3.5 md:text-sm md:ring-1 md:ring-slate-200 md:hover:ring-slate-300 xl:w-80 dark:md:bg-slate-800/75 dark:md:ring-inset dark:md:ring-white/5 dark:md:hover:bg-slate-700/40 dark:md:hover:ring-slate-500"
className="group flex h-6 w-6 items-center justify-center sm:justify-start md:h-auto md:w-60 md:flex-none md:rounded-lg md:py-2.5 md:pl-4 md:pr-3.5 md:text-sm md:ring-1 md:ring-slate-200 md:hover:ring-slate-300 xl:w-80 dark:text-slate-400 dark:ring-inset dark:ring-white/10 dark:hover:ring-white/20"
onClick={onOpen}>
<SearchIcon className="h-5 w-5 flex-none fill-slate-400 group-hover:fill-slate-500 md:group-hover:fill-slate-400 dark:fill-slate-500" />
<span className="sr-only md:not-sr-only md:pl-2 md:text-slate-500 md:dark:text-slate-400">
Expand All @@ -71,7 +106,7 @@ export function Search() {
hitComponent={Hit}
navigator={{
navigate({ itemUrl }) {
Router.push(itemUrl);
window.location.href = itemUrl;
},
}}
/>,
Expand Down
3 changes: 2 additions & 1 deletion apps/formbricks-com/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"dependencies": {
"@algolia/autocomplete-core": "^1.17.0",
"@calcom/embed-react": "^1.3.2",
"@docsearch/css": "3",
"@docsearch/react": "^3.6.0",
"@formbricks/lib": "workspace:*",
"@formbricks/types": "workspace:*",
"@formbricks/ui": "workspace:*",
"@headlessui/react": "^1.7.18",
"@headlessui/tailwindcss": "^0.2.0",
"lucide-react": "^0.356.0",
"@mapbox/rehype-prism": "^0.9.0",
"@mdx-js/loader": "^3.0.1",
"@mdx-js/react": "^3.0.1",
Expand All @@ -36,6 +36,7 @@
"framer-motion": "11.0.13",
"lottie-web": "^5.12.2",
"lucide": "^0.350.0",
"lucide-react": "^0.356.0",
"mdast-util-to-string": "^4.0.0",
"mdx-annotations": "^0.1.4",
"next": "14.1.3",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading