Buttons

Cancel With Elapsed

Cancelling a long operation with an honest timer: elapsed time ticks in monospace figures, and past a threshold the plate changes tone and explains the delay.

  • button
  • cancel
  • progress
  • async

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/button-061?lang=en

Importing 4,210 rows00:00
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "button-061" (Cancel With Elapsed) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/button-061.json

Registry item: https://vibeui.ru/r/button-061.json
Installs to: components/vibeui/button-061.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
Cancelling a long operation with an honest timer: elapsed time ticks in monospace figures, and past a threshold the plate changes tone and explains the delay.

A running-operation plate with a cancel button. A spinner turns on the left, the middle says what is happening and how long it has taken, and Cancel sits on the right. Past the slowAfter threshold the tone turns to warning and a 'longer than usual' line appears, so cancelling stops looking like panic. Zero dependencies, one file.

## 3. How to use it
import { Button061 } from "@/components/vibeui/button-061"

<Button061 running={isImporting} task="Importing 4,210 rows" slowAfter={20} onCancel={abort}>
  Cancel
</Button061>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the elapsed time: without it there is no telling whether the operation runs or hangs, and cancelling becomes guesswork
- the slowAfter threshold and the tone change: it separates 'working' from 'something is wrong'
- monospace digits with tabular-nums — otherwise the plate twitches every second
- clearing the interval in the useEffect cleanup: otherwise timers pile up on every restart
- the cancel button as a separate element rather than the whole plate: a stray click on the row must not abort the work
- disabling the button once the operation is over — there is nothing left to cancel

## 6. You may change
- the cancel button's label
- the operation description through the task prop
- the running flag through the running prop, owned by your app
- the delay threshold through the slowAfter prop, in seconds
- the delay line through the slowHint prop, and the accent colour through the accent prop

## 7. Rules
- The component neither runs nor aborts anything: it counts time and calls onCancel, the abort is your app's job.
- Switch running to false when the work is done — otherwise the timer keeps going and lies about the state.
- Do not set slowAfter below the operation's typical duration: the warning would always show and stop meaning anything.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/button-061.json
https://vibeui.ru/r/button-061.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-button-061-*. Клиентский компонент: интервал заводится в useEffect при running и снимается при остановке или размонтировании, счётчик сбрасывается на каждом запуске. Сама операция живёт в приложении — компонент только считает время и зовёт onCancel. Порог slowAfter в секундах переводит плашку в предупреждающий тон через data-slow; спиннер и рамка меняют цвет вместе. Время выведено моноширинным с tabular-nums.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useEffect, useState } from "react"
import type {
  ComponentPropsWithoutRef,
  CSSProperties,
  MouseEventHandler,
} from "react"

export type Button061Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onClick"
> & {
  children?: string
  /** Что именно выполняется: строка над таймером. */
  task?: string
  /** Операция идёт. Управляется снаружи: компонент ничего не выполняет. */
  running?: boolean
  /** Секунды, после которых операция считается затянувшейся. */
  slowAfter?: number
  slowHint?: string
  onCancel?: MouseEventHandler<HTMLButtonElement>
  accent?: string
}

// Идея компонента: отмена длительной операции с честным таймером. Кнопка
// «Отменить» рядом с прошедшим временем отвечает на вопрос «оно вообще
// живо?» — а после порога slowAfter плашка меняет тон и добавляет строку
// про задержку, чтобы отмена перестала выглядеть паникой. Время считает
// сам компонент, работу — приложение.
const STYLES = `
:where([data-vibeui-block="button-061"]){
--vibeui-button-061-surface:oklch(1 0 0);
--vibeui-button-061-border:oklch(0.89 0.006 265);
--vibeui-button-061-fg:oklch(0.26 0.02 265);
--vibeui-button-061-muted:oklch(0.56 0.014 265);
--vibeui-button-061-accent:oklch(0.55 0.16 250);
--vibeui-button-061-warn:oklch(0.62 0.15 70);
--vibeui-button-061-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
--vibeui-button-061-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace;
}
[data-vibeui-block="button-061"]{
display:flex;align-items:center;gap:0.75rem;box-sizing:border-box;
width:100%;max-width:23rem;padding:0.625rem 0.625rem 0.625rem 0.875rem;
border:1px solid var(--vibeui-button-061-border);border-radius:0.875rem;
background:var(--vibeui-button-061-surface);color:var(--vibeui-button-061-fg);
font-family:var(--vibeui-button-061-font);
transition:border-color .2s ease,background-color .2s ease;
}
[data-vibeui-block="button-061"][data-slow="true"]{
border-color:var(--vibeui-button-061-warn);
background:color-mix(in oklab,var(--vibeui-button-061-warn) 7%,var(--vibeui-button-061-surface));
}
[data-vibeui-block="button-061"] [data-part="spinner"]{
flex:none;width:1.125rem;height:1.125rem;border-radius:50%;
border:2px solid color-mix(in oklab,var(--vibeui-button-061-accent) 25%,transparent);
border-top-color:var(--vibeui-button-061-accent);
animation:vibeui-button-061-spin .9s linear infinite;
}
[data-vibeui-block="button-061"][data-slow="true"] [data-part="spinner"]{
border-color:color-mix(in oklab,var(--vibeui-button-061-warn) 30%,transparent);
border-top-color:var(--vibeui-button-061-warn);
}
[data-vibeui-block="button-061"][data-running="false"] [data-part="spinner"]{
animation:none;border-top-color:var(--vibeui-button-061-muted);
}
@keyframes vibeui-button-061-spin{to{transform:rotate(360deg)}}
[data-vibeui-block="button-061"] [data-part="text"]{display:flex;flex-direction:column;gap:0.1875rem;min-width:0;flex:1}
[data-vibeui-block="button-061"] [data-part="task"]{
font-size:0.875rem;font-weight:650;line-height:1.2;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
[data-vibeui-block="button-061"] [data-part="meta"]{
display:flex;align-items:center;gap:0.375rem;
font-size:0.75rem;color:var(--vibeui-button-061-muted);
}
[data-vibeui-block="button-061"] [data-part="clock"]{
font-family:var(--vibeui-button-061-mono);font-variant-numeric:tabular-nums;
letter-spacing:0.02em;
}
[data-vibeui-block="button-061"][data-slow="true"] [data-part="meta"]{color:var(--vibeui-button-061-warn)}
[data-vibeui-block="button-061"] [data-part="cancel"]{
appearance:none;cursor:pointer;flex:none;
height:2.125rem;padding:0 0.875rem;border-radius:0.5rem;
border:1px solid var(--vibeui-button-061-border);
background:transparent;color:var(--vibeui-button-061-fg);
font:inherit;font-size:0.8125rem;font-weight:650;line-height:1;
transition:border-color .16s ease,color .16s ease,background-color .16s ease;
}
[data-vibeui-block="button-061"] [data-part="cancel"]:hover:not(:disabled){
border-color:var(--vibeui-button-061-warn);color:var(--vibeui-button-061-warn);
background:color-mix(in oklab,var(--vibeui-button-061-warn) 10%,transparent);
}
[data-vibeui-block="button-061"] [data-part="cancel"]:focus-visible{outline:2px solid var(--vibeui-button-061-warn);outline-offset:2px}
[data-vibeui-block="button-061"] [data-part="cancel"]:disabled{cursor:not-allowed;opacity:.45}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="button-061"] *{animation:none!important;transition:none!important}}
`

function clock(seconds: number) {
  const minutes = Math.floor(seconds / 60)

  return `${String(minutes).padStart(2, "0")}:${String(seconds % 60).padStart(2, "0")}`
}

/**
 * Отмена длительной операции с прошедшим временем и порогом «дольше обычного».
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Button061({
  children = "Отменить",
  task = "Импортируем 4 210 строк",
  running = true,
  slowAfter = 20,
  slowHint = "дольше обычного",
  onCancel,
  accent,
  className,
  style,
  ...props
}: Button061Props) {
  // В состоянии лежит отметка запуска вместе с числом секунд: сбрасывать
  // счётчик отдельным вызовом из эффекта нельзя, а по паре видно, относится
  // ли прошлое значение к текущему запуску.
  const [tick, setTick] = useState<{ startedAt: number; seconds: number }>({
    startedAt: 0,
    seconds: 0,
  })

  useEffect(() => {
    if (!running) return

    const startedAt = Date.now()

    const timer = window.setInterval(() => {
      setTick({
        startedAt,
        seconds: Math.round((Date.now() - startedAt) / 1000),
      })
    }, 1000)

    return () => window.clearInterval(timer)
  }, [running])

  const seconds = running ? tick.seconds : 0

  const slow = running && seconds >= slowAfter

  const palette = {
    ...(accent ? { "--vibeui-button-061-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-button-061" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="button-061"
        data-running={String(running)}
        data-slow={String(slow)}
        className={className}
        style={palette}
      >
        <span data-part="spinner" aria-hidden="true" />
        <span data-part="text">
          <span data-part="task">{task}</span>
          <span data-part="meta">
            <span data-part="clock">{clock(seconds)}</span>
            {slow ? <span data-part="slow">· {slowHint}</span> : null}
          </span>
        </span>
        <button
          type="button"
          data-part="cancel"
          disabled={!running}
          onClick={onCancel}
        >
          {children}
        </button>
      </div>
    </>
  )
}