Skip to content

Commit f00e90e

Browse files
committed
feat: default content for search component
1 parent 7934831 commit f00e90e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

apps/insights/src/components/Root/search-button.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { NoResults } from "@pythnetwork/component-library/NoResults";
88
import { SearchButton as SearchButtonComponent } from "@pythnetwork/component-library/SearchButton";
99
import { SearchInput } from "@pythnetwork/component-library/SearchInput";
1010
import { SingleToggleGroup } from "@pythnetwork/component-library/SingleToggleGroup";
11-
import { Skeleton } from "@pythnetwork/component-library/Skeleton";
1211
import {
1312
ListLayout,
1413
Virtualizer,
@@ -22,7 +21,7 @@ import { useDrawer } from "@pythnetwork/component-library/useDrawer";
2221
import { useLogger } from "@pythnetwork/component-library/useLogger";
2322
import type { ReactNode } from "react";
2423
import { useCallback, useEffect, useMemo, useState } from "react";
25-
import { useCollator, useFilter, useIsSSR } from "react-aria";
24+
import { useCollator, useFilter } from "react-aria";
2625

2726
import { Cluster, ClusterToName } from "../../services/pyth";
2827
import { AssetClassBadge } from "../AssetClassBadge";
@@ -76,8 +75,6 @@ const SearchButtonImpl = (
7675
<SearchButtonComponent
7776
size="sm"
7877
{...props}
79-
smallScreenContent={<SearchShortcutText />}
80-
largeScreenContent={<SearchShortcutText />}
8178
/>
8279
);
8380

@@ -133,16 +130,6 @@ const useSearchHotkey = (openSearchDrawer: () => void) => {
133130
}, [handleKeyDown]);
134131
};
135132

136-
const SearchShortcutText = () => {
137-
const isSSR = useIsSSR();
138-
return isSSR ? <Skeleton width={7} /> : <SearchTextImpl />;
139-
};
140-
141-
const SearchTextImpl = () => {
142-
const isMac = useMemo(() => navigator.userAgent.includes("Mac"), []);
143-
return isMac ? "⌘ K" : "Ctrl K";
144-
};
145-
146133
type SearchDialogContentsProps = ResolvedSearchButtonProps;
147134

148135
const SearchDialogContents = ({

packages/component-library/src/SearchButton/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import { MagnifyingGlass } from "@phosphor-icons/react/dist/ssr/MagnifyingGlass";
44
import clsx from "clsx";
55
import type { ReactNode } from "react";
6+
import { useMemo } from "react";
7+
import { useIsSSR } from "react-aria";
68
import { Button as BaseButton } from "react-aria-components";
79

810
import type { Props as ButtonProps } from "../Button";
911
import { Button } from "../Button";
12+
import { Skeleton } from "../Skeleton";
1013
import styles from "./index.module.scss";
1114

1215
type OwnProps = {
@@ -20,6 +23,16 @@ type Props = Pick<
2023
> &
2124
OwnProps;
2225

26+
const SearchShortcutText = () => {
27+
const isSSR = useIsSSR();
28+
return isSSR ? <Skeleton width={7} /> : <SearchTextImpl />;
29+
};
30+
31+
const SearchTextImpl = () => {
32+
const isMac = useMemo(() => navigator.userAgent.includes("Mac"), []);
33+
return isMac ? "⌘ K" : "Ctrl K";
34+
};
35+
2336
export const SearchButton = ({
2437
beforeIcon,
2538
largeScreenContent,
@@ -36,7 +49,7 @@ export const SearchButton = ({
3649
rounded
3750
{...props}
3851
>
39-
{largeScreenContent}
52+
{largeScreenContent ?? <SearchShortcutText />}
4053
</Button>
4154
<Button
4255
className={clsx(styles.smallScreenSearchButton, props.className)}
@@ -47,7 +60,7 @@ export const SearchButton = ({
4760
rounded
4861
{...props}
4962
>
50-
{smallScreenContent}
63+
{smallScreenContent ?? <SearchShortcutText />}
5164
</Button>
5265
</div>
5366
);

0 commit comments

Comments
 (0)