使用阿里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;
相关推荐
我不是外星人6 小时前
一键还原任意网站,这套 Playwright + 多 Agent 工程流太猛了
前端·后端·ai编程
用户059540174466 小时前
AI 客服突然“失忆”,排查 6 小时发现 LangChain 记忆存储的 3 个致命坑
前端·css
IT_陈寒6 小时前
Vue的v-if和v-show,我竟然用错了这么久
前端·人工智能·后端
云絮.6 小时前
计算机相关工作原理
服务器·前端·数据库
随风一样自由6 小时前
【前端+React+缓存竞态】导航切换缓存刷新机制
前端·react.js·缓存
恋猫de小郭7 小时前
Flutter 开发怎么做 Agent ?从工程实战详细给你解读下
android·前端·flutter
IT_陈寒7 小时前
React状态更新延迟搞晕我,原来是闭包在捣鬼
前端·人工智能·后端
晓得迷路了7 小时前
栗子前端技术周刊第 136 期 - pnpr、Flow 重构移植 Rust、Astryx...
前端·javascript·css
binbin_527 小时前
React Native 鸿蒙环境搭建完整实战:从 RN 工程到 RNOH 运行
深度学习·react native·react.js·harmonyos
柳杉7 小时前
别再手写大屏了!用这套「3D 地图 + 拖拽脚手架」示例源码,交付效率提升 80%
前端·three.js·数据可视化