UNPKG

2.72 kBJavaScriptView Raw
1import React from "react";
2import { Button as AntButton } from "antd";
3import {
4 PlusOutlined,
5 EditOutlined,
6 CaretLeftOutlined,
7 CloseOutlined,
8 SearchOutlined,
9 RedoOutlined,
10 SaveOutlined,
11} from "@ant-design/icons";
12import { useDebounceFn } from "ahooks";
13
14const debounceOption = {
15 wait: 1000,
16 leading: true,
17 trailing: false,
18};
19
20export function DebounceBtn({ onClick, ...props }) {
21 const { run } = useDebounceFn(() => onClick(), debounceOption);
22 return <Base type="primary" {...props} onClick={run} />;
23}
24
25function Base({ color, ...rest }) {
26 const style = { margin: "0 5px" };
27 if (color) {
28 style.background = color;
29 style.borderColor = color;
30 style.color = "white";
31 }
32 return <AntButton style={style} {...rest} />;
33}
34
35export function Button(props) {
36 return <Base type="primary" {...props} />;
37}
38
39export function AddButton(props) {
40 return (
41 <Base {...props} type="primary" icon={<PlusOutlined />}>
42 添加
43 </Base>
44 );
45}
46
47export function EditButton(props) {
48 return (
49 <Base color="#11c962" icon={<EditOutlined />} {...props}>
50 修改
51 </Base>
52 );
53}
54
55export function DeleteButton(props) {
56 return (
57 <Base color="#ff4500" icon={<CloseOutlined />} {...props}>
58 删除
59 </Base>
60 );
61}
62
63export function SubmitButton(props) {
64 return (
65 <Base type="primary" icon={<SaveOutlined />} {...props}>
66 提交
67 </Base>
68 );
69}
70
71export function CancelButton(props) {
72 return (
73 <Base color="#a2a2a2" icon={<CloseOutlined />} {...props}>
74 取消
75 </Base>
76 );
77}
78
79export function BackButton(props) {
80 return (
81 <Base color="#a2a2a2" icon={<CaretLeftOutlined />} {...props}>
82 返回
83 </Base>
84 );
85}
86
87export function ButtonGroup({ onClickAdd, onClickEdit, onClickDelete }) {
88 return (
89 <>
90 <Button onClick={onClickAdd}>添加</Button>
91 <Button color="#11c962" onClick={onClickEdit}>
92 修改
93 </Button>
94 <Button color="#ff4500" onClick={onClickDelete}>
95 删除
96 </Button>
97 </>
98 );
99}
100
101export function AddCircle(props) {
102 return (
103 <Base shape="circle" type="primary" icon={<PlusOutlined />} {...props} />
104 );
105}
106export function EditCircle(props) {
107 return (
108 <Base shape="circle" color="#11c962" icon={<EditOutlined />} {...props} />
109 );
110}
111export function DeleteCircle(props) {
112 return (
113 <Base shape="circle" color="#ff4500" icon={<CloseOutlined />} {...props} />
114 );
115}
116
117export function SearchButton(props) {
118 return (
119 <Base type="primary" icon={<SearchOutlined />} {...props}>
120 搜索
121 </Base>
122 );
123}
124
125export function ResetButton(props) {
126 return (
127 <Base icon={<RedoOutlined />} color="gray" {...props}>
128 重置
129 </Base>
130 );
131}