1 Star 0 Fork 0

LS/ls-design

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
zh-CN-react.md 4.11 KB
一键复制 编辑 原始数据 按行查看 历史

SwipeCell


简介

可以左右滑动来展示操作按钮的单元格组件。

安装使用

import { SwipeCell } from "@ls-design/ui-react";

基础用法

export default () => {
  return (
    <SwipeCell>
      <Cell title="这是标题" desc="描述文字" />
      <div slot="left">
        <Button type="primary" shape="square">
          选择
        </Button>
      </div>
      <div slot="right">
        <Button type="danger" shape="square">
          删除
        </Button>
        <Button type="primary" shape="square">
          收藏
        </Button>
      </div>
    </SwipeCell>
  );
};

自定义内容

SwipeCell 可以嵌套任意内容。

export default () => {
  return (
    <SwipeCell>
      <Empty title="暂无数据" desc="快去添加数据吧~" type="local" />
      <div slot="right">
        <Button type="primary" shape="square">
          添加
        </Button>
      </div>
    </SwipeCell>
  );
};

异步关闭

通过setBeforeClose方法,设置回调函数,可以自定义两侧滑动内容关闭时的行为。

export default () => {
  const swipeCellRef = useRef<SwipeCellRef>(null);

  useEffect(() => {
    const { current } = swipeCellRef;
    current.setBeforeClose((position: SwipeCellPosition) => {
      if (position === "right") {
        return new Promise((resolve) => {
          const toast = Toast.loading("请求中");
          setTimeout(() => {
            toast.hide();
            Toast.success("删除成功");
            resolve(true);
          }, 1000);
        });
      } else {
        return true;
      }
    });
  }, []);

  return (
    <SwipeCell ref={swipeCellRef}>
      <Cell title="这是标题" desc="描述文字" />
      <div slot="right">
        <Button type="primary" shape="square">
          删除
        </Button>
      </div>
    </SwipeCell>
  );
};

Props

方法名 说明 类型 默认值
name 唯一标识符 number | string ''
leftwidth 指定左侧滑动区域宽度 number auto
rightwidth 指定右侧滑动区域宽度 number auto
disabled 是否禁用滑动 boolean false
onClick 点击时触发 (args: { detail: { positon: SwipeCellPosition } }) => void
onOpen 打开时触发 (args: Params) => void
onClose 关闭时触发 (args: Params) => void

Methods

名称 说明 类型
open 打开单元格侧边栏 (args: SwipeCellSide) => void
close 收起单元格侧边栏 () => void
setBeforeClose 设置关闭前的回调函数,返回 false 可阻止关闭,支持返回 Promise (args: SwipeCellPosition) => boolean | Promise<boolean>

Slots

名称 说明
default 默认显示的内容
left 左侧滑动区域的内容
right 右侧滑动区域的内容

类型定义

type SwipeCellSide = "left" | "right";
type SwipeCellPosition = SwipeCellSide | "cell" | "outside";
type Params = {
  detail: {
    name: string | number;
    position: SwipeCellPosition;
  };
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LShere/ls-design.git
git@gitee.com:LShere/ls-design.git
LShere
ls-design
ls-design
master

搜索帮助