antd-mobile 5.2.1 → 5.3.1
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/2x/cjs/components/avatar/avatar.js +1 -0
- package/2x/cjs/components/calendar/calendar.js +23 -20
- package/2x/cjs/components/date-picker/date-picker.js +3 -7
- package/2x/cjs/components/dialog/dialog.css +27 -18
- package/2x/cjs/components/dialog/dialog.js +39 -42
- package/2x/cjs/components/dropdown/dropdown.css +2 -1
- package/2x/cjs/components/ellipsis/ellipsis.d.ts +2 -0
- package/2x/cjs/components/ellipsis/ellipsis.js +8 -5
- package/2x/cjs/components/form/context.d.ts +2 -1
- package/2x/cjs/components/form/context.js +6 -5
- package/2x/cjs/components/form/form-item.css +27 -1
- package/2x/cjs/components/form/form-item.d.ts +1 -0
- package/2x/cjs/components/form/form-item.js +44 -13
- package/2x/cjs/components/form/form.js +18 -9
- package/2x/cjs/components/form/index.css +27 -1
- package/2x/cjs/components/input/input.js +2 -2
- package/2x/cjs/components/modal/modal.css +27 -21
- package/2x/cjs/components/modal/modal.js +39 -36
- package/2x/cjs/components/popover/arrow.js +1 -2
- package/2x/cjs/components/pull-to-refresh/pull-to-refresh.js +1 -1
- package/2x/cjs/components/switch/spin-icon.d.ts +3 -0
- package/2x/cjs/components/switch/spin-icon.js +37 -0
- package/2x/cjs/components/switch/switch.css +1 -1
- package/2x/cjs/components/switch/switch.js +4 -6
- package/2x/cjs/locales/base.d.ts +51 -0
- package/2x/cjs/locales/base.js +52 -0
- package/2x/cjs/locales/en-US.d.ts +51 -0
- package/2x/cjs/locales/zh-CN.d.ts +51 -0
- package/2x/cjs/locales/zh-CN.js +52 -0
- package/2x/es/components/avatar/avatar.js +1 -0
- package/2x/es/components/calendar/calendar.js +23 -19
- package/2x/es/components/date-picker/date-picker.js +3 -7
- package/2x/es/components/dialog/dialog.css +27 -18
- package/2x/es/components/dialog/dialog.js +37 -41
- package/2x/es/components/dropdown/dropdown.css +2 -1
- package/2x/es/components/ellipsis/ellipsis.d.ts +2 -0
- package/2x/es/components/ellipsis/ellipsis.js +7 -5
- package/2x/es/components/form/context.d.ts +2 -1
- package/2x/es/components/form/context.js +4 -3
- package/2x/es/components/form/form-item.css +27 -1
- package/2x/es/components/form/form-item.d.ts +1 -0
- package/2x/es/components/form/form-item.js +43 -13
- package/2x/es/components/form/form.js +18 -11
- package/2x/es/components/form/index.css +27 -1
- package/2x/es/components/input/input.js +2 -2
- package/2x/es/components/modal/modal.css +27 -21
- package/2x/es/components/modal/modal.js +37 -36
- package/2x/es/components/popover/arrow.js +1 -2
- package/2x/es/components/pull-to-refresh/pull-to-refresh.js +1 -1
- package/2x/es/components/switch/spin-icon.d.ts +3 -0
- package/2x/es/components/switch/spin-icon.js +23 -0
- package/2x/es/components/switch/switch.css +1 -1
- package/2x/es/components/switch/switch.js +3 -5
- package/2x/es/locales/base.d.ts +51 -0
- package/2x/es/locales/base.js +52 -0
- package/2x/es/locales/en-US.d.ts +51 -0
- package/2x/es/locales/zh-CN.d.ts +51 -0
- package/2x/es/locales/zh-CN.js +52 -0
- package/2x/package.json +4 -4
- package/cjs/components/avatar/avatar.js +1 -0
- package/cjs/components/calendar/calendar.js +23 -20
- package/cjs/components/date-picker/date-picker.js +3 -7
- package/cjs/components/dialog/dialog.css +26 -18
- package/cjs/components/dialog/dialog.js +39 -42
- package/cjs/components/dropdown/dropdown.css +2 -1
- package/cjs/components/ellipsis/ellipsis.d.ts +2 -0
- package/cjs/components/ellipsis/ellipsis.js +8 -5
- package/cjs/components/form/context.d.ts +2 -1
- package/cjs/components/form/context.js +6 -5
- package/cjs/components/form/form-item.css +21 -1
- package/cjs/components/form/form-item.d.ts +1 -0
- package/cjs/components/form/form-item.js +44 -13
- package/cjs/components/form/form.js +18 -9
- package/cjs/components/form/index.css +21 -1
- package/cjs/components/input/input.js +2 -2
- package/cjs/components/modal/modal.css +26 -20
- package/cjs/components/modal/modal.js +39 -36
- package/cjs/components/popover/arrow.js +1 -2
- package/cjs/components/pull-to-refresh/pull-to-refresh.js +1 -1
- package/cjs/components/switch/spin-icon.d.ts +3 -0
- package/cjs/components/switch/spin-icon.js +37 -0
- package/cjs/components/switch/switch.css +1 -1
- package/cjs/components/switch/switch.js +4 -6
- package/cjs/locales/base.d.ts +51 -0
- package/cjs/locales/base.js +52 -0
- package/cjs/locales/en-US.d.ts +51 -0
- package/cjs/locales/zh-CN.d.ts +51 -0
- package/cjs/locales/zh-CN.js +52 -0
- package/es/components/avatar/avatar.js +1 -0
- package/es/components/calendar/calendar.js +23 -19
- package/es/components/date-picker/date-picker.js +3 -7
- package/es/components/dialog/dialog.css +26 -18
- package/es/components/dialog/dialog.js +37 -41
- package/es/components/dropdown/dropdown.css +2 -1
- package/es/components/ellipsis/ellipsis.d.ts +2 -0
- package/es/components/ellipsis/ellipsis.js +7 -5
- package/es/components/form/context.d.ts +2 -1
- package/es/components/form/context.js +4 -3
- package/es/components/form/form-item.css +21 -1
- package/es/components/form/form-item.d.ts +1 -0
- package/es/components/form/form-item.js +43 -13
- package/es/components/form/form.js +18 -11
- package/es/components/form/index.css +21 -1
- package/es/components/input/input.js +2 -2
- package/es/components/modal/modal.css +26 -20
- package/es/components/modal/modal.js +37 -36
- package/es/components/popover/arrow.js +1 -2
- package/es/components/pull-to-refresh/pull-to-refresh.js +1 -1
- package/es/components/switch/spin-icon.d.ts +3 -0
- package/es/components/switch/spin-icon.js +23 -0
- package/es/components/switch/switch.css +1 -1
- package/es/components/switch/switch.js +3 -5
- package/es/locales/base.d.ts +51 -0
- package/es/locales/base.js +52 -0
- package/es/locales/en-US.d.ts +51 -0
- package/es/locales/zh-CN.d.ts +51 -0
- package/es/locales/zh-CN.js +52 -0
- package/package.json +4 -4
- package/umd/antd-mobile.js +1 -1
- package/umd/antd-mobile.js.LICENSE.txt +0 -24
- package/2x/assets/spin.svg +0 -12
- package/2x/cjs/assets/spin.svg +0 -12
- package/2x/es/assets/spin.svg +0 -12
- package/assets/spin.svg +0 -12
- package/cjs/assets/spin.svg +0 -12
- package/es/assets/spin.svg +0 -12
|
@@ -26,7 +26,29 @@ export const Calendar = forwardRef((p, ref) => {
|
|
|
26
26
|
if (item) markItems.unshift(item);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const dateRange = useMemo(() => {
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
|
+
|
|
32
|
+
if (props.selectionMode === 'single') {
|
|
33
|
+
const value = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.defaultValue) !== null && _b !== void 0 ? _b : null;
|
|
34
|
+
return [value, value];
|
|
35
|
+
} else if (props.selectionMode === 'range') {
|
|
36
|
+
return (_d = (_c = props.value) !== null && _c !== void 0 ? _c : props.defaultValue) !== null && _d !== void 0 ? _d : [null, null];
|
|
37
|
+
} else {
|
|
38
|
+
return [null, null];
|
|
39
|
+
}
|
|
40
|
+
}, [props.selectionMode, props.value, props.defaultValue]);
|
|
41
|
+
const [begin, setBegin] = useState(null);
|
|
42
|
+
const [end, setEnd] = useState(null);
|
|
43
|
+
useIsomorphicLayoutEffect(() => {
|
|
44
|
+
setBegin(dateRange[0] ? dayjs(dateRange[0]) : null);
|
|
45
|
+
setEnd(dateRange[1] ? dayjs(dateRange[1]) : null);
|
|
46
|
+
}, [dateRange[0], dateRange[1]]);
|
|
47
|
+
const [current, setCurrent] = useState(() => {
|
|
48
|
+
var _a;
|
|
49
|
+
|
|
50
|
+
return dayjs((_a = dateRange[0]) !== null && _a !== void 0 ? _a : today).date(1);
|
|
51
|
+
});
|
|
30
52
|
useUpdateEffect(() => {
|
|
31
53
|
var _a;
|
|
32
54
|
|
|
@@ -76,24 +98,6 @@ export const Calendar = forwardRef((p, ref) => {
|
|
|
76
98
|
setCurrent(current.add(1, 'year'));
|
|
77
99
|
}
|
|
78
100
|
}, React.createElement(ArrowLeftDouble, null)));
|
|
79
|
-
const dateRange = useMemo(() => {
|
|
80
|
-
var _a, _b, _c, _d;
|
|
81
|
-
|
|
82
|
-
if (props.selectionMode === 'single') {
|
|
83
|
-
const value = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.defaultValue) !== null && _b !== void 0 ? _b : null;
|
|
84
|
-
return [value, value];
|
|
85
|
-
} else if (props.selectionMode === 'range') {
|
|
86
|
-
return (_d = (_c = props.value) !== null && _c !== void 0 ? _c : props.defaultValue) !== null && _d !== void 0 ? _d : [null, null];
|
|
87
|
-
} else {
|
|
88
|
-
return [null, null];
|
|
89
|
-
}
|
|
90
|
-
}, [props.selectionMode, props.value, props.defaultValue]);
|
|
91
|
-
const [begin, setBegin] = useState(null);
|
|
92
|
-
const [end, setEnd] = useState(null);
|
|
93
|
-
useIsomorphicLayoutEffect(() => {
|
|
94
|
-
setBegin(dateRange[0] ? dayjs(dateRange[0]) : null);
|
|
95
|
-
setEnd(dateRange[1] ? dayjs(dateRange[1]) : null);
|
|
96
|
-
}, [dateRange[0], dateRange[1]]);
|
|
97
101
|
|
|
98
102
|
function renderCells() {
|
|
99
103
|
var _a;
|
|
@@ -28,14 +28,10 @@ export const DatePicker = p => {
|
|
|
28
28
|
});
|
|
29
29
|
const now = useMemo(() => new Date(), []);
|
|
30
30
|
const pickerValue = useMemo(() => {
|
|
31
|
-
let date = value;
|
|
32
|
-
|
|
33
|
-
if (date === null) {
|
|
34
|
-
date = new Date(bound(now.getDate(), props.min.getDate(), props.max.getDate()));
|
|
35
|
-
}
|
|
36
|
-
|
|
31
|
+
let date = value !== null && value !== void 0 ? value : now;
|
|
32
|
+
date = new Date(bound(date.getTime(), props.min.getTime(), props.max.getTime()));
|
|
37
33
|
return convertDateToStringArray(date, props.precision);
|
|
38
|
-
}, [value, props.precision]);
|
|
34
|
+
}, [value, props.precision, props.min, props.max]);
|
|
39
35
|
const onConfirm = useCallback(val => {
|
|
40
36
|
setValue(convertStringArrayToDate(val, props.precision));
|
|
41
37
|
}, [setValue, props.precision]);
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
transform: translate(-50%, -50%);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
.adm-dialog-
|
|
21
|
+
.adm-dialog-body {
|
|
22
22
|
width: 100%;
|
|
23
23
|
max-height: 70vh;
|
|
24
24
|
font-size: 28px;
|
|
@@ -29,35 +29,39 @@
|
|
|
29
29
|
flex-direction: column;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
.adm-dialog-
|
|
32
|
+
.adm-dialog-body > * {
|
|
33
33
|
flex: none;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
.adm-dialog-
|
|
36
|
+
.adm-dialog-body > .adm-dialog-content {
|
|
37
37
|
flex: auto;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
.adm-dialog-
|
|
41
|
-
padding-top:
|
|
40
|
+
.adm-dialog-body:not(.adm-dialog-with-image) {
|
|
41
|
+
padding-top: 40px;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
.adm-dialog-
|
|
45
|
-
|
|
44
|
+
.adm-dialog-body .adm-dialog-image-container {
|
|
45
|
+
margin-bottom: 24px;
|
|
46
|
+
max-height: 40vh;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
.adm-dialog-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
.adm-dialog-body .adm-dialog-header {
|
|
50
|
+
margin-bottom: 16px;
|
|
51
|
+
padding: 0 24px;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
.adm-dialog-
|
|
54
|
+
.adm-dialog-body .adm-dialog-title {
|
|
55
|
+
margin-bottom: 16px;
|
|
56
|
+
padding: 0 24px;
|
|
54
57
|
font-weight: bold;
|
|
55
58
|
font-size: 36px;
|
|
56
59
|
line-height: 50px;
|
|
57
60
|
text-align: center;
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
.adm-dialog-
|
|
63
|
+
.adm-dialog-body .adm-dialog-content {
|
|
64
|
+
padding: 0 24px 40px;
|
|
61
65
|
max-height: 70vh;
|
|
62
66
|
overflow-x: hidden;
|
|
63
67
|
overflow-y: auto;
|
|
@@ -66,21 +70,26 @@
|
|
|
66
70
|
color: #333;
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
.adm-dialog-
|
|
73
|
+
.adm-dialog-body .adm-dialog-content-empty {
|
|
74
|
+
padding: 0;
|
|
75
|
+
height: 24px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.adm-dialog-body .adm-dialog-footer {
|
|
70
79
|
user-select: none;
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
.adm-dialog-
|
|
82
|
+
.adm-dialog-body .adm-dialog-footer .adm-dialog-action-row {
|
|
74
83
|
display: flex;
|
|
75
84
|
align-items: stretch;
|
|
76
85
|
border-top: 1px solid var(--adm-border-color);
|
|
77
86
|
}
|
|
78
87
|
|
|
79
|
-
.adm-dialog-
|
|
88
|
+
.adm-dialog-body .adm-dialog-footer .adm-dialog-action-row > * {
|
|
80
89
|
flex: 1;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
.adm-dialog-
|
|
92
|
+
.adm-dialog-body .adm-dialog-footer .adm-dialog-action-row > .adm-dialog-button {
|
|
84
93
|
padding: 20px;
|
|
85
94
|
font-size: 36px;
|
|
86
95
|
line-height: 50px;
|
|
@@ -88,11 +97,11 @@
|
|
|
88
97
|
border-right: solid 1px var(--adm-border-color);
|
|
89
98
|
}
|
|
90
99
|
|
|
91
|
-
.adm-dialog-
|
|
100
|
+
.adm-dialog-body .adm-dialog-footer .adm-dialog-action-row > .adm-dialog-button-bold {
|
|
92
101
|
font-weight: bold;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
.adm-dialog-
|
|
104
|
+
.adm-dialog-body .adm-dialog-footer .adm-dialog-action-row > .adm-dialog-button:last-child {
|
|
96
105
|
border-right: none;
|
|
97
106
|
}
|
|
98
107
|
|
|
@@ -6,13 +6,11 @@ import { useUnmountedRef } from 'ahooks';
|
|
|
6
6
|
import Mask from '../mask';
|
|
7
7
|
import { DialogActionButton } from './dialog-action-button';
|
|
8
8
|
import Image from '../image';
|
|
9
|
-
import Space from '../space';
|
|
10
9
|
import { renderToContainer } from '../../utils/render-to-container';
|
|
11
10
|
import { withStopPropagation } from '../../utils/with-stop-propagation';
|
|
12
11
|
import AutoCenter from '../auto-center';
|
|
13
12
|
import { useSpring, animated } from '@react-spring/web';
|
|
14
13
|
import { withNativeProps } from '../../utils/native-props';
|
|
15
|
-
const classPrefix = `adm-dialog`;
|
|
16
14
|
const defaultProps = {
|
|
17
15
|
visible: false,
|
|
18
16
|
actions: [],
|
|
@@ -50,51 +48,27 @@ export const Dialog = p => {
|
|
|
50
48
|
}
|
|
51
49
|
});
|
|
52
50
|
const [active, setActive] = useState(props.visible);
|
|
53
|
-
const
|
|
54
|
-
className:
|
|
55
|
-
style:
|
|
56
|
-
display: active ? 'unset' : 'none'
|
|
57
|
-
}
|
|
58
|
-
}, React.createElement(Mask, {
|
|
59
|
-
visible: props.visible,
|
|
60
|
-
onMaskClick: props.closeOnMaskClick ? props.onClose : undefined,
|
|
61
|
-
style: props.maskStyle,
|
|
62
|
-
className: classNames(`${classPrefix}-mask`, props.maskClassName)
|
|
63
|
-
}), React.createElement("div", {
|
|
64
|
-
className: `${classPrefix}-wrap`,
|
|
65
|
-
style: {
|
|
66
|
-
pointerEvents: props.visible ? 'unset' : 'none'
|
|
67
|
-
}
|
|
68
|
-
}, React.createElement(animated.div, {
|
|
69
|
-
style: Object.assign({}, style),
|
|
70
|
-
onClick: e => e.stopPropagation(),
|
|
71
|
-
className: `${classPrefix}-main`
|
|
51
|
+
const body = React.createElement("div", {
|
|
52
|
+
className: classNames(cls('body'), props.image && cls('with-image'), props.bodyClassName),
|
|
53
|
+
style: props.bodyStyle
|
|
72
54
|
}, !!props.image && React.createElement("div", {
|
|
73
|
-
className:
|
|
55
|
+
className: cls('image-container')
|
|
74
56
|
}, React.createElement(Image, {
|
|
75
57
|
src: props.image,
|
|
76
58
|
alt: 'dialog header image',
|
|
77
59
|
width: '100%'
|
|
78
|
-
})), React.createElement("div", {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
className:
|
|
86
|
-
}, React.createElement("div", {
|
|
87
|
-
className: `${classPrefix}-body-header`
|
|
88
|
-
}, props.header)), !!props.title && React.createElement("div", {
|
|
89
|
-
className: `${classPrefix}-body-title`
|
|
90
|
-
}, props.title), !!props.content && React.createElement("div", {
|
|
91
|
-
className: `${classPrefix}-body-content`
|
|
92
|
-
}, typeof props.content === 'string' ? React.createElement(AutoCenter, null, props.content) : props.content))), React.createElement("div", {
|
|
93
|
-
className: `${classPrefix}-footer`
|
|
60
|
+
})), !!props.header && React.createElement("div", {
|
|
61
|
+
className: cls('header')
|
|
62
|
+
}, React.createElement(AutoCenter, null, props.header)), !!props.title && React.createElement("div", {
|
|
63
|
+
className: cls('title')
|
|
64
|
+
}, props.title), React.createElement("div", {
|
|
65
|
+
className: classNames(cls('content'), !props.content && cls('content-empty'))
|
|
66
|
+
}, typeof props.content === 'string' ? React.createElement(AutoCenter, null, props.content) : props.content), React.createElement("div", {
|
|
67
|
+
className: cls('footer')
|
|
94
68
|
}, props.actions.map((row, index) => {
|
|
95
69
|
const actions = Array.isArray(row) ? row : [row];
|
|
96
70
|
return React.createElement("div", {
|
|
97
|
-
className:
|
|
71
|
+
className: cls('action-row'),
|
|
98
72
|
key: index
|
|
99
73
|
}, actions.map((action, index) => React.createElement(DialogActionButton, {
|
|
100
74
|
key: action.key,
|
|
@@ -109,6 +83,28 @@ export const Dialog = p => {
|
|
|
109
83
|
}
|
|
110
84
|
})
|
|
111
85
|
})));
|
|
112
|
-
})))
|
|
86
|
+
})));
|
|
87
|
+
const node = withNativeProps(props, React.createElement("div", {
|
|
88
|
+
className: cls(),
|
|
89
|
+
style: {
|
|
90
|
+
display: active ? 'unset' : 'none'
|
|
91
|
+
}
|
|
92
|
+
}, React.createElement(Mask, {
|
|
93
|
+
visible: props.visible,
|
|
94
|
+
onMaskClick: props.closeOnMaskClick ? props.onClose : undefined,
|
|
95
|
+
style: props.maskStyle,
|
|
96
|
+
className: classNames(cls('mask'), props.maskClassName)
|
|
97
|
+
}), React.createElement("div", {
|
|
98
|
+
className: cls('wrap'),
|
|
99
|
+
style: {
|
|
100
|
+
pointerEvents: props.visible ? 'unset' : 'none'
|
|
101
|
+
}
|
|
102
|
+
}, React.createElement(animated.div, {
|
|
103
|
+
style: style
|
|
104
|
+
}, body))));
|
|
113
105
|
return renderToContainer(props.getContainer, withStopPropagation(props.stopPropagation, node));
|
|
114
|
-
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
function cls(name = '') {
|
|
109
|
+
return 'adm-dialog' + (name && '-') + name;
|
|
110
|
+
}
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
.adm-dropdown .adm-dropdown-nav {
|
|
6
6
|
display: flex;
|
|
7
|
+
border-bottom: 2px solid transparent;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
.adm-dropdown-open .adm-dropdown-nav {
|
|
10
|
-
border-bottom:
|
|
11
|
+
border-bottom-color: var(--adm-border-color);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
.adm-dropdown-item {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
|
+
import { PropagationEvent } from '../../utils/with-stop-propagation';
|
|
3
4
|
export declare type EllipsisProps = {
|
|
4
5
|
content: string;
|
|
5
6
|
direction?: 'start' | 'end' | 'middle';
|
|
6
7
|
rows?: number;
|
|
7
8
|
expandText?: string;
|
|
8
9
|
collapseText?: string;
|
|
10
|
+
stopPropagationForActionButtons?: PropagationEvent[];
|
|
9
11
|
} & NativeProps;
|
|
10
12
|
export declare const Ellipsis: FC<EllipsisProps>;
|
|
@@ -3,12 +3,14 @@ import { mergeProps } from '../../utils/with-default-props';
|
|
|
3
3
|
import { withNativeProps } from '../../utils/native-props';
|
|
4
4
|
import { useResizeEffect } from '../../utils/use-resize-effect';
|
|
5
5
|
import { useIsomorphicLayoutEffect } from 'ahooks';
|
|
6
|
+
import { withStopPropagation } from '../../utils/with-stop-propagation';
|
|
6
7
|
const classPrefix = `adm-ellipsis`;
|
|
7
8
|
const defaultProps = {
|
|
8
9
|
direction: 'end',
|
|
9
10
|
rows: 1,
|
|
10
11
|
expandText: '',
|
|
11
|
-
collapseText: ''
|
|
12
|
+
collapseText: '',
|
|
13
|
+
stopPropagationForActionButtons: []
|
|
12
14
|
};
|
|
13
15
|
export const Ellipsis = p => {
|
|
14
16
|
const props = mergeProps(defaultProps, p);
|
|
@@ -117,16 +119,16 @@ export const Ellipsis = p => {
|
|
|
117
119
|
useIsomorphicLayoutEffect(() => {
|
|
118
120
|
calcEllipsised();
|
|
119
121
|
}, [props.content, props.direction, props.rows, props.expandText, props.collapseText]);
|
|
120
|
-
const expandActionElement = exceeded && props.expandText ? React.createElement("a", {
|
|
122
|
+
const expandActionElement = exceeded && props.expandText ? withStopPropagation(props.stopPropagationForActionButtons, React.createElement("a", {
|
|
121
123
|
onClick: () => {
|
|
122
124
|
setExpanded(true);
|
|
123
125
|
}
|
|
124
|
-
}, props.expandText) : null;
|
|
125
|
-
const collapseActionElement = exceeded && props.expandText ? React.createElement("a", {
|
|
126
|
+
}, props.expandText)) : null;
|
|
127
|
+
const collapseActionElement = exceeded && props.expandText ? withStopPropagation(props.stopPropagationForActionButtons, React.createElement("a", {
|
|
126
128
|
onClick: () => {
|
|
127
129
|
setExpanded(false);
|
|
128
130
|
}
|
|
129
|
-
}, props.collapseText) : null;
|
|
131
|
+
}, props.collapseText)) : null;
|
|
130
132
|
|
|
131
133
|
const renderContent = () => {
|
|
132
134
|
if (!exceeded) {
|
|
@@ -4,8 +4,9 @@ import type { Meta, InternalNamePath } from 'rc-field-form/lib/interface';
|
|
|
4
4
|
export declare type FormContextType = {
|
|
5
5
|
hasFeedback: boolean;
|
|
6
6
|
layout: FormLayout;
|
|
7
|
+
requiredMarkStyle: 'asterisk' | 'text-required' | 'text-optional';
|
|
7
8
|
};
|
|
8
|
-
export declare const
|
|
9
|
+
export declare const defaultFormContext: FormContextType;
|
|
9
10
|
export declare const FormContext: React.Context<FormContextType>;
|
|
10
11
|
export declare type OnSubMetaChange = (meta: Meta & {
|
|
11
12
|
destroy?: boolean;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export const
|
|
2
|
+
export const defaultFormContext = {
|
|
3
3
|
hasFeedback: true,
|
|
4
|
-
layout: 'vertical'
|
|
4
|
+
layout: 'vertical',
|
|
5
|
+
requiredMarkStyle: 'asterisk'
|
|
5
6
|
};
|
|
6
|
-
export const FormContext = React.createContext(
|
|
7
|
+
export const FormContext = React.createContext(defaultFormContext);
|
|
7
8
|
export const NoStyleItemContext = React.createContext(null);
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
color: #666666;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
.adm-form-item-label-required {
|
|
14
|
+
.adm-form-item-label .adm-form-item-required-asterisk {
|
|
15
15
|
position: absolute;
|
|
16
16
|
left: -0.6em;
|
|
17
17
|
top: 0;
|
|
@@ -20,8 +20,34 @@
|
|
|
20
20
|
user-select: none;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
.adm-form-item-label .adm-form-item-required-text {
|
|
24
|
+
margin-left: 8px;
|
|
25
|
+
color: var(--adm-color-weak);
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
.adm-form-item-label-help {
|
|
24
29
|
margin-left: 8px;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.adm-form-item-child {
|
|
34
|
+
display: flex;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.adm-form-item-child-position-normal {
|
|
38
|
+
justify-content: normal;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.adm-form-item-child-position-normal > * {
|
|
42
|
+
flex: auto;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.adm-form-item-child-position-right {
|
|
46
|
+
justify-content: right;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.adm-form-item-child-position-right > * {
|
|
50
|
+
flex: none;
|
|
25
51
|
}
|
|
26
52
|
|
|
27
53
|
.adm-form-item-footer {
|
|
@@ -16,6 +16,7 @@ export declare type FormItemProps = Pick<RcFieldProps, 'dependencies' | 'valuePr
|
|
|
16
16
|
disabled?: boolean;
|
|
17
17
|
hidden?: boolean;
|
|
18
18
|
layout?: FormLayout;
|
|
19
|
+
childElementPosition?: 'normal' | 'right';
|
|
19
20
|
children: ChildrenType;
|
|
20
21
|
} & NativeProps;
|
|
21
22
|
export declare const FormItem: FC<FormItemProps>;
|
|
@@ -9,6 +9,7 @@ import { toArray } from './utils';
|
|
|
9
9
|
import List from '../list';
|
|
10
10
|
import Popover from '../popover';
|
|
11
11
|
import { QuestionCircleOutline } from 'antd-mobile-icons';
|
|
12
|
+
import { useConfig } from '../config-provider';
|
|
12
13
|
const NAME_SPLIT = '__SPLIT__';
|
|
13
14
|
const classPrefix = `adm-form-item`;
|
|
14
15
|
const MemoInput = React.memo(({
|
|
@@ -29,18 +30,47 @@ const FormItemLayout = props => {
|
|
|
29
30
|
hidden,
|
|
30
31
|
errors,
|
|
31
32
|
arrow,
|
|
32
|
-
description
|
|
33
|
+
description,
|
|
34
|
+
childElementPosition = 'normal'
|
|
33
35
|
} = props;
|
|
34
36
|
const context = useContext(FormContext);
|
|
37
|
+
const {
|
|
38
|
+
locale
|
|
39
|
+
} = useConfig();
|
|
35
40
|
const hasFeedback = props.hasFeedback !== undefined ? props.hasFeedback : context.hasFeedback;
|
|
36
41
|
const layout = props.layout || context.layout;
|
|
37
42
|
const feedback = hasFeedback && errors && errors.length > 0 ? errors[0] : null;
|
|
43
|
+
|
|
44
|
+
const requiredMark = (() => {
|
|
45
|
+
const {
|
|
46
|
+
requiredMarkStyle
|
|
47
|
+
} = context;
|
|
48
|
+
|
|
49
|
+
switch (requiredMarkStyle) {
|
|
50
|
+
case 'asterisk':
|
|
51
|
+
return required && React.createElement("span", {
|
|
52
|
+
className: `${classPrefix}-required-asterisk`
|
|
53
|
+
}, "*");
|
|
54
|
+
|
|
55
|
+
case 'text-required':
|
|
56
|
+
return required && React.createElement("span", {
|
|
57
|
+
className: `${classPrefix}-required-text`
|
|
58
|
+
}, "(", locale.Form.required, ")");
|
|
59
|
+
|
|
60
|
+
case 'text-optional':
|
|
61
|
+
return !required && React.createElement("span", {
|
|
62
|
+
className: `${classPrefix}-required-text`
|
|
63
|
+
}, "(", locale.Form.optional, ")");
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
69
|
+
|
|
38
70
|
const labelElement = label ? React.createElement("label", {
|
|
39
71
|
className: `${classPrefix}-label`,
|
|
40
72
|
htmlFor: htmlFor
|
|
41
|
-
}, label,
|
|
42
|
-
className: `${classPrefix}-label-required`
|
|
43
|
-
}, "*"), help && React.createElement("span", {
|
|
73
|
+
}, label, requiredMark, help && React.createElement("span", {
|
|
44
74
|
className: `${classPrefix}-label-help`
|
|
45
75
|
}, React.createElement(Popover, {
|
|
46
76
|
content: help,
|
|
@@ -62,7 +92,11 @@ const FormItemLayout = props => {
|
|
|
62
92
|
disabled: disabled,
|
|
63
93
|
onClick: props.onClick,
|
|
64
94
|
arrow: arrow
|
|
65
|
-
},
|
|
95
|
+
}, React.createElement("div", {
|
|
96
|
+
className: classNames(`${classPrefix}-child`, `${classPrefix}-child-position-${childElementPosition}`)
|
|
97
|
+
}, React.createElement("div", {
|
|
98
|
+
className: classNames(`${classPrefix}-child-inner`)
|
|
99
|
+
}, children)));
|
|
66
100
|
};
|
|
67
101
|
|
|
68
102
|
export const FormItem = props => {
|
|
@@ -80,6 +114,7 @@ export const FormItem = props => {
|
|
|
80
114
|
noStyle,
|
|
81
115
|
hidden,
|
|
82
116
|
layout,
|
|
117
|
+
childElementPosition,
|
|
83
118
|
description,
|
|
84
119
|
// Field 相关
|
|
85
120
|
disabled,
|
|
@@ -93,7 +128,7 @@ export const FormItem = props => {
|
|
|
93
128
|
dependencies,
|
|
94
129
|
arrow
|
|
95
130
|
} = props,
|
|
96
|
-
fieldProps = __rest(props, ["className", "style", "label", "help", "extra", "hasFeedback", "name", "required", "noStyle", "hidden", "layout", "description", "disabled", "rules", "children", "messageVariables", "trigger", "validateTrigger", "onClick", "shouldUpdate", "dependencies", "arrow"]);
|
|
131
|
+
fieldProps = __rest(props, ["className", "style", "label", "help", "extra", "hasFeedback", "name", "required", "noStyle", "hidden", "layout", "childElementPosition", "description", "disabled", "rules", "children", "messageVariables", "trigger", "validateTrigger", "onClick", "shouldUpdate", "dependencies", "arrow"]);
|
|
97
132
|
|
|
98
133
|
const {
|
|
99
134
|
validateTrigger: contextValidateTrigger
|
|
@@ -151,6 +186,7 @@ export const FormItem = props => {
|
|
|
151
186
|
onClick: onClick,
|
|
152
187
|
hidden: hidden,
|
|
153
188
|
layout: layout,
|
|
189
|
+
childElementPosition: childElementPosition,
|
|
154
190
|
arrow: arrow
|
|
155
191
|
}, React.createElement(NoStyleItemContext.Provider, {
|
|
156
192
|
value: onSubMetaChange
|
|
@@ -193,13 +229,7 @@ export const FormItem = props => {
|
|
|
193
229
|
messageVariables: Variables
|
|
194
230
|
}), (control, meta, context) => {
|
|
195
231
|
let childNode = null;
|
|
196
|
-
const isRequired = required !== undefined ? required :
|
|
197
|
-
if (rule && typeof rule === 'object' && rule.required) {
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return false;
|
|
202
|
-
}));
|
|
232
|
+
const isRequired = required !== undefined ? required : rules && rules.some(rule => !!(rule && typeof rule === 'object' && rule.required));
|
|
203
233
|
const fieldId = (toArray(name).length && meta ? meta.name : []).join('_');
|
|
204
234
|
|
|
205
235
|
if (shouldUpdate && dependencies) {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import React, { forwardRef } from 'react';
|
|
2
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import List from '../list';
|
|
5
5
|
import RcForm from 'rc-field-form';
|
|
6
|
-
import { FormContext } from './context';
|
|
6
|
+
import { defaultFormContext, FormContext } from './context';
|
|
7
7
|
import { mergeProps } from '../../utils/with-default-props';
|
|
8
8
|
import { Header } from './header';
|
|
9
|
+
import { useConfig } from '../config-provider';
|
|
10
|
+
import merge from 'lodash/merge';
|
|
9
11
|
const classPrefix = 'adm-form';
|
|
10
|
-
const defaultProps =
|
|
11
|
-
hasFeedback: true,
|
|
12
|
-
layout: 'vertical'
|
|
13
|
-
};
|
|
12
|
+
const defaultProps = defaultFormContext;
|
|
14
13
|
export const Form = forwardRef((p, ref) => {
|
|
15
14
|
const props = mergeProps(defaultProps, p);
|
|
16
15
|
|
|
@@ -21,10 +20,15 @@ export const Form = forwardRef((p, ref) => {
|
|
|
21
20
|
children,
|
|
22
21
|
layout,
|
|
23
22
|
footer,
|
|
24
|
-
mode
|
|
23
|
+
mode,
|
|
24
|
+
requiredMarkStyle
|
|
25
25
|
} = props,
|
|
26
|
-
formProps = __rest(props, ["className", "style", "hasFeedback", "children", "layout", "footer", "mode"]);
|
|
26
|
+
formProps = __rest(props, ["className", "style", "hasFeedback", "children", "layout", "footer", "mode", "requiredMarkStyle"]);
|
|
27
27
|
|
|
28
|
+
const {
|
|
29
|
+
locale
|
|
30
|
+
} = useConfig();
|
|
31
|
+
const validateMessages = useMemo(() => merge({}, locale.Form.defaultValidateMessages, formProps.validateMessages), [locale.Form.defaultValidateMessages, formProps.validateMessages]);
|
|
28
32
|
const lists = [];
|
|
29
33
|
let currentHeader = null;
|
|
30
34
|
let items = [];
|
|
@@ -54,10 +58,13 @@ export const Form = forwardRef((p, ref) => {
|
|
|
54
58
|
className: classNames(classPrefix, className),
|
|
55
59
|
style: style,
|
|
56
60
|
ref: ref
|
|
57
|
-
}, formProps
|
|
61
|
+
}, formProps, {
|
|
62
|
+
validateMessages: validateMessages
|
|
63
|
+
}), React.createElement(FormContext.Provider, {
|
|
58
64
|
value: {
|
|
59
|
-
hasFeedback
|
|
60
|
-
layout
|
|
65
|
+
hasFeedback,
|
|
66
|
+
layout,
|
|
67
|
+
requiredMarkStyle
|
|
61
68
|
}
|
|
62
69
|
}, lists), footer && React.createElement("div", {
|
|
63
70
|
className: `${classPrefix}-footer`
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
color: #666666;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
.adm-form-item-label-required {
|
|
35
|
+
.adm-form-item-label .adm-form-item-required-asterisk {
|
|
36
36
|
position: absolute;
|
|
37
37
|
left: -0.6em;
|
|
38
38
|
top: 0;
|
|
@@ -41,8 +41,34 @@
|
|
|
41
41
|
user-select: none;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
.adm-form-item-label .adm-form-item-required-text {
|
|
45
|
+
margin-left: 8px;
|
|
46
|
+
color: var(--adm-color-weak);
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
.adm-form-item-label-help {
|
|
45
50
|
margin-left: 8px;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.adm-form-item-child {
|
|
55
|
+
display: flex;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.adm-form-item-child-position-normal {
|
|
59
|
+
justify-content: normal;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.adm-form-item-child-position-normal > * {
|
|
63
|
+
flex: auto;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.adm-form-item-child-position-right {
|
|
67
|
+
justify-content: right;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.adm-form-item-child-position-right > * {
|
|
71
|
+
flex: none;
|
|
46
72
|
}
|
|
47
73
|
|
|
48
74
|
.adm-form-item-footer {
|
|
@@ -57,7 +57,7 @@ export const Input = forwardRef((p, ref) => {
|
|
|
57
57
|
let nextValue = value;
|
|
58
58
|
|
|
59
59
|
if (props.type === 'number') {
|
|
60
|
-
nextValue = bound(parseFloat(nextValue), props.min, props.max).toString();
|
|
60
|
+
nextValue = nextValue && bound(parseFloat(nextValue), props.min, props.max).toString();
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
if (nextValue !== value) {
|
|
@@ -105,7 +105,7 @@ export const Input = forwardRef((p, ref) => {
|
|
|
105
105
|
onKeyUp: props.onKeyUp,
|
|
106
106
|
onCompositionStart: props.onCompositionStart,
|
|
107
107
|
onCompositionEnd: props.onCompositionEnd
|
|
108
|
-
}), props.clearable && !!value && !props.readOnly && React.createElement("div", {
|
|
108
|
+
}), props.clearable && !!value && !props.readOnly && hasFocus && React.createElement("div", {
|
|
109
109
|
className: `${classPrefix}-clear`,
|
|
110
110
|
onMouseDown: e => {
|
|
111
111
|
e.preventDefault();
|