@cloudbase/weda-ui 0.2.11 → 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.
Files changed (108) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/package.json +61 -40
  3. package/src/.DS_Store +0 -0
  4. package/src/configs/.DS_Store +0 -0
  5. package/src/configs/components/button.json +7 -3
  6. package/src/configs/components/form/richText.json +1 -1
  7. package/src/configs/components/form/uploader.json +29 -1
  8. package/src/configs/components/form/uploaderFile.json +158 -0
  9. package/src/configs/components/image.json +12 -3
  10. package/src/configs/components/link.json +3 -3
  11. package/src/configs/components/richtextview.json +2 -2
  12. package/src/configs/components/scrollVeiw.json +5 -5
  13. package/src/configs/components/swiper.json +6 -6
  14. package/src/configs/components/tabs.json +3 -3
  15. package/src/configs/components/text.json +39 -4
  16. package/src/configs/index.js +5 -3
  17. package/src/mp/.gitignore +10 -0
  18. package/src/mp/components/button/index.js +1 -0
  19. package/src/mp/components/button/index.wxss +8 -0
  20. package/src/mp/components/form/select/index.js +18 -0
  21. package/src/mp/components/form/uploader/index.js +26 -29
  22. package/src/mp/components/form/uploaderFile/index.js +247 -0
  23. package/src/mp/components/form/uploaderFile/index.json +9 -0
  24. package/src/mp/components/form/uploaderFile/index.wxml +46 -0
  25. package/src/mp/components/form/uploaderFile/index.wxss +104 -0
  26. package/src/mp/components/text/index.js +33 -0
  27. package/src/mp/components/text/index.wxml +1 -1
  28. package/src/mp/components/text/index.wxss +18 -0
  29. package/src/mp/index.json +1 -0
  30. package/src/mp/utils/platform.js +20 -0
  31. package/src/mp/utils/tcb.js +11 -0
  32. package/src/web/.DS_Store +0 -0
  33. package/src/web/actions/showModal/{index.jsx → index.tsx} +53 -3
  34. package/src/web/components/auth/index.js +2 -2
  35. package/src/web/components/button/index.css +9 -0
  36. package/src/web/components/button/{index.jsx → index.tsx} +27 -41
  37. package/src/web/components/container/{index.jsx → index.tsx} +6 -10
  38. package/src/web/components/drawer/index.tsx +57 -0
  39. package/src/web/components/form/checkbox/{index.jsx → index.tsx} +24 -48
  40. package/src/web/components/form/enumSelect/{NormalSelect.jsx → NormalSelect.tsx} +2 -9
  41. package/src/web/components/form/form/index.tsx +48 -0
  42. package/src/web/components/form/formcell/{index.jsx → index.tsx} +6 -13
  43. package/src/web/components/form/input/index.css +4 -0
  44. package/src/web/components/form/input/{index.jsx → index.tsx} +33 -67
  45. package/src/web/components/form/radio/{index.jsx → index.tsx} +19 -42
  46. package/src/web/components/form/{renderDecorator.jsx → renderDecorator.tsx} +1 -3
  47. package/src/web/components/form/select/{h5.jsx → h5.tsx} +18 -62
  48. package/src/web/components/form/select/{index.jsx → index.tsx} +51 -94
  49. package/src/web/components/form/select/region/{cities.js → cities.ts} +1 -1
  50. package/src/web/components/form/select/region/{index.js → index.ts} +3 -3
  51. package/src/web/components/form/select/region/{provinces.js → provinces.ts} +1 -1
  52. package/src/web/components/form/select/region/{regions.js → regions.ts} +1 -1
  53. package/src/web/components/form/select/time.jsx +2 -2
  54. package/src/web/components/form/switch/{index.jsx → index.tsx} +30 -47
  55. package/src/web/components/form/textarea/{index.jsx → index.tsx} +22 -55
  56. package/src/web/components/form/tips/{index.jsx → index.tsx} +8 -22
  57. package/src/web/components/form/types.d.ts +12 -0
  58. package/src/web/components/form/uploader/{index.jsx → index.tsx} +16 -14
  59. package/src/web/components/form/uploader/{uploader.h5.jsx → uploader.h5.tsx} +67 -57
  60. package/src/web/components/form/uploader/{uploader.pc.jsx → uploader.pc.tsx} +26 -43
  61. package/src/web/components/form/uploaderFile/fail.svg +12 -0
  62. package/src/web/components/form/uploaderFile/index.css +423 -0
  63. package/src/web/components/form/uploaderFile/index.jsx +30 -0
  64. package/src/web/components/form/uploaderFile/pending.svg +18 -0
  65. package/src/web/components/form/uploaderFile/success.svg +12 -0
  66. package/src/web/components/form/uploaderFile/uploadFile.h5.jsx +562 -0
  67. package/src/web/components/form/uploaderFile/uploadFile.pc.jsx +487 -0
  68. package/src/web/components/image/{image.jsx → image.tsx} +8 -21
  69. package/src/web/components/image/{index.jsx → index.tsx} +22 -37
  70. package/src/web/components/index.js +35 -1
  71. package/src/web/components/link/{index.jsx → index.tsx} +19 -36
  72. package/src/web/components/modal/{index.jsx → index.tsx} +22 -9
  73. package/src/web/components/picker/{datePicker.jsx → datePicker.tsx} +11 -12
  74. package/src/web/components/picker/{picker.jsx → picker.tsx} +7 -10
  75. package/src/web/components/picker/{timePicker.jsx → timePicker.tsx} +8 -16
  76. package/src/web/components/richText/{const.js → const.ts} +0 -0
  77. package/src/web/components/richText/index.jsx +5 -2
  78. package/src/web/components/richTextView/index.tsx +67 -0
  79. package/src/web/components/scrollView/{index.jsx → index.tsx} +18 -33
  80. package/src/web/components/slot/{index.jsx → index.tsx} +8 -9
  81. package/src/web/components/swiper/index.css +1 -1
  82. package/src/web/components/swiper/{index.jsx → index.tsx} +66 -73
  83. package/src/web/components/tabs/index.tsx +33 -0
  84. package/src/web/components/tabs/{tabs.h5.jsx → tabs.h5.tsx} +4 -33
  85. package/src/web/components/tabs/{tabs.pc.jsx → tabs.pc.tsx} +5 -39
  86. package/src/web/components/text/index.css +18 -0
  87. package/src/web/components/text/index.tsx +69 -0
  88. package/src/web/components/uploaderFileView/index.css +11 -0
  89. package/src/web/components/uploaderFileView/index.jsx +75 -0
  90. package/src/web/components/uploaderView/{index.jsx → index.tsx} +12 -15
  91. package/src/web/types.d.ts +20 -0
  92. package/src/web/utils/constant.js +2 -0
  93. package/src/web/utils/loading-fallback.tsx +2 -0
  94. package/src/web/utils/platform.js +77 -6
  95. package/src/web/utils/useSetState.ts +14 -0
  96. package/src/web/utils/useSyncValue.ts +17 -0
  97. package/src/web/wedatheme/.git +1 -0
  98. package/src/web/wedatheme/.gitignore +5 -0
  99. package/src/web/wedatheme/.npmrc +1 -0
  100. package/src/web/wedatheme/package-lock.json +14335 -0
  101. package/src/configs/components/button.svg +0 -18
  102. package/src/web/components/drawer/index.jsx +0 -64
  103. package/src/web/components/form/form/index.jsx +0 -76
  104. package/src/web/components/link/test/__snapshots__/storybook.test.js.snap +0 -754
  105. package/src/web/components/richTextView/index.jsx +0 -89
  106. package/src/web/components/tabs/index.jsx +0 -10
  107. package/src/web/components/text/index.jsx +0 -71
  108. 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
- import * as PropTypes from 'prop-types';
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 default function WeDaModal(_props) {
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,
@@ -16,6 +27,7 @@ export default function WeDaModal(_props) {
16
27
  } = _props;
17
28
 
18
29
  return (
30
+ <ConfigProvider classPrefix="wedatea2td">
19
31
  <Modal
20
32
  className={classNames('weda-ui', 'lcap-modal', 'container', className)}
21
33
  visible={visible}
@@ -23,23 +35,24 @@ export default function WeDaModal(_props) {
23
35
  emit('close', {});
24
36
  }}
25
37
  {...props}
26
- >
38
+ >
27
39
  <Modal.Body>{content ? content : customContent}</Modal.Body>
28
40
  <Modal.Footer>
29
41
  {isDefaultButton ? (
30
42
  <Button
31
- type="primary"
32
- onClick={() => {
33
- emit('confirm', {});
34
- // events.confirm();
35
- }}
43
+ type="primary"
44
+ onClick={() => {
45
+ emit('confirm', {});
46
+ // events.confirm();
47
+ }}
36
48
  >
37
49
  确定
38
50
  </Button>
39
51
  ) : (
40
52
  customButton
41
- )}
53
+ )}
42
54
  </Modal.Footer>
43
55
  </Modal>
56
+ </ConfigProvider>
44
57
  );
45
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 default function DatePicker(props) {
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 default function TimePicker(props) {
8
- const { title, defaultValue, children, className } = props;
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
+ }
@@ -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 'react-use';
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
- import FormCell from '../form/formcell';
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 * as PropTypes from 'prop-types';
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
- scrollY,
9
- scrollX,
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 default function Slot({ compositeParent, name, className }) {
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
+ }
@@ -35,7 +35,7 @@
35
35
  height: 100%;
36
36
  }
37
37
 
38
- .g-swiper-item > * {
38
+ .g-swiper-item > div > * {
39
39
  width: 100%;
40
40
  height: auto;
41
41
  max-width: 100%;
@@ -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 cb = useCallback(
59
- (node) => {
60
- if (node) {
61
- const h =
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
- onLoad={(e) => {
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
- Swiper.defaultProps = {
238
- current: 0,
239
- duration: 500,
240
- indicatorDots: true,
241
- autoplay: true,
242
- circular: true,
243
- interval: 5000,
244
- vertical: false,
245
- indicatorColor: 'rgba(200, 200, 200, 0.9)',
246
- indicatorActiveColor: 'rgba(0, 0, 0, 0.9)',
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
- Swiper.propTypes = {
250
- /**
251
- * 是否启用指示点
252
- */
253
- indicatorDots: propTypes.bool,
254
- /**
255
- * 是否自动切换
256
- */
257
- autoplay: propTypes.bool,
258
- /**
259
- * 当前索引值
260
- */
261
- current: propTypes.number,
262
- interval: propTypes.number,
263
- duration: propTypes.number,
264
- circular: propTypes.bool,
265
- vertical: propTypes.bool,
266
- indicatorColor: propTypes.string,
267
- indicatorActiveColor: propTypes.string,
268
- children: propTypes.any,
269
- className: propTypes.string,
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
+ }