feat: 轮播图组件支持点击小圆点切换 (#3710)

* feat: 轮播图组件支持点击小圆点切换

* 去掉 console.log
This commit is contained in:
吴多益 2022-03-10 15:33:34 +08:00 committed by GitHub
parent 62611cc6ea
commit 1c8db2a682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -470,7 +470,7 @@
--Carousel-bg: #f6f8f8;
--Carousel-dot-borderRadius: #{px2rem(4px)};
--Carousel-dot-height: #{px2rem(8px)};
--Carousel-dot-margin: #{px2rem(7px)} var(--gap-xs);
--Carousel-dot-margin: #{px2rem(8px)} var(--gap-xs);
--Carousel-dot-width: #{px2rem(8px)};
--Carousel-height: #{px2rem(200px)};
--Carousel-imageDescription-bottom: #{px2rem(25px)};

View File

@ -149,6 +149,7 @@
text-align: center;
.#{$ns}Carousel-dot {
cursor: pointer;
display: inline-block;
height: var(--Carousel-dot-width);
width: var(--Carousel-dot-height);

View File

@ -278,6 +278,13 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
clearTimeout(this.durationTimeout as number);
}
@autobind
changeSlide(index: number) {
this.setState({
current: index
});
}
renderDots() {
const {classnames: cx} = this.props;
const {current, options} = this.state;
@ -290,6 +297,7 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
{Array.from({length: options.length}).map((_, i) => (
<span
key={i}
onClick={() => this.changeSlide(i)}
className={cx('Carousel-dot', current === i ? 'is-active' : '')}
/>
))}