使用阿里lowcode,手搓一个Carousel 走马灯容器组件

1、先看效果

2、上代码

components

ProgressSteps.tsx

tsx 复制代码
import React, { createElement } from 'react';
import { Slider } from '@alifd/next';

export interface CarouselSlotProps {
  height?: number;
  width?: number;
  autoplay?: boolean;
  interval?: number;
  child?: React.ReactNode[]
  children?: any[];
}

const CarouselSlot: React.FC<CarouselSlotProps> = ({
  height = '100%',
  width = '100%',
  autoplay = true,
  interval = 3000,
  child = [1, 2],
  children,
}) => {

  const pages = Array.isArray(child) && child.length > 0 ? child : [1, 2];

  return (
    <div style={{ width, height }}>
      <Slider
        autoplay={autoplay}
        autoplaySpeed={interval}
        style={{ width: '100%', height: '100%' }}
        animation="slide"
        // arrows
        // dots
      >
        {pages.map((_, idx) => (
          <div key={idx} style={{ width: '100%', height: '100%' }}>
            {Array.isArray(children) ? children[idx] : children}
          </div>
        ))}
      </Slider>
    </div>
  );
};

export default CarouselSlot;

lowcode

meta:

ts 复制代码
import { IPublicModelComponentMeta } from '@alilc/lowcode-types';

const CarouselSlotMeta: IPublicModelComponentMeta = {
  componentName: 'CarouselSlot',
  title: '走马灯容器',
  group: 'xxx组件',
  category: 'xxx',
  devMode: 'proCode',
  npm: {
    package: 'xxxxxx',
    version: '0.1.0',
    exportName: 'CarouselSlot',
    main: 'src/index.tsx',
    destructuring: true,
  },

  props: [
    {
      name: 'width',
      title: { label: '宽度', tip: '组件宽度' },
      setter: 'StringSetter',
      defaultValue: '400px',
    },
    {
      name: 'height',
      title: { label: '高度', tip: '组件高度' },
      setter: 'StringSetter',
      defaultValue: '180px',
    },
    {
      name: 'autoplay',
      title: { label: '自动播放', tip: '是否自动切换' },
      setter: 'BoolSetter',
      defaultValue: true,
    },
    {
      name: 'interval',
      title: { label: '切换间隔(ms)', tip: '单位毫秒' },
      setter: 'NumberSetter',
      defaultValue: 3000,
    },
    {
      name: 'child',
      title: { label: '走马灯页数', tip: '走马灯页数' },
      setter: {
        componentName: 'ArraySetter',
        props: {
          itemSetter: {
            componentName: 'NumberSetter',
          }
        }
      },
      defaultValue: [1,2],
    },
  ],

  configure: {
    // @ts-ignore
    component: {
      isContainer: true
    },
    supports: {
      style: true,
    },
  },

  snippets: [
    {
      title: '走马灯容器',
      schema: {
        componentName: 'CarouselSlot',
        props: {
          width: '400px',
          height: '300px',
          autoplay: true,
          interval: 3000,
        },
        child:[1,2],
      },
    },
  ],
};

export default CarouselSlotMeta;
相关推荐
xkxnq15 分钟前
第二阶段:Vue 组件化开发(第 16天)
前端·javascript·vue.js
烛阴20 分钟前
拒绝配置地狱!5 分钟搭建 Three.js + Parcel 完美开发环境
前端·webgl·three.js
xkxnq36 分钟前
第一阶段:Vue 基础入门(第 15天)
前端·javascript·vue.js
anyup2 小时前
2026第一站:分享我在高德大赛现场学到的技术、产品与心得
前端·架构·harmonyos
BBBBBAAAAAi2 小时前
Claude Code安装记录
开发语言·前端·javascript
xiaolyuh1232 小时前
【XXL-JOB】 GLUE模式 底层实现原理
java·开发语言·前端·python·xxl-job
源码获取_wx:Fegn08952 小时前
基于 vue智慧养老院系统
开发语言·前端·javascript·vue.js·spring boot·后端·课程设计
毕设十刻2 小时前
基于Vue的人事管理系统67zzz(程序 + 源码 + 数据库 + 调试部署 + 开发环境配置),配套论文文档字数达万字以上,文末可获取,系统界面展示置于文末
前端·数据库·vue.js
anyup2 小时前
从赛场到产品:分享我在高德大赛现场学到的技术、产品与心得
前端·harmonyos·产品
前端工作日常3 小时前
我学习到的A2UI的功能:纯粹的UI生成
前端