-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the ability to save visible columns in views
- Loading branch information
1 parent
953f5ee
commit 7017623
Showing
6 changed files
with
136 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use client" | ||
|
||
import { createContext, useContext, useState } from "react" | ||
import type { Table } from "@tanstack/react-table" | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
interface TableInstanceContextProps<T = any> { | ||
tableInstance: Table<T> | ||
setTableInstance: React.Dispatch<React.SetStateAction<Table<T>>> | ||
} | ||
|
||
const TableInstanceContext = createContext<TableInstanceContextProps>({ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
tableInstance: {} as Table<any>, | ||
setTableInstance: () => {}, | ||
}) | ||
|
||
export function useTableInstanceContext() { | ||
const context = useContext(TableInstanceContext) | ||
if (!context) { | ||
throw new Error( | ||
"useTableInstanceContext must be used within a TableInstanceProvider" | ||
) | ||
} | ||
return context | ||
} | ||
|
||
export function TableInstanceProvider<T>({ | ||
table, | ||
children, | ||
}: { | ||
table: Table<T> | ||
children: React.ReactNode | ||
}) { | ||
const [tableInstance, setTableInstance] = useState<Table<T>>(table) | ||
|
||
return ( | ||
<TableInstanceContext.Provider value={{ tableInstance, setTableInstance }}> | ||
{children} | ||
</TableInstanceContext.Provider> | ||
) | ||
} |
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
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