From aeeeb07c63999edde8b66d8dfe3c15e0ad26bca0 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 22 Jul 2021 17:43:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(web):=20=E5=88=9B=E5=BB=BA=E7=BE=A4?= =?UTF-8?q?=E7=BB=84=E6=97=B6=E7=9A=84=E6=BB=9A=E5=8A=A8UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/Slides.less | 5 +++ web/src/components/Slides.tsx | 53 +++++++++++++++++++++++ web/src/components/modals/CreateGroup.tsx | 14 +++--- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 web/src/components/Slides.less create mode 100644 web/src/components/Slides.tsx 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(() => {
-
+
); });