-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react,styles): add grid layout for table component (#1748)
- Loading branch information
Showing
11 changed files
with
586 additions
and
115 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
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,47 @@ | ||
import React, { | ||
createContext, | ||
useContext, | ||
useState, | ||
useMemo, | ||
useRef | ||
} from 'react'; | ||
import type { Column } from './Table'; | ||
|
||
type TableContext = { | ||
layout: 'table' | 'grid'; | ||
columns: Array<Column>; | ||
}; | ||
|
||
type TableProvider = { | ||
children: React.ReactNode; | ||
layout: 'table' | 'grid'; | ||
columns: Array<Column>; | ||
}; | ||
|
||
const TableContext = createContext<TableContext>({ | ||
layout: 'table', | ||
columns: [] | ||
}); | ||
|
||
function TableProvider({ | ||
children, | ||
layout, | ||
columns | ||
}: TableProvider): JSX.Element { | ||
const { Provider } = TableContext as React.Context<TableContext>; | ||
const contextValue: TableContext = useMemo( | ||
() => ({ | ||
layout, | ||
columns | ||
}), | ||
[layout, columns] | ||
); | ||
|
||
return <Provider value={contextValue}>{children}</Provider>; | ||
} | ||
|
||
function useTable(): TableContext { | ||
return useContext(TableContext); | ||
} | ||
|
||
export { TableProvider, useTable }; |
Oops, something went wrong.