---
title: "Queue"
description: "Separate remaining work from completed items."
---

# Queue

Separate remaining work from completed items.

## Usage

Expand pending and completed groups. Replay moves the scripted tasks through their statuses.

## Example

```contract
use uiFontFamily, BubbleFrame from "@rightui/ui"
use ButtonAI as ButtonContent from "@rightui/ui"
use TraceFrame, TraceLine, TraceCollapsible, TraceDisclosure, TraceSource, CodeBlockContent from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state started = -1
  derive elapsed = started < 0 ? 15600 : max(0, rightuiDemoTime - started)
  derive busy = elapsed < 5600
  action replay
    started = rightuiDemoTime
    rightuiRunDemo(9600)
  view
    column gap="ui.space-16" min-width=0 min-height=288 max-width="24rem" width="100%" padding="ui.space-24 ui.space-0"
      BubbleFrame(id="ai-queue-question", align="end", variant="muted")
        text "Add dark mode to the settings page." font-family=uiFontFamily(uiFont) data-rightui-font="body"
      TraceFrame()
      if elapsed < 5600
        TraceCollapsible(id="ai-queue-pending", title=((4 - min(4, floor(elapsed / 1400))).toString() + " to do"), icon="list", status="", initiallyOpen=true, reduced=reduced)
          if elapsed < 1400
            TraceLine(title="Add a dark variant to the theme tokens", icon=(elapsed >= 0 ? "dot" : "check"), status=(elapsed >= 0 ? "running" : "pending"), reduced=reduced)
          if elapsed < 2800
            TraceLine(title="Read the theme from a cookie", icon=(elapsed >= 1400 ? "dot" : "check"), status=(elapsed >= 1400 ? "running" : "pending"), reduced=reduced)
          if elapsed < 4200
            TraceLine(title="Add a toggle to the settings page", icon=(elapsed >= 2800 ? "dot" : "check"), status=(elapsed >= 2800 ? "running" : "pending"), reduced=reduced)
          if elapsed < 5600
            TraceLine(title="Check contrast on the charts", icon=(elapsed >= 4200 ? "dot" : "check"), status=(elapsed >= 4200 ? "running" : "pending"), reduced=reduced)
      if elapsed >= 1400
        TraceCollapsible(id="ai-queue-0", title=(min(4, floor(elapsed / 1400)).toString() + " completed"), icon="list", status="", initiallyOpen=true, reduced=reduced)
          if elapsed >= 1400
            TraceLine(title="Add a dark variant to the theme tokens", icon="check", status="", reduced=reduced)
          if elapsed >= 2800
            TraceLine(title="Read the theme from a cookie", icon="check", status="", reduced=reduced)
          if elapsed >= 4200
            TraceLine(title="Add a toggle to the settings page", icon="check", status="", reduced=reduced)
          if elapsed >= 5600
            TraceLine(title="Check contrast on the charts", icon="check", status="", reduced=reduced)
      if elapsed >= 5600
        text "Dark mode is in. The toggle is under Settings, Appearance.".slice(0, started < 0 or reduced ? 58 : floor((elapsed - 5600) / 20)) font-size="ui.text-sm" line-height="ui.leading-relaxed" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if not busy
        row margin-top="auto" align-items="flex-start"
          ButtonContent(id="ai-queue-replay", label="Replay", variant="outline", size="sm", disabled=false, press=replay)
            text "Replay" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```

## Keyboard

Tab to actions and disclosures; Enter or Space activates them.

## Demo runtime

Timed examples use an injected clock. Add these members to your root component. Replace the scripted state with events from your TypeScript or Rust data source when connecting a model.

```contract
use defaultFontWeights from "@rightui/ui"
  state demoTime = 0
  state demoUntil = 0
  provide
    uiFont = "theme"
    uiWeights = defaultFontWeights()
    rightuiDemoTime = demoTime
    rightuiRunDemo = runDemo
  action runDemo(duration: number)
    demoUntil = max(demoUntil, demoTime + duration)
  action tickDemo
    demoTime = min(demoUntil, demoTime + 32)
  task demoClock when demoTime < demoUntil
    every(32, tickDemo)
```

## Source

File: patterns/ai-elements/queue.contract

```contract
use uiFontFamily, BubbleFrame from "@rightui/ui"
use ButtonAI as ButtonContent from "@rightui/ui"
use TraceFrame, TraceLine, TraceCollapsible, TraceDisclosure, TraceSource, CodeBlockContent from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiFont: string
    rightuiDemoTime: number
    rightuiRunDemo: action
  state started = -1
  derive elapsed = started < 0 ? 15600 : max(0, rightuiDemoTime - started)
  derive busy = elapsed < 5600
  action replay
    started = rightuiDemoTime
    rightuiRunDemo(9600)
  view
    column gap="ui.space-16" min-width=0 min-height=288 max-width="24rem" width="100%" padding="ui.space-24 ui.space-0"
      BubbleFrame(id="ai-queue-question", align="end", variant="muted")
        text "Add dark mode to the settings page." font-family=uiFontFamily(uiFont) data-rightui-font="body"
      TraceFrame()
      if elapsed < 5600
        TraceCollapsible(id="ai-queue-pending", title=((4 - min(4, floor(elapsed / 1400))).toString() + " to do"), icon="list", status="", initiallyOpen=true, reduced=reduced)
          if elapsed < 1400
            TraceLine(title="Add a dark variant to the theme tokens", icon=(elapsed >= 0 ? "dot" : "check"), status=(elapsed >= 0 ? "running" : "pending"), reduced=reduced)
          if elapsed < 2800
            TraceLine(title="Read the theme from a cookie", icon=(elapsed >= 1400 ? "dot" : "check"), status=(elapsed >= 1400 ? "running" : "pending"), reduced=reduced)
          if elapsed < 4200
            TraceLine(title="Add a toggle to the settings page", icon=(elapsed >= 2800 ? "dot" : "check"), status=(elapsed >= 2800 ? "running" : "pending"), reduced=reduced)
          if elapsed < 5600
            TraceLine(title="Check contrast on the charts", icon=(elapsed >= 4200 ? "dot" : "check"), status=(elapsed >= 4200 ? "running" : "pending"), reduced=reduced)
      if elapsed >= 1400
        TraceCollapsible(id="ai-queue-0", title=(min(4, floor(elapsed / 1400)).toString() + " completed"), icon="list", status="", initiallyOpen=true, reduced=reduced)
          if elapsed >= 1400
            TraceLine(title="Add a dark variant to the theme tokens", icon="check", status="", reduced=reduced)
          if elapsed >= 2800
            TraceLine(title="Read the theme from a cookie", icon="check", status="", reduced=reduced)
          if elapsed >= 4200
            TraceLine(title="Add a toggle to the settings page", icon="check", status="", reduced=reduced)
          if elapsed >= 5600
            TraceLine(title="Check contrast on the charts", icon="check", status="", reduced=reduced)
      if elapsed >= 5600
        text "Dark mode is in. The toggle is under Settings, Appearance.".slice(0, started < 0 or reduced ? 58 : floor((elapsed - 5600) / 20)) font-size="ui.text-sm" line-height="ui.leading-relaxed" font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if not busy
        row margin-top="auto" align-items="flex-start"
          ButtonContent(id="ai-queue-replay", label="Replay", variant="outline", size="sm", disabled=false, press=replay)
            text "Replay" font-family=uiFontFamily(uiFont) data-rightui-font="body"

```
