@cloudbase/weda-ui 0.2.8 → 0.2.12
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/package.json +62 -41
- package/src/configs/.DS_Store +0 -0
- package/src/configs/components/button.json +7 -3
- package/src/configs/components/form/richText.json +1 -1
- package/src/configs/components/form/uploader.json +29 -1
- package/src/configs/components/form/uploaderFile.json +158 -0
- package/src/configs/components/image.json +12 -3
- package/src/configs/components/link.json +3 -3
- package/src/configs/components/richtextview.json +2 -2
- package/src/configs/components/scrollVeiw.json +5 -5
- package/src/configs/components/swiper.json +6 -6
- package/src/configs/components/tabs.json +3 -3
- package/src/configs/components/text.json +39 -4
- package/src/configs/index.js +6 -5
- package/src/mp/components/button/index.js +1 -0
- package/src/mp/components/button/index.wxss +8 -0
- package/src/mp/components/form/select/index.js +18 -0
- package/src/mp/components/form/uploader/index.js +26 -29
- package/src/mp/components/form/uploaderFile/index.js +247 -0
- package/src/mp/components/form/uploaderFile/index.json +9 -0
- package/src/mp/components/form/uploaderFile/index.wxml +46 -0
- package/src/mp/components/form/uploaderFile/index.wxss +104 -0
- package/src/mp/components/text/index.js +33 -0
- package/src/mp/components/text/index.wxml +1 -1
- package/src/mp/components/text/index.wxss +18 -0
- package/src/mp/index.json +1 -0
- package/src/mp/utils/platform.js +20 -0
- package/src/mp/utils/tcb.js +11 -0
- package/src/web/actions/showModal/{index.jsx → index.tsx} +53 -3
- package/src/web/components/auth/index.js +2 -2
- package/src/web/components/button/index.css +9 -0
- package/src/web/components/button/{index.jsx → index.tsx} +27 -41
- package/src/web/components/container/{index.jsx → index.tsx} +6 -10
- package/src/web/components/drawer/index.tsx +57 -0
- package/src/web/components/form/checkbox/{index.jsx → index.tsx} +24 -48
- package/src/web/components/form/enumSelect/MultipleSelect.jsx +89 -0
- package/src/web/components/form/enumSelect/NormalSelect.tsx +94 -0
- package/src/web/components/form/enumSelect/SelectContainer.jsx +43 -0
- package/src/web/components/form/enumSelect/index.jsx +9 -0
- package/src/web/components/form/enumSelect/props/defaultProps.js +39 -0
- package/src/web/components/form/enumSelect/props/propsTypes.js +50 -0
- package/src/web/components/form/form/index.tsx +48 -0
- package/src/web/components/form/formcell/{index.jsx → index.tsx} +6 -13
- package/src/web/components/form/input/index.css +4 -0
- package/src/web/components/form/input/{index.jsx → index.tsx} +33 -67
- package/src/web/components/form/radio/{index.jsx → index.tsx} +19 -42
- package/src/web/components/form/{renderDecorator.jsx → renderDecorator.tsx} +1 -3
- package/src/web/components/form/select/{h5.jsx → h5.tsx} +18 -62
- package/src/web/components/form/select/{index.jsx → index.tsx} +51 -94
- package/src/web/components/form/select/region/{cities.js → cities.ts} +1 -1
- package/src/web/components/form/select/region/{index.js → index.ts} +3 -3
- package/src/web/components/form/select/region/{provinces.js → provinces.ts} +1 -1
- package/src/web/components/form/select/region/{regions.js → regions.ts} +1 -1
- package/src/web/components/form/select/time.jsx +2 -2
- package/src/web/components/form/switch/{index.jsx → index.tsx} +30 -47
- package/src/web/components/form/textarea/{index.jsx → index.tsx} +22 -55
- package/src/web/components/form/tips/{index.jsx → index.tsx} +8 -22
- package/src/web/components/form/types.d.ts +12 -0
- package/src/web/components/form/uploader/{index.jsx → index.tsx} +16 -14
- package/src/web/components/form/uploader/{uploader.h5.jsx → uploader.h5.tsx} +67 -57
- package/src/web/components/form/uploader/{uploader.pc.jsx → uploader.pc.tsx} +26 -43
- package/src/web/components/form/uploaderFile/fail.svg +12 -0
- package/src/web/components/form/uploaderFile/index.css +423 -0
- package/src/web/components/form/uploaderFile/index.jsx +30 -0
- package/src/web/components/form/uploaderFile/pending.svg +18 -0
- package/src/web/components/form/uploaderFile/success.svg +12 -0
- package/src/web/components/form/uploaderFile/uploadFile.h5.jsx +562 -0
- package/src/web/components/form/uploaderFile/uploadFile.pc.jsx +487 -0
- package/src/web/components/image/{image.jsx → image.tsx} +8 -21
- package/src/web/components/image/{index.jsx → index.tsx} +22 -37
- package/src/web/components/index.js +36 -1
- package/src/web/components/link/{index.jsx → index.tsx} +19 -36
- package/src/web/components/modal/{index.jsx → index.tsx} +24 -10
- package/src/web/components/picker/{datePicker.jsx → datePicker.tsx} +11 -12
- package/src/web/components/picker/{picker.jsx → picker.tsx} +7 -10
- package/src/web/components/picker/{timePicker.jsx → timePicker.tsx} +8 -16
- package/src/web/components/richText/{const.js → const.ts} +0 -0
- package/src/web/components/richText/index.jsx +5 -2
- package/src/web/components/richTextView/index.tsx +67 -0
- package/src/web/components/scrollView/{index.jsx → index.tsx} +18 -33
- package/src/web/components/slot/{index.jsx → index.tsx} +8 -9
- package/src/web/components/swiper/index.css +1 -1
- package/src/web/components/swiper/{index.jsx → index.tsx} +66 -73
- package/src/web/components/tabs/index.tsx +33 -0
- package/src/web/components/tabs/{tabs.h5.jsx → tabs.h5.tsx} +4 -33
- package/src/web/components/tabs/{tabs.pc.jsx → tabs.pc.tsx} +5 -39
- package/src/web/components/text/index.css +18 -0
- package/src/web/components/text/index.tsx +69 -0
- package/src/web/components/uploaderFileView/index.css +11 -0
- package/src/web/components/uploaderFileView/index.jsx +75 -0
- package/src/web/components/uploaderView/{index.jsx → index.tsx} +12 -15
- package/src/web/types.d.ts +20 -0
- package/src/web/utils/constant.js +2 -0
- package/src/web/utils/loading-fallback.tsx +2 -0
- package/src/web/utils/platform.js +77 -6
- package/src/web/utils/useSetState.ts +14 -0
- package/src/web/utils/useSyncValue.ts +17 -0
- package/src/configs/components/button.svg +0 -18
- package/src/web/components/drawer/index.jsx +0 -64
- package/src/web/components/form/form/index.jsx +0 -76
- package/src/web/components/richTextView/index.jsx +0 -89
- package/src/web/components/tabs/index.jsx +0 -10
- package/src/web/components/text/index.jsx +0 -71
- package/src/web/utils/useSyncValue.js +0 -14
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { CommonPropsType } from '../../types';
|
|
2
3
|
import classNames from '../../utils/classnames';
|
|
3
4
|
import './index.css';
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
export interface PropsType extends CommonPropsType {
|
|
7
|
+
/**
|
|
8
|
+
* 内容
|
|
9
|
+
*/
|
|
10
|
+
content?: string;
|
|
11
|
+
/**
|
|
12
|
+
* 链接地址
|
|
13
|
+
*/
|
|
14
|
+
url?: string;
|
|
15
|
+
/**
|
|
16
|
+
* 参数
|
|
17
|
+
*/
|
|
18
|
+
params?: {key: string, value: string}[];
|
|
19
|
+
contentSlot?: React.ReactNode;
|
|
20
|
+
}
|
|
5
21
|
|
|
6
22
|
// 所有绝对地址直接交由浏览器,新开窗口交由浏览器
|
|
7
23
|
// 当前窗口相对地址交给平台
|
|
@@ -13,7 +29,7 @@ export default function Link({
|
|
|
13
29
|
className,
|
|
14
30
|
contentSlot,
|
|
15
31
|
params = [], // TODO 格式定义
|
|
16
|
-
}) {
|
|
32
|
+
}: PropsType) {
|
|
17
33
|
url = url.trim();
|
|
18
34
|
const cls = classNames({
|
|
19
35
|
'weda-link': true,
|
|
@@ -97,37 +113,4 @@ export default function Link({
|
|
|
97
113
|
{content}
|
|
98
114
|
</a>
|
|
99
115
|
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
Link.propTypes = {
|
|
103
|
-
// 系统属性
|
|
104
|
-
/**
|
|
105
|
-
* 类名
|
|
106
|
-
*/
|
|
107
|
-
className: PropTypes.string,
|
|
108
|
-
/**
|
|
109
|
-
* 事件
|
|
110
|
-
*/
|
|
111
|
-
events: PropTypes.objectOf(PropTypes.func),
|
|
112
|
-
/**
|
|
113
|
-
* 内联样式
|
|
114
|
-
*/
|
|
115
|
-
style: PropTypes.object,
|
|
116
|
-
// 组件属性
|
|
117
|
-
/**
|
|
118
|
-
* 内容
|
|
119
|
-
*/
|
|
120
|
-
content: PropTypes.string,
|
|
121
|
-
/**
|
|
122
|
-
* 链接地址
|
|
123
|
-
*/
|
|
124
|
-
url: PropTypes.string,
|
|
125
|
-
/**
|
|
126
|
-
* 参数
|
|
127
|
-
*/
|
|
128
|
-
params: PropTypes.array,
|
|
129
|
-
|
|
130
|
-
contentSlot: PropTypes.any,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
Link.defaultProps = {};
|
|
116
|
+
}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Modal, Button } from 'tea-component';
|
|
2
|
+
import { Modal, Button, ModalProps, ConfigProvider } from 'tea-component';
|
|
3
|
+
import { unknownFunction } from '../../types';
|
|
3
4
|
import classNames from '../../utils/classnames';
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
+
export interface PropTypes extends ModalProps {
|
|
7
|
+
content: string,
|
|
8
|
+
customButton: React.ReactNode,
|
|
9
|
+
customContent: React.ReactNode,
|
|
10
|
+
isDefaultButton: boolean,
|
|
11
|
+
emit?: unknownFunction,
|
|
12
|
+
events: Record<string, unknownFunction>,
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default function WeDaModal(_props: PropTypes) {
|
|
6
17
|
const {
|
|
7
18
|
className,
|
|
8
19
|
content,
|
|
@@ -11,34 +22,37 @@ export default function WeDaModal(_props) {
|
|
|
11
22
|
customContent,
|
|
12
23
|
isDefaultButton,
|
|
13
24
|
emit,
|
|
25
|
+
events,
|
|
14
26
|
...props
|
|
15
27
|
} = _props;
|
|
16
28
|
|
|
17
29
|
return (
|
|
30
|
+
<ConfigProvider classPrefix="wedatea2td">
|
|
18
31
|
<Modal
|
|
19
32
|
className={classNames('weda-ui', 'lcap-modal', 'container', className)}
|
|
20
33
|
visible={visible}
|
|
21
34
|
onClose={() => {
|
|
22
|
-
emit('close');
|
|
35
|
+
emit('close', {});
|
|
23
36
|
}}
|
|
24
37
|
{...props}
|
|
25
|
-
|
|
38
|
+
>
|
|
26
39
|
<Modal.Body>{content ? content : customContent}</Modal.Body>
|
|
27
40
|
<Modal.Footer>
|
|
28
41
|
{isDefaultButton ? (
|
|
29
42
|
<Button
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
type="primary"
|
|
44
|
+
onClick={() => {
|
|
45
|
+
emit('confirm', {});
|
|
46
|
+
// events.confirm();
|
|
47
|
+
}}
|
|
35
48
|
>
|
|
36
49
|
确定
|
|
37
50
|
</Button>
|
|
38
51
|
) : (
|
|
39
52
|
customButton
|
|
40
|
-
|
|
53
|
+
)}
|
|
41
54
|
</Modal.Footer>
|
|
42
55
|
</Modal>
|
|
56
|
+
</ConfigProvider>
|
|
43
57
|
);
|
|
44
58
|
}
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
2
|
import weui from '../../utils/weui';
|
|
4
3
|
|
|
5
4
|
import classNames from '../../utils/classnames';
|
|
5
|
+
import { CommonPropsType } from '../../types';
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export interface PropsType extends CommonPropsType {
|
|
8
|
+
start: string;
|
|
9
|
+
end: string;
|
|
10
|
+
defaultValue: string;
|
|
11
|
+
title: string;
|
|
12
|
+
children?: React.ReactNode|undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default function DatePicker(props: PropsType) {
|
|
8
16
|
const { start, end, defaultValue, title, children, className } = props;
|
|
9
17
|
const click = function () {
|
|
10
18
|
let fixedDefaultValue = undefined;
|
|
@@ -37,13 +45,4 @@ export default function DatePicker(props) {
|
|
|
37
45
|
{children}
|
|
38
46
|
</div>
|
|
39
47
|
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
DatePicker.propTypes = {
|
|
43
|
-
start: PropTypes.string,
|
|
44
|
-
end: PropTypes.string,
|
|
45
|
-
defaultValue: PropTypes.string,
|
|
46
|
-
title: PropTypes.string,
|
|
47
|
-
children: PropTypes.any,
|
|
48
|
-
className: PropTypes.string,
|
|
49
|
-
};
|
|
48
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
2
|
import weui from '../../utils/weui';
|
|
4
|
-
|
|
5
3
|
import classNames from '../../utils/classnames';
|
|
4
|
+
import { CommonPropsType } from '../../types';
|
|
5
|
+
|
|
6
|
+
export interface PropsType extends CommonPropsType {
|
|
7
|
+
title?: string
|
|
8
|
+
}
|
|
6
9
|
|
|
7
|
-
export default function Picker(props) {
|
|
10
|
+
export default function Picker(props: PropsType) {
|
|
8
11
|
const { title, children, className } = props;
|
|
9
12
|
const click = function () {
|
|
10
13
|
weui.picker(
|
|
@@ -53,10 +56,4 @@ export default function Picker(props) {
|
|
|
53
56
|
{children}
|
|
54
57
|
</div>
|
|
55
58
|
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
Picker.propTypes = {
|
|
59
|
-
title: PropTypes.string,
|
|
60
|
-
children: PropTypes.any,
|
|
61
|
-
className: PropTypes.string,
|
|
62
|
-
};
|
|
59
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
2
|
import weui from '../../utils/weui';
|
|
4
3
|
|
|
5
4
|
import classNames from '../../utils/classnames';
|
|
5
|
+
import { CommonPropsType } from '../../types';
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
7
|
+
export interface PropsType extends CommonPropsType {
|
|
8
|
+
defaultValue?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
}
|
|
11
|
+
export default function TimePicker(props: PropsType) {
|
|
12
|
+
const { title = '时间', defaultValue = '', children, className } = props;
|
|
9
13
|
|
|
10
14
|
const click = function () {
|
|
11
15
|
const hour = [];
|
|
@@ -49,16 +53,4 @@ export default function TimePicker(props) {
|
|
|
49
53
|
{children}
|
|
50
54
|
</div>
|
|
51
55
|
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
TimePicker.propTypes = {
|
|
55
|
-
title: PropTypes.string,
|
|
56
|
-
defaultValue: PropTypes.string,
|
|
57
|
-
children: PropTypes.any,
|
|
58
|
-
className: PropTypes.string,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
TimePicker.defaultProps = {
|
|
62
|
-
title: '时间',
|
|
63
|
-
defaultValue: '',
|
|
64
|
-
};
|
|
56
|
+
}
|
|
File without changes
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import React, { useEffect, useState } from 'react';
|
|
2
3
|
import BraftEditor from 'braft-editor';
|
|
3
|
-
import { useSetState } from '
|
|
4
|
+
import { useSetState } from '../../utils/useSetState';
|
|
4
5
|
import * as PropsTypes from 'prop-types';
|
|
5
6
|
import { ContentUtils } from 'braft-utils';
|
|
6
7
|
import classNames from '../../utils/classnames';
|
|
7
|
-
|
|
8
|
+
|
|
8
9
|
import { getCloudInstance, getTempFileURL } from '../../utils/tcb';
|
|
9
10
|
import {
|
|
10
11
|
message,
|
|
@@ -149,6 +150,7 @@ export default function RichText({
|
|
|
149
150
|
}
|
|
150
151
|
}}
|
|
151
152
|
excludeControls={['media', 'fullscreen']}
|
|
153
|
+
/** @ts-ignore */
|
|
152
154
|
extendControls={extendControls}
|
|
153
155
|
handleKeyCommand={(command, editState) => {
|
|
154
156
|
const newState = ContentUtils.handleKeyCommand(
|
|
@@ -194,6 +196,7 @@ export const CustomUploader = (props) => {
|
|
|
194
196
|
const getBase64 = (file) => {
|
|
195
197
|
const reader = new FileReader();
|
|
196
198
|
reader.onloadend = () => {
|
|
199
|
+
// @ts-ignore
|
|
197
200
|
setState({ previewImg: reader.result });
|
|
198
201
|
};
|
|
199
202
|
reader.readAsDataURL(file);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import classNames from '../../utils/classnames';
|
|
3
|
+
import { getTempFileURL } from '../../utils/tcb';
|
|
4
|
+
import './index.css';
|
|
5
|
+
import { LOAD_ERR_IMG_BASE64 } from '../../utils/constant';
|
|
6
|
+
import { CommonPropsType } from '../../types';
|
|
7
|
+
|
|
8
|
+
export interface PropsType extends CommonPropsType {
|
|
9
|
+
value: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default function RichTextView({
|
|
13
|
+
value = '',
|
|
14
|
+
className,
|
|
15
|
+
style,
|
|
16
|
+
id
|
|
17
|
+
}: PropsType) {
|
|
18
|
+
let parseValue = value;
|
|
19
|
+
try {
|
|
20
|
+
parseValue = JSON.parse(value);
|
|
21
|
+
} catch (e) {}
|
|
22
|
+
const cls = classNames({
|
|
23
|
+
'weda-ui': true,
|
|
24
|
+
'weda-RichTextView': true,
|
|
25
|
+
[className]: className,
|
|
26
|
+
});
|
|
27
|
+
const [displayValue, setDisplayValue] = useState('');
|
|
28
|
+
const regex = new RegExp(/<img [^>]*src=\\*"([^"]*?)\\*"/g);
|
|
29
|
+
const iferror = `javascript:this.width='80';this.src='${LOAD_ERR_IMG_BASE64}';this.onerror=null`;
|
|
30
|
+
|
|
31
|
+
let tempValue = parseValue
|
|
32
|
+
.toString()
|
|
33
|
+
.replace(/<img /g, `<img onerror=${iferror} style="max-width:100%" `);
|
|
34
|
+
|
|
35
|
+
const getSrc = async (img) => {
|
|
36
|
+
const url = img.replace(regex, '$1');
|
|
37
|
+
if (img.includes('cloud://')) {
|
|
38
|
+
const newURL = await getTempFileURL(url);
|
|
39
|
+
if (newURL) {
|
|
40
|
+
tempValue = tempValue.replace(new RegExp(url, 'g'), newURL);
|
|
41
|
+
setDisplayValue(tempValue);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
setDisplayValue(tempValue);
|
|
48
|
+
try {
|
|
49
|
+
const imgs = parseValue.match(regex);
|
|
50
|
+
if (imgs && imgs.length > 0) {
|
|
51
|
+
imgs.forEach((img) => {
|
|
52
|
+
getSrc(img);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {}
|
|
56
|
+
}, [value]);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
displayValue && (
|
|
60
|
+
<div className={cls} style={style}
|
|
61
|
+
id={id}
|
|
62
|
+
>
|
|
63
|
+
<div dangerouslySetInnerHTML={{ __html: displayValue }}></div>
|
|
64
|
+
</div>
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { CommonPropsType } from '../../types';
|
|
4
3
|
import classNames from '../../utils/classnames';
|
|
5
4
|
|
|
5
|
+
export interface PropsType extends CommonPropsType {
|
|
6
|
+
scrollX?: boolean;
|
|
7
|
+
scrollY?: boolean;
|
|
8
|
+
scrollTop?: number;
|
|
9
|
+
scrollLeft?: number;
|
|
10
|
+
scrollIntoView?: string;
|
|
11
|
+
upperThreshold?: number;
|
|
12
|
+
lowerThreshold?: number;
|
|
13
|
+
domRef?: any;
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
export default function ScrollView({
|
|
7
17
|
id,
|
|
8
|
-
|
|
9
|
-
|
|
18
|
+
scrollX = false,
|
|
19
|
+
scrollY = true,
|
|
10
20
|
style,
|
|
11
21
|
scrollTop,
|
|
12
22
|
scrollLeft,
|
|
@@ -23,7 +33,7 @@ export default function ScrollView({
|
|
|
23
33
|
const [scrollLeftPos, setScrollLeftPos] = React.useState(0);
|
|
24
34
|
const [scrollTopPos, setScrollTopPos] = React.useState(0);
|
|
25
35
|
|
|
26
|
-
const scrollViewRef = domRef || React.useRef(null);
|
|
36
|
+
const scrollViewRef = domRef || React.useRef<HTMLElement>(null);
|
|
27
37
|
|
|
28
38
|
const handleOnScroll = function (e) {
|
|
29
39
|
const detail = {
|
|
@@ -35,7 +45,6 @@ export default function ScrollView({
|
|
|
35
45
|
const deltaY = scrollY ? e.target.scrollTop - scrollTopPos : 0;
|
|
36
46
|
const deltaX = scrollX ? e.target.scrollLeft - scrollLeftPos : 0;
|
|
37
47
|
let delta;
|
|
38
|
-
// console.log(">>>>", deltaY, deltaX,e.target.scrollLeft,e.target.scrollTop)
|
|
39
48
|
// 横向滚动
|
|
40
49
|
if (Math.abs(deltaX) > Math.abs(deltaY)) {
|
|
41
50
|
delta = deltaX;
|
|
@@ -101,8 +110,8 @@ export default function ScrollView({
|
|
|
101
110
|
React.useEffect(() => {
|
|
102
111
|
if (scrollIntoView) {
|
|
103
112
|
const children = scrollViewRef.current.children;
|
|
104
|
-
const item = Array.from(children).find(
|
|
105
|
-
(item) => item && item.id === scrollIntoView
|
|
113
|
+
const item: any = Array.from(children).find(
|
|
114
|
+
(item: any) => item && item.id === scrollIntoView
|
|
106
115
|
);
|
|
107
116
|
scrollY && (scrollViewRef.current.scrollTop = item.offsetTop);
|
|
108
117
|
scrollX && (scrollViewRef.current.scrollLeft = item.offsetLeft);
|
|
@@ -136,28 +145,4 @@ export default function ScrollView({
|
|
|
136
145
|
{children}
|
|
137
146
|
</div>
|
|
138
147
|
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
ScrollView.propTypes = {
|
|
142
|
-
scrollX: PropTypes.bool,
|
|
143
|
-
scrollY: PropTypes.bool,
|
|
144
|
-
scrollTop: PropTypes.number,
|
|
145
|
-
scrollLeft: PropTypes.number,
|
|
146
|
-
scrollIntoView: PropTypes.string,
|
|
147
|
-
upperThreshold: PropTypes.number,
|
|
148
|
-
lowerThreshold: PropTypes.number,
|
|
149
|
-
domRef: PropTypes.any,
|
|
150
|
-
children: PropTypes.any,
|
|
151
|
-
id: PropTypes.string,
|
|
152
|
-
className: PropTypes.string,
|
|
153
|
-
style: PropTypes.string,
|
|
154
|
-
events: PropTypes.objectOf(PropTypes.func),
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
ScrollView.defaultProps = {
|
|
158
|
-
scrollX: false,
|
|
159
|
-
scrollY: true,
|
|
160
|
-
upperThreshold: 50,
|
|
161
|
-
lowerThreshold: 50,
|
|
162
|
-
events: {},
|
|
163
|
-
};
|
|
148
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as PropTypes from 'prop-types';
|
|
3
2
|
|
|
4
|
-
export
|
|
3
|
+
export interface PropsType {
|
|
4
|
+
className?: string,
|
|
5
|
+
name: string,
|
|
6
|
+
compositeParent: any
|
|
7
|
+
|
|
8
|
+
}
|
|
9
|
+
export default function Slot({ compositeParent, name, className }: PropsType) {
|
|
5
10
|
if (!compositeParent) {
|
|
6
11
|
console.warn('Slot组件只能用于实现复合组件');
|
|
7
12
|
// 兼容编辑器点击,可选中 Slot 组件
|
|
@@ -12,10 +17,4 @@ export default function Slot({ compositeParent, name, className }) {
|
|
|
12
17
|
);
|
|
13
18
|
}
|
|
14
19
|
return compositeParent.props.data[name] || null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
Slot.propTypes = {
|
|
18
|
-
className: PropTypes.string,
|
|
19
|
-
name: PropTypes.string,
|
|
20
|
-
compositeParent: PropTypes.any,
|
|
21
|
-
};
|
|
20
|
+
}
|
|
@@ -1,27 +1,49 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
3
|
-
import * as propTypes from 'prop-types';
|
|
4
3
|
import classNames from '../../utils/classnames';
|
|
5
4
|
import Swipe from 'react-easy-swipe';
|
|
5
|
+
import {useDebouncedCallback, useEventListener, useResizeObserver} from '@react-hookz/web'
|
|
6
6
|
|
|
7
7
|
import './index.css';
|
|
8
|
+
import { CommonPropsType } from '../../types';
|
|
9
|
+
|
|
10
|
+
export interface PropsType extends CommonPropsType {
|
|
11
|
+
/**
|
|
12
|
+
* 是否启用指示点
|
|
13
|
+
*/
|
|
14
|
+
indicatorDots: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 是否自动切换
|
|
17
|
+
*/
|
|
18
|
+
autoplay: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 当前索引值
|
|
21
|
+
*/
|
|
22
|
+
current: number;
|
|
23
|
+
interval: number;
|
|
24
|
+
duration: number;
|
|
25
|
+
circular: boolean;
|
|
26
|
+
vertical: boolean;
|
|
27
|
+
indicatorColor: string;
|
|
28
|
+
indicatorActiveColor: string;
|
|
29
|
+
}
|
|
8
30
|
|
|
9
31
|
export default function Swiper({
|
|
10
32
|
children,
|
|
11
33
|
className,
|
|
12
34
|
style = {},
|
|
13
|
-
autoplay,
|
|
14
|
-
circular,
|
|
15
|
-
vertical,
|
|
35
|
+
autoplay = true,
|
|
36
|
+
circular = true,
|
|
37
|
+
vertical = false,
|
|
16
38
|
indicatorDots,
|
|
17
|
-
indicatorColor,
|
|
18
|
-
indicatorActiveColor,
|
|
39
|
+
indicatorColor = 'rgba(200, 200, 200, 0.9)',
|
|
40
|
+
indicatorActiveColor = 'rgba(0, 0, 0, 0.9)',
|
|
19
41
|
duration = 500,
|
|
20
42
|
interval = 5000,
|
|
21
43
|
current = 0,
|
|
22
44
|
events = {},
|
|
23
45
|
id,
|
|
24
|
-
}) {
|
|
46
|
+
}: PropsType) {
|
|
25
47
|
const itemCount = React.Children.count(children);
|
|
26
48
|
current = Math.max(0, Math.min(itemCount - 1, current));
|
|
27
49
|
|
|
@@ -55,23 +77,11 @@ export default function Swiper({
|
|
|
55
77
|
};
|
|
56
78
|
}, [currentIndex, vertical]);
|
|
57
79
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
node.children[0] &&
|
|
63
|
-
node.children[0].getBoundingClientRect() &&
|
|
64
|
-
node.children[0].getBoundingClientRect().height;
|
|
80
|
+
const outerWrapRef = useRef<HTMLDivElement>();
|
|
81
|
+
useEventListener(outerWrapRef, 'load', (e) => {
|
|
82
|
+
setHeight(e.target.clientHeight);
|
|
83
|
+
});
|
|
65
84
|
|
|
66
|
-
if (h && height) {
|
|
67
|
-
setHeight(Math.min(h, height));
|
|
68
|
-
} else {
|
|
69
|
-
setHeight(Math.max(h, height));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
[height]
|
|
74
|
-
);
|
|
75
85
|
|
|
76
86
|
const itemsClone = React.Children.map(children, (x, i) => {
|
|
77
87
|
return (
|
|
@@ -148,9 +158,7 @@ export default function Swiper({
|
|
|
148
158
|
vertical: vertical,
|
|
149
159
|
})}
|
|
150
160
|
style={{ height: height ? height : 'auto', ...style }}
|
|
151
|
-
|
|
152
|
-
cb(e.target.closest('.g-swiper-item'));
|
|
153
|
-
}}
|
|
161
|
+
ref={outerWrapRef}
|
|
154
162
|
id={id}
|
|
155
163
|
>
|
|
156
164
|
{itemCount > 0 ? (
|
|
@@ -173,17 +181,7 @@ export default function Swiper({
|
|
|
173
181
|
>
|
|
174
182
|
{itemsClone[itemCount - 1]}
|
|
175
183
|
{React.Children.map(children, (x, i) => {
|
|
176
|
-
return
|
|
177
|
-
<div
|
|
178
|
-
className={classNames('g-swiper-item', {
|
|
179
|
-
current: i === currentIndex,
|
|
180
|
-
})}
|
|
181
|
-
ref={cb}
|
|
182
|
-
data-index={i}
|
|
183
|
-
>
|
|
184
|
-
{x}
|
|
185
|
-
</div>
|
|
186
|
-
);
|
|
184
|
+
return <SwiperItem setHeight={setHeight} currentIndex={currentIndex} index={i}>{x}</SwiperItem>;
|
|
187
185
|
})}
|
|
188
186
|
{itemsClone[0]}
|
|
189
187
|
</Swipe>
|
|
@@ -234,40 +232,35 @@ export default function Swiper({
|
|
|
234
232
|
);
|
|
235
233
|
}
|
|
236
234
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
};
|
|
235
|
+
const SwiperItem: React.FC<{
|
|
236
|
+
setHeight: React.Dispatch<React.SetStateAction<number>>,
|
|
237
|
+
currentIndex: number,
|
|
238
|
+
index: number,
|
|
239
|
+
children?: React.ReactNode
|
|
240
|
+
}> = ({setHeight, children, currentIndex, index}) => {
|
|
241
|
+
const firstChildRef = useRef<HTMLDivElement>(null);
|
|
242
|
+
const syncHeight = useDebouncedCallback((e) => {
|
|
243
|
+
setHeight(e.contentRect.height);
|
|
244
|
+
}, [setHeight], 500, 2000) // 必须debounce延迟,让resize完成后再设置高度
|
|
248
245
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
style: propTypes.object,
|
|
271
|
-
events: propTypes.objectOf(propTypes.func),
|
|
272
|
-
id: propTypes.string,
|
|
273
|
-
};
|
|
246
|
+
// 因为有loading 所以得用resizeobserver
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
useResizeObserver(firstChildRef, (e) => {
|
|
249
|
+
if(currentIndex === index) {
|
|
250
|
+
syncHeight(e)
|
|
251
|
+
}
|
|
252
|
+
})
|
|
253
|
+
const wrapRef = useRef<HTMLDivElement>();
|
|
254
|
+
return (
|
|
255
|
+
<div
|
|
256
|
+
className={classNames('g-swiper-item', {
|
|
257
|
+
current: index === currentIndex,
|
|
258
|
+
})}
|
|
259
|
+
data-index={index}
|
|
260
|
+
>
|
|
261
|
+
<div ref={firstChildRef}>
|
|
262
|
+
{children}
|
|
263
|
+
</div>
|
|
264
|
+
</div>
|
|
265
|
+
);
|
|
266
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import loadable from '@loadable/component';
|
|
3
|
+
import { CommonPropsType } from '../../types';
|
|
4
|
+
import { usePlatform } from '../../utils/platform';
|
|
5
|
+
import { fallback } from '../../utils/loading-fallback';
|
|
6
|
+
import TabsH5 from './tabs.h5';
|
|
7
|
+
import TabsPc from './tabs.pc';
|
|
8
|
+
|
|
9
|
+
// const TabsH5 = loadable(() => import('./tabs.h5'), { fallback });
|
|
10
|
+
// const TabsPc = loadable(() => import('./tabs.pc'), { fallback });
|
|
11
|
+
|
|
12
|
+
export interface PropsType extends CommonPropsType {
|
|
13
|
+
tabs: {
|
|
14
|
+
title: string;
|
|
15
|
+
|
|
16
|
+
// @deprecated
|
|
17
|
+
name?: string;
|
|
18
|
+
}[];
|
|
19
|
+
selectedIndex: number
|
|
20
|
+
[key: string]: React.ReactNode
|
|
21
|
+
// [panel: `panel${number}`]: React.ReactNode; // require typescript@4.4
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function Tabs(props: PropsType) {
|
|
25
|
+
const platform = usePlatform();
|
|
26
|
+
if (props?.showType === 'pc') {
|
|
27
|
+
return <TabsPc {...props} />;
|
|
28
|
+
}
|
|
29
|
+
if (props?.showType === 'h5') {
|
|
30
|
+
return <TabsH5 {...props} />;
|
|
31
|
+
}
|
|
32
|
+
return platform === 'h5' ? <TabsH5 {...props} /> : <TabsPc {...props} />;
|
|
33
|
+
}
|