Skip to content

Commit dd7ccf0

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

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

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

Lines changed: 2 additions & 20 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";
@@ -72,14 +71,7 @@ const ResolvedSearchButton = (props: ResolvedSearchButtonProps) => {
7271

7372
const SearchButtonImpl = (
7473
props: Omit<ButtonProps<typeof UnstyledButton>, "children">,
75-
) => (
76-
<SearchButtonComponent
77-
size="sm"
78-
{...props}
79-
smallScreenContent={<SearchShortcutText />}
80-
largeScreenContent={<SearchShortcutText />}
81-
/>
82-
);
74+
) => <SearchButtonComponent size="sm" {...props} />;
8375

8476
const useSearchDrawer = ({ feeds, publishers }: ResolvedSearchButtonProps) => {
8577
const drawer = useDrawer();
@@ -133,16 +125,6 @@ const useSearchHotkey = (openSearchDrawer: () => void) => {
133125
}, [handleKeyDown]);
134126
};
135127

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-
146128
type SearchDialogContentsProps = ResolvedSearchButtonProps;
147129

148130
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)