Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Commit for Vue UI SDK

A git commit an agent made, as one card: its message, short hash, author and time, with the changed files below. For Vue on UI SDK.

On this page11 sections

Commit shows a git commit as one card: the message, the short hash, who made it and when, and a button that copies the full hash. The files it changed open below, each with a letter for what happened to it and its line counts.

Use it when a coding agent commits during a chat, so the reader sees what changed without opening git. One edited file reads better as a Trace line, and the diff itself belongs in a Code Block.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Commit anatomy: root, header, message, copy button, content, file status

Usage

<script setup lang="ts">
import {
  Commit, CommitActions, CommitContent, CommitCopyButton, CommitFile,
  CommitFileAdditions, CommitFileChanges, CommitFileDeletions,
  CommitFileIcon, CommitFileInfo, CommitFilePath, CommitFiles,
  CommitFileStatus, CommitHash, CommitHeader, CommitInfo, CommitMessage,
  CommitMetadata, CommitSeparator, CommitTimestamp,
} from "@/components/ui/commit";
</script>
<Commit>
  <CommitHeader>
    <CommitInfo>
      <CommitMessage>Add user authentication flow</CommitMessage>
      <CommitMetadata>
        <CommitHash>a1b2c3d</CommitHash>
        <CommitSeparator />
        <CommitTimestamp date={new Date("2026-10-21T14:30:00Z")} />
      </CommitMetadata>
    </CommitInfo>
    <CommitActions>
      <CommitCopyButton hash="a1b2c3d4e5f6" />
    </CommitActions>
  </CommitHeader>
  <CommitContent>
    <CommitFiles>
      <CommitFile>
        <CommitFileInfo>
          <CommitFileStatus status="added" />
          <CommitFileIcon />
          <CommitFilePath>src/auth/login.tsx</CommitFilePath>
        </CommitFileInfo>
        <CommitFileChanges>
          <CommitFileAdditions count={45} />
          <CommitFileDeletions count={0} />
        </CommitFileChanges>
      </CommitFile>
    </CommitFiles>
  </CommitContent>
</Commit>

CommitHeader lays one invisible button over the whole row, so a click anywhere on it opens the file list. CommitActions sits above that button, which is why the copy button still takes its own click.

Accessibility

The header's trigger is a native <button> with aria-expanded, named by label on CommitHeader, Changed files unless you set it. The message, hash and time beside it are read as plain text, so on a page with several commits give each header a label that names its commit, as the History demo does. On a card with no CommitContent, set collapsible to false on CommitHeader, which leaves out the button and the chevron. CommitFiles is a list, each status letter is read as its word, and the line counts end in lines added and lines removed. The copy button is named Copy commit hash and announces Copied once the hash is on the clipboard.

Tab
Moves focus to the header's trigger, then to the copy button and anything else in CommitActions.
Shift+Tab
Moves focus to the previous focusable element.
Enter
When focus is on the header's trigger, opens or closes the file list. On the copy button, copies the hash.
Space
When focus is on the header's trigger, opens or closes the file list. On the copy button, copies the hash.

Demos

File statuses

Replace the throttle with a rate limiter opens on four files, one for each status of CommitFileStatus: added, modified, deleted and renamed. A, M and R take the success, warning and info colors the install adds for light and dark, D takes the theme's destructive color, and screen readers hear the word. The renamed file shows no line counts, because a count of 0 renders nothing.

Preview width

Author

Two commits with CommitAuthor at the start of the header: one from shadcn with a picture in src, one from Coding agent with only its initials, AI, and each name in CommitMetadata. Neither card has a file list, so collapsible is set to false and the header has no button or chevron. Show the author when people and agents commit to the same branch.

Preview width

History

Three commits from one checkout task, newest first, each closed until the reader opens it. The metadata ends in a file count, 1 file or 2 files, so the reader knows how much is inside. Each header's label names its commit, such as Changed files in Drop the legacy charge path, so a screen reader can tell the three buttons apart.

Preview width

Copy

Cache the model list for an hour shows 3f9e2a1 in its header, and its copy button writes the whole 40-character hash. The demo's @copy handler writes Copied 3f9e2a1… under the card, its @error handler writes a message when the browser blocks the clipboard, and timeout keeps the check for 1.5 seconds instead of 2.

Preview width

AI SDK

Give the agent a tool that commits and returns the commit, gitCommit in this example: its hash, message and date, and each changed file with its status from git show --name-status and its line counts from git show --numstat. Render a Commit for each call whose output has arrived.

import { Chat } from "@ai-sdk/vue";
import { computed } from "vue";

const chat = new Chat({});

const commits = computed(() =>
  (chat.messages.at(-1)?.parts ?? [])
    .filter((part) => part.type === "tool-gitCommit")
    .filter((part) => part.state === "output-available")
    .map((part) => part.output)
);

Each output maps onto the parts:

Output fieldPart
messageCommitMessage
hashCommitHash (its first 7 characters) and CommitCopyButton's hash
date (an ISO string)CommitTimestamp's date, as new Date(date)
files[].pathCommitFilePath
files[].statusCommitFileStatus's status: added, modified, deleted or renamed
files[].additions, files[].deletionsCommitFileAdditions and CommitFileDeletions' count

Migrating from AI SDK Elements

AI SDK Elements is for React. In Vue, the parts have the same names and props, so its examples still read as a guide.

FAQ

When should I use a Commit card instead of a Trace line?

Use Commit when the commit itself is the news: the agent finished a piece of work and the reader wants its message, hash and the list of files it touched in one place. It suits the end of a task, or a short history of the commits one task made.

While the agent is still working, its edits read better as Trace lines, Edited app/login/page.tsx with +2 −2 after it, which can open each diff in a sheet. Trace's own Commit demo draws a commit that way, as one line that expands.

What file statuses does the Commit component show?

Four: added, modified, deleted and renamed, set with status on CommitFileStatus. Each shows its letter, A, M, D or R, in its own color, and screen readers hear the whole word instead of the letter.

The File statuses demo has one of each. Git's other states, such as copied or type changed, have no value of their own here, so map each to the nearest of the four.

How do I show the lines added and removed in a Commit?

Put CommitFileAdditions and CommitFileDeletions inside CommitFileChanges and pass each its count. They show +45 in green and −3 in red, and screen readers hear 45 lines added and 3 lines removed.

A count of 0 renders nothing, so a renamed file with no edits stays clean, and a binary file, which git show --numstat reports with a dash instead of a number, can pass 0 to show no counts at all.

How do I show a Commit's changed files open by default?

Set defaultOpen on Commit, as the File statuses demo does. Every card starts closed without it.

To open and close it from your own code, bind a ref to it with v-model:open, which reads and writes the open state as a boolean.

How does the copy button on a Commit work?

CommitCopyButton writes its hash to the clipboard, swaps its icon for a check for timeout milliseconds, 2000 by default, and announces Copied to screen readers. Pass the full hash, even when CommitHash shows only seven characters.

Listen with @copy for a copy, and with @error for when the browser refuses, as on a page served over plain HTTP. The Copy demo writes both to a line under the card.

Why does the Commit timestamp show a date first, then 2 hours ago?

The server can't know the reader's clock, so CommitTimestamp writes the date in UTC until the page runs, and the server's HTML and the browser's first render agree. Then it switches to words such as 2 hours ago or yesterday, and hovering shows the full date and time.

locale sets the language of both, en-US by default. To write your own words instead, put them inside CommitTimestamp, and the time element keeps the exact date in its datetime attribute.

Can I open a Commit with the keyboard?

Yes. The header's trigger is a real button: Tab reaches it, and Enter or Space opens and closes the file list. Tab then moves on to the copy button, which sits above the trigger rather than inside it, so each control has its own stop.

On a page with several commits, every trigger is called Changed files unless you pass label to CommitHeader. Name each one after its commit, as the History demo does, so a screen reader's list of buttons says which file list each opens.

API Reference

Commit

data-slot="commit"

PropType
open?boolean

Whether the panel is open. Pass it to control the collapsible. Two-way with v-model or v-model:open.

defaultOpen?boolean

Whether the panel is open at first, when uncontrolled.

Default
false
controller?CollapsibleController

Opens and closes the panel from anywhere. Create one with createCollapsibleController().

debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Stops the trigger from opening or closing the panel. The trigger stays focusable.

Default
false
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

EventType
@open-change(open: boolean, details: ChangeDetails<CollapsibleOpenChangeReason>) → void

Runs when the panel wants to open or close. details.reason says why, and details.cancel() stops it.

Type
(open: boolean, details: ChangeDetails<CollapsibleOpenChangeReason>) → void
Parameters

open – boolean

details – ChangeDetails<CollapsibleOpenChangeReason>

Returns
void
@open-change-complete(open: boolean) → void

Runs once the panel has finished opening or closing, after any animation.

Parameters

open – boolean

Returns
void

CommitActions

<div> data-slot="commit-actions"

PropType
class?string

Merged with the part's classes.

CommitAuthor

<div> data-slot="commit-author"

PropType
class?string

Merged with the part's classes.

CommitAuthorAvatar

data-slot="commit-author-avatar"

PropType
initialsstring

The letters shown until the picture loads, or without one.

alt?string

The picture's text alternative: empty when the author's name is beside it.

Default
""
debug?boolean

Logs every state change with its reason to the console, in development builds.

size?"default" | "sm" | "lg"

The size.

Type
"default" | "sm" | "lg"
src?string

The author's picture.

#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

EventType
@loading-status-change(status: AvatarLoadingStatus, details: ChangeDetails<AvatarLoadingStatusChangeReason>) → void

Runs when the image's loading status changes: "loading" when it gets a source, "loaded", "error", and "idle" when it leaves the page. details.reason says why, and details.event is the image's load or error event, or undefined when the status was known at once, like for a cached image.

Type
(status: AvatarLoadingStatus, details: ChangeDetails<AvatarLoadingStatusChangeReason>) → void
Parameters

status – AvatarLoadingStatus

details – ChangeDetails<AvatarLoadingStatusChangeReason>

Returns
void

CommitContent

data-slot="commit-content"

PropType
disableAnimation?boolean

Opens and closes it at once, without the height animation.

hiddenUntilFound?boolean

Keeps the closed panel in the page as hidden="until-found", so the browser's find in page can match its text and open it.

Default
false
keepMounted?boolean

Whether the panel stays in the page, hidden, while closed.

Default
false
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

CommitCopyButton

PropType
hashstring

The full hash it copies.

clickEffect?boolean

Apply a click effect to the button.

Default
true
debug?boolean

Logs every state change with its reason to the console, in development builds.

disabled?boolean

Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.

Default
false
focusableWhenDisabled?boolean

Keeps a disabled button in the tab order with aria-disabled instead of the native attribute, so it can hold focus while it becomes disabled and host a tooltip that says why. Presses still do nothing.

Default
false
isLoading?boolean

Show a loading indicator.

Default
false
pendingAnnouncement?string

What screen readers hear once the button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.

Default
"Loading"
pill?boolean

Fully rounded corners.

Default
false
size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"

Button's default: md.

Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Default
"icon-sm"
timeout?number

How long the check shows after a copy, in milliseconds. * * @default 2000.

Default
2000
type?"button" | "reset" | "submit"

What a native button does in a form: "submit" submits it and "reset" resets it. Ignored when the button renders as something else.

Type
"button" | "reset" | "submit"
Default
"button"
variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

Button's default: default.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
"ghost"
#render?{ props, state, children }

A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.

class?string

Merged with the part's classes.

EventType
@click( event: MouseEvent, details?: ButtonActionDetails ) → unknown

Runs when the button is pressed. Return a Promise to keep it pending (data-pending) until it settles. details.source says how it was pressed; a wrapper passing the click on may leave it out.

Type
( event: MouseEvent, details?: ButtonActionDetails ) → unknown
Parameters

event – React.MouseEvent<HTMLButtonElement>

details? – ButtonActionDetails

Returns
unknown
@copy() → void

Called once the hash is on the clipboard.

Returns
void
@error(error: Error) → void

Called when the browser refuses the clipboard.

Parameters

error – Error

Returns
void

CommitFile

<li> data-slot="commit-file"

PropType
class?string

Merged with the part's classes.

CommitFileAdditions

<span> data-slot="commit-file-additions"

PropType
countnumber

Lines added. Nothing renders at 0.

class?string

Merged with the part's classes.

CommitFileChanges

<div> data-slot="commit-file-changes"

PropType
class?string

Merged with the part's classes.

CommitFileDeletions

<span> data-slot="commit-file-deletions"

PropType
countnumber

Lines removed. Nothing renders at 0.

class?string

Merged with the part's classes.

CommitFileIcon

data-slot="commit-file-icon"

PropType
class?string

Merged with the part's classes.

CommitFileInfo

<div> data-slot="commit-file-info"

PropType
class?string

Merged with the part's classes.

CommitFilePath

<span> data-slot="commit-file-path"

PropType
class?string

Merged with the part's classes.

CommitFileStatus

<span> data-slot="commit-file-status"

PropType
statusCommitFileStatusValue

What the commit did to the file: its letter and color.

class?string

Merged with the part's classes.

AttributeType
data-status?string

Mirrors status.

CommitFiles

<ul> data-slot="commit-files"

PropType
class?string

Merged with the part's classes.

CommitHash

<span> data-slot="commit-hash"

PropType
class?string

Merged with the part's classes.

CommitHeader

<div> data-slot="commit-header"

PropType
collapsible?boolean

Whether the header opens and closes the card's CommitContent. Set it to * false on a card with no file list, so the header has no button and no * chevron that would open nothing. * * @default true.

Default
true
label?string

What the button that opens the file list is called by assistive tech.

Default
"Changed files"
class?string

Merged with the part's classes.

Default
{cn("flex shrink-0 items-center gap-2"

CommitInfo

<div> data-slot="commit-info"

PropType
class?string

Merged with the part's classes.

CommitMessage

<span> data-slot="commit-message"

PropType
class?string

Merged with the part's classes.

CommitMetadata

<div> data-slot="commit-metadata"

PropType
class?string

Merged with the part's classes.

CommitSeparator

<span> data-slot="commit-separator"

PropType
class?string

Merged with the part's classes.

CommitTimestamp

<time>

PropType
dateDate

When the commit was made.

locale?string

The locale the words are written in. Fixed by default, so the server * and the browser write the date the same way. * * @default "en-US".

Default
"en-US"
class?string

Merged with the part's classes.