Skip to content

Slide Action

Import

import {Terminal} from '@kaiverse/k/ui'

Usage

When users swiped all the way to the end, we can call it a successful or confirmatory action.

Swipe to confirm
basic.tsx
<SlideAction
label="Swipe to confirm"
onSwipeEnd={() => {
// do sth when users swiped to the end, e.g. call API, mutation data, etc...
}}
/>

Reset

How to reset the component status?

Call reset function that shipped with onSwipeEnd callback.

Swipe to confirm

Status: Waiting for confirmation

slide-action-interactive.tsx
import {SlideAction, type SlideActionOnSwipeEnd} from '@kaiverse/k/ui'
const handleOnSwipeEnd = useCallback<SlideActionOnSwipeEnd>((reset) => {
// do sth when users swiped to the end, e.g. call API, mutation data, etc...
setTimeout(() => {
reset()
}, 1000)
}, [])
return (
<SlideAction
label="Swipe to confirm"
color={status ? '#059669' : undefined}
icon={status ? <IconCheck className="size-5 text-white" /> : undefined}
onSwipeEnd={handleOnSwipeEnd}
/>
)

Customization

Effects

  • slideType: the slide progress effect.
  • labelType: label effect.

Slide effect

Default: Slide background
Static fade-in background

Label effect

Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia, temporibus voluptatibus! Dolorum tenetur in distinctio quaerat, hic a soluta, veniam ut id porro adipisci molestias cumque perspiciatis asperiores facilis voluptatem.

Icon

Slide to power off

Color 🎨

You can use the color prop to change the theme color.

Default color: #1d4ed8 (--k-slide-action-theme)

color: #475569

Slide background
Fadein background
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Culpa non ipsum, pariatur in eveniet neque dolores sequi, numquam aspernatur ratione veritatis nemo earum maxime aut distinctio repellat dolorum ipsa deleniti!

Gradient slide background

Slide to see bg color change

Compact

Lorem ipsum dolor sit amet consectetur, adipisicing elit. Reiciendis ab, dicta consequatur harum iusto cumque, sunt quia dolor, adipisci commodi repellendus perferendis iste.
compact.tsx
<SlideAction compact />

Styling Elements

classNames and styles are 2 more available options for styling the <SlideAction> component.
See SlideActionStylingSelectors in the Special Types section below for available selectors.

Slide to see progress Lorem ipsum dolor sit, amet consectetur adipisicing elit. Consectetur amet ut repellat quia natus asperiores facere.

allowSwipeAfterEnd

Avoid enabling this flag as much as possible. If you wanna reset the component status, see the Reset section.

By default, users can NOT swipe this component after the action is settled/confirmed. Set allowSwipeAfterEnd to true to disable this behavior.

Successful / confirmatory action count: 0

Can swipe after success
allowSwipeAfterEnd.tsx
<SlideAction allowSwipeAfterEnd />

Special Types

NameTypeDescription
SlideActionOnSwipeEnd(reset: () => void) => voidType of onSwipeEnd callback
SlideActionOnChange(isSuccess: boolean) => voidType of onChange callback
SlideActionStylingSelectors'dragger' | 'label' | 'progress'Available selectors of special styles APIs: classNames, styles.
SlideActionRefHTMLDivElement & {resetState: () => void;}<SlideAction> element ref.
Call ref.resetState() to reset component status. See the reset section.

<SlideAction> Props

NameTypeDefaultDescription
childrenReactNodeWill be consider as a label. If provided, label prop will be ignored.
classNamesPartial<Record<SlideActionStylingSelectors, string>>Applies className to related selector element.
stylesPartial<Record<SlideActionStylingSelectors, CSSProperties>>Applies inline styles to related selector element.
iconReactNodeDouble arrow rightIcon for the swiper.
colorstring--k-slide-action-theme - #1d4ed8Component theme color.
Includes label, slide background, border and the dragger color
labelstring'Slide'
labelType'default' | 'slide''default'Label effect
slideType'slide' | 'static''slide'The left behind background color’s effect.
'slide': progress effect (default).
onSwipeEndSlideActionOnSwipeEndTrigger when users swiped all the way to the end.
Call the 1st argument to reset the component status. See the reset section.
onChangeSlideActionOnChangeTrigger when component’s status changes.
compactbooleanfalseCompact size.
allowSwipeAfterEndbooleanfalseSee the allowSwipeAfterEnd section.