Skip to content

Commit 466dcde

Browse files
authored
feat: make input search sticky in sidebar
1 parent 7fa9939 commit 466dcde

File tree

1 file changed

+74
-70
lines changed

1 file changed

+74
-70
lines changed

src/components/sidebar/Sidebar.tsx

Lines changed: 74 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
InputRightElement,
77
DarkMode,
88
IconButton,
9+
Flex,
910
} from '@chakra-ui/react'
1011
import { CloseIcon, SearchIcon } from '@chakra-ui/icons'
1112
import DragItem from './DragItem'
@@ -22,90 +23,93 @@ const Menu = () => {
2223
overflowX="visible"
2324
boxShadow="xl"
2425
flex="0 0 14rem"
25-
p={5}
2626
m={0}
27+
p={0}
2728
as="menu"
2829
backgroundColor="#2e3748"
2930
width="15rem"
3031
>
31-
<InputGroup size="sm" mb={4}>
32-
<Input
33-
value={searchTerm}
34-
color="gray.300"
35-
placeholder="Search component…"
36-
onChange={(event: ChangeEvent<HTMLInputElement>) =>
37-
setSearchTerm(event.target.value)
38-
}
39-
borderColor="rgba(255, 255, 255, 0.04)"
40-
bg="rgba(255, 255, 255, 0.06)"
41-
_hover={{
42-
borderColor: 'rgba(255, 255, 255, 0.08)',
43-
}}
44-
zIndex={0}
45-
/>
46-
<InputRightElement zIndex={1}>
47-
{searchTerm ? (
48-
<IconButton
49-
color="gray.300"
50-
aria-label="clear"
51-
icon={<CloseIcon path="" />}
52-
size="xs"
53-
onClick={() => setSearchTerm('')}
54-
/>
55-
) : (
56-
<SearchIcon path="" color="gray.300" />
57-
)}
58-
</InputRightElement>
59-
</InputGroup>
32+
<Box p={5} pb={1} position="sticky" w="100%" bgColor="#2e3748" top={0}>
33+
<InputGroup size="sm" mb={4}>
34+
<Input
35+
value={searchTerm}
36+
color="gray.300"
37+
placeholder="Search component…"
38+
onChange={(event: ChangeEvent<HTMLInputElement>) =>
39+
setSearchTerm(event.target.value)
40+
}
41+
borderColor="rgba(255, 255, 255, 0.04)"
42+
bg="rgba(255, 255, 255, 0.06)"
43+
_hover={{
44+
borderColor: 'rgba(255, 255, 255, 0.08)',
45+
}}
46+
zIndex={0}
47+
/>
48+
<InputRightElement zIndex={1}>
49+
{searchTerm ? (
50+
<IconButton
51+
color="gray.300"
52+
aria-label="clear"
53+
icon={<CloseIcon path="" />}
54+
size="xs"
55+
onClick={() => setSearchTerm('')}
56+
/>
57+
) : (
58+
<SearchIcon path="" color="gray.300" />
59+
)}
60+
</InputRightElement>
61+
</InputGroup>
62+
</Box>
63+
<Box p={5} pt={0}>
64+
{(Object.keys(menuItems) as ComponentType[])
65+
.filter(c => c.toLowerCase().includes(searchTerm.toLowerCase()))
66+
.map(name => {
67+
const { children, soon } = menuItems[name] as MenuItem
6068

61-
{(Object.keys(menuItems) as ComponentType[])
62-
.filter(c => c.toLowerCase().includes(searchTerm.toLowerCase()))
63-
.map(name => {
64-
const { children, soon } = menuItems[name] as MenuItem
69+
if (children) {
70+
const elements = Object.keys(children).map(childName => (
71+
<DragItem
72+
isChild
73+
key={childName}
74+
label={childName}
75+
type={childName as any}
76+
id={childName as any}
77+
rootParentType={menuItems[name]?.rootParentType || name}
78+
>
79+
{childName}
80+
</DragItem>
81+
))
6582

66-
if (children) {
67-
const elements = Object.keys(children).map(childName => (
68-
<DragItem
69-
isChild
70-
key={childName}
71-
label={childName}
72-
type={childName as any}
73-
id={childName as any}
74-
rootParentType={menuItems[name]?.rootParentType || name}
75-
>
76-
{childName}
77-
</DragItem>
78-
))
83+
return [
84+
<DragItem
85+
isMeta
86+
soon={soon}
87+
key={`${name}Meta`}
88+
label={name}
89+
type={`${name}Meta` as any}
90+
id={`${name}Meta` as any}
91+
rootParentType={menuItems[name]?.rootParentType || name}
92+
>
93+
{name}
94+
</DragItem>,
95+
...elements,
96+
]
97+
}
7998

80-
return [
99+
return (
81100
<DragItem
82-
isMeta
83101
soon={soon}
84-
key={`${name}Meta`}
102+
key={name}
85103
label={name}
86-
type={`${name}Meta` as any}
87-
id={`${name}Meta` as any}
104+
type={name as any}
105+
id={name as any}
88106
rootParentType={menuItems[name]?.rootParentType || name}
89107
>
90108
{name}
91-
</DragItem>,
92-
...elements,
93-
]
94-
}
95-
96-
return (
97-
<DragItem
98-
soon={soon}
99-
key={name}
100-
label={name}
101-
type={name as any}
102-
id={name as any}
103-
rootParentType={menuItems[name]?.rootParentType || name}
104-
>
105-
{name}
106-
</DragItem>
107-
)
108-
})}
109+
</DragItem>
110+
)
111+
})}
112+
</Box>
109113
</Box>
110114
</DarkMode>
111115
)

0 commit comments

Comments
 (0)