-
Notifications
You must be signed in to change notification settings - Fork 3
/
ReactTableUI.tsx
55 lines (47 loc) · 1.41 KB
/
ReactTableUI.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from 'react'
import { tableContext } from '../context'
import useReactTableUI from '../logic/useReactTableUI'
import useTheme from '../logic/useTheme'
import clsx, { commonClassName } from '../utilities/clsx'
import type { DataType, ReactTableUIProps, TableInstance } from '../types'
import TitleBar from './TitleBar'
import Table from './Table'
import StatusBar from './StatusBar'
import Modal from './Modal'
/**
* React Table UI
* ---
*
* Styled table with all things configured.
*
* @category Component
*/
export default function ReactTableUI<Data extends DataType>({
tableInstanceRef,
...tableProps
}: ReactTableUIProps<Data> & {
tableInstanceRef?: React.RefObject<TableInstance<Data>>
}): JSX.Element {
// Internal ref for table
const tableRef = React.useRef<HTMLDivElement>(null)
// Add styles to DOM
useTheme(tableProps)
// Create Table's context
const context = useReactTableUI(tableProps, tableRef)
// Set TableInstance to tableInstanceRef
React.useImperativeHandle(tableInstanceRef, () => context.tableInstance)
const { borderless = false } = context.tableProps.styleOptions || {}
return (
<tableContext.Provider value={context}>
<div
ref={tableRef}
className={clsx(commonClassName, borderless ? '' : 'withBorder')}
>
<TitleBar />
<Table />
<StatusBar />
<Modal />
</div>
</tableContext.Provider>
)
}