Skip to content

Commit 12e8c82

Browse files
committed
Merge branch 'app' into zk/members
2 parents 67871a2 + ad531f8 commit 12e8c82

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { type ClassValue, clsx } from "clsx";
2+
import { twMerge } from "tailwind-merge";
3+
4+
export function cn(...inputs: ClassValue[]) {
5+
return twMerge(clsx(inputs));
6+
}

packages/fern-docs/bundle/src/app/[host]/[domain]/layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
getAllSidebarRootNodes,
3535
getSidebarRootNodeIdToChildToParentsMap,
3636
} from "@/state/navigation-server";
37+
import { SetIsAskAiEnabled } from "@/state/search";
3738
import { Whitelabeled } from "@/state/whitelabeled";
3839

3940
import { GlobalStyles } from "../../global-styles";
@@ -107,6 +108,7 @@ export default async function Layout({
107108
<DarkCode value={edgeFlags.isDarkCodeEnabled} />
108109
<Whitelabeled value={edgeFlags.isWhitelabeled} />
109110
<SetColors colors={colors} />
111+
<SetIsAskAiEnabled isAskAiEnabled={edgeFlags.isAskAiEnabled} />
110112
<FernUser domain={domain} host={host} />
111113
<GlobalStyles
112114
domain={domain}
@@ -120,7 +122,7 @@ export default async function Layout({
120122
{children}
121123
</FeatureFlagProvider>
122124
<React.Suspense fallback={null}>
123-
<SearchV2 domain={domain} isAskAiEnabled={edgeFlags.isAskAiEnabled} />
125+
<SearchV2 domain={domain} />
124126
</React.Suspense>
125127
{jsConfig != null && <JavascriptProvider config={jsConfig} />}
126128
{VERCEL_ENV === "production" && (

packages/fern-docs/bundle/src/components/search.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import { useCurrentPathname } from "@/hooks/use-current-pathname";
3030
import { useSetTheme, useThemeSwitchEnabled } from "@/hooks/use-theme";
3131
import { useIsDarkCode } from "@/state/dark-code";
3232
import { useFernUser } from "@/state/fern-user";
33-
import { searchDialogOpenAtom, searchInitializedAtom } from "@/state/search";
33+
import {
34+
searchDialogOpenAtom,
35+
searchInitializedAtom,
36+
useIsAskAiEnabled,
37+
} from "@/state/search";
3438
import { atomWithStorageString } from "@/state/utils/atomWithStorageString";
3539

3640
const ALGOLIA_USER_TOKEN_KEY = "algolia-user-token";
@@ -56,15 +60,14 @@ const askAiAtom = atom(false);
5660
export const SearchV2 = React.memo(function SearchV2({
5761
domain,
5862
version,
59-
isAskAiEnabled,
6063
}: {
6164
domain: string;
62-
isAskAiEnabled: boolean;
6365
version?: VersionSwitcherInfo;
6466
}) {
6567
const isDarkCodeEnabled = useIsDarkCode();
6668
const userToken = useAlgoliaUserToken();
6769
const user = useFernUser();
70+
const isAskAiEnabled = useIsAskAiEnabled();
6871

6972
const [open, setOpen] = useCommandTrigger();
7073
const [askAi, setAskAi] = useAtom(askAiAtom);

packages/fern-docs/bundle/src/state/search.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,31 @@ import React from "react";
44

55
import { composeEventHandlers } from "@radix-ui/primitive";
66
import { atom, useAtomValue, useSetAtom } from "jotai";
7+
import { useHydrateAtoms } from "jotai/utils";
78

89
import { DesktopSearchButton } from "@fern-docs/search-ui";
10+
import { useIsMobile } from "@fern-ui/react-commons";
911

1012
import { FERN_SEARCH_BUTTON_ID } from "@/components/constants";
1113

1214
export const searchDialogOpenAtom = atom(false);
1315
export const searchInitializedAtom = atom(false);
16+
export const isAskAiEnabledAtom = atom(false);
17+
18+
export const SetIsAskAiEnabled = ({
19+
isAskAiEnabled,
20+
}: {
21+
isAskAiEnabled: boolean;
22+
}) => {
23+
useHydrateAtoms([[isAskAiEnabledAtom, isAskAiEnabled]], {
24+
dangerouslyForceHydrate: true,
25+
});
26+
return null;
27+
};
28+
29+
export const useIsAskAiEnabled = () => {
30+
return useAtomValue(isAskAiEnabledAtom);
31+
};
1432

1533
searchInitializedAtom.onMount = (setInitialized) => {
1634
if (typeof window === "undefined") {
@@ -33,6 +51,9 @@ export const SearchV2Trigger = React.memo(function SearchV2Trigger(
3351
) {
3452
const isInitialized = useAtomValue(searchInitializedAtom);
3553
const toggleSearchDialog = useToggleSearchDialog();
54+
const isAskAiEnabled = useIsAskAiEnabled();
55+
const isMobile = useIsMobile();
56+
3657
return (
3758
<DesktopSearchButton
3859
/**
@@ -43,6 +64,13 @@ export const SearchV2Trigger = React.memo(function SearchV2Trigger(
4364
{...props}
4465
onClick={composeEventHandlers(props.onClick, toggleSearchDialog)}
4566
variant={isInitialized ? "default" : "loading"}
67+
placeholder={
68+
isAskAiEnabled
69+
? isMobile
70+
? "Search or ask AI"
71+
: "Search docs or ask AI a question"
72+
: "Search"
73+
}
4674
/>
4775
);
4876
});

packages/fern-docs/search-ui/src/components/desktop/desktop-search-button.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const buttonVariants = cva(
1414
default:
1515
"bg-(color:--grayscale-a3) text-(color:--grayscale-a10) hover:bg-(color:--grayscale-a4)",
1616
loading:
17-
"bg-(color:--grayscale-a3) text-(color:--grayscale-a10) cursor-default",
17+
"bg-(color:--grayscale-a3) text-(color:--grayscale-a10) cursor-not-allowed",
1818
},
1919
},
2020
defaultVariants: {
@@ -25,16 +25,19 @@ const buttonVariants = cva(
2525

2626
export const DesktopSearchButton = forwardRef<
2727
HTMLButtonElement,
28-
ComponentPropsWithoutRef<"button"> & VariantProps<typeof buttonVariants>
29-
>(({ children, variant, className, ...rest }, ref) => {
28+
ComponentPropsWithoutRef<"button"> &
29+
VariantProps<typeof buttonVariants> & {
30+
placeholder?: string;
31+
}
32+
>(({ children, variant, placeholder = "Search", className, ...rest }, ref) => {
3033
return (
3134
<button
3235
{...rest}
3336
className={buttonVariants({ variant, className })}
3437
ref={ref}
3538
>
3639
<SearchIcon />
37-
Search
40+
{placeholder}
3841
<CommandKbd className="pointer-coarse:hidden ml-auto" />
3942
</button>
4043
);

0 commit comments

Comments
 (0)