pixuireactcomponents 1.2.2 → 1.2.31
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/index.d.ts +15 -0
- package/index.js +16 -20
- package/package.json +9 -9
- package/tools/EventDispatcherJs.d.ts +10 -0
- package/tools/EventDispatcherJs.js +71 -0
- package/tools/Logger.d.ts +6 -0
- package/tools/Logger.js +138 -0
- package/ui/components/button/Button.d.ts +5 -0
- package/ui/components/button/Button.js +37 -0
- package/ui/components/carousel/Carousel.d.ts +5 -0
- package/ui/components/carousel/Carousel.js +219 -0
- package/ui/components/dropdown/Dropdown.d.ts +30 -0
- package/ui/components/dropdown/Dropdown.js +92 -0
- package/ui/components/dropdown/DropdownOptionUI.d.ts +11 -0
- package/ui/components/dropdown/DropdownOptionUI.js +28 -0
- package/ui/components/dropdown/DropdownSpreadMainUI.d.ts +9 -0
- package/ui/components/dropdown/DropdownSpreadMainUI.js +27 -0
- package/ui/components/dropdown/DropdownUnspreadMainUI.d.ts +9 -0
- package/ui/components/dropdown/DropdownUnspreadMainUI.js +27 -0
- package/ui/components/gradient/GradientText.d.ts +63 -0
- package/ui/components/gradient/{GradientText.tsx → GradientText.js} +174 -183
- package/ui/components/outlinetext/OutlineText.d.ts +94 -0
- package/ui/components/outlinetext/OutlineText.js +168 -0
- package/ui/components/progress/Progress.d.ts +34 -0
- package/ui/components/progress/Progress.js +142 -0
- package/ui/components/slapface/Slapface.d.ts +12 -0
- package/ui/components/slapface/Slapface.js +235 -0
- package/ui/components/slider/Slider.d.ts +57 -0
- package/ui/components/slider/Slider.js +289 -0
- package/ui/components/tab/Tab.d.ts +6 -0
- package/ui/components/tab/Tab.js +27 -0
- package/ui/components/tab/Tabs.d.ts +12 -0
- package/ui/components/tab/Tabs.js +54 -0
- package/cmdAfterTsBuild.js +0 -8
- package/tools/EventDispatcherJs.tsx +0 -74
- package/tools/Logger.tsx +0 -161
- package/tools/img/logger.png +0 -0
- package/tsconfig.json +0 -45
- package/ui/components/bulletscreen/BulletItemAnimation.tsx +0 -117
- package/ui/components/bulletscreen/BulletScreenAnimation.tsx +0 -278
- package/ui/components/bulletscreen/bullet.less +0 -17
- package/ui/components/button/Button.tsx +0 -18
- package/ui/components/carousel/Carousel.tsx +0 -279
- package/ui/components/checkBox/CheckBox.tsx +0 -40
- package/ui/components/dropdown/Dropdown.tsx +0 -126
- package/ui/components/dropdown/DropdownOptionUI.tsx +0 -14
- package/ui/components/dropdown/DropdownSpreadMainUI.tsx +0 -11
- package/ui/components/dropdown/DropdownUnspreadMainUI.tsx +0 -11
- package/ui/components/outlinetext/OutlineText.tsx +0 -184
- package/ui/components/progress/Progress.tsx +0 -174
- package/ui/components/slapface/Slapface.tsx +0 -284
- package/ui/components/slider/Slider.tsx +0 -366
- package/ui/components/tab/Tab.tsx +0 -12
- package/ui/components/tab/Tabs.tsx +0 -56
- package/ui/components/togglegroup/ToggleGroup.tsx +0 -105
- package/ui/components/videoplayer/VideoPlayer.tsx +0 -200
- package/ui/components/waterfallcomponent/WaterfallComponent.jsx +0 -687
- package/ui/components/waterfallcomponent/less/WaterfallComponent.less +0 -13
- package/ui/sample/Images.tsx +0 -60
- package/ui/sample/OutlineText/OutlineDemo.tsx +0 -61
- package/ui/sample/Slapface/SlapfaceDemo.tsx +0 -30
- package/ui/sample/asset/btn_close.png +0 -0
- package/ui/sample/asset/changtai_button.jpg +0 -0
- package/ui/sample/asset/checkbox0.png +0 -0
- package/ui/sample/asset/checkbox1.png +0 -0
- package/ui/sample/asset/data_arrow_down.png +0 -0
- package/ui/sample/asset/data_arrow_up.png +0 -0
- package/ui/sample/asset/dot.png +0 -0
- package/ui/sample/asset/inner.png +0 -0
- package/ui/sample/asset/item_reddot.png +0 -0
- package/ui/sample/asset/loading.png +0 -0
- package/ui/sample/asset/money_dropdown.png +0 -0
- package/ui/sample/asset/money_dropdownall.png +0 -0
- package/ui/sample/asset/outer.png +0 -0
- package/ui/sample/asset/slapface_samplepic1.png +0 -0
- package/ui/sample/asset/slapface_samplepic2.png +0 -0
- package/ui/sample/asset/slapface_samplepic3.png +0 -0
- package/ui/sample/asset/slapface_samplepic4.png +0 -0
- package/ui/sample/asset/slapface_samplepic5.png +0 -0
- package/ui/sample/asset/slapface_samplepic6.png +0 -0
- package/ui/sample/asset/tab_choosed.png +0 -0
- package/ui/sample/asset/tabs_bg.png +0 -0
- package/ui/sample/asset/video_pause.png +0 -0
- package/ui/sample/asset/video_play.png +0 -0
- package/ui/sample/asset/video_reload.png +0 -0
- package/ui/sample/asset/xuanfu_button.jpg +0 -0
- package/ui/sample/asset/yaxia_button.jpg +0 -0
- package/ui/sample/bulletscreen/BulletDemo.tsx +0 -84
- package/ui/sample/button/ButtonDemo.tsx +0 -19
- package/ui/sample/carousel/carouselDemo.tsx +0 -52
- package/ui/sample/checkBox/checkBoxDemo.tsx +0 -7
- package/ui/sample/dropdown/DropdownDemo.tsx +0 -65
- package/ui/sample/dropdown/MoneyDropdownOption.tsx +0 -50
- package/ui/sample/dropdown/MoneyDropdownSpreadMain.tsx +0 -42
- package/ui/sample/dropdown/MoneyDropdownUnspreadMain.tsx +0 -44
- package/ui/sample/gradient/GradientDemo.tsx +0 -51
- package/ui/sample/less/video.less +0 -144
- package/ui/sample/progress/ProgressDemo.tsx +0 -74
- package/ui/sample/slider/SliderDemo.tsx +0 -116
- package/ui/sample/tab/TabDemo.tsx +0 -67
- package/ui/sample/tab/TopTab.tsx +0 -74
- package/ui/sample/togglegroup/ToggleGroupDemo.tsx +0 -35
- package/ui/sample/videoplayer/VideoPlayerDemo.tsx +0 -57
- package/ui/sample/waterfallcomponent/WaterfallComponentDemo.jsx +0 -137
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import { Component, CSSProperties, h } from 'preact';
|
|
2
|
-
import React, { useState, useEffect, useRef, useMemo, useImperativeHandle } from '../../../../../lib/preact/hooks/src';
|
|
3
|
-
// import React, { useState, useEffect, useRef, useMemo } from 'preact/hooks';
|
|
4
|
-
|
|
5
|
-
const indicatorStyle: CSSProperties = { width: '20px', height: '8px', margin: '5px', backgroundColor: '#cecfda', borderRadius: '3px' };
|
|
6
|
-
const indicatorSelectedStyle = { ...indicatorStyle, backgroundColor: '#fafbfc' };
|
|
7
|
-
|
|
8
|
-
export function Carousel(props) {
|
|
9
|
-
const {
|
|
10
|
-
children = [],
|
|
11
|
-
defaultIndex = 1,
|
|
12
|
-
compWidth = 100,
|
|
13
|
-
compHeight = 100,
|
|
14
|
-
autoplay = true,
|
|
15
|
-
switchDuration = 3000,
|
|
16
|
-
loop = true,
|
|
17
|
-
isVertical = false,
|
|
18
|
-
touchable = true,
|
|
19
|
-
onSlideChange = null,
|
|
20
|
-
onclickEvent = null,
|
|
21
|
-
}: {
|
|
22
|
-
children: HTMLElement[];
|
|
23
|
-
defaultIndex: number;
|
|
24
|
-
compWidth: number;
|
|
25
|
-
compHeight: number;
|
|
26
|
-
autoplay: boolean;
|
|
27
|
-
switchDuration: number;
|
|
28
|
-
loop: boolean;
|
|
29
|
-
isVertical: boolean;
|
|
30
|
-
touchable: boolean;
|
|
31
|
-
onSlideChange: Function | null;
|
|
32
|
-
onclickEvent: Function | null;
|
|
33
|
-
} = props;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
useImperativeHandle(props.cRef, () => ({
|
|
37
|
-
handleNext: handleNext,
|
|
38
|
-
handlePrev: handlePrev
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
const duration = switchDuration < 1000 ? 1000 : switchDuration;
|
|
42
|
-
const [showIndex, setShowIndex] = useState(defaultIndex);
|
|
43
|
-
//轮播元素正在滚动
|
|
44
|
-
let isMoving = useRef(false);
|
|
45
|
-
//鼠标手势信息
|
|
46
|
-
let isMouseDown = useRef(false);
|
|
47
|
-
let mouseDownX = useRef(0);
|
|
48
|
-
let mouseDownY = useRef(0);
|
|
49
|
-
|
|
50
|
-
const handleNextRef = useRef(() => { });
|
|
51
|
-
const nextInterval = useRef();
|
|
52
|
-
const [showTransition, setShowTransition] = useState(true);
|
|
53
|
-
const [gesteroffset, setGesteroffset] = useState([0, 0]);
|
|
54
|
-
|
|
55
|
-
const [logTex, setLogTex] = useState('');
|
|
56
|
-
|
|
57
|
-
const offset = useMemo(() => -(isVertical ? compHeight : compWidth) * showIndex, [showIndex]);
|
|
58
|
-
|
|
59
|
-
const itemBoxStyle = { minWidth: compWidth + 'px', minHeight: compHeight + 'px', maxWidth: compWidth + 'px', maxHeight: compHeight + 'px', };
|
|
60
|
-
|
|
61
|
-
const carouselItems = useMemo(() => {
|
|
62
|
-
const firstChild = children[0];
|
|
63
|
-
const lastChild = children[children.length - 1];
|
|
64
|
-
return [lastChild, ...children, firstChild];
|
|
65
|
-
}, [children]);
|
|
66
|
-
|
|
67
|
-
const isLastCarouseItem = () => showIndex === carouselItems.length - 1;
|
|
68
|
-
const isFirstCarouseLastItem = () => showIndex === 0;
|
|
69
|
-
|
|
70
|
-
useEffect(()=>{
|
|
71
|
-
setNextInterval();
|
|
72
|
-
},[autoplay])
|
|
73
|
-
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
//每次跳转前判断打开动画,否则动画关闭以后不会调用handleTransitionEnd
|
|
76
|
-
if (!isLastCarouseItem() && !isFirstCarouseLastItem()) {
|
|
77
|
-
setShowTransition(true);
|
|
78
|
-
}
|
|
79
|
-
}, [showIndex]);
|
|
80
|
-
|
|
81
|
-
//更新handleNext的环境
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
handleNextRef.current = handleNext;
|
|
84
|
-
});
|
|
85
|
-
const setNextInterval = () => {
|
|
86
|
-
clearInterval(nextInterval.current as NodeJS.Timeout);
|
|
87
|
-
if (autoplay) {
|
|
88
|
-
nextInterval.current = setInterval(() => {
|
|
89
|
-
handleNextRef.current();
|
|
90
|
-
}, duration);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
setNextInterval();
|
|
95
|
-
}, []);
|
|
96
|
-
|
|
97
|
-
const handlePrev = () => {
|
|
98
|
-
if (isMoving.current) return;
|
|
99
|
-
isMoving.current = true;
|
|
100
|
-
|
|
101
|
-
if (showIndex === 0) {
|
|
102
|
-
setShowIndex(carouselItems.length - 1);
|
|
103
|
-
} else {
|
|
104
|
-
setShowIndex(showIndex - 1);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const handleNext = () => {
|
|
109
|
-
// console.log('nex', isMoving.current, showIndex, isVertical ? `translate(0px, ${offset}px)` : `translate(${offset}px, 0px)`)
|
|
110
|
-
if (!loop && showIndex == carouselItems.length - 2) return;
|
|
111
|
-
if (isMoving.current) return;
|
|
112
|
-
isMoving.current = true;
|
|
113
|
-
setShowIndex(showIndex + 1);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const handleTransitionEnd = () => {
|
|
117
|
-
|
|
118
|
-
//判断前后补位元素准备跳转
|
|
119
|
-
//在动画结束以后关掉,否则用鼠标拖动的时候不能补充剩下的offset
|
|
120
|
-
if (isLastCarouseItem() || isFirstCarouseLastItem()) {
|
|
121
|
-
setShowTransition(false);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// console.log('showIndex' + showIndex)
|
|
125
|
-
isMoving.current = false;
|
|
126
|
-
//触发onSlideChange
|
|
127
|
-
if (!isLastCarouseItem() && !isFirstCarouseLastItem() && onSlideChange) onSlideChange(showIndex - 1);
|
|
128
|
-
|
|
129
|
-
// 处理首尾特殊case
|
|
130
|
-
if (isLastCarouseItem()) {
|
|
131
|
-
setShowIndex(1);
|
|
132
|
-
}
|
|
133
|
-
if (isFirstCarouseLastItem()) {
|
|
134
|
-
setShowIndex(carouselItems.length - 2);
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const gestureUp = () => {
|
|
139
|
-
// setLogTex(logTex + 'UP ');
|
|
140
|
-
if (!touchable) return;
|
|
141
|
-
if (isMoving.current) return;
|
|
142
|
-
//打开动画
|
|
143
|
-
setShowTransition(true);
|
|
144
|
-
isMouseDown.current = false;
|
|
145
|
-
|
|
146
|
-
//拖动大于1/3的时候跳转
|
|
147
|
-
if (isVertical) {
|
|
148
|
-
if (gesteroffset[1] > compHeight / 3) {
|
|
149
|
-
handlePrev();
|
|
150
|
-
} else if (gesteroffset[1] < -compHeight / 3) {
|
|
151
|
-
handleNext();
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
if (gesteroffset[0] > compWidth / 3) {
|
|
155
|
-
handlePrev();
|
|
156
|
-
} else if (gesteroffset[0] < -compWidth / 3) {
|
|
157
|
-
handleNext();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
setGesteroffset([0, 0]);
|
|
161
|
-
setNextInterval();
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const gestureMove = (e) => {
|
|
165
|
-
if (!touchable) return;
|
|
166
|
-
if (!isMouseDown.current) return;
|
|
167
|
-
|
|
168
|
-
let l = e.target.getBoundingClientRect().left;
|
|
169
|
-
let r = e.target.getBoundingClientRect().right;
|
|
170
|
-
let t = e.target.getBoundingClientRect().top;
|
|
171
|
-
let b = e.target.getBoundingClientRect().bottom;
|
|
172
|
-
let x = e.clientX;
|
|
173
|
-
let y = e.clientY;
|
|
174
|
-
setGesteroffset([e.clientX - mouseDownX.current, e.clientY - mouseDownY.current]);
|
|
175
|
-
//计算滑动超出元素范围
|
|
176
|
-
if (x < l || x > r || y > b || y < t) {
|
|
177
|
-
gestureUp();
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
const gestureDown = (e) => {
|
|
182
|
-
if (!touchable) return;
|
|
183
|
-
if (isMoving.current) return;
|
|
184
|
-
if (nextInterval.current) {
|
|
185
|
-
clearInterval(nextInterval.current as NodeJS.Timeout);
|
|
186
|
-
nextInterval.current = null;
|
|
187
|
-
}
|
|
188
|
-
mouseDownX.current = e.clientX;
|
|
189
|
-
mouseDownY.current = e.clientY;
|
|
190
|
-
isMouseDown.current = true;
|
|
191
|
-
//拖动时关闭动画
|
|
192
|
-
setShowTransition(false);
|
|
193
|
-
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
const gestureClick = (props) => {
|
|
197
|
-
if (isMoving.current) return;
|
|
198
|
-
if (onclickEvent) {
|
|
199
|
-
onclickEvent(showIndex - 1);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
return (
|
|
204
|
-
<div style={{ flexDirection: 'column'}}>
|
|
205
|
-
|
|
206
|
-
<div
|
|
207
|
-
style={{
|
|
208
|
-
position: 'relative',
|
|
209
|
-
...itemBoxStyle,
|
|
210
|
-
overflow: 'hidden',
|
|
211
|
-
flexShrink: 0,
|
|
212
|
-
}}
|
|
213
|
-
>
|
|
214
|
-
<div
|
|
215
|
-
style={{
|
|
216
|
-
display: 'flex',
|
|
217
|
-
width: isVertical ? compWidth : compWidth * carouselItems.length + 'px',
|
|
218
|
-
height: isVertical ? compHeight * carouselItems.length : compHeight + 'px',
|
|
219
|
-
transition: `transform ${showTransition ? '0.5s' : '0s'} ease 0s`,
|
|
220
|
-
transform: isVertical ? `translate(0px, ${offset + gesteroffset[1]}px)` : `translate(${offset + gesteroffset[0]}px, 0px)`,
|
|
221
|
-
flexDirection: isVertical ? 'column' : 'row',
|
|
222
|
-
flexShrink: 0,
|
|
223
|
-
}}
|
|
224
|
-
class='wrapper'
|
|
225
|
-
onTransitionEnd={handleTransitionEnd}
|
|
226
|
-
>
|
|
227
|
-
{carouselItems.map((child) => child)}
|
|
228
|
-
</div>
|
|
229
|
-
</div>
|
|
230
|
-
|
|
231
|
-
{/* 手势 */}
|
|
232
|
-
<div draggable={true} style={{
|
|
233
|
-
...itemBoxStyle, position: 'absolute',
|
|
234
|
-
// backgroundColor: 'rgba(255,0,0,0.5)',
|
|
235
|
-
}}
|
|
236
|
-
onClick={() => { gestureClick(props); }}
|
|
237
|
-
class={'GestureComp'}
|
|
238
|
-
// onMouseUp={() => { gestureUp(); }}
|
|
239
|
-
// onMouseMove={(e) => { gestureMove(e); }}
|
|
240
|
-
// onMouseDown={gestureDown}
|
|
241
|
-
onDragStart={gestureDown}
|
|
242
|
-
// onMouseOut={() => { gestureUp(); }}
|
|
243
|
-
// onTouchEnd={() => { gestureUp(); }}
|
|
244
|
-
onDrag={(e) => {
|
|
245
|
-
gestureMove(e);
|
|
246
|
-
// setLogTex(logTex + ((e.target as any).className == 'GestureComp' ? '' : '111'));
|
|
247
|
-
}}
|
|
248
|
-
onDragEnd={() => { gestureUp(); }}
|
|
249
|
-
// onTouchStart={() => { setLogTex(logTex + 'st') }}
|
|
250
|
-
/>
|
|
251
|
-
|
|
252
|
-
{/* 调试信息 */}
|
|
253
|
-
{/* {logTex}
|
|
254
|
-
{gesteroffset[0]}
|
|
255
|
-
{gesteroffset[1]} */}
|
|
256
|
-
|
|
257
|
-
{/* 页码图标 */}
|
|
258
|
-
<div style={{ flexDirection: isVertical ? 'column' : 'row', }}>
|
|
259
|
-
{children.map((v, i) => {
|
|
260
|
-
return <div
|
|
261
|
-
style={(showIndex == i + 1) ? indicatorSelectedStyle : indicatorStyle}
|
|
262
|
-
onClick={() => { setShowIndex(i + 1); }}
|
|
263
|
-
/>;
|
|
264
|
-
})}
|
|
265
|
-
|
|
266
|
-
</div>
|
|
267
|
-
</div >
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
Carousel.Item = (props) => {
|
|
272
|
-
|
|
273
|
-
return <div style={{
|
|
274
|
-
// width: '100%',
|
|
275
|
-
// height: '100%',
|
|
276
|
-
// flexShrink: 0,
|
|
277
|
-
}}
|
|
278
|
-
> {props.children}</div >;
|
|
279
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Component, CSSProperties, h } from 'preact';
|
|
2
|
-
import React, { useState, useEffect, useRef, useMemo, useImperativeHandle } from '../../../../../lib/preact/hooks/src';
|
|
3
|
-
import { Images } from '../../sample/Images';
|
|
4
|
-
// import React, { useState, useEffect, useRef, useMemo } from 'preact/hooks';
|
|
5
|
-
|
|
6
|
-
const rootStyle: CSSProperties = { width: '20px', height: '20px' };
|
|
7
|
-
const boxNormalStyle: CSSProperties = {
|
|
8
|
-
width: '100%',
|
|
9
|
-
height: '100%',
|
|
10
|
-
backgroundImage: `url(${Images.checkbox0})`,
|
|
11
|
-
backgroundSize: '100% 100%',
|
|
12
|
-
};
|
|
13
|
-
const boxCheckedStyle: CSSProperties = {
|
|
14
|
-
width: '100%',
|
|
15
|
-
height: '100%',
|
|
16
|
-
backgroundImage: `url(${Images.checkbox1})`,
|
|
17
|
-
backgroundSize: '100% 100%',
|
|
18
|
-
};
|
|
19
|
-
export function Checkbox(props) {
|
|
20
|
-
const {
|
|
21
|
-
selectedChanged = null,
|
|
22
|
-
defauleSelected = false,
|
|
23
|
-
}: {
|
|
24
|
-
selectedChanged: Function | null;
|
|
25
|
-
defauleSelected: boolean;
|
|
26
|
-
} = props;
|
|
27
|
-
const [selected, setSelected] = useState(defauleSelected);
|
|
28
|
-
const cli = () => {
|
|
29
|
-
if (selectedChanged) {
|
|
30
|
-
selectedChanged(!selected);
|
|
31
|
-
}
|
|
32
|
-
setSelected(!selected);
|
|
33
|
-
};
|
|
34
|
-
return (
|
|
35
|
-
<div style={rootStyle} onClick={cli}>
|
|
36
|
-
{selected ? <div style={boxCheckedStyle} /> : <div style={boxNormalStyle} />}
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
);
|
|
40
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Component, CSSProperties, h } from 'preact';
|
|
2
|
-
import { DropdownOptionUI } from './DropdownOptionUI';
|
|
3
|
-
import { DropdownSpreadMainUI } from './DropdownSpreadMainUI';
|
|
4
|
-
import { DropdownUnspreadMainUI } from './DropdownUnspreadMainUI';
|
|
5
|
-
|
|
6
|
-
export interface DropdownConfig<T> {
|
|
7
|
-
spreadStyle: CSSProperties;
|
|
8
|
-
datas: T[];
|
|
9
|
-
}
|
|
10
|
-
const optionsDivStyle: CSSProperties = {
|
|
11
|
-
marginTop: 3,
|
|
12
|
-
display: 'flex',
|
|
13
|
-
flexDirection: 'column',
|
|
14
|
-
justifyContent: 'flex-start',
|
|
15
|
-
alignItems: 'center',
|
|
16
|
-
height: 'auto',
|
|
17
|
-
overflow: 'scroll',
|
|
18
|
-
overflowStyle: 'none',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export class Dropdown<
|
|
23
|
-
T,
|
|
24
|
-
DDUnspreadMainUI extends DropdownUnspreadMainUI<T>,
|
|
25
|
-
DDSpreadMainUI extends DropdownSpreadMainUI<T>,
|
|
26
|
-
DDOptionUI extends DropdownOptionUI<T>>
|
|
27
|
-
extends Component<
|
|
28
|
-
{
|
|
29
|
-
config: DropdownConfig<T>;
|
|
30
|
-
onChoose: Function;
|
|
31
|
-
defaultIndex: number | null;
|
|
32
|
-
unspreadMainUI: DDUnspreadMainUI;
|
|
33
|
-
spreadMainUI: DDSpreadMainUI;
|
|
34
|
-
optionsUI: DDOptionUI[];
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
selectedIndex: number;
|
|
38
|
-
isSpread: boolean; // dropdown 列表是否展开
|
|
39
|
-
}>{
|
|
40
|
-
|
|
41
|
-
constructor(props) {
|
|
42
|
-
super(props);
|
|
43
|
-
|
|
44
|
-
this.addNetEvents();
|
|
45
|
-
this.addLogicEvents();
|
|
46
|
-
|
|
47
|
-
let initIndex: number = this.props.defaultIndex == null ? 0 : this.props.defaultIndex;
|
|
48
|
-
|
|
49
|
-
this.state = {
|
|
50
|
-
selectedIndex: initIndex,
|
|
51
|
-
isSpread: false
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
componentWillUnmount() {
|
|
56
|
-
this.removeLogicEvents();
|
|
57
|
-
this.removeNetEvents();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
addNetEvents = () => {
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
removeNetEvents = () => {
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
addLogicEvents = () => {
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
removeLogicEvents = () => {
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
openList = () => {
|
|
77
|
-
// console.warn("open dropdown====")
|
|
78
|
-
this.setState({
|
|
79
|
-
isSpread: true
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
closeList = () => {
|
|
84
|
-
// console.warn("close dropdown====")
|
|
85
|
-
this.setState({
|
|
86
|
-
isSpread: false
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
onChoose = (index: number) => {
|
|
91
|
-
this.props.onChoose(index);
|
|
92
|
-
// console.warn('dropdown-=----', index)
|
|
93
|
-
this.setState({
|
|
94
|
-
selectedIndex: index,
|
|
95
|
-
isSpread: false
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
render() {
|
|
100
|
-
if (!this.state.isSpread) {
|
|
101
|
-
this.props.unspreadMainUI.props.info = this.props.config.datas[this.state.selectedIndex];
|
|
102
|
-
this.props.unspreadMainUI.props.openList = this.openList;
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<div>
|
|
106
|
-
{this.props.unspreadMainUI}
|
|
107
|
-
</div>);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.props.spreadMainUI.props.info = this.props.config.datas[this.state.selectedIndex];
|
|
111
|
-
this.props.spreadMainUI.props.closeList = this.closeList;
|
|
112
|
-
|
|
113
|
-
this.props.optionsUI.forEach((v, index) => { v.props.onChoose = () => { this.onChoose(index); }; });
|
|
114
|
-
let _optionsUI = this.props.optionsUI.filter(v => v.props.index != this.state.selectedIndex);
|
|
115
|
-
if (_optionsUI.length > 0) _optionsUI[_optionsUI.length - 1].props['isLast'] = true;
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<div>
|
|
119
|
-
<div style={this.props.config.spreadStyle}>
|
|
120
|
-
{this.props.spreadMainUI}
|
|
121
|
-
<div style={optionsDivStyle}>{_optionsUI}</div>
|
|
122
|
-
</div>
|
|
123
|
-
</div>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Component, JSX } from 'preact';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* dropdown 打开时options列表的单个Item UI
|
|
5
|
-
* 如果要使用滚动条,在创建改该组件时最外层div样式里面需添加flex-shrink : 0
|
|
6
|
-
*/
|
|
7
|
-
export abstract class DropdownOptionUI<T> extends Component<
|
|
8
|
-
{
|
|
9
|
-
info: T;
|
|
10
|
-
onChoose: Function;
|
|
11
|
-
index: number; // 数据下标
|
|
12
|
-
}, any> {
|
|
13
|
-
|
|
14
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Component, CSSProperties, h} from 'preact';
|
|
2
|
-
export enum FontStyle{
|
|
3
|
-
Normal,
|
|
4
|
-
Bold,
|
|
5
|
-
Italic,
|
|
6
|
-
BoldAndItalic
|
|
7
|
-
}
|
|
8
|
-
export enum TextAnchor{
|
|
9
|
-
UpperLeft,
|
|
10
|
-
UpperCenter,
|
|
11
|
-
UpperRight,
|
|
12
|
-
MiddleLeft,
|
|
13
|
-
MiddleCenter,
|
|
14
|
-
MiddleRight,
|
|
15
|
-
LowerLeft,
|
|
16
|
-
LowerCenter,
|
|
17
|
-
LowerRight,
|
|
18
|
-
}
|
|
19
|
-
export enum HorizontalWrapMode{
|
|
20
|
-
Wrap,
|
|
21
|
-
Overflow
|
|
22
|
-
}
|
|
23
|
-
export enum VerticalWrapMode{
|
|
24
|
-
Truncate,
|
|
25
|
-
Overflow
|
|
26
|
-
}
|
|
27
|
-
const defaultStyle: CSSProperties = {
|
|
28
|
-
width : 200,
|
|
29
|
-
height : 200
|
|
30
|
-
};
|
|
31
|
-
export interface OutlineTextProps{
|
|
32
|
-
style?: CSSProperties;
|
|
33
|
-
text?: string;
|
|
34
|
-
font?: string;
|
|
35
|
-
fontStyle?: FontStyle;
|
|
36
|
-
fontSize?: number;
|
|
37
|
-
lineSpacing?: number;
|
|
38
|
-
alignment?: TextAnchor;
|
|
39
|
-
alignByGeometry?: boolean;
|
|
40
|
-
horizontalOverflow?: HorizontalWrapMode;
|
|
41
|
-
verticalOverflow?: VerticalWrapMode;
|
|
42
|
-
color: {
|
|
43
|
-
r: number;
|
|
44
|
-
g: number;
|
|
45
|
-
b: number;
|
|
46
|
-
a: number;
|
|
47
|
-
};
|
|
48
|
-
outlineColor: {
|
|
49
|
-
r: number;
|
|
50
|
-
g: number;
|
|
51
|
-
b: number;
|
|
52
|
-
a: number;
|
|
53
|
-
};
|
|
54
|
-
outlineDistance: {
|
|
55
|
-
x: number;
|
|
56
|
-
y: number;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export class OutlineText extends Component<
|
|
61
|
-
OutlineTextProps,
|
|
62
|
-
OutlineTextProps>{
|
|
63
|
-
text: any;
|
|
64
|
-
outline: any;
|
|
65
|
-
textColor: any;
|
|
66
|
-
effectColor: any;
|
|
67
|
-
constructor(props){
|
|
68
|
-
super(props);
|
|
69
|
-
}
|
|
70
|
-
static defaultProps= {
|
|
71
|
-
style : defaultStyle,
|
|
72
|
-
text : 'NEW TEXT',
|
|
73
|
-
font : 'gamefont',
|
|
74
|
-
fontStyle : FontStyle.Normal,
|
|
75
|
-
fontSize : 14,
|
|
76
|
-
lineSpacing : 1,
|
|
77
|
-
alignment : TextAnchor.UpperLeft,
|
|
78
|
-
alignByGeometry : false,
|
|
79
|
-
horizontalOverflow : HorizontalWrapMode.Wrap,
|
|
80
|
-
verticalOverflow : VerticalWrapMode.Truncate,
|
|
81
|
-
color : {
|
|
82
|
-
r:1,
|
|
83
|
-
g:1,
|
|
84
|
-
b:1,
|
|
85
|
-
a:1
|
|
86
|
-
},
|
|
87
|
-
outlineColor : {
|
|
88
|
-
r:0,
|
|
89
|
-
g:0,
|
|
90
|
-
b:0,
|
|
91
|
-
a:1
|
|
92
|
-
},
|
|
93
|
-
outlineDistance : {
|
|
94
|
-
x : 1,
|
|
95
|
-
y : -1
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
componentDidUpdate () {
|
|
99
|
-
console.log('componentDidUpdate');
|
|
100
|
-
this.updateOutlineText();
|
|
101
|
-
}
|
|
102
|
-
OnLoad = (e) => {
|
|
103
|
-
console.log('!!!!!!!!!!!!!!');
|
|
104
|
-
if (!require) {
|
|
105
|
-
console.error('need puerts env');
|
|
106
|
-
}
|
|
107
|
-
const CS = require('csharp');
|
|
108
|
-
if (!CS) {
|
|
109
|
-
console.error('need puerts env');
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const puerts = require('puerts');
|
|
113
|
-
console.log('?????');
|
|
114
|
-
const windowId = (window as any).external.id;
|
|
115
|
-
|
|
116
|
-
const handle = e.target.attachment.handle;
|
|
117
|
-
const attachment = CS.com.tencent.pandora.CSharpInterface.GetSlotAttachmentByHandle(windowId, handle);
|
|
118
|
-
if (!attachment) {
|
|
119
|
-
console.error(`can't get relected attachment, handle:${handle}`);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
console.log('windowId:' + windowId.toString() + ' handle:' + handle.toString());
|
|
123
|
-
const placeholder = attachment.GetMountingGameObject();
|
|
124
|
-
const text = placeholder.AddComponent(puerts.$typeof(CS.UnityEngine.UI.Text));
|
|
125
|
-
this.text = text;
|
|
126
|
-
const outline = placeholder.AddComponent(puerts.$typeof(CS.UnityEngine.UI.Outline));
|
|
127
|
-
this.outline = outline;
|
|
128
|
-
this.updateOutlineText();
|
|
129
|
-
}
|
|
130
|
-
colorRgb (colorStr) {
|
|
131
|
-
//十六进制颜色值的正则表达式
|
|
132
|
-
let reg = /^#([0-9a-fA-f]{0,}|)$/;
|
|
133
|
-
let matchRes = colorStr.toString().toLowerCase().match(reg);
|
|
134
|
-
let transColor = '';
|
|
135
|
-
if (matchRes.length > 0) transColor = matchRes[matchRes.length - 1];
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-array-constructor
|
|
137
|
-
let colorList = new Array();
|
|
138
|
-
while(transColor != '') {
|
|
139
|
-
let hex = '0x' + transColor.substring(0, 2);
|
|
140
|
-
colorList.push(parseInt(hex, 16));
|
|
141
|
-
transColor = transColor.substring(2, transColor.length);
|
|
142
|
-
}
|
|
143
|
-
let r,g,b,a = 1;
|
|
144
|
-
for(let i = 0; i < colorList.length; i++) {
|
|
145
|
-
if (i == 0 && colorList[i] != null && colorList[i] != undefined){
|
|
146
|
-
r = colorList[i]/255;
|
|
147
|
-
}
|
|
148
|
-
if (i == 1 && colorList[i] != null && colorList[i] != undefined) {
|
|
149
|
-
g = colorList[i]/255;
|
|
150
|
-
}
|
|
151
|
-
if (i == 2 && colorList[i] != null && colorList[i] != undefined) {
|
|
152
|
-
b = colorList[i]/255;
|
|
153
|
-
}
|
|
154
|
-
if (i == 3 && colorList[i] != null && colorList[i] != undefined) {
|
|
155
|
-
a = colorList[i]/255;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
const CS = (window as any).require('csharp');
|
|
159
|
-
return CS.UnityEngine.Color(r, g, b, a);
|
|
160
|
-
}
|
|
161
|
-
updateOutlineText(){
|
|
162
|
-
const CS = (window as any).require('csharp');
|
|
163
|
-
this.text.text = this.props.text;
|
|
164
|
-
this.text.font = CS.com.tencent.pandora.TextPartner.GetFont.Invoke(this.props.font);
|
|
165
|
-
this.text.fontStyle = this.props.fontStyle;
|
|
166
|
-
this.text.fontSize = this.props.fontSize;
|
|
167
|
-
this.text.lineSpacing = this.props.lineSpacing;
|
|
168
|
-
this.text.alignment = this.props.alignment;
|
|
169
|
-
this.text.alignByGeometry = this.props.alignByGeometry;
|
|
170
|
-
this.text.horizontalOverflow = this.props.horizontalOverflow;
|
|
171
|
-
this.text.verticalOverflow = this.props.verticalOverflow;
|
|
172
|
-
this.text.color = CS.UnityEngine.Color(this.props.color.r, this.props.color.g, this.props.color.b, this.props.color.a);
|
|
173
|
-
this.outline.effectColor = CS.UnityEngine.Color(this.props.outlineColor.r, this.props.outlineColor.g, this.props.outlineColor.b, this.props.outlineColor.a);
|
|
174
|
-
this.outline.effectDistance = new CS.UnityEngine.Vector2(this.props.outlineDistance.x , this.props.outlineDistance.y);
|
|
175
|
-
}
|
|
176
|
-
render(){
|
|
177
|
-
return (
|
|
178
|
-
<div style={this.props.style}>
|
|
179
|
-
<pixslot style={{width:'100%', height:'100%'}} src={'pixui://method:placeholder'} onLoad= {this.OnLoad.bind(this)} />
|
|
180
|
-
</div>
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
}
|