Skip to content

Commit 11c7541

Browse files
committed
refactor: convert search to mantine spotlight
1 parent 9dabd1f commit 11c7541

8 files changed

Lines changed: 245 additions & 365 deletions

File tree

app/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import '@mantine/core/styles.css'
1717
import {Notifications} from '@mantine/notifications'
1818
import '@mantine/notifications/styles.css'
19+
import '@mantine/spotlight/styles.css'
1920
import type {Metadata, Viewport} from 'next'
2021

2122
if (!isProduction()) {

components/layout/Header/Header.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {SearchBar} from '@/components/ui/SearchBar/SearchBar'
2-
import {ThemeToggle} from '@/components/ui/ThemeToggle/ThemeToggle'
3-
import {ActionIcon, Box, Group} from '@mantine/core'
4-
import {IconSearch} from '@tabler/icons-react'
1+
import {MobileSearch} from '@/components/layout/Header/MobileSearch'
52
import {Logo} from '@/components/layout/Logo/Logo'
63
import {SidebarToggle} from '@/components/layout/Sidebar/SidebarToggle'
74
import {UserMenu} from '@/components/layout/UserMenu/UserMenu'
5+
import {ThemeToggle} from '@/components/ui/ThemeToggle/ThemeToggle'
6+
import {Group} from '@mantine/core'
87

98
/**
109
* Props for the Header component.
@@ -37,20 +36,7 @@ export function Header({
3736
</Group>
3837

3938
<Group gap="xs">
40-
<ActionIcon
41-
variant="subtle"
42-
color="gray"
43-
size="lg"
44-
hiddenFrom="sm"
45-
aria-label="Search"
46-
data-umami-event="open-mobile-search"
47-
>
48-
<IconSearch aria-hidden="true" size={20} />
49-
</ActionIcon>
50-
51-
<Box visibleFrom="sm">
52-
<SearchBar />
53-
</Box>
39+
<MobileSearch />
5440

5541
<ThemeToggle />
5642

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use client'
2+
3+
import {SearchBar} from '@/components/ui/SearchBar/SearchBar'
4+
import {ActionIcon, Group, Text, UnstyledButton} from '@mantine/core'
5+
import {spotlight} from '@mantine/spotlight'
6+
import {IconSearch} from '@tabler/icons-react'
7+
8+
/**
9+
* Search triggers for the header.
10+
* Mobile shows an icon button; desktop shows a search input button.
11+
* Both open the Spotlight overlay. The Spotlight overlay is also rendered here.
12+
*/
13+
export function MobileSearch() {
14+
return (
15+
<>
16+
{/* Mobile: icon button */}
17+
<ActionIcon
18+
variant="subtle"
19+
color="gray"
20+
size="lg"
21+
hiddenFrom="sm"
22+
aria-label="Search"
23+
data-umami-event="open-mobile-search"
24+
onClick={spotlight.open}
25+
>
26+
<IconSearch aria-hidden="true" size={20} />
27+
</ActionIcon>
28+
29+
{/* Desktop: input-styled button */}
30+
<UnstyledButton
31+
visibleFrom="sm"
32+
onClick={spotlight.open}
33+
aria-label="Open search"
34+
data-umami-event="open-desktop-search"
35+
style={{
36+
display: 'flex',
37+
alignItems: 'center',
38+
gap: 8,
39+
padding: '6px 12px',
40+
borderRadius: 'var(--mantine-radius-md)',
41+
border: '1px solid var(--mantine-color-default-border)',
42+
background: 'var(--mantine-color-default)',
43+
color: 'var(--mantine-color-dimmed)',
44+
width: 280,
45+
fontSize: 'var(--mantine-font-size-sm)',
46+
cursor: 'pointer'
47+
}}
48+
>
49+
<IconSearch size={14} aria-hidden="true" />
50+
<Text size="sm" c="dimmed" style={{flex: 1}}>
51+
Search Reddit...
52+
</Text>
53+
<Group gap={4}>
54+
<kbd
55+
style={{
56+
padding: '1px 5px',
57+
borderRadius: 4,
58+
border: '1px solid var(--mantine-color-default-border)',
59+
fontSize: 11,
60+
background: 'var(--mantine-color-default)'
61+
}}
62+
>
63+
/
64+
</kbd>
65+
</Group>
66+
</UnstyledButton>
67+
68+
{/* Spotlight overlay – mounted once, opened programmatically */}
69+
<SearchBar />
70+
</>
71+
)
72+
}

0 commit comments

Comments
 (0)