Unverified Commit 0eec1d43 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Doc] support doc home page Carousel component (#3328)

parent b0bf25fc
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
"docusaurus-plugin-less": "^2.0.2", "docusaurus-plugin-less": "^2.0.2",
"less-loader": "10.2.0", "less-loader": "10.2.0",
"prism-react-renderer": "^1.3.1", "prism-react-renderer": "^1.3.1",
"react": "^17.0.2", "react": "^18.2.0",
"react-dom": "^17.0.2", "react-dom": "^18.0.0",
"yarn": "^1.22.19" "yarn": "^1.22.19"
}, },
"browserslist": { "browserslist": {
......
.container {
overflow: hidden;
}
.inner {
white-space: nowrap;
transition: transform 0.3s;
}
.carousel_item {
display: inline-flex;
align-items: center;
justify-content: center;
height: 200px;
color: #fff;
background-color: #312520;
}
.loading {
position: absolute;
bottom: -25px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
margin-bottom: 10px;
width: 100%;
}
.indicator_outer {
width: 90px;
height: 7px;
background-color: #0000001a;
margin-left: 20px;
border-radius: 5px;
}
.indicator_inside {
height: 100%;
border-radius: 5px;
animation-fill-mode: forwards;
animation-name: progressBar;
animation-iteration-count: infinite;
}
@keyframes progressBar {
0% {
width: 0;
}
100% {
width: 100%;
}
}
import React, {useEffect, useState} from "react";
import style from "./carousel.module.css";
import {CarouselItemInfo} from "../CarouselList";
/**
* @param {children} children ReactNode
* @param {width} width 宽度
* @param {height} height 高度
* @param {styles} styles 样式
* @returns 轮播图 单项
*/
type CarouselItemProps = {
children: React.ReactNode;
width?: string | number;
height?: string | number;
styles?: React.CSSProperties;
}
export const CarouselItem = (props: CarouselItemProps) => {
const {children, width = "100%", height = "100%", styles = {}} = props;
return (
<div
className={style.carousel_item}
style={{width: width, height: height, ...styles}}
>
{children}
</div>
);
};
/**
* @returns 轮播图 主体
* @param props
*/
export const CarouselInfo: React.FC<CarouselItemInfo> = (props: { item: CarouselItemInfo; }) => {
const {item} = props;
return (
<div className="carousel_info_container">
{/*<div className="carousel_info_info">*/}
{/* <h1>{item.title}</h1>*/}
{/* <span>{item.describe}</span>*/}
{/*</div>*/}
<div className="carousel_info_image_container">
<img src={item.image} alt="Jay" className="carousel_info_image"/>
</div>
</div>
);
};
/**
* @param {children} children ReactNode
* @param {switchingTime} switchingTime 间隔时间 默认3秒 以毫秒为单位 3000ms = 3s
* @returns 轮播图 容器
*/
const Carousel = ({
children = React.createElement("div"),
switchingTime = 3000,
}) => {
const time = ((switchingTime % 60000) / 1000).toFixed(0); // 将毫秒转换为秒
const [activeIndex, setActiveIndex] = useState(0); // 对应索引
/**
* 更新索引
* @param {newIndex} newIndex 更新索引
*/
const onUpdateIndex = (newIndex: React.SetStateAction<number>) => {
if (newIndex < 0) {
newIndex = React.Children.count(children) - 1;
} else if (newIndex >= React.Children.count(children)) {
newIndex = 0;
}
setActiveIndex(newIndex);
replayAnimations();
};
/**
* 重置动画
*/
const replayAnimations = () => {
document.getAnimations().forEach((anim) => {
anim.cancel();
anim.play();
});
};
/**
* 底部加载条点击事件
* @param {index} index 跳转索引
*/
const onClickCarouselIndex = (index: React.SetStateAction<number>) => {
onUpdateIndex(index);
replayAnimations();
};
useEffect(() => {
const interval = setInterval(() => {
onUpdateIndex(activeIndex + 1);
}, switchingTime);
return () => {
if (interval) {
clearInterval(interval);
}
};
});
/**
* Renders the children elements with specific styles and transformations.
*
* @return {JSX.Element} The rendered JSX elements with modified styles.
*/
const renderChildren = () => {
return (
<div
className={style.inner}
style={{transform: `translateX(-${activeIndex * 100}%)`}}
>
{React.Children.map(children, (child) => {
return React.cloneElement(child, {width: "100%", height: "100%"});
})}
</div>
)
}
/**
* Function to render loading indicators for each child component.
*
* @return {JSX.Element} The loading indicators JSX element
*/
const renderLoading = () => {
return (
<div className={style.loading}>
{React.Children.map(children, (child, index) => {
return (
<div
className={style.indicator_outer}
onClick={() => onClickCarouselIndex(index)}
>
<div
className={style.indicator_inside}
style={{
animationDuration: index === activeIndex ? `${time}s` : "0s",
backgroundColor: index === activeIndex ? "#041d81" : null,
}}
/>
</div>
);
})}
</div>
)
}
return (
<div className={style.container}>
{renderChildren()}
{renderLoading()}
</div>
);
};
export default Carousel;
import Carousel, {CarouselInfo, CarouselItem} from "../Carousel";
import React from "react";
/**
* @param {id} id 轮播图id
* @param {title} title 标题
* @param {describe} describe 描述
* @param {image} image 图片
* @param {imageWidth} imageWidth 图片宽度
* @param {imageHeight} imageHeight 图片高度
* @param {backgroundColor} backgroundColor 背景颜色
* @param {jumpUrl} jumpUrl 跳转链接
* @returns 轮播图信息
* @constructor
*/
export interface CarouselItemInfo {
id: number;
title?: string;
describe?: string;
image: string | React.ReactNode;
imageWidth?: string | number;
imageHeight?: string | number;
backgroundColor?: string;
jumpUrl?: string;
}
/**
* @param {items} items 轮播图列表
*/
type CarouselItemProps = {
items: CarouselItemInfo[];
}
/**
* @returns 轮播图列表
* @param props
* @constructor
*/
const CarouselList:React.FC<CarouselItemProps> = (props: { items: CarouselItemInfo[]; }) => {
const {items} = props
return (
<Carousel>
{items?.map((item :CarouselItemInfo)=> {
return (
<CarouselItem
key={item.id}
width={item.imageWidth}
height={item.imageHeight}
// styles={{ backgroundColor: item.backgroundColor }}
>
<CarouselInfo item={item}/>
</CarouselItem>
);
})}
</Carousel>
);
};
export default CarouselList;
...@@ -251,6 +251,10 @@ div[class^='announcementBar_'] { ...@@ -251,6 +251,10 @@ div[class^='announcementBar_'] {
text-decoration:none; text-decoration:none;
} }
.container{
width: 100%;
margin-right: 50vw;
}
.container .desc{ .container .desc{
width: 100%; width: 100%;
...@@ -269,6 +273,10 @@ div[class^='announcementBar_'] { ...@@ -269,6 +273,10 @@ div[class^='announcementBar_'] {
} }
.container .desc_left{ .container .desc_left{
width:50%; width:50%;
display:flex;
flex-direction: column;
align-content: center;
align-items: center;
} }
.container .desc_left .hero__title{ .container .desc_left .hero__title{
font-size:2.5rem; font-size:2.5rem;
...@@ -291,8 +299,7 @@ div[class^='announcementBar_'] { ...@@ -291,8 +299,7 @@ div[class^='announcementBar_'] {
display:flex; display:flex;
position: relative; position: relative;
width:100%; width:100%;
height: 20%; height:100%;
padding-left: 80px;
} }
.container .desc .desc_right img .fly_svg{ .container .desc .desc_right img .fly_svg{
width:100%; width:100%;
......
...@@ -24,8 +24,33 @@ import Link from '@docusaurus/Link'; ...@@ -24,8 +24,33 @@ import Link from '@docusaurus/Link';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import styles from './index.module.css'; import styles from './index.module.css';
import HomepageFeatures from '@site/src/components/HomepageFeatures'; import HomepageFeatures from '@site/src/components/HomepageFeatures';
import CarouselList from "../components/CarouselList";
// 轮播图数据
const info = [
{
id: 1,
image: 'https://pic.dinky.org.cn/dinky/docs/zh-CN/home/datastudio.png',
},
{
id: 2,
image: 'https://pic.dinky.org.cn/dinky/docs/zh-CN/home/checksql.png',
},
{
id: 3,
image: 'https://pic.dinky.org.cn/dinky/docs/zh-CN/home/versiondiff.png',
},
{
id: 4,
image: 'https://pic.dinky.org.cn/dinky/docs/zh-CN/home/lineage.png',
},
{
id: 5,
image: 'https://pic.dinky.org.cn/dinky/docs/zh-CN/home/monitor.png',
},
];
function HomepageHeader() { function HomepageHeader() {
const {siteConfig} = useDocusaurusContext(); const {siteConfig} = useDocusaurusContext();
return ( return (
...@@ -75,17 +100,25 @@ function HomepageHeader() { ...@@ -75,17 +100,25 @@ function HomepageHeader() {
</div> </div>
<div className={styles.buttonLink}> <div className={styles.buttonLink}>
<iframe style={{width:"100px",height:"30px"}} <iframe style={{width:"150px",height:"30px"}}
src="https://ghbtns.com/github-btn.html?user=DataLinkDC&amp;repo=dinky&amp;type=star&amp;count=true&amp;size=large" src="https://ghbtns.com/github-btn.html?user=DataLinkDC&amp;repo=dinky&amp;type=star&amp;count=true&amp;size=large"
title="GitHub Stars" title="GitHub Stars"
/> />
</div> </div>
</div> </div>
</div> </div>
<div className={clsx("desc_right", styles.box,styles.descRight)}> {/*<div className={clsx("desc_right", styles.box,styles.descRight)}>*/}
<div> {/* <div>*/}
<img src="home.png" className="fly_svg"></img> {/* <img src="home.png" className="fly_svg"></img>*/}
</div> {/* </div>*/}
{/*</div>*/}
<div style={{
position: "absolute",
width: "40vw",
right: "10vw",
zIndex: "1"
}}>
<CarouselList items={info}/>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
.buttons { .buttons {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-around; justify-content: center;
width: 30rem; width: 30rem;
height: 10rem; height: 10rem;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment