使用阿里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;
相关推荐
llxxyy卢1 分钟前
XSS跨站之订单及shell箱子反杀记
前端·xss
q***64976 分钟前
SpringSecurity踢出指定用户
android·前端·后端
q***76669 分钟前
SpringSecurity 实现token 认证
android·前端·后端
llxxyy卢10 分钟前
xss-maps(1-12)尝试思路过关加源码分析
前端·xss
小璞14 分钟前
一、React Fiber 架构与任务调度详解
前端·react.js·前端框架
小璞14 分钟前
四、虚拟 DOM 与 Diff 算法:架构设计的智慧
前端·react.js·前端框架
南蓝15 分钟前
【AI 日记】调用大模型的时候如何按照 sse 格式输出
前端·人工智能
一树论17 分钟前
浏览器插件开发经验分享二:如何处理日期控件
前端·javascript
小璞17 分钟前
六、React 并发模式:让应用"感觉"更快的架构智慧
前端·react.js·架构
Yanni4Night18 分钟前
LogTape:零依赖的现代JavaScript日志解决方案
前端·javascript