From 1cfd104f6f4992571c53d1f30eab8ab578e1b526 Mon Sep 17 00:00:00 2001 From: qiuchenfan <2035024011@qq.com> Date: Fri, 21 Nov 2025 15:12:21 +0800 Subject: [PATCH] =?UTF-8?q?kiro=E5=88=9D=E4=BD=BF=E7=94=A8=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E7=9F=A5=E9=81=93=E4=B8=BA=E4=BB=80=E4=B9=88=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E5=A5=BD=E5=83=8F=E5=8F=AA=E6=98=AF=E6=94=B9?= =?UTF-8?q?=E5=8F=98=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 +++ app/components/Carousel.tsx | 42 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5480842 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "kiroAgent.configureMCP": "Disabled" +} \ No newline at end of file diff --git a/app/components/Carousel.tsx b/app/components/Carousel.tsx index 334b57c..7264d2f 100755 --- a/app/components/Carousel.tsx +++ b/app/components/Carousel.tsx @@ -28,16 +28,16 @@ const imageUrls = [ // 定义组件接收的 props 接口,提供类型安全 export interface CarouselDemoProps { // 分页指示器位置:'left' 表示左下角,'right' 表示右下角,默认为 'right' - paginationPosition?: 'left' | 'right'; + paginationPosition?: "left" | "right"; // 分页指示器样式:'dot' 为圆形小点,'bar' 为横向小条,默认为 'dot' - paginationStyle?: 'dot' | 'bar'; + paginationStyle?: "dot" | "bar"; } // 导出 CarouselDemo 组件,接收两个可选 props,并设置默认值 export function CarouselDemo({ - paginationPosition = 'right', // 默认右下角 - paginationStyle = 'dot', // 默认圆形指示器 + paginationPosition = "right", // 默认右下角 + paginationStyle = "dot", // 默认圆形指示器 }: CarouselDemoProps) { // 轮播实例的引用 当前激活的幻灯片索引 总共的幻灯片数量 图片总数 const [api, setApi] = React.useState(); @@ -47,11 +47,11 @@ export function CarouselDemo({ // 监听 api ,初始化轮播状态并绑定 select 事件 获取幻灯片总数 设置当前选中的 snap 索引 用户手动滑动或自动播放时触发 更新当前激活项 React.useEffect(() => { - if (!api) return; + if (!api) return; setCount(api.scrollSnapList().length); setCurrent(api.selectedScrollSnap()); api.on("select", () => { - setCurrent(api.selectedScrollSnap()); + setCurrent(api.selectedScrollSnap()); }); }, [api]); // 仅当 api 发生变化时重新执行 @@ -59,11 +59,10 @@ export function CarouselDemo({ return ( // 外层容器:相对定位,占满父容器宽高
- {/* 轮播主容器 */} {/* 遍历图片数组,为每张图创建一个轮播项 */} {imageUrls.map((src, index) => ( - + {/* 内部包裹层:无内边距,占满 移除默认间距 自动填充容器,保持比例裁剪*/} @@ -112,8 +108,9 @@ export function CarouselDemo({ {/* 分页指示器容器:绝对定位在底部 */}
{/* 动态生成指示器按钮 */} {Array.from({ length: count }).map((_, index) => ( @@ -122,17 +119,18 @@ export function CarouselDemo({ onClick={() => api?.scrollTo(index)} // 点击跳转到对应幻灯片 className={`transition-colors ${ // 根据 paginationStyle 决定形状 - paginationStyle === 'dot' - ? 'h-2 w-2 rounded-full' // 圆形:宽高相等 + 全圆角 - : 'h-1 w-6 rounded' // 块状 - } ${index === current - ? 'bg-white' // 当前项为纯白色 - : 'bg-white/50' // 非当前项为半透明白色 - }`} + paginationStyle === "dot" + ? "h-2 w-2 rounded-full" // 圆形:宽高相等 + 全圆角 + : "h-1 w-6 rounded" // 块状 + } ${ + index === current + ? "bg-white" // 当前项为纯白色 + : "bg-white/50" // 非当前项为半透明白色 + }`} aria-label={`Go to slide ${index + 1}`} // 无障碍支持 /> ))}
); -} \ No newline at end of file +}