PXD

Hold Button

Press and hold the button to trigger some logic (such as delete).

Default

HoldButton extends the Button component.

<script setup>
import confetti from 'canvas-confetti'

function onConfirm() {
  confetti()
}

function onFinished(isFinished) {
  if (!isFinished) {
    return
  }

  confetti({
    particleCount: 100,
    spread: 70,
    origin: { y: 0.7 },
  })
}
</script>

<template>
  <PHoldButton @confirm="onConfirm" @release="onFinished"> Hole me </PHoldButton>
</template>

Durations

Set the durations property to determine how long it will trigger.

It receives a number or a number of string type (if it cannot be converted by Number(), the default value will be 2000).

<template>
  <PHoldButton :durations="1000"> Lasts one second </PHoldButton>
</template>

Variants

You can set the same variant property as the button.

<template>
  <PStack>
    <PHoldButton>default</PHoldButton>
    <PHoldButton variant="ghost">ghost</PHoldButton>
    <PHoldButton variant="error">error</PHoldButton>
    <PHoldButton variant="primary" progress-color="var(--color-background-100)">primary</PHoldButton>
    <PHoldButton variant="success">success</PHoldButton>
    <PHoldButton disabled>disabled</PHoldButton>
    <PHoldButton loading>loading</PHoldButton>
  </PStack>
</template>

Colors

Set progress-color to modify the color of the progress bar.

<template>
  <PHoldButton durations="1000" progress-color="var(--color-red-500)"> Lasts one second </PHoldButton>
</template>

Cancelable

After cancelable is set, the process can be cancelled while mouse is holding and leaving the button. At the same time, you can listen to the cancel event to know when it has been cancelled.

<script setup>
import confetti from 'canvas-confetti'

function onCanceled() {
  alert('canceled')
}

function onFinished(isFinished) {
  if (isFinished) {
    confetti({
      particleCount: 100,
      spread: 70,
      origin: { y: 0.7 },
    })
  }
}
</script>

<template>
  <PHoldButton durations="1000" cancelable @cancel="onCanceled" @release="onFinished">
    Lasts one second
  </PHoldButton>
</template>

Scalable

Set scalable="false" to disable zooming when pressed.

<template>
  <PHoldButton durations="1000" :scalable="false"> Lasts one second </PHoldButton>
</template>

Props

NameTypeDefaultDescription
vibratebooleantrueVibrate the device for 100 ms after release
disabledboolean-Disable the button and ignore pointer interaction
scalablebooleantrueScale the button down while it is pressed
durationsnumber | string-Hold time in ms before confirm, defaults to 2000
cancelableboolean-Allow cancelling by moving the pointer off the button
progress-colorstring-CSS colour used for the filling progress overlay

Events

NameTypeDescription
cancel() => voidEmitted when a holding pointer leaves the button while cancelable is set.
confirm() => voidEmitted when the progress overlay has fully filled up.
release(confirmed: boolean) => voidEmitted when the pointer is released or cancelled after a press.
pointerup(ev: PointerEvent) => voidEmitted together with release when the document receives a pointer release after a press.
pointerdown(ev: PointerEvent) => voidEmitted when the button is pressed.

Slots

NameDescription
defaultDefault slot

Source

Source