Skip to content

Commit 44750fc

Browse files
alexcamboseaditya520
authored andcommitted
feat: default content for search component
1 parent 81d7bb4 commit 44750fc

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,
@@ -23,7 +22,7 @@ import { useLogger } from "@pythnetwork/component-library/useLogger";
2322
import { matchSorter } from "match-sorter";
2423
import type { ReactNode } from "react";
2524
import { useCallback, useEffect, useMemo, useState } from "react";
26-
import { useCollator, useFilter, useIsSSR } from "react-aria";
25+
import { useCollator, useFilter } from "react-aria";
2726

2827
import { Cluster, ClusterToName } from "../../services/pyth";
2928
import { AssetClassBadge } from "../AssetClassBadge";
@@ -74,14 +73,7 @@ const ResolvedSearchButton = (props: ResolvedSearchButtonProps) => {
7473

7574
const SearchButtonImpl = (
7675
props: Omit<ButtonProps<typeof UnstyledButton>, "children">,
77-
) => (
78-
<SearchButtonComponent
79-
size="sm"
80-
{...props}
81-
smallScreenContent={<SearchShortcutText />}
82-
largeScreenContent={<SearchShortcutText />}
83-
/>
84-
);
76+
) => <SearchButtonComponent size="sm" {...props} />;
8577

8678
const useSearchDrawer = ({ feeds, publishers }: ResolvedSearchButtonProps) => {
8779
const drawer = useDrawer();
@@ -135,16 +127,6 @@ const useSearchHotkey = (openSearchDrawer: () => void) => {
135127
}, [handleKeyDown]);
136128
};
137129

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

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