使用阿里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;
相关推荐
陈天伟教授2 小时前
人工智能训练师认证教程(2)Python os入门教程
前端·数据库·python
信看3 小时前
NMEA-GNSS-RTK 定位html小工具
前端·javascript·html
Tony Bai3 小时前
【API 设计之道】04 字段掩码模式:让前端决定后端返回什么
前端
苏打水com4 小时前
第十四篇:Day40-42 前端架构设计入门——从“功能实现”到“架构思维”(对标职场“大型项目架构”需求)
前端·架构
king王一帅4 小时前
流式渲染 Incremark、ant-design-x markdown、streammarkdown-vue 全流程方案对比
前端·javascript·人工智能
苏打水com4 小时前
第十八篇:Day52-54 前端跨端开发进阶——从“多端适配”到“跨端统一”(对标职场“全栈化”需求)
前端
Bigger4 小时前
后端拒写接口?前端硬核自救:纯前端实现静态资源下载全链路解析
前端·浏览器·vite
BD_Marathon4 小时前
【JavaWeb】路径问题_前端绝对路径问题
前端
阿里巴啦5 小时前
React + Three.js + R3F + Vite 实战:可交互的三维粒子化展厅
react.js·three.js·粒子化·drei·postprocessing·三维粒子化