Skip to content

Commit

Permalink
refactor(ui): refactor slides component
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove `swiper`
  • Loading branch information
xiejay97 committed Nov 18, 2022
1 parent 1cdbc77 commit c71e227
Show file tree
Hide file tree
Showing 20 changed files with 800 additions and 260 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"stylelint-config-recommended-scss": "^8.0.0",
"stylelint-config-standard": "^29.0.0",
"stylelint-scss": "^4.3.0",
"swiper": "^8.4.4",
"table": "^6.8.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/hooks/src/useAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ class AsyncInstance {
}
}

setTimeout(handler: TimerHandler, timeout?: number) {
setTimeout(handler: TimerHandler, timeout?: number, clearFn?: () => void) {
const tid = window.setTimeout(handler, timeout);
const clear = () => {
clearFn?.();
clearTimeout(tid);
};
this.clearFns.add(clear);

return clear;
}

requestAnimationFrame(...args: Parameters<typeof requestAnimationFrame>) {
const tid = requestAnimationFrame(...args);
requestAnimationFrame(cb: FrameRequestCallback, clearFn?: () => void) {
const tid = requestAnimationFrame(cb);
const clear = () => {
clearFn?.();
cancelAnimationFrame(tid);
};
this.clearFns.add(clear);
Expand Down
12 changes: 2 additions & 10 deletions packages/hooks/src/useId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { useMemo } from 'react';

const STR = 'abcdefghijklmnopqrstuvwxyz';

function randomString(length: number) {
let result = '';
for (let i = length; i > 0; --i) {
result += STR[Math.floor(Math.random() * STR.length)];
}
return result;
}
const [prefix, suffix] = [randomString(2), randomString(2)];

const ID = [-1];
export function useId(): string {
return useMemo(() => {
Expand All @@ -25,6 +16,7 @@ export function useId(): string {
};
reduce(0);

return `${prefix}${ID.map((charIndex) => STR[charIndex]).join('')}${suffix}`;
return `${useId.PREFIX}${ID.map((charIndex) => STR[charIndex]).join('')}`;
}, []);
}
useId.PREFIX = 'ID';
3 changes: 1 addition & 2 deletions packages/site/src/styles/_app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,8 @@ h3 {
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
height: 160px;
color: map.get($rd-colors, 'white');
background: rgb(54 77 121);
}
}

Expand Down
3 changes: 1 addition & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"immer": "^9.0.16",
"lodash": "^4.17.21",
"rfs": "^9.0.6",
"rxjs": "^7.5.7",
"swiper": "^8.4.4"
"rxjs": "^7.5.7"
},
"peerDependencies": {
"dayjs": "^1.11.6",
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/components/image/ImagePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
}
}, [visible]);

const listenWindow = visible && isDragging;
const listenDragEvent = visible && isDragging;

useEvent<TouchEvent>(
windowRef,
Expand Down Expand Up @@ -197,7 +197,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
handleMove();
},
{ passive: false },
!listenWindow
!listenDragEvent
);

useEvent<MouseEvent>(
Expand All @@ -219,7 +219,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
handleMove();
},
{},
!listenWindow
!listenDragEvent
);

useEvent(
Expand All @@ -229,7 +229,7 @@ export function DImagePreview(props: DImagePreviewProps): JSX.Element | null {
setIsDragging(false);
},
{},
!listenWindow
!listenDragEvent
);

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export { DSkeleton } from './skeleton';
export type { DSliderProps } from './slider';
export { DSlider } from './slider';

export type { DSlidesProps, DSlidesSlideProps } from './slides';
export type { DSlidesProps } from './slides';
export { DSlides } from './slides';

export type { DSpinnerProps } from './spinner';
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/src/components/root/contex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type { DSelectProps } from '../select';
import type { DSeparatorProps } from '../separator';
import type { DSkeletonProps } from '../skeleton';
import type { DSliderProps } from '../slider';
import type { DSlidesProps, DSlidesSlideProps } from '../slides';
import type { DSlidesProps } from '../slides';
import type { DSpinnerProps } from '../spinner';
import type { DStepperProps } from '../stepper';
import type { DSwitchProps } from '../switch';
Expand Down Expand Up @@ -115,8 +115,7 @@ export type DComponentConfig = {
DSeparator: DSeparatorProps;
DSkeleton: DSkeletonProps;
DSlider: DSliderProps;
DSlides: DSlidesProps;
'DSlides.Slide': DSlidesSlideProps;
DSlides: DSlidesProps<any, any>;
DSpinner: DSpinnerProps;
DStepper: DStepperProps<any>;
DSwitch: DSwitchProps;
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/components/slider/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
}
}, [focusDot, _value, thumbPoint]);

const listenWindow = !isNull(draggableDot) || !isNull(thumbPoint);
const listenDragEvent = !isNull(draggableDot) || !isNull(thumbPoint);

useEvent<TouchEvent>(
windowRef,
Expand All @@ -277,7 +277,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
}
},
{ passive: false },
!listenWindow
!listenDragEvent
);
useEvent<MouseEvent>(
windowRef,
Expand All @@ -295,7 +295,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
}
},
{},
!listenWindow
!listenDragEvent
);
useEvent(
windowRef,
Expand All @@ -305,7 +305,7 @@ export function DSlider(props: DSliderProps): JSX.Element | null {
setThumbPoint(null);
},
{},
!listenWindow
!listenDragEvent
);

const marks = (() => {
Expand Down
Loading

0 comments on commit c71e227

Please sign in to comment.