|
1
|
import { DataTableFilterBar } from "@/blocks/data-table/components/data-table-filter-bar" |
|
2
|
import { clx } from "@/utils/clx" |
|
3
|
import * as React from "react" |
|
4
|
|
|
5
|
interface DataTableToolbarTranslations { |
|
6
|
/** |
|
7
|
* The label for the clear all filters button |
|
8
|
* @default "Clear all" |
|
9
|
*/ |
|
10
|
clearAll?: string |
|
11
|
/** |
|
12
|
* The tooltip for the sorting menu |
|
13
|
*/ |
|
14
|
sort?: string |
|
15
|
/** |
|
16
|
* The tooltip for the columns menu |
|
17
|
*/ |
|
18
|
columns?: string |
|
19
|
} |
|
20
|
|
|
21
|
interface DataTableToolbarProps { |
|
22
|
/** |
|
23
|
* Additional classes to pass to the wrapper `div` of the component. |
|
24
|
*/ |
|
25
|
className?: string |
|
26
|
/** |
|
27
|
* The children to show in the toolbar. |
|
28
|
*/ |
|
29
|
children?: React.ReactNode |
|
30
|
/** |
|
31
|
* The translations of strings in the toolbar. |
|
32
|
*/ |
|
33
|
translations?: DataTableToolbarTranslations |
|
34
|
/** |
|
35
|
* Custom content to render in the filter bar |
|
36
|
*/ |
|
37
|
filterBarContent?: React.ReactNode |
|
38
|
/** |
|
39
|
* Whether to always render the filter bar, even when there are no active |
|
40
|
* filters or custom content. Useful to reserve its space and avoid layout |
|
41
|
* shifts when filters are added or removed. |
|
42
|
*/ |
|
43
|
alwaysShowFilterBar?: boolean |
|
44
|
} |
|
45
|
|
|
46
|
/** |
|
47
|
* Toolbar shown for the data table. |
|
48
|
*/ |
|
49
|
const DataTableToolbar = (props: DataTableToolbarProps) => { |
|
50
|
return ( |
|
51
|
<div className="flex flex-col divide-y"> |
|
52
|
<div className={clx("flex items-center px-6 py-4", props.className)}> |
|
53
|
{props.children} |
|
54
|
</div> |
|
55
|
<DataTableFilterBar |
|
56
|
clearAllFiltersLabel={props.translations?.clearAll} |
|
57
|
alwaysShow={props.alwaysShowFilterBar} |
|
58
|
> |
|
59
|
{props.filterBarContent} |
|
60
|
</DataTableFilterBar> |
|
61
|
</div> |
|
62
|
) |
|
63
|
} |
|
64
|
|
|
65
|
export { DataTableToolbar } |
|
66
|
export type { DataTableToolbarProps, DataTableToolbarTranslations } |
|
67
|
|