import { Context } from "@replicas/ui";

export default function ContextDemo() {
  return (
    <Context.Root>
      <Context.Trigger value={84_300} max={200_000} />
      <Context.Popup>
        <Context.Header value="84.3K / 200K" />
        <Context.Bar value={84_300} max={200_000} />
        <Context.Rows>
          <Context.Row label="Input" value="61.2K" />
          <Context.Row label="Output" value="9.8K" />
          <Context.Row label="Reasoning" value="13.3K" />
          <Context.Row label="Cache read" value="40.1K" />
        </Context.Rows>
        <Context.Footer>
          <span>Cost</span>
          <span>$0.42</span>
        </Context.Footer>
      </Context.Popup>
    </Context.Root>
  );
}

Prompt

Copy Prompt hands your agent everything it needs to build the Context in the Codex style: the measured tokens, the CSS and the structure.

Show Prompt
# Codex Context

How much of the model's context window the conversation has used.

Build a Context in this project that looks and behaves like Codex's. Measured from the running Codex app (openai.com/codex). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or Base UI primitives if it has none.

Fidelity: Partly measured from the Codex composer context ring and its tooltip. The 12px ring and ink tooltip match the live app. The usage bar, token rows and cost footer aren’t in the app and are derived.

## Tokens

| Token | Light | Dark |
| --- | --- | --- |
| `--text-tertiary` | `rgb(21 28 42 / 0.494)` | `rgb(255 255 255 / 0.498)` |
| `--ghost-bg-hover` | `rgb(26 28 31 / 0.055)` | `rgb(255 255 255 / 0.078)` |
| `--ink-surface` | `#1a1c1f` | `#2d2d2d` |
| `--ink-text` | `#ffffff` | `#ffffff` |
| `--tooltip-border` | `rgb(255 255 255 / 0.05)` | `rgb(255 255 255 / 0.05)` |
| `--focus-ring` | `#339cff` | `rgb(131 195 255 / 0.76)` |
| `--font-regular` | `-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif` | `-apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif` |
| `--font-size-mini` | `12px` | `12px` |
| `--font-size-small` | `13px` | `13px` |
| `--font-weight-normal` | `430` | `430` |
| `--radius-2xl` | `calc(16px * var(--radius-scale))` | `calc(16px * var(--radius-scale))` |
| `--radius-rounded` | `9999px` | `9999px` |
| `--cubic-enter` | `cubic-bezier(0.19, 1, 0.22, 1)` | `cubic-bezier(0.19, 1, 0.22, 1)` |
| `--cubic-exit` | `cubic-bezier(0.8, 0, 0.4, 1)` | `cubic-bezier(0.8, 0, 0.4, 1)` |
| `--ease-basic` | `ease` | `ease` |
| `--duration-basic` | `0.15s` | `0.15s` |
| `--duration-menu-exit` | `0.1s` | `0.1s` |
| `--duration-tooltip` | `0.25s` | `0.25s` |

## CSS

Scoped under `[data-style="codex"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.

```css
[data-style="codex"] {
  .ui-context-trigger {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 28px;
    height: 28px;
    margin: 0;
    padding: 0 7px;
    flex-shrink: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-rounded);
    background: none;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: var(--font-size-small);
    line-height: 18px;
    cursor: default;
    transition: background-color var(--duration-basic) var(--ease-basic);

    &:hover,
    &[data-popup-open] {
      background-color: var(--ghost-bg-hover);
    }

    &:focus-visible {
      outline: 2px solid var(--focus-ring);
      outline-offset: -2px;
    }
  }

  .ui-context-ring {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
  }

  .ui-context-ring-track {
    stroke: currentColor;
    opacity: 0.16;
  }

  .ui-context-ring-value {
    stroke: currentColor;
    stroke-linecap: round;
    transition: stroke-dasharray 120ms ease-out;
  }

  .ui-context-percent {
    display: none;
  }

  .ui-context-positioner {
    z-index: 50;
    outline: none;
  }

  .ui-context-popup {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid var(--tooltip-border);
    border-radius: var(--radius-2xl);
    background-color: var(--ink-surface);
    color: var(--ink-text);
    font-family: var(--font-regular);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-normal);
    line-height: 18px;
    letter-spacing: -0.15px;
    outline: none;
    transform-origin: var(--transform-origin);
    transition:
      opacity var(--duration-tooltip) var(--cubic-enter),
      scale var(--duration-tooltip) var(--cubic-enter);

    &[data-starting-style],
    &[data-ending-style] {
      opacity: 0;
      scale: 0.96;
    }

    &[data-ending-style] {
      transition-duration: var(--duration-menu-exit);
      transition-timing-function: var(--cubic-exit);
    }
  }

  .ui-context-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .ui-context-title {
    opacity: 0.6;
  }

  .ui-context-value {
    font-variant-numeric: tabular-nums;
  }

  .ui-context-bar {
    height: 4px;
    overflow: hidden;
    border-radius: var(--radius-rounded);
    background-color: color-mix(in srgb, var(--ink-text) 16%, transparent);
  }

  .ui-context-bar-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background-color: currentColor;
  }

  .ui-context-rows {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
  }

  .ui-context-row,
  .ui-context-footer {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    font-size: var(--font-size-mini);
    line-height: 16px;
  }

  .ui-context-row-label {
    opacity: 0.6;
  }

  .ui-context-row-value {
    margin: 0;
    font-variant-numeric: tabular-nums;
  }

  .ui-context-footer {
    padding-top: 6px;
    border-top: 1px solid color-mix(in srgb, var(--ink-text) 10%, transparent);

    & > :first-child {
      opacity: 0.6;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .ui-context-trigger,
    .ui-context-ring-value,
    .ui-context-popup {
      transition: none;
    }
  }
}
```

## Structure

How Replicas assembles it on Base UI.

```tsx
import { PreviewCard as BasePreviewCard } from "@base-ui/react/preview-card";
import type { ComponentProps, ReactNode } from "react";
import { usePortalContainer } from "./portal";
import { join } from "./utils";

const percent = (value: number, max: number) => Math.min(100, Math.max(0, max > 0 ? (value / max) * 100 : 0));

type TriggerProps = Omit<BasePreviewCard.Trigger.Props, "className"> & {
  className?: string;
  value: number;
  max: number;
};

function Trigger({ className, value, max, delay = 100, children, ...props }: TriggerProps) {
  const used = percent(value, max);
  return (
    <BasePreviewCard.Trigger
      className={join("ui-context-trigger", className)}
      render={<button type="button" />}
      delay={delay}
      aria-label={`${Math.round(used)}% of context used`}
      {...props}
    >
      <svg className="ui-context-ring" viewBox="0 0 16 16" fill="none" aria-hidden>
        <circle className="ui-context-ring-track" cx="8" cy="8" r="6" strokeWidth="2" />
        <circle
          className="ui-context-ring-value"
          cx="8"
          cy="8"
          r="6"
          strokeWidth="2"
          pathLength={100}
          strokeDasharray={`${used} 100`}
          transform="rotate(-90 8 8)"
        />
      </svg>
      {children ?? <span className="ui-context-percent">{Math.round(used)}%</span>}
    </BasePreviewCard.Trigger>
  );
}

type PopupProps = Omit<BasePreviewCard.Popup.Props, "className"> & {
  className?: string;
  side?: BasePreviewCard.Positioner.Props["side"];
  align?: BasePreviewCard.Positioner.Props["align"];
  sideOffset?: number;
};

function Popup({ className, side = "top", align = "end", sideOffset = 8, ...props }: PopupProps) {
  return (
    <BasePreviewCard.Portal container={usePortalContainer()}>
      <BasePreviewCard.Positioner className="ui-context-positioner" side={side} align={align} sideOffset={sideOffset}>
        <BasePreviewCard.Popup className={join("ui-context-popup", className)} {...props} />
      </BasePreviewCard.Positioner>
    </BasePreviewCard.Portal>
  );
}

type HeaderProps = Omit<ComponentProps<"div">, "title"> & { title?: ReactNode; value: ReactNode };

function Header({ className, title = "Context", value, ...props }: HeaderProps) {
  return (
    <div className={join("ui-context-header", className)} {...props}>
      <span className="ui-context-title">{title}</span>
      <span className="ui-context-value">{value}</span>
    </div>
  );
}

function Bar({ className, value, max, ...props }: ComponentProps<"div"> & { value: number; max: number }) {
  return (
    <div className={join("ui-context-bar", className)} aria-hidden {...props}>
      <span className="ui-context-bar-fill" style={{ width: `${percent(value, max)}%` }} />
    </div>
  );
}

function Rows({ className, ...props }: ComponentProps<"dl">) {
  return <dl className={join("ui-context-rows", className)} {...props} />;
}

type RowProps = Omit<ComponentProps<"div">, "children"> & { label: ReactNode; value: ReactNode };

function Row({ className, label, value, ...props }: RowProps) {
  return (
    <div className={join("ui-context-row", className)} {...props}>
      <dt className="ui-context-row-label">{label}</dt>
      <dd className="ui-context-row-value">{value}</dd>
    </div>
  );
}

function Footer({ className, ...props }: ComponentProps<"div">) {
  return <div className={join("ui-context-footer", className)} {...props} />;
}

export const Context = {
  Root: BasePreviewCard.Root,
  Trigger,
  Popup,
  Header,
  Bar,
  Rows,
  Row,
  Footer,
};
```

## Example

```tsx
import { Context } from "@replicas/ui";

export default function ContextDemo() {
  return (
    <Context.Root>
      <Context.Trigger value={84_300} max={200_000} />
      <Context.Popup>
        <Context.Header value="84.3K / 200K" />
        <Context.Bar value={84_300} max={200_000} />
        <Context.Rows>
          <Context.Row label="Input" value="61.2K" />
          <Context.Row label="Output" value="9.8K" />
          <Context.Row label="Reasoning" value="13.3K" />
          <Context.Row label="Cache read" value="40.1K" />
        </Context.Rows>
        <Context.Footer>
          <span>Cost</span>
          <span>$0.42</span>
        </Context.Footer>
      </Context.Popup>
    </Context.Root>
  );
}
```

## Foundations

The rest of the Codex style, as a skill: https://replicas.raphaelsalaja.com/skills/codex/SKILL.md