Skip to content

Commit

Permalink
feat: add useAccordion props
Browse files Browse the repository at this point in the history
  • Loading branch information
agustinusnathaniel committed Dec 25, 2020
1 parent 78112a2 commit a0db791
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 31 deletions.
78 changes: 50 additions & 28 deletions src/components/item/ItemCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import { ListItem } from "../models/list";

type ItemCardProps = {
value: ListItem;
useAccordion?: boolean;
};

const ItemCard = ({ value }: ItemCardProps) => {
const ItemCard = ({ value, useAccordion = true }: ItemCardProps) => {
const { colorMode } = useColorMode();

const {
Expand All @@ -37,6 +38,13 @@ const ItemCard = ({ value }: ItemCardProps) => {
Link: APILink,
} = value;

const apiDetailsProps: APIDetailsProps = {
Cors,
HTTPS,
Category,
Auth,
};

const toast = useToast();

const handleCopy = () => {
Expand All @@ -62,33 +70,23 @@ const ItemCard = ({ value }: ItemCardProps) => {
<Text>{Description}</Text>
</Box>

<Accordion allowToggle marginY={2}>
<AccordionItem>
<AccordionButton>
<Box flex="1" textAlign="left">
<Text fontSize="sm">Details</Text>
</Box>
<AccordionIcon />
</AccordionButton>
<AccordionPanel>
<Text>Category: {Category}</Text>
<Text>Support: </Text>
<Box marginLeft={4}>
<Flex alignItems="center">
<Text marginRight={2}>HTTPS :</Text>
{HTTPS ? (
<AiFillCheckCircle color="green" />
) : (
<AiFillCloseCircle color="red" />
)}
</Flex>

<Text>CORS : {Cors}</Text>
</Box>
{Auth && <Text>Auth : {Auth}</Text>}
</AccordionPanel>
</AccordionItem>
</Accordion>
{useAccordion ? (
<Accordion allowToggle marginY={2}>
<AccordionItem>
<AccordionButton>
<Box flex="1" textAlign="left">
<Text fontSize="sm">Details</Text>
</Box>
<AccordionIcon />
</AccordionButton>
<AccordionPanel>
<APIDetails {...apiDetailsProps} />
</AccordionPanel>
</AccordionItem>
</Accordion>
) : (
<APIDetails {...apiDetailsProps} />
)}

<Box>
<Text>API Link: </Text>
Expand All @@ -111,4 +109,28 @@ const ItemCard = ({ value }: ItemCardProps) => {
);
};

type APIDetailsProps = Omit<ListItem, "API" | "Description" | "Link">;

const APIDetails = ({ Category, HTTPS, Cors, Auth }: APIDetailsProps) => {
return (
<>
<Text>Category: {Category}</Text>
<Text>Support: </Text>
<Box marginLeft={4}>
<Flex alignItems="center">
<Text marginRight={2}>HTTPS :</Text>
{HTTPS ? (
<AiFillCheckCircle color="green" />
) : (
<AiFillCloseCircle color="red" />
)}
</Flex>

<Text>CORS : {Cors}</Text>
</Box>
{Auth && <Text>Auth : {Auth}</Text>}
</>
);
};

export default ItemCard;
5 changes: 3 additions & 2 deletions src/components/item/ItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { ListItem } from "../models/list";

type ItemContainerProps = {
entries: Array<ListItem>;
useAccordion?: boolean;
};

const ItemContainer = ({ entries }: ItemContainerProps) => {
const ItemContainer = ({ entries, useAccordion }: ItemContainerProps) => {
return (
<Grid
templateColumns={["repeat(1)", "repeat(1)", "repeat(2, 1fr)"]}
gap={2}
>
{entries.map((entry, index) => (
<ItemCard value={entry} key={index} />
<ItemCard value={entry} key={index} useAccordion={useAccordion} />
))}
</Grid>
);
Expand Down
4 changes: 3 additions & 1 deletion src/pages/all.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const All = () => {
</Button>
</Link>
<Skeleton isLoaded={!isLoading} minHeight="80vh">
{data && data.entries && <ItemContainer entries={sortedData} />}
{data && data.entries && (
<ItemContainer entries={sortedData} useAccordion={false} />
)}
</Skeleton>
</Box>
);
Expand Down

1 comment on commit a0db791

@vercel
Copy link

@vercel vercel bot commented on a0db791 Dec 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.