Skip to content

Commit a54f58d

Browse files
committed
refactor: add TitleIcon to Section
1 parent fa353f5 commit a54f58d

File tree

5 files changed

+27
-59
lines changed

5 files changed

+27
-59
lines changed

src/components/children.tsx

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
Card,
3-
Checkbox,
4-
HStack,
5-
Icon,
6-
Link,
7-
Stack,
8-
Text,
9-
} from "@chakra-ui/react";
1+
import { Card, Checkbox, Link, Stack, Text } from "@chakra-ui/react";
102
import { useEffect, useState, type ReactNode } from "react";
113
import { LuFolderPlus, LuFolderSearch } from "react-icons/lu";
124
import { MarkdownHooks } from "react-markdown";
@@ -62,16 +54,7 @@ export function Children({
6254
filteredCollections &&
6355
filteredCollections?.length > 0 && (
6456
<>
65-
<Section
66-
title={
67-
<HStack>
68-
<Icon>
69-
<LuFolderSearch></LuFolderSearch>
70-
</Icon>{" "}
71-
Collection search
72-
</HStack>
73-
}
74-
>
57+
<Section TitleIcon={LuFolderSearch} title={"Collection search"}>
7558
<CollectionSearch
7659
href={selfHref}
7760
setHref={setHref}
@@ -80,17 +63,13 @@ export function Children({
8063
</Section>
8164

8265
<Section
66+
TitleIcon={LuFolderPlus}
8367
title={
84-
<HStack>
85-
<Icon>
86-
<LuFolderPlus></LuFolderPlus>
87-
</Icon>{" "}
88-
Collections (
89-
{(filterByViewport &&
90-
filteredCollections.length + "/" + collections.length) ||
91-
collections.length}
92-
)
93-
</HStack>
68+
"Collections (" +
69+
((filterByViewport &&
70+
filteredCollections.length + "/" + collections.length) ||
71+
collections.length) +
72+
")"
9473
}
9574
>
9675
<Stack>

src/components/collection.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Box,
44
DataList,
55
HStack,
6-
Icon,
6+
Span,
77
Stack,
88
Text,
99
} from "@chakra-ui/react";
@@ -47,14 +47,12 @@ export function Collection({
4747

4848
{searchLinks.length > 0 && (
4949
<Section
50+
TitleIcon={LuFileSearch}
5051
title={
51-
<HStack>
52-
<Icon>
53-
<LuFileSearch></LuFileSearch>
54-
</Icon>{" "}
55-
Item search
52+
<Span>
53+
Item search{" "}
5654
<Badge colorPalette={"orange"}>Under development</Badge>
57-
</HStack>
55+
</Span>
5856
}
5957
>
6058
<ItemSearch

src/components/item.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HStack, Icon, Stack } from "@chakra-ui/react";
1+
import { Stack } from "@chakra-ui/react";
22
import { LuFileImage } from "react-icons/lu";
33
import type { StacItem } from "stac-ts";
44
import Assets from "./assets";
@@ -9,16 +9,7 @@ export default function Item({ item }: { item: StacItem }) {
99
return (
1010
<Stack>
1111
<Value value={item}></Value>
12-
<Section
13-
title={
14-
<HStack>
15-
<Icon>
16-
<LuFileImage></LuFileImage>
17-
</Icon>{" "}
18-
Assets
19-
</HStack>
20-
}
21-
>
12+
<Section TitleIcon={LuFileImage} title={"Assets"}>
2213
<Assets assets={item.assets}></Assets>
2314
</Section>
2415
</Stack>

src/components/search/item.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
Group,
1010
Heading,
1111
HStack,
12-
Icon,
1312
IconButton,
1413
Input,
1514
Link,
@@ -260,16 +259,7 @@ export function ItemSearchResults({
260259
const value = items?.length || 0;
261260

262261
return (
263-
<Section
264-
title={
265-
<HStack>
266-
<Icon>
267-
<LuFiles></LuFiles>
268-
</Icon>
269-
Item search results
270-
</HStack>
271-
}
272-
>
262+
<Section TitleIcon={LuFiles} title={"Item search results"}>
273263
<Stack>
274264
<Progress.Root
275265
value={results.isFetching && !numberMatched ? null : value}

src/components/section.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Collapsible, HStack, Heading, Icon } from "@chakra-ui/react";
22
import { type ReactNode, useState } from "react";
3+
import type { IconType } from "react-icons/lib";
34
import { LuChevronDown, LuChevronRight } from "react-icons/lu";
45

56
export default function Section({
67
title,
8+
TitleIcon,
79
titleSize = "lg",
810
children,
911
}: {
1012
title: ReactNode;
13+
TitleIcon?: IconType;
1114
titleSize?:
1215
| "sm"
1316
| "md"
@@ -32,7 +35,14 @@ export default function Section({
3235
<Collapsible.Trigger>
3336
<HStack pb={4}>
3437
<Heading size={titleSize} textAlign="left">
35-
{title}
38+
<HStack>
39+
{TitleIcon && (
40+
<Icon>
41+
<TitleIcon></TitleIcon>
42+
</Icon>
43+
)}
44+
{title}
45+
</HStack>
3646
</Heading>
3747
<Icon size={"sm"}>
3848
{(open && <LuChevronDown></LuChevronDown>) || (

0 commit comments

Comments
 (0)