SwipeCell sliding cell

introduce

Cell components that can be swiped left or right to display action buttons.

Code Demo

Basic usage

The SwipeCell component provides two slots, left and right, for defining the contents of the sliding areas on both sides.

<z-swipe-cell>
   <template #left>
     <z-button square type="primary" text="select" />
   </template>
   <z-cell :border="false" title="cell" value="content" />
   <template #right>
     <z-button square type="danger" text="Delete" />
     <z-button square type="primary" text="Collection" />
   </template>
</z-swipe-cell>

Custom content

SwipeCell can nest any content, such as nesting a product card.

<z-swipe-cell>
   <z-card title="title" :cover="cover" header-bordered>
     This is a text
     <template #actions>
       <z-button type="primary" size="mini">Operation</z-button>
     </template>
   </z-card>
   <template #right>
     <z-button
       square
       type="danger"
       text="delete"
       :custom-style="{ height: '100%' }"
     />
   </template>
</z-swipe-cell>
import { ref } from 'vue'
const cover = ref(
   'https://cdn.zebraui.com/zebra-ui/images/swipe-demo/swipe1.jpg'
)

Asynchronous shutdown

By passing in the before-close callback function, you can customize the behavior when the sliding content on both sides is closed.

<z-swipe-cell :before-close="beforeClose">
   <template #left>
     <z-button square type="primary" text="select" />
   </template>
   <z-cell :border="false" title="cell" value="content" />
   <template #right>
     <z-button square type="danger" text="Delete" />
   </template>
</z-swipe-cell>
import { useDialog } from '../../uni_modules/zebra-ui'
const dialog = useDialog()
const beforeClose = ({ position }: { position: string }) => {
   switch (position) {
     case 'left':
     case 'cell':
     case 'outside':
       return true
     case 'right':
       return new Promise<boolean>((resolve) => {
         dialog
           .showConfirmDialog({
             title: 'Are you sure to delete'
           })
           .then(() => resolve(true))
           .catch(() => resolve(false))
       })
   }
}

API

Props

ParametersDescriptionTypeDefault value
nameIdentifier, usually a unique string or number, which can be obtained in the event parametersnumber | string''
left-widthSpecifies the width of the left sliding area in pxnumber | stringauto
right-widthSpecifies the width of the right sliding area, in pxnumber | stringauto
before-closeCallback function before closing, return false to prevent closing, support returning Promise(args) => boolean | Promise<boolean>-
disabledWhether to disable slidingbooleanfalse

Slots

NameDescription
defaultContent displayed by default
leftContents of the left sliding area
rightContents of the right sliding area

Events

Event nameDescriptionCallback parameters
clickTriggered when clickedposition: 'left' | 'right' | 'cell' | 'outside'
openTriggered when opened{ name: string | number, position: 'left' | 'right' }
closeTriggered when closed{ name: string | number, position: 'left' | 'right' | 'cell' | 'outside' }

beforeClose parameter

The first parameter of beforeClose is an object, which contains the following properties:

Parameter nameDescriptionType
nameidentifierstring | number
positionClick position when closing'left' | 'right' | 'cell' | 'outside'

method

Through ref, you can get the SwipeCell instance and call the instance method.

Method nameDescriptionParametersReturn value
openOpen the cell sidebarposition: left | right-
closeCollapse cell sidebar--