-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from NYPL/feature/DR-3193/refactor-grid-compo…
…nent DR-3193/refactor grid component
- Loading branch information
Showing
12 changed files
with
506 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { render, screen, within } from "@testing-library/react"; | ||
import { mockCollections } from "__tests__/__mocks__/data/mockCollections"; | ||
import { mockItems } from "__tests__/__mocks__/data/mockItems"; | ||
import { CardsGrid } from "./cardsGrid"; | ||
|
||
describe("Collections CardsGrid component", () => { | ||
it("renders the correct collection data", async () => { | ||
render(<CardsGrid records={mockCollections} />); | ||
const headingElement = screen.getByRole("heading", { | ||
name: /Posada Collection/i, | ||
}); | ||
expect(headingElement).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("Item CardsGrid component", () => { | ||
it("renders the correct item data", async () => { | ||
render(<CardsGrid records={mockItems} />); | ||
const headingElement = screen.getByRole("heading", { | ||
name: /Sarah Myers Blackwell sitting in a tree/i, | ||
}); | ||
expect(headingElement).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"use client"; | ||
|
||
import React, { useRef } from "react"; | ||
import useBreakpoints from "../../hooks/useBreakpoints"; | ||
import CollectionDataType from "../../types/CollectionDataType"; | ||
import ItemDataType from "@/src/types/ItemDataType"; | ||
import { isCollectionType } from "@/src/utils/utils"; | ||
import { CollectionCardModel } from "../../models/collectionCard"; | ||
import { ItemCardModel } from "@/src/models/itemCard"; | ||
import { SimpleGrid as DCSimpleGrid } from "../simpleGrid/simpleGrid"; | ||
import { Card as DCCard } from "../card/card"; | ||
import { useTooltipOffset } from "@/src/hooks/useTooltipOffset"; | ||
|
||
interface CardsGridProps { | ||
records: CollectionDataType[] | ItemDataType[]; | ||
} | ||
|
||
export const CardsGrid = ({ records }: CardsGridProps) => { | ||
const { isLargerThanLargeTablet } = useBreakpoints(); | ||
const isCollections = isCollectionType(records); | ||
const cardRef = useRef<HTMLDivElement>(null); | ||
const tooltipOffset = useTooltipOffset(cardRef); | ||
|
||
return ( | ||
<DCSimpleGrid> | ||
{records?.map((record, index) => { | ||
if (isCollections) { | ||
const collectionCardModel = new CollectionCardModel(record); | ||
return ( | ||
<DCCard | ||
key={index} | ||
id={index} | ||
ref={cardRef} | ||
tooltipOffset={tooltipOffset} | ||
record={collectionCardModel} | ||
isLargerThanLargeTablet={isLargerThanLargeTablet} | ||
/> | ||
); | ||
} else { | ||
const itemCardModel = new ItemCardModel(record); | ||
return ( | ||
<DCCard | ||
key={index} | ||
id={index} | ||
ref={cardRef} | ||
tooltipOffset={tooltipOffset} | ||
record={itemCardModel} | ||
isLargerThanLargeTablet={isLargerThanLargeTablet} | ||
/> | ||
); | ||
} | ||
})} | ||
</DCSimpleGrid> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.