Skip to content

Commit

Permalink
chore: fix review with hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaCG committed Oct 12, 2023
1 parent 7ec85b7 commit e0cb6a0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/hooks/useListNavigation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@ The hook returns the following:
- `activeItemIndex` - active item index
- `reset` - function, which should be called when you want to reset navigation

## Properties

| Name | Description | Type | Default |
| :-------------- | :---------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------: | :-----: |
| items | List items. Item can be any object. Also, it can contain `items` property, which represents sub-items | `ItemType[]` | |
| skip | Returns true if the item should not participate in navigation (Called for each item) | `(item: ItemType) => boolean` | |
| pageSize | Items page size, if passed, then navigates by pageSize on PageDown/PageUp | `number` | |
| processHomeKey | Navigate to the start of the list on Home key | `boolean` | `false` |
| processEndKey | Navigate to the end of the list on End key | `boolean` | `false` |
| disabled | Disable navigation | `boolean` | `false` |
| initialValue | Initial active item index | `number` | `-1` |
| anchorRef | HTMLElement reference, the hook will listen keydown event on that element | `RefObject<AnchorType>` | |
| onAnchorKeyDown | Custom keydown handler, if returns false, then the hook won't process keydown | `(activeItemIndex: number, event: KeyboardEvent) => boolean or void` | |

## Result

| Name | Description | Type |
| :----------------- | :----------------------- | :-----------------------: |
| activeItemIndex | Index of the active item | `number` |
| setActiveItemIndex | Active item index setter | `(index: number) => void` |
| reset | Resets navigation | `() => void` |

## Examples

```tsx
Expand Down Expand Up @@ -83,3 +61,25 @@ useListNavigation({
},
});
```

## Properties

| Name | Description | Type | Default |
| :-------------- | :---------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------: | :-----: |
| items | List items. Item can be any object. Also, it can contain `items` property, which represents sub-items | `ItemType[]` | |
| skip | Returns true if the item should not participate in navigation (Called for each item) | `(item: ItemType) => boolean` | |
| pageSize | Items page size, if passed, then navigates by pageSize on PageDown/PageUp | `number` | |
| processHomeKey | Navigate to the start of the list on Home key | `boolean` | `false` |
| processEndKey | Navigate to the end of the list on End key | `boolean` | `false` |
| disabled | Disable navigation | `boolean` | `false` |
| initialValue | Initial active item index | `number` | `-1` |
| anchorRef | HTMLElement reference, the hook will listen keydown event on that element | `RefObject<AnchorType>` | |
| onAnchorKeyDown | Custom keydown handler, if returns false, then the hook won't process keydown | `(activeItemIndex: number, event: KeyboardEvent) => boolean or void` | |

## Result

| Name | Description | Type |
| :----------------- | :----------------------- | :-----------------------: |
| activeItemIndex | Index of the active item | `number` |
| setActiveItemIndex | Active item index setter | `(index: number) => void` |
| reset | Resets navigation | `() => void` |
3 changes: 3 additions & 0 deletions src/hooks/useSelect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export type UseSelectResult<T> = {
activeIndex: number | undefined;
handleSelection: (option: UseSelectOption<T>) => void;
handleClearValue: () => void;
/**
* @deprecated use toggleOpen
*/
setOpen: (val?: boolean | undefined) => void;
toggleOpen: (val?: boolean | undefined) => void;
setActiveIndex: React.Dispatch<React.SetStateAction<number | undefined>>;
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useTimeout/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {useTimeout} from './useTimeout';
export type {UseTimeoutProps} from './useTimeout';
4 changes: 4 additions & 0 deletions src/hooks/useTimeout/useTimeout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';

export type UseTimeoutProps = Parameters<
(callback: VoidFunction, ms: number | null | undefined) => void
>;

export function useTimeout(callback: VoidFunction, ms: number | null | undefined): void {
React.useEffect(() => {
if (typeof ms !== 'number') {
Expand Down

0 comments on commit e0cb6a0

Please sign in to comment.