Timer button
Timer button component, a button with a bar that fills while time passes and calls a function when it is full, for autoplay, tours and undo actions, and a hold to confirm button.
How to use it
Run npx @blossomui/react add timer-button, or copy src/components/UI/TimerButton/TimerButton.tsx into your React project and import it.
import { TimerButton, HoldButton } from './components/ui/TimerButton'Props
TimerButtonLabels
| Prop | Type | Description |
|---|---|---|
| pause (required) | string | Accessible name of the button while it counts. |
| play (required) | string | Accessible name of the button while it is paused. |
| remaining (required) | (seconds: number) => string | Text with the time that is left, for example "4s". |
TimerButtonProps
| Prop | Type | Description |
|---|---|---|
| labels | Partial<TimerButtonLabels> | Texts of the component. Pass only the ones you want to change, for example to translate it. |
| duration | number | Milliseconds the bar takes to fill. |
| onComplete | () => void | Called every time the bar is full. Use it to go to the next slide, the next step, to submit... |
| loop | boolean | Start again after it is full. With `false` it stops and waits for the user. |
| running | boolean | Controlled state. Use together with `onRunningChange`. |
| defaultRunning | boolean | Initial state when the button is not controlled. Autoplay should not start by itself for people who asked for less motion, so check `prefers-reduced-motion` before you pass `true`. |
| onRunningChange | (running: boolean) => void | |
| resetKey | unknown | When this value changes the bar starts from zero, for example the number of the current slide. |
| showTime | boolean | Show the seconds that are left. |
| children | ReactNode | Text of the button, for example "Auto". |
| size | 'sm' | 'md' | 'lg' | |
| color | string | Accent color of the bar: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| className | string |
HoldButtonProps
| Prop | Type | Description |
|---|---|---|
| children (required) | ReactNode | Text of the button, for example "Hold to delete". |
| onComplete | () => void | Called once, when the button was held for the whole `duration`. |
| duration | number | Milliseconds the button has to be held. |
| hint | string | Explains the gesture to screen readers. |
| disabled | boolean | |
| size | 'sm' | 'md' | 'lg' | |
| color | string | Accent color of the bar: any CSS color. Without it the component uses `--blossom-accent`, which is pink by default. |
| className | string |