Skip to content

Commit

Permalink
feat(@clayui/core): adds the index available in the item collection…
Browse files Browse the repository at this point in the history
… API
  • Loading branch information
matuzalemsteles committed Mar 28, 2024
1 parent 85ce1a2 commit 06fc444
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/clay-core/src/collection/types.ts
Expand Up @@ -20,7 +20,7 @@ export type ChildElement = IReactTypeElement & {

export type ChildrenFunction<T, P> = P extends Array<unknown>
? (item: T, ...args: P) => React.ReactElement
: (item: T) => React.ReactElement;
: (item: T, index?: number) => React.ReactElement;

export interface ICollectionProps<T, P> {
/**
Expand Down
9 changes: 6 additions & 3 deletions packages/clay-core/src/collection/useCollection.tsx
Expand Up @@ -219,7 +219,7 @@ export function useCollection<
: (item as T);
const child = Array.isArray(publicApi)
? (children(publicItem, ...publicApi) as ChildElement)
: (children(publicItem) as ChildElement);
: (children(publicItem, index) as ChildElement);

callNestedChild(child);

Expand Down Expand Up @@ -274,7 +274,10 @@ export function useCollection<
publicItem,
...publicApi
) as ChildElement)
: (children(publicItem) as ChildElement);
: (children(
publicItem,
virtual.index
) as ChildElement);

const props = {
'data-index': virtual.index,
Expand Down Expand Up @@ -317,7 +320,7 @@ export function useCollection<
: item;
const child = Array.isArray(publicApi)
? (children(publicItem, ...publicApi) as ChildElement)
: (children(publicItem) as ChildElement);
: (children(publicItem, index) as ChildElement);

const key = getKey(
index,
Expand Down

0 comments on commit 06fc444

Please sign in to comment.