forked from BuilderIO/cloudscape-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder-components.tsx
62 lines (56 loc) · 1.61 KB
/
builder-components.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
56
57
58
59
60
61
62
import {
TableProps,
Table as TableBase,
AppLayout as AppLayoutBase,
AppLayoutProps,
AreaChartProps,
AreaChart as AreaChartBase,
BarChartProps,
BarChart as BarChartBase,
} from "@cloudscape-design/components";
export {
Button,
TopNavigation,
Header,
Pagination,
TextFilter,
Input,
BreadcrumbGroup,
Icon,
Link,
FormField,
Checkbox,
SideNavigation,
HelpPanel,
} from "@cloudscape-design/components";
export const AreaChart = (props: AreaChartProps<any>) => {
return <AreaChartBase {...props} series={props.series || []} />;
};
export const BarChart = (props: BarChartProps<any>) => {
return <BarChartBase {...props} series={props.series || []} />;
};
// Workaround for AppLayout not accepting children - full fix coming shortly
export const AppLayout = (props: React.PropsWithChildren<AppLayoutProps>) => {
return <AppLayoutBase {...props} content={props.children} />;
};
// Workaround for the lack of cell function in the Table component - coming shortly
type TablePropsWithoutCellFunction = Omit<TableProps, "columnDefinitions"> & {
columnDefinitions: Omit<TableProps.ColumnDefinition<any>, "cell">[];
};
export const Table = (props: TablePropsWithoutCellFunction) => {
return (
<TableBase
{...props}
columnDefinitions={(props.columnDefinitions || []).map((col) => ({
...col,
cell: (item: any) =>
get(item, col.sortingField || col.id || "") ||
get(item, col.id || ""),
}))}
/>
);
};
const get = (obj: any, path: string) => {
const value = path.split(".").reduce((acc, part) => acc && acc[part], obj);
return value;
};