-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid): added hook to access grid list size
This is much more useful than the children renderer function since you'll be able to get the size at **any** child without any prop drilling.
- Loading branch information
Showing
4 changed files
with
82 additions
and
20 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,28 @@ | ||
import { createContext, useContext } from "react"; | ||
|
||
export interface GridListSize { | ||
/** | ||
* The current number of columns in the `GridList`. | ||
*/ | ||
columns: number; | ||
|
||
/** | ||
* The current width of each cell within the grid. | ||
*/ | ||
cellWidth: number; | ||
} | ||
|
||
const context = createContext<GridListSize>({ | ||
columns: -1, | ||
cellWidth: -1, | ||
}); | ||
|
||
export const { Provider: GridListSizeProvider } = context; | ||
|
||
/** | ||
* Gets the current size of each cell within the `GridList` component. If this | ||
* is used without a parent `GridList` component, `-1` is returned instead. | ||
*/ | ||
export function useGridListSize(): GridListSize { | ||
return useContext(context); | ||
} |
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