Skip to content

Extend timer api with current state for useToastState #4649

Open
@yarastqt

Description

@yarastqt

🙋 Feature Request

Provide timer state (ex. isRunning) for toast.

🤔 Expected Behavior

A toast.timer provide state of current timer.

😯 Current Behavior

A toast.timer has private property timerId for check timer state.

💁 Possible Solution

Add property isRunning for Timer (or state="running | paused"):

class Timer {
private timerId;
private startTime: number;
private remaining: number;
private callback: () => void;

🔦 Context

I create toasts with progress bar and when toast is hovered we can't stop animation because timer api doesn't have current state.

💻 Examples

function Snackbar<T>(props: ToastProps<T>) {
  const { toast } = props;

  // @ts-expect-error (timerId is private API)
  const timerId = toast?.timer?.timerId;

  return (
    <div className={styles.root}>
      <div
        className={styles.progress}
        style={{
          animationDuration: `${toast.timeout}ms`,
          animationPlayState: timerId === null ? "paused" : "running",
          // Better solution:
          // animationPlayState: toast.timer.isRunning ? "running" : "paused",
        }}
      />
    </div>
  );
}

🧢 Your Company/Team

Yandex

🎁 Tracking Ticket (optional)

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      📋 Waiting for Sprint

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions