@refinedev/antd 5.13.2 → 5.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/dist/components/themedLayoutV2/header/index.d.ts.map +1 -1
- package/dist/components/themedLayoutV2/sider/index.d.ts.map +1 -1
- package/dist/components/themedLayoutV2/types.d.ts +4 -1
- package/dist/components/themedLayoutV2/types.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/form/useModalForm/useModalForm.d.ts +6 -3
- package/dist/hooks/form/useModalForm/useModalForm.d.ts.map +1 -1
- package/dist/hooks/table/useEditableTable/useEditableTable.d.ts +7 -2
- package/dist/hooks/table/useEditableTable/useEditableTable.d.ts.map +1 -1
- package/dist/iife/index.js +6 -6
- package/dist/iife/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/themedLayoutV2/header/index.tsx +7 -2
- package/src/components/themedLayoutV2/sider/index.tsx +94 -73
- package/src/components/themedLayoutV2/types.ts +5 -1
- package/src/hooks/form/useDrawerForm/useDrawerForm.ts +14 -14
- package/src/hooks/form/useModalForm/useModalForm.ts +46 -17
- package/src/hooks/table/useEditableTable/useEditableTable.ts +26 -10
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@refinedev/antd",
|
3
|
-
"version": "5.
|
3
|
+
"version": "5.14.0",
|
4
4
|
"description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
|
5
5
|
"private": false,
|
6
6
|
"main": "dist/index.js",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"devDependencies": {
|
26
26
|
"@refinedev/cli": "^2.5.3",
|
27
27
|
"@refinedev/ui-tests": "^1.3.2",
|
28
|
-
"@refinedev/core": "^4.14.
|
28
|
+
"@refinedev/core": "^4.14.1",
|
29
29
|
"@esbuild-plugins/node-resolve": "^0.1.4",
|
30
30
|
"@testing-library/jest-dom": "^5.16.4",
|
31
31
|
"@testing-library/react": "^13.1.1",
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import { Layout as AntdLayout, Typography, Avatar, Space, theme } from "antd";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
pickNotDeprecated,
|
5
|
+
useActiveAuthProvider,
|
6
|
+
useGetIdentity,
|
7
|
+
} from "@refinedev/core";
|
4
8
|
import { RefineThemedLayoutV2HeaderProps } from "../types";
|
5
9
|
|
6
10
|
const { Text } = Typography;
|
@@ -8,6 +12,7 @@ const { useToken } = theme;
|
|
8
12
|
|
9
13
|
export const ThemedHeaderV2: React.FC<RefineThemedLayoutV2HeaderProps> = ({
|
10
14
|
isSticky,
|
15
|
+
sticky,
|
11
16
|
}) => {
|
12
17
|
const { token } = useToken();
|
13
18
|
|
@@ -31,7 +36,7 @@ export const ThemedHeaderV2: React.FC<RefineThemedLayoutV2HeaderProps> = ({
|
|
31
36
|
height: "64px",
|
32
37
|
};
|
33
38
|
|
34
|
-
if (isSticky) {
|
39
|
+
if (pickNotDeprecated(sticky, isSticky)) {
|
35
40
|
headerStyles.position = "sticky";
|
36
41
|
headerStyles.top = 0;
|
37
42
|
headerStyles.zIndex = 1;
|
@@ -37,6 +37,7 @@ export const ThemedSiderV2: React.FC<RefineThemedLayoutV2SiderProps> = ({
|
|
37
37
|
Title: TitleFromProps,
|
38
38
|
render,
|
39
39
|
meta,
|
40
|
+
fixed,
|
40
41
|
}) => {
|
41
42
|
const { token } = useToken();
|
42
43
|
const {
|
@@ -189,25 +190,25 @@ export const ThemedSiderV2: React.FC<RefineThemedLayoutV2SiderProps> = ({
|
|
189
190
|
|
190
191
|
const renderMenu = () => {
|
191
192
|
return (
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
}
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
193
|
+
<Menu
|
194
|
+
selectedKeys={selectedKey ? [selectedKey] : []}
|
195
|
+
defaultOpenKeys={defaultOpenKeys}
|
196
|
+
mode="inline"
|
197
|
+
style={{
|
198
|
+
paddingTop: "8px",
|
199
|
+
border: "none",
|
200
|
+
overflow: "auto",
|
201
|
+
height: "calc(100% - 72px)",
|
202
|
+
}}
|
203
|
+
onClick={() => {
|
204
|
+
setSiderVisible?.(false);
|
205
|
+
if (!breakpoint.lg) {
|
206
|
+
setDrawerSiderVisible?.(true);
|
207
|
+
}
|
208
|
+
}}
|
209
|
+
>
|
210
|
+
{renderSider()}
|
211
|
+
</Menu>
|
211
212
|
);
|
212
213
|
};
|
213
214
|
|
@@ -229,7 +230,6 @@ export const ThemedSiderV2: React.FC<RefineThemedLayoutV2SiderProps> = ({
|
|
229
230
|
<Layout.Sider
|
230
231
|
style={{
|
231
232
|
height: "100vh",
|
232
|
-
overflow: "hidden",
|
233
233
|
backgroundColor: token.colorBgContainer,
|
234
234
|
borderRight: `1px solid ${token.colorBgElevated}`,
|
235
235
|
}}
|
@@ -243,6 +243,7 @@ export const ThemedSiderV2: React.FC<RefineThemedLayoutV2SiderProps> = ({
|
|
243
243
|
alignItems: "center",
|
244
244
|
height: "64px",
|
245
245
|
backgroundColor: token.colorBgElevated,
|
246
|
+
borderBottom: `1px solid ${token.colorBorder}`,
|
246
247
|
}}
|
247
248
|
>
|
248
249
|
<RenderToTitle collapsed={false} />
|
@@ -265,64 +266,84 @@ export const ThemedSiderV2: React.FC<RefineThemedLayoutV2SiderProps> = ({
|
|
265
266
|
return renderDrawerSider();
|
266
267
|
}
|
267
268
|
|
269
|
+
const siderStyles: React.CSSProperties = {
|
270
|
+
backgroundColor: token.colorBgContainer,
|
271
|
+
borderRight: `1px solid ${token.colorBgElevated}`,
|
272
|
+
};
|
273
|
+
|
274
|
+
if (fixed) {
|
275
|
+
siderStyles.position = "fixed";
|
276
|
+
siderStyles.top = 0;
|
277
|
+
siderStyles.height = "100vh";
|
278
|
+
siderStyles.zIndex = 999;
|
279
|
+
}
|
280
|
+
|
268
281
|
return (
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
282
|
+
<>
|
283
|
+
{fixed && (
|
284
|
+
<div
|
285
|
+
style={{
|
286
|
+
width: drawerSiderVisible ? "80px" : "200px",
|
287
|
+
transition: "all 0.2s",
|
288
|
+
}}
|
289
|
+
/>
|
290
|
+
)}
|
291
|
+
<Layout.Sider
|
292
|
+
style={siderStyles}
|
293
|
+
collapsible
|
294
|
+
collapsed={drawerSiderVisible}
|
295
|
+
onCollapse={(collapsed, type) => {
|
296
|
+
if (type === "clickTrigger") {
|
297
|
+
setDrawerSiderVisible?.(collapsed);
|
298
|
+
}
|
299
|
+
}}
|
300
|
+
collapsedWidth={80}
|
301
|
+
breakpoint="lg"
|
302
|
+
trigger={
|
303
|
+
<Button
|
304
|
+
type="text"
|
305
|
+
style={{
|
306
|
+
borderRadius: 0,
|
307
|
+
height: "100%",
|
308
|
+
width: "100%",
|
309
|
+
backgroundColor: token.colorBgElevated,
|
310
|
+
}}
|
311
|
+
>
|
312
|
+
{drawerSiderVisible ? (
|
313
|
+
<RightOutlined
|
314
|
+
style={{
|
315
|
+
color: token.colorPrimary,
|
316
|
+
}}
|
317
|
+
/>
|
318
|
+
) : (
|
319
|
+
<LeftOutlined
|
320
|
+
style={{
|
321
|
+
color: token.colorPrimary,
|
322
|
+
}}
|
323
|
+
/>
|
324
|
+
)}
|
325
|
+
</Button>
|
279
326
|
}
|
280
|
-
|
281
|
-
|
282
|
-
breakpoint="lg"
|
283
|
-
trigger={
|
284
|
-
<Button
|
285
|
-
type="text"
|
327
|
+
>
|
328
|
+
<div
|
286
329
|
style={{
|
287
|
-
|
288
|
-
|
289
|
-
|
330
|
+
width: drawerSiderVisible ? "80px" : "200px",
|
331
|
+
padding: drawerSiderVisible ? "0" : "0 16px",
|
332
|
+
display: "flex",
|
333
|
+
justifyContent: drawerSiderVisible
|
334
|
+
? "center"
|
335
|
+
: "flex-start",
|
336
|
+
alignItems: "center",
|
337
|
+
height: "64px",
|
290
338
|
backgroundColor: token.colorBgElevated,
|
339
|
+
fontSize: "14px",
|
340
|
+
borderBottom: `1px solid ${token.colorBorder}`,
|
291
341
|
}}
|
292
342
|
>
|
293
|
-
{drawerSiderVisible
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
/>
|
299
|
-
) : (
|
300
|
-
<LeftOutlined
|
301
|
-
style={{
|
302
|
-
color: token.colorPrimary,
|
303
|
-
}}
|
304
|
-
/>
|
305
|
-
)}
|
306
|
-
</Button>
|
307
|
-
}
|
308
|
-
>
|
309
|
-
<div
|
310
|
-
style={{
|
311
|
-
width: drawerSiderVisible ? "80px" : "200px",
|
312
|
-
padding: drawerSiderVisible ? "0" : "0 16px",
|
313
|
-
display: "flex",
|
314
|
-
justifyContent: drawerSiderVisible
|
315
|
-
? "center"
|
316
|
-
: "flex-start",
|
317
|
-
alignItems: "center",
|
318
|
-
height: "64px",
|
319
|
-
backgroundColor: token.colorBgElevated,
|
320
|
-
fontSize: "14px",
|
321
|
-
}}
|
322
|
-
>
|
323
|
-
<RenderToTitle collapsed={drawerSiderVisible} />
|
324
|
-
</div>
|
325
|
-
{renderMenu()}
|
326
|
-
</Layout.Sider>
|
343
|
+
<RenderToTitle collapsed={drawerSiderVisible} />
|
344
|
+
</div>
|
345
|
+
{renderMenu()}
|
346
|
+
</Layout.Sider>
|
347
|
+
</>
|
327
348
|
);
|
328
349
|
};
|
@@ -1,10 +1,14 @@
|
|
1
1
|
import type {
|
2
|
-
RefineThemedLayoutV2SiderProps,
|
2
|
+
RefineThemedLayoutV2SiderProps as BaseRefineThemedLayoutV2SiderProps,
|
3
3
|
RefineThemedLayoutV2HeaderProps,
|
4
4
|
RefineThemedLayoutV2Props,
|
5
5
|
RefineLayoutThemedTitleProps,
|
6
6
|
} from "@refinedev/ui-types";
|
7
7
|
|
8
|
+
type RefineThemedLayoutV2SiderProps = BaseRefineThemedLayoutV2SiderProps & {
|
9
|
+
fixed?: boolean;
|
10
|
+
};
|
11
|
+
|
8
12
|
export type {
|
9
13
|
RefineLayoutThemedTitleProps,
|
10
14
|
RefineThemedLayoutV2SiderProps,
|
@@ -208,21 +208,11 @@ export const useDrawerForm = <
|
|
208
208
|
|
209
209
|
const { warnWhen, setWarnWhen } = useWarnAboutChange();
|
210
210
|
|
211
|
-
const submit = async () => {
|
212
|
-
await onFinish(form.getFieldsValue());
|
213
|
-
|
214
|
-
if (autoSubmitClose) {
|
215
|
-
close();
|
216
|
-
}
|
217
|
-
|
218
|
-
if (autoResetForm) {
|
219
|
-
form.resetFields();
|
220
|
-
}
|
221
|
-
};
|
222
|
-
|
223
211
|
const saveButtonProps = {
|
224
212
|
disabled: formLoading,
|
225
|
-
onClick:
|
213
|
+
onClick: () => {
|
214
|
+
form.submit();
|
215
|
+
},
|
226
216
|
loading: formLoading,
|
227
217
|
};
|
228
218
|
|
@@ -278,7 +268,17 @@ export const useDrawerForm = <
|
|
278
268
|
...useFormProps.formProps,
|
279
269
|
onValuesChange: formProps?.onValuesChange,
|
280
270
|
onKeyUp: formProps?.onKeyUp,
|
281
|
-
onFinish:
|
271
|
+
onFinish: async (values) => {
|
272
|
+
await onFinish(values);
|
273
|
+
|
274
|
+
if (autoSubmitClose) {
|
275
|
+
close();
|
276
|
+
}
|
277
|
+
|
278
|
+
if (autoResetForm) {
|
279
|
+
form.resetFields();
|
280
|
+
}
|
281
|
+
},
|
282
282
|
},
|
283
283
|
drawerProps: {
|
284
284
|
width: "500px",
|
@@ -1,9 +1,5 @@
|
|
1
1
|
import React, { useCallback } from "react";
|
2
2
|
import { FormInstance, FormProps, ModalProps } from "antd";
|
3
|
-
import {
|
4
|
-
useModalForm as useModalFormSF,
|
5
|
-
UseModalFormConfig as UseModalFormConfigSF,
|
6
|
-
} from "sunflower-antd";
|
7
3
|
|
8
4
|
import {
|
9
5
|
useTranslate,
|
@@ -20,6 +16,7 @@ import {
|
|
20
16
|
useGo,
|
21
17
|
} from "@refinedev/core";
|
22
18
|
import { useForm, UseFormProps, UseFormReturnType } from "../useForm";
|
19
|
+
import { useModal } from "@hooks/modal";
|
23
20
|
|
24
21
|
export type useModalFormFromSFReturnType<TResponse, TVariables> = {
|
25
22
|
open: boolean;
|
@@ -85,10 +82,13 @@ export type UseModalFormProps<
|
|
85
82
|
TResponse,
|
86
83
|
TResponseError
|
87
84
|
> &
|
88
|
-
UseModalFormConfigSF &
|
89
85
|
useModalFormConfig &
|
90
86
|
LiveModeProps &
|
91
|
-
FormWithSyncWithLocationParams
|
87
|
+
FormWithSyncWithLocationParams & {
|
88
|
+
defaultVisible?: boolean;
|
89
|
+
autoSubmitClose?: boolean;
|
90
|
+
autoResetForm?: boolean;
|
91
|
+
};
|
92
92
|
/**
|
93
93
|
* `useModalForm` hook allows you to manage a form within a modal. It returns Ant Design {@link https://ant.design/components/form/ Form} and {@link https://ant.design/components/modal/ Modal} components props.
|
94
94
|
*
|
@@ -109,6 +109,9 @@ export const useModalForm = <
|
|
109
109
|
TResponseError extends HttpError = TError,
|
110
110
|
>({
|
111
111
|
syncWithLocation,
|
112
|
+
defaultVisible = false,
|
113
|
+
autoSubmitClose = true,
|
114
|
+
autoResetForm = true,
|
112
115
|
...rest
|
113
116
|
}: UseModalFormProps<
|
114
117
|
TQueryFnData,
|
@@ -161,18 +164,31 @@ export const useModalForm = <
|
|
161
164
|
|
162
165
|
const { warnWhen, setWarnWhen } = useWarnAboutChange();
|
163
166
|
|
164
|
-
const
|
165
|
-
|
166
|
-
|
167
|
-
|
167
|
+
const { show, close, modalProps } = useModal({
|
168
|
+
modalProps: {
|
169
|
+
open: defaultVisible,
|
170
|
+
},
|
168
171
|
});
|
169
172
|
|
170
|
-
const
|
171
|
-
|
172
|
-
|
173
|
-
|
173
|
+
const visible = modalProps.open || false;
|
174
|
+
const sunflowerUseModal: useModalFormFromSFReturnType<
|
175
|
+
TResponse,
|
176
|
+
TVariables
|
177
|
+
> = {
|
174
178
|
modalProps,
|
175
|
-
|
179
|
+
form,
|
180
|
+
formLoading,
|
181
|
+
formProps,
|
182
|
+
formResult: undefined,
|
183
|
+
formValues: form.getFieldsValue,
|
184
|
+
defaultFormValuesLoading: false,
|
185
|
+
initialValues: {},
|
186
|
+
submit: onFinish as any,
|
187
|
+
close,
|
188
|
+
open: modalProps.open || false,
|
189
|
+
show,
|
190
|
+
visible,
|
191
|
+
};
|
176
192
|
|
177
193
|
React.useEffect(() => {
|
178
194
|
if (initiallySynced.current === false && syncWithLocationKey) {
|
@@ -227,6 +243,9 @@ export const useModalForm = <
|
|
227
243
|
const saveButtonPropsSF = {
|
228
244
|
disabled: formLoading,
|
229
245
|
loading: formLoading,
|
246
|
+
onClick: () => {
|
247
|
+
form.submit();
|
248
|
+
},
|
230
249
|
};
|
231
250
|
|
232
251
|
const handleClose = useCallback(() => {
|
@@ -274,11 +293,21 @@ export const useModalForm = <
|
|
274
293
|
close: handleClose,
|
275
294
|
open: visible,
|
276
295
|
formProps: {
|
277
|
-
...
|
296
|
+
...formProps,
|
278
297
|
...useFormProps.formProps,
|
279
298
|
onValuesChange: formProps?.onValuesChange,
|
280
299
|
onKeyUp: formProps?.onKeyUp,
|
281
|
-
onFinish:
|
300
|
+
onFinish: async (values) => {
|
301
|
+
await onFinish(values);
|
302
|
+
|
303
|
+
if (autoSubmitClose) {
|
304
|
+
close();
|
305
|
+
}
|
306
|
+
|
307
|
+
if (autoResetForm) {
|
308
|
+
form.resetFields();
|
309
|
+
}
|
310
|
+
},
|
282
311
|
},
|
283
312
|
modalProps: {
|
284
313
|
...newModalProps,
|
@@ -35,7 +35,12 @@ type useEditableTableProps<
|
|
35
35
|
useTableProps<TQueryFnData, TError, TSearchVariables, TData>,
|
36
36
|
"successNotification" | "errorNotification"
|
37
37
|
> &
|
38
|
-
UseFormProps<TQueryFnData, TError, TVariables
|
38
|
+
UseFormProps<TQueryFnData, TError, TVariables> & {
|
39
|
+
/**
|
40
|
+
* When true, row will be closed after successful submit.
|
41
|
+
*/
|
42
|
+
autoSubmitClose?: boolean;
|
43
|
+
};
|
39
44
|
|
40
45
|
/**
|
41
46
|
* `useEditeableTable` allows you to implement edit feature on the table with ease,
|
@@ -58,15 +63,16 @@ export const useEditableTable = <
|
|
58
63
|
TVariables = {},
|
59
64
|
TSearchVariables = unknown,
|
60
65
|
TData extends BaseRecord = TQueryFnData,
|
61
|
-
>(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
>({
|
67
|
+
autoSubmitClose = true,
|
68
|
+
...props
|
69
|
+
}: useEditableTableProps<
|
70
|
+
TQueryFnData,
|
71
|
+
TError,
|
72
|
+
TVariables,
|
73
|
+
TSearchVariables,
|
74
|
+
TData
|
75
|
+
> = {}): useEditableTableReturnType<
|
70
76
|
TQueryFnData,
|
71
77
|
TError,
|
72
78
|
TVariables,
|
@@ -103,6 +109,16 @@ export const useEditableTable = <
|
|
103
109
|
return {
|
104
110
|
...table,
|
105
111
|
...edit,
|
112
|
+
formProps: {
|
113
|
+
...edit.formProps,
|
114
|
+
onFinish: async (values) => {
|
115
|
+
const result = await edit.onFinish(values);
|
116
|
+
if (autoSubmitClose) {
|
117
|
+
setId(undefined);
|
118
|
+
}
|
119
|
+
return result;
|
120
|
+
},
|
121
|
+
},
|
106
122
|
saveButtonProps,
|
107
123
|
cancelButtonProps,
|
108
124
|
editButtonProps,
|