forked from rjsf-team/react-jsonschema-form
/
index.tsx
58 lines (52 loc) · 1.74 KB
/
index.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
import React from "react";
import { IconButtonProps, getUiOptions } from "@rjsf/utils";
import Button, { ButtonProps, ButtonType } from "antd/lib/button";
import ArrowDownOutlined from "@ant-design/icons/ArrowDownOutlined";
import ArrowUpOutlined from "@ant-design/icons/ArrowUpOutlined";
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
import PlusCircleOutlined from "@ant-design/icons/PlusCircleOutlined";
// The `type` for IconButtonProps collides with the `type` for `ButtonProps` so omit it to avoid Typescript issue
export type AntdIconButtonProps = Omit<IconButtonProps, "type">;
export default function IconButton(props: AntdIconButtonProps & ButtonProps) {
const {
iconType = "default",
icon,
uiSchema,
registry,
...otherProps
} = props;
return <Button type={iconType as ButtonType} icon={icon} {...otherProps} />;
}
export function AddButton(props: AntdIconButtonProps) {
return (
<IconButton
title="Add Item"
{...props}
block
iconType="primary"
icon={<PlusCircleOutlined />}
/>
);
}
export function MoveDownButton(props: AntdIconButtonProps) {
return (
<IconButton title="Move down" {...props} icon={<ArrowDownOutlined />} />
);
}
export function MoveUpButton(props: AntdIconButtonProps) {
return <IconButton title="Move up" {...props} icon={<ArrowUpOutlined />} />;
}
export function RemoveButton(props: AntdIconButtonProps) {
// The `block` prop is not part of the `IconButtonProps` defined in the template, so get it from the uiSchema instead
const options = getUiOptions(props.uiSchema);
return (
<IconButton
title="Remove"
{...props}
danger
block={!!options.block}
iconType="primary"
icon={<DeleteOutlined />}
/>
);
}