Skip to content

Commit

Permalink
add new utilitary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRibeiro committed Apr 17, 2021
1 parent 068f5a9 commit dc33f3c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/reakit/src/Composite/__utils/fillGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ function createEmptyItem(groupId?: string) {
};
}

// TODO: implement unit test
export function createEmptyItems(size: number, groupId?: string) {
const items = [];

for (let i = 0; i++; i < size) {
items.push({
id: "__EMPTY_ITEM__",
disabled: true,
ref: { current: null },
groupId,
});
}

return items;
}

/**
* Turns [[row1, row1], [row2]] into [[row1, row1], [row2, row2]]
*/
Expand Down
10 changes: 10 additions & 0 deletions packages/reakit/src/Composite/__utils/findFirstEnabledItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ export function findFirstEnabledItem(items: Item[], excludeId?: string) {
}
return items.find((item) => !item.disabled);
}

// TODO: define function's return type
export function findLastEnabledItem(items: Item[], excludeId?: string) {
if (excludeId) {
return items
.reverse()
.find((item) => !item.disabled && item.id !== excludeId);
}
return items.reverse().find((item) => !item.disabled);
}
5 changes: 5 additions & 0 deletions packages/reakit/src/Composite/__utils/getItemsInGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ import { Item } from "./types";
export function getItemsInGroup(items: Item[], groupId?: string) {
return items.filter((item) => item.groupId === groupId);
}

// TODO: implement unit test
export function getDisabledItems(items: Item[]) {
return items.filter((item) => item.disabled);
}
1 change: 1 addition & 0 deletions packages/reakit/src/Composite/__utils/groupItems.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Item } from "./types";

// todo: define this function return type
export function groupItems(items: Item[]) {
const groups = [[]] as Item[][];

Expand Down

0 comments on commit dc33f3c

Please sign in to comment.