Skip to content

Commit

Permalink
Re-refactored getCollectionElements, sorry for confusing you, perso…
Browse files Browse the repository at this point in the history
…n who's watching this commits :D
  • Loading branch information
alexiglesias93 committed Oct 10, 2021
1 parent be0d43c commit 2479442
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finsweet/ts-utils",
"version": "0.18.2",
"version": "0.18.3",
"description": "Typescript utils for custom Webflow projects.",
"main": "index.ts",
"module": "index.ts",
Expand Down
19 changes: 10 additions & 9 deletions webflow/getCollectionElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ const { wrapper, list, paginationNext, paginationPrevious, emptyState } = CMS_CS
* @param page The page document.
* @returns The specified collection element/elements.
*/
export function getCollectionElements(
reference: string | Element,
target: 'items',
page?: Document
): CollectionItemElement[];
export function getCollectionElements(
reference: string | Element,
target: 'next' | 'previous',
Expand All @@ -33,6 +28,11 @@ export function getCollectionElements(
target: 'empty',
page?: Document
): CollectionEmptyElement | null | undefined;
export function getCollectionElements(
reference: string | Element,
target: 'items',
page?: Document
): CollectionItemElement[];
export function getCollectionElements(
reference: string | Element,
target: 'list',
Expand All @@ -45,7 +45,7 @@ export function getCollectionElements(
): CollectionListWrapperElement | null | undefined;
export function getCollectionElements(
reference: string | Element,
target: 'wrapper' | 'list' | 'empty' | 'items' | 'next' | 'previous',
target: 'wrapper' | 'list' | 'items' | 'empty' | 'next' | 'previous',
page: Document = document
):
| CollectionListWrapperElement
Expand All @@ -66,7 +66,8 @@ export function getCollectionElements(
if (target === 'list') return collectionList;
if (target === 'items') return [...(collectionList?.children || [])] as CollectionItemElement[];
if (target === 'empty') return collectionListWrapper.querySelector<CollectionListWrapperElement>(`.${emptyState}`);
if (target === 'next') return collectionListWrapper.querySelector<PaginationButtonElement>(`.${paginationNext}`);
if (target === 'previous')
return collectionListWrapper.querySelector<PaginationButtonElement>(`.${paginationPrevious}`);

return collectionListWrapper.querySelector<PaginationButtonElement>(
`.${target === 'next' ? paginationNext : paginationPrevious}`
);
}

0 comments on commit 2479442

Please sign in to comment.