-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from fortanix/feature/component-data-table
New components: DataTable + variants
- Loading branch information
Showing
56 changed files
with
6,812 additions
and
34 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,34 @@ | ||
/* Copyright (c) Fortanix, Inc. | ||
|* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of | ||
|* the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as React from 'react'; | ||
import type * as ReactTable from 'react-table'; | ||
|
||
|
||
export type DataTableStatus = { | ||
ready: boolean, // Whether the data is ready to be used/shown in the UI | ||
loading: boolean, // Whether we're (re)loading the data | ||
error: null | Error, // Whether the last loading attempt resulted in an error | ||
}; | ||
|
||
export type TableContextState<D extends object> = { | ||
status: DataTableStatus, | ||
setStatus: (status: DataTableStatus) => void, | ||
reload: () => void, | ||
table: ReactTable.TableInstance<D>, | ||
}; | ||
|
||
const TableContext = React.createContext<null | TableContextState<object>>(null); // Memoized | ||
export const createTableContext = <D extends object>() => TableContext as React.Context<null | TableContextState<D>>; | ||
|
||
|
||
export const useTable = <D extends object>(): TableContextState<D> => { | ||
const context = React.useContext(TableContext as React.Context<null | TableContextState<D>>); | ||
|
||
if (context === null) { | ||
throw new TypeError('TableContext not yet initialized'); | ||
} | ||
|
||
return context; | ||
}; |
Oops, something went wrong.