diff --git a/web/src/components/Slides.less b/web/src/components/Slides.less new file mode 100644 index 00000000..01d06741 --- /dev/null +++ b/web/src/components/Slides.less @@ -0,0 +1,5 @@ +.slides { + .slick-list { + transition: height .2s ease-in-out; + } +} diff --git a/web/src/components/Slides.tsx b/web/src/components/Slides.tsx new file mode 100644 index 00000000..55179b0e --- /dev/null +++ b/web/src/components/Slides.tsx @@ -0,0 +1,53 @@ +import { Carousel } from 'antd'; +import type { CarouselProps, CarouselRef } from 'antd/lib/carousel'; +import React, { useImperativeHandle, useRef } from 'react'; + +import './Slides.less'; + +export interface SlidesRef { + next: () => void; + prev: () => void; +} + +/** + * 类似于走马灯, 但是用于分步操作 + * + * 会随内容的变化动态改变高度 + * + * Reference: https://react-slick.neostack.com/docs/api + */ +export const Slides = React.forwardRef( + (props, ref) => { + const carouselRef = useRef(null); + + useImperativeHandle( + ref, + () => ({ + next() { + carouselRef.current?.next(); + }, + prev() { + carouselRef.current?.prev(); + }, + }), + [] + ); + + return ( + { + console.log(current, next, carouselRef.current?.innerSlider); + }} + > + {props.children} + + ); + } +); +Slides.displayName = 'Slides'; diff --git a/web/src/components/modals/CreateGroup.tsx b/web/src/components/modals/CreateGroup.tsx index bdc55436..ebe22a39 100644 --- a/web/src/components/modals/CreateGroup.tsx +++ b/web/src/components/modals/CreateGroup.tsx @@ -1,20 +1,20 @@ -import { Button, Carousel, Divider, Input, Typography } from 'antd'; -import type { CarouselRef } from 'antd/lib/carousel'; +import { Button, Divider, Input, Typography } from 'antd'; import React, { useCallback, useRef, useState } from 'react'; import { Avatar } from '../Avatar'; import { ModalWrapper } from '../Modal'; +import { Slides, SlidesRef } from '../Slides'; export const ModalCreateGroup: React.FC = React.memo(() => { - const carouselRef = useRef(null); + const slidesRef = useRef(null); const [name, setName] = useState(''); const handleSelectTemplate = useCallback(() => { // TODO - carouselRef.current?.next(); + slidesRef.current?.next(); }, []); const handleBack = useCallback(() => { - carouselRef.current?.prev(); + slidesRef.current?.prev(); }, []); const handleCreate = useCallback(() => { @@ -23,7 +23,7 @@ export const ModalCreateGroup: React.FC = React.memo(() => { return ( - +
创建群组 @@ -81,7 +81,7 @@ export const ModalCreateGroup: React.FC = React.memo(() => {
-
+
); });