Skip to content

Commit 76de768

Browse files
authored
refactor: simplify SearchItem component structure and improve styling (#683)
* refactor: simplify SearchItem component structure and improve styling * style: adjust padding in AlertContainer and SearchResults components
1 parent ecf904c commit 76de768

File tree

2 files changed

+49
-59
lines changed

2 files changed

+49
-59
lines changed

src/components/MDXComponents/Alert.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ function AlertContainer(props: { children: React.ReactNode }) {
1010
return (
1111
<Box
1212
sx={{
13-
paddingTop: "0.5rem",
14-
paddingBottom: "0.5rem",
13+
paddingTop: "1rem",
1514
"& .MuiAlert-message p": {
1615
marginBottom: 0,
1716
marginTop: 0,

src/components/Search/Results.tsx

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default function SearchResults(props: {
8484
return (
8585
<Box
8686
sx={{
87-
padding: "2rem 0",
87+
padding: "1rem 0",
8888
}}
8989
className={clsx("algolia-autocomplete", props.className)}
9090
>
@@ -188,37 +188,27 @@ function SearchItem(props: { data: any }) {
188188

189189
return (
190190
<Stack spacing={1}>
191-
<Box
191+
<Typography
192+
variant="h5"
193+
component="a"
194+
href={data.url}
192195
sx={{
193-
display: "flex",
194-
alignItems: "flex-start",
195-
flexWrap: "wrap",
196-
gap: "0.5rem",
196+
textDecoration: "none",
197+
"& >div": {
198+
width: "100%",
199+
maxWidth: "100%",
200+
},
197201
}}
198202
>
199-
<Typography
200-
variant="h5"
201-
component="a"
202-
href={data.url}
203-
sx={{
204-
textDecoration: "none",
205-
minWidth: 0,
206-
flex: "1 1 16rem",
207-
overflowWrap: "anywhere",
208-
"& >div": {
209-
width: "100%",
210-
maxWidth: "100%",
211-
},
212-
}}
213-
>
214-
{!!data._highlightResult?.hierarchy?.lvl0 && (
215-
<div
216-
dangerouslySetInnerHTML={{
217-
__html: data._highlightResult.hierarchy.lvl0?.value,
218-
}}
219-
/>
220-
)}
221-
</Typography>
203+
{!!data._highlightResult?.hierarchy?.lvl0 && (
204+
<div
205+
dangerouslySetInnerHTML={{
206+
__html: data._highlightResult.hierarchy.lvl0?.value,
207+
}}
208+
/>
209+
)}
210+
</Typography>
211+
<Stack direction="row" spacing={1} alignItems="center">
222212
{!!category && !!categoryLabel && (
223213
<Chip
224214
size="small"
@@ -233,36 +223,37 @@ function SearchItem(props: { data: any }) {
233223
}}
234224
/>
235225
)}
236-
</Box>
237-
{data?._highlightResult?.url ? (
238-
<Typography
239-
variant="body1"
240-
component="a"
241-
href={data.url}
242-
sx={{
243-
textDecoration: "none",
244-
width: "fit-content",
245-
"& >div": {
226+
{data?._highlightResult?.url ? (
227+
<Typography
228+
variant="body1"
229+
component="a"
230+
href={data.url}
231+
sx={{
232+
textDecoration: "none",
246233
width: "fit-content",
247-
},
248-
}}
249-
>
250-
<div
251-
dangerouslySetInnerHTML={{
252-
__html: data._highlightResult.url.value,
234+
"& >div": {
235+
width: "fit-content",
236+
},
237+
color: "carbon.700",
253238
}}
254-
/>
255-
</Typography>
256-
) : (
257-
<Typography
258-
sx={{
259-
textDecoration: "none",
260-
width: "fit-content",
261-
}}
262-
>
263-
{data.url}
264-
</Typography>
265-
)}
239+
>
240+
<div
241+
dangerouslySetInnerHTML={{
242+
__html: data._highlightResult.url.value,
243+
}}
244+
/>
245+
</Typography>
246+
) : (
247+
<Typography
248+
sx={{
249+
textDecoration: "none",
250+
width: "fit-content",
251+
}}
252+
>
253+
{data.url}
254+
</Typography>
255+
)}
256+
</Stack>
266257
<Typography component="div" sx={{}}>
267258
<div
268259
dangerouslySetInnerHTML={{

0 commit comments

Comments
 (0)