refactor(web): 创建群组时的滚动UI

pull/13/head
moonrailgun 4 years ago
parent 07e32d0168
commit aeeeb07c63

@ -0,0 +1,5 @@
.slides {
.slick-list {
transition: height .2s ease-in-out;
}
}

@ -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<SlidesRef, CarouselProps>(
(props, ref) => {
const carouselRef = useRef<CarouselRef>(null);
useImperativeHandle(
ref,
() => ({
next() {
carouselRef.current?.next();
},
prev() {
carouselRef.current?.prev();
},
}),
[]
);
return (
<Carousel
className="slides"
ref={carouselRef}
{...props}
dots={false}
adaptiveHeight={true}
infinite={false}
beforeChange={(current, next) => {
console.log(current, next, carouselRef.current?.innerSlider);
}}
>
{props.children}
</Carousel>
);
}
);
Slides.displayName = 'Slides';

@ -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<CarouselRef>(null);
const slidesRef = useRef<SlidesRef>(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 (
<ModalWrapper style={{ width: 440 }}>
<Carousel ref={carouselRef} dots={false}>
<Slides ref={slidesRef}>
<div>
<Typography.Title level={4} className="text-center mb-4">
@ -81,7 +81,7 @@ export const ModalCreateGroup: React.FC = React.memo(() => {
</Button>
</div>
</div>
</Carousel>
</Slides>
</ModalWrapper>
);
});

Loading…
Cancel
Save