Skip to content

Commit c71e227

Browse files
committed
refactor(ui): refactor slides component
BREAKING CHANGE: remove `swiper`
1 parent 1cdbc77 commit c71e227

File tree

20 files changed

+800
-260
lines changed

20 files changed

+800
-260
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
"stylelint-config-recommended-scss": "^8.0.0",
112112
"stylelint-config-standard": "^29.0.0",
113113
"stylelint-scss": "^4.3.0",
114-
"swiper": "^8.4.4",
115114
"table": "^6.8.1",
116115
"ts-jest": "^27.1.4",
117116
"ts-node": "^10.9.1",

packages/hooks/src/useAsync.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ class AsyncInstance {
1111
}
1212
}
1313

14-
setTimeout(handler: TimerHandler, timeout?: number) {
14+
setTimeout(handler: TimerHandler, timeout?: number, clearFn?: () => void) {
1515
const tid = window.setTimeout(handler, timeout);
1616
const clear = () => {
17+
clearFn?.();
1718
clearTimeout(tid);
1819
};
1920
this.clearFns.add(clear);
2021

2122
return clear;
2223
}
2324

24-
requestAnimationFrame(...args: Parameters<typeof requestAnimationFrame>) {
25-
const tid = requestAnimationFrame(...args);
25+
requestAnimationFrame(cb: FrameRequestCallback, clearFn?: () => void) {
26+
const tid = requestAnimationFrame(cb);
2627
const clear = () => {
28+
clearFn?.();
2729
cancelAnimationFrame(tid);
2830
};
2931
this.clearFns.add(clear);

packages/hooks/src/useId.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ import { useMemo } from 'react';
22

33
const STR = 'abcdefghijklmnopqrstuvwxyz';
44

5-
function randomString(length: number) {
6-
let result = '';
7-
for (let i = length; i > 0; --i) {
8-
result += STR[Math.floor(Math.random() * STR.length)];
9-
}
10-
return result;
11-
}
12-
const [prefix, suffix] = [randomString(2), randomString(2)];
13-
145
const ID = [-1];
156
export function useId(): string {
167
return useMemo(() => {
@@ -25,6 +16,7 @@ export function useId(): string {
2516
};
2617
reduce(0);
2718

28-
return `${prefix}${ID.map((charIndex) => STR[charIndex]).join('')}${suffix}`;
19+
return `${useId.PREFIX}${ID.map((charIndex) => STR[charIndex]).join('')}`;
2920
}, []);
3021
}
22+
useId.PREFIX = 'ID';

packages/site/src/styles/_app.scss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ h3 {
313313
align-items: center;
314314
justify-content: center;
315315
width: 100%;
316-
height: 100%;
316+
height: 160px;
317317
color: map.get($rd-colors, 'white');
318-
background: rgb(54 77 121);
319318
}
320319
}
321320

packages/ui/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"immer": "^9.0.16",
3131
"lodash": "^4.17.21",
3232
"rfs": "^9.0.6",
33-
"rxjs": "^7.5.7",
34-
"swiper": "^8.4.4"
33+
"rxjs": "^7.5.7"
3534
},
3635
"peerDependencies": {
3736
"dayjs": "^1.11.6",

packages/ui/src/components/image/ImagePreview.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
158158
}
159159
}, [visible]);
160160

161-
const listenWindow = visible && isDragging;
161+
const listenDragEvent = visible && isDragging;
162162

163163
useEvent<TouchEvent>(
164164
windowRef,
@@ -197,7 +197,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
197197
handleMove();
198198
},
199199
{ passive: false },
200-
!listenWindow
200+
!listenDragEvent
201201
);
202202

203203
useEvent<MouseEvent>(
@@ -219,7 +219,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
219219
handleMove();
220220
},
221221
{},
222-
!listenWindow
222+
!listenDragEvent
223223
);
224224

225225
useEvent(
@@ -229,7 +229,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
229229
setIsDragging(false);
230230
},
231231
{},
232-
!listenWindow
232+
!listenDragEvent
233233
);
234234

235235
return (

packages/ui/src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export { DSkeleton } from './skeleton';
100100
export type { DSliderProps } from './slider';
101101
export { DSlider } from './slider';
102102

103-
export type { DSlidesProps, DSlidesSlideProps } from './slides';
103+
export type { DSlidesProps } from './slides';
104104
export { DSlides } from './slides';
105105

106106
export type { DSpinnerProps } from './spinner';

packages/ui/src/components/root/contex.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import type { DSelectProps } from '../select';
3333
import type { DSeparatorProps } from '../separator';
3434
import type { DSkeletonProps } from '../skeleton';
3535
import type { DSliderProps } from '../slider';
36-
import type { DSlidesProps, DSlidesSlideProps } from '../slides';
36+
import type { DSlidesProps } from '../slides';
3737
import type { DSpinnerProps } from '../spinner';
3838
import type { DStepperProps } from '../stepper';
3939
import type { DSwitchProps } from '../switch';
@@ -115,8 +115,7 @@ export type DComponentConfig = {
115115
DSeparator: DSeparatorProps;
116116
DSkeleton: DSkeletonProps;
117117
DSlider: DSliderProps;
118-
DSlides: DSlidesProps;
119-
'DSlides.Slide': DSlidesSlideProps;
118+
DSlides: DSlidesProps<any, any>;
120119
DSpinner: DSpinnerProps;
121120
DStepper: DStepperProps<any>;
122121
DSwitch: DSwitchProps;

packages/ui/src/components/slider/Slider.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
259259
}
260260
}, [focusDot, _value, thumbPoint]);
261261

262-
const listenWindow = !isNull(draggableDot) || !isNull(thumbPoint);
262+
const listenDragEvent = !isNull(draggableDot) || !isNull(thumbPoint);
263263

264264
useEvent<TouchEvent>(
265265
windowRef,
@@ -277,7 +277,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
277277
}
278278
},
279279
{ passive: false },
280-
!listenWindow
280+
!listenDragEvent
281281
);
282282
useEvent<MouseEvent>(
283283
windowRef,
@@ -295,7 +295,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
295295
}
296296
},
297297
{},
298-
!listenWindow
298+
!listenDragEvent
299299
);
300300
useEvent(
301301
windowRef,
@@ -305,7 +305,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
305305
setThumbPoint(null);
306306
},
307307
{},
308-
!listenWindow
308+
!listenDragEvent
309309
);
310310

311311
const marks = (() => {

0 commit comments

Comments
 (0)