Skip to content

Slide Action

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

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

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

How to reset the component status?

Call reset function that shipped with onSwipeEnd callback.

Crafting demo...
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}
/>
)
  • slideType: the slide progress effect.
  • labelType: label effect.
Crafting demo...
Crafting demo...

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

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

Crafting demo...
Crafting demo...
compact.tsx
<SlideAction compact />

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

Crafting demo...

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.

Crafting demo...
allowSwipeAfterEnd.tsx
<SlideAction allowSwipeAfterEnd />
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.
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.
iconReactElementDouble 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.