Skip to content

Commit aa938f0

Browse files
committed
feat: search button component
1 parent d7cc062 commit aa938f0

File tree

7 files changed

+137
-59
lines changed

7 files changed

+137
-59
lines changed

apps/developer-hub/src/components/search-button.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
"use client";
22

3-
import { MagnifyingGlass } from "@phosphor-icons/react/dist/ssr/MagnifyingGlass";
4-
import { Button } from "@pythnetwork/component-library/Button";
3+
import { SearchButton as SearchButtonComponent } from "@pythnetwork/component-library/SearchButton";
54
import DefaultSearchDialog from "fumadocs-ui/components/dialog/search-default";
6-
import { useState } from "react";
5+
import { useCallback, useState } from "react";
76

87
export const SearchButton = () => {
98
const [open, setOpen] = useState(false);
109

10+
const handleSearch = useCallback(() => {
11+
setOpen(true);
12+
}, []);
13+
1114
return (
1215
<>
13-
<Button
14-
onClick={() => {
15-
setOpen(true);
16-
}}
17-
variant="outline"
18-
size="sm"
19-
rounded
20-
beforeIcon={<MagnifyingGlass size={16} />}
21-
>
22-
Search
23-
</Button>
16+
<SearchButtonComponent size='sm' smallScreenText="Search" largeScreenText="Search" onClick={handleSearch} />
2417
<DefaultSearchDialog
2518
open={open}
2619
onOpenChange={setOpen}

apps/insights/src/cache.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const transformer = {
1212
// export const DEFAULT_CACHE_TTL = 3600; // 1 hour
1313
// export const DEFAULT_CACHE_STALE = 86_400; // 24 hours
1414

15-
1615
export const DEFAULT_CACHE_TTL = 60; // 1 minute
1716
export const DEFAULT_CACHE_STALE = 60; // 1 minute
1817

apps/insights/src/components/Root/search-button.module.scss

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
@use "@pythnetwork/component-library/theme";
22

3-
.searchButton {
4-
.largeScreenSearchButton {
5-
display: none;
6-
7-
@include theme.breakpoint("md") {
8-
display: inline-flex;
9-
}
10-
}
11-
12-
.smallScreenSearchButton {
13-
@include theme.breakpoint("md") {
14-
display: none;
15-
}
16-
}
17-
}
18-
193
.searchDialogContents {
204
gap: theme.spacing(1);
215
display: flex;

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

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"use client";
22

3-
import { MagnifyingGlass } from "@phosphor-icons/react/dist/ssr/MagnifyingGlass";
43
import { XCircle } from "@phosphor-icons/react/dist/ssr/XCircle";
54
import { Badge } from "@pythnetwork/component-library/Badge";
65
import type { Props as ButtonProps } from "@pythnetwork/component-library/Button";
76
import { Button } from "@pythnetwork/component-library/Button";
87
import { NoResults } from "@pythnetwork/component-library/NoResults";
8+
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";
1111
import { Skeleton } from "@pythnetwork/component-library/Skeleton";
1212
import {
13-
Virtualizer,
1413
ListLayout,
14+
Virtualizer,
1515
} from "@pythnetwork/component-library/Virtualizer";
1616
import type { Button as UnstyledButton } from "@pythnetwork/component-library/unstyled/Button";
1717
import {
@@ -21,15 +21,15 @@ import {
2121
import { useDrawer } from "@pythnetwork/component-library/useDrawer";
2222
import { useLogger } from "@pythnetwork/component-library/useLogger";
2323
import type { ReactNode } from "react";
24-
import { useMemo, useCallback, useEffect, useState } from "react";
25-
import { useIsSSR, useCollator, useFilter } from "react-aria";
24+
import { useCallback, useEffect, useMemo, useState } from "react";
25+
import { useCollator, useFilter, useIsSSR } from "react-aria";
2626

27-
import styles from "./search-button.module.scss";
2827
import { Cluster, ClusterToName } from "../../services/pyth";
2928
import { AssetClassBadge } from "../AssetClassBadge";
3029
import { PriceFeedTag } from "../PriceFeedTag";
3130
import { PublisherTag } from "../PublisherTag";
3231
import { Score } from "../Score";
32+
import styles from "./search-button.module.scss";
3333

3434
const INPUTS = new Set(["input", "select", "button", "textarea"]);
3535

@@ -73,29 +73,12 @@ const ResolvedSearchButton = (props: ResolvedSearchButtonProps) => {
7373
const SearchButtonImpl = (
7474
props: Omit<ButtonProps<typeof UnstyledButton>, "children">,
7575
) => (
76-
<div className={styles.searchButton}>
77-
<Button
78-
className={styles.largeScreenSearchButton ?? ""}
79-
variant="outline"
80-
beforeIcon={<MagnifyingGlass />}
81-
size="sm"
82-
rounded
83-
{...props}
84-
>
85-
<SearchShortcutText />
86-
</Button>
87-
<Button
88-
className={styles.smallScreenSearchButton ?? ""}
89-
hideText
90-
variant="ghost"
91-
beforeIcon={<MagnifyingGlass />}
92-
size="sm"
93-
rounded
94-
{...props}
95-
>
96-
Search
97-
</Button>
98-
</div>
76+
<SearchButtonComponent
77+
size="sm"
78+
{...props}
79+
smallScreenText={<SearchShortcutText />}
80+
largeScreenText={<SearchShortcutText />}
81+
/>
9982
);
10083

10184
const useSearchDrawer = ({ feeds, publishers }: ResolvedSearchButtonProps) => {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@use "@pythnetwork/component-library/theme";
2+
3+
.searchButton {
4+
.largeScreenSearchButton {
5+
display: none;
6+
7+
@include theme.breakpoint("md") {
8+
display: inline-flex;
9+
}
10+
}
11+
12+
.smallScreenSearchButton {
13+
@include theme.breakpoint("md") {
14+
display: none;
15+
}
16+
}
17+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as icons from "@phosphor-icons/react/dist/ssr";
2+
import type { Meta, StoryObj } from "@storybook/react";
3+
4+
import { MagnifyingGlass } from '@phosphor-icons/react/dist/ssr';
5+
import { SearchButton as SearchButtonComponent } from "./index.jsx";
6+
import { SIZES } from "../Button/index.jsx";
7+
8+
9+
const iconControl = {
10+
control: "select",
11+
options: Object.keys(icons),
12+
mapping: Object.fromEntries(
13+
Object.entries(icons).map(([iconName, Icon]) => [
14+
iconName,
15+
<Icon key={iconName} weights={new Map()} />,
16+
]),
17+
),
18+
} as const;
19+
20+
const meta = {
21+
component: SearchButtonComponent,
22+
argTypes: {
23+
size: {
24+
control: "inline-radio",
25+
options: SIZES,
26+
table: {
27+
category: "Variant",
28+
},
29+
},
30+
beforeIcon: {
31+
...iconControl,
32+
defaultValue: <MagnifyingGlass />,
33+
table: {
34+
category: "Contents",
35+
},
36+
},
37+
38+
},
39+
} satisfies Meta<typeof SearchButtonComponent>;
40+
export default meta;
41+
42+
export const SearchButton = {
43+
args: {
44+
largeScreenText: "Search",
45+
smallScreenText: "Search",
46+
size: "sm",
47+
beforeIcon: <MagnifyingGlass />,
48+
},
49+
} satisfies StoryObj<typeof SearchButtonComponent>;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"use client";
2+
3+
import { MagnifyingGlass } from '@phosphor-icons/react/dist/ssr/MagnifyingGlass';
4+
import type { ComponentProps, ReactNode } from "react";
5+
6+
import { Button } from "../Button";
7+
import styles from "./index.module.scss";
8+
9+
10+
type OwnProps = {
11+
largeScreenText?: ReactNode | undefined;
12+
smallScreenText?: ReactNode | undefined;
13+
};
14+
15+
type Props = Pick<
16+
ComponentProps<typeof Button>,
17+
'beforeIcon' | 'size' | 'onClick'
18+
> &
19+
OwnProps;
20+
21+
export const SearchButton = ({
22+
beforeIcon,
23+
largeScreenText,
24+
smallScreenText,
25+
...props
26+
}: Props) => {
27+
return (
28+
<div className={styles.searchButton}>
29+
<Button
30+
className={styles.largeScreenSearchButton ?? ""}
31+
variant="outline"
32+
beforeIcon={beforeIcon ?? <MagnifyingGlass />}
33+
size="sm"
34+
rounded
35+
36+
{...props}
37+
>
38+
{largeScreenText}
39+
</Button>
40+
<Button
41+
className={styles.smallScreenSearchButton ?? ""}
42+
hideText
43+
variant="ghost"
44+
beforeIcon={beforeIcon ?? <MagnifyingGlass />}
45+
size="sm"
46+
rounded
47+
{...props}
48+
>
49+
{smallScreenText}
50+
</Button>
51+
</div>
52+
);
53+
};

0 commit comments

Comments
 (0)