shadcn.io is an independent project built on shadcn/ui
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.
Installation
Anatomy

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.
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.
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.
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.
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 field | Part |
|---|---|
message | CommitMessage |
hash | CommitHash (its first 7 characters) and CommitCopyButton's hash |
date (an ISO string) | CommitTimestamp's date, as new Date(date) |
files[].path | CommitFilePath |
files[].status | CommitFileStatus's status: added, modified, deleted or renamed |
files[].additions, files[].deletions | CommitFileAdditions 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.
Why can't I click a link or select text in a Commit header?
The header's trigger is an invisible button laid over the whole row, so a click on the message, the hash or the author lands on that button and opens the file list. Dragging across the message or the hash selects nothing, and a link there can't be clicked.
Put anything that needs its own click in CommitActions, which sits above the trigger: a link to the commit on GitHub, for example, next to the copy button. For the hash, the copy button already covers what selecting it was for.
A card with no file list needs no trigger: set collapsible to false on its CommitHeader, as the Author demo does, and the header's text selects and its links work as anywhere else.
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"
open?boolean
The controlled open state of the collapsible. Two-way with v-model:open.
defaultOpen?boolean
The initial open state of the collapsible when rendered. Use when you don't need to control the open state of the collapsible.
collapsedHeight?number | string
The height of the content when collapsed.
- Type
number | string
collapsedWidth?number | string
The width of the content when collapsed.
- Type
number | string
dir?"ltr" | "rtl"
The document's text/writing direction.
- Type
"ltr" | "rtl"- Default
"ltr"
disabled?boolean
Whether the collapsible is disabled.
hideMode?"display-none" | "activity"
How to hide content when mounted but not present.
- display-none: HTML hidden attribute. Effects stay alive.
- activity: React 19 <Activity mode="hidden">. Effects pause. Requires React 19+.
- Type
"display-none" | "activity"- Default
"display-none"
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the collapsible. Useful for composition.
- Type
{ root?: string; image?: string; fallback?: string }
lazyMount?boolean
Whether to enable lazy mounting.
- Default
false
onExitComplete?VoidFunction
The callback invoked when the exit animation completes.
unmountOnExit?boolean
Whether to unmount on exit.
- Default
false
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
@open-change(details: OpenChangeDetails) → void
The callback invoked when the open state changes.
- Type
(details: OpenChangeDetails) → void- Parameters
details– { open: boolean }- Returns
void
CommitActions
<div> data-slot="commit-actions"
class?string
Merged with the part's classes.
CommitAuthor
<div> data-slot="commit-author"
class?string
Merged with the part's classes.
CommitAuthorAvatar
data-slot="commit-author-avatar"
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
""
dir?"ltr" | "rtl"
The document's text/writing direction.
- Type
"ltr" | "rtl"- Default
"ltr"
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the avatar. Useful for composition.
- Type
{ root?: string; image?: string; fallback?: string }
size?"default" | "sm" | "lg"
The size.
- Type
"default" | "sm" | "lg"
src?string
The author's picture.
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
@status-change(details: StatusChangeDetails) → void
Functional called when the image loading status changes.
- Type
(details: StatusChangeDetails) → void- Parameters
details– { status: LoadStatus }- Returns
void
CommitContent
data-slot="commit-content"
disableAnimation?boolean
Opens and closes it at once, without the height animation.
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
CommitCopyButton
hashstring
The full hash it copies.
clickEffect?boolean
Apply a click effect to the button.
- Default
true
isLoading?boolean
Show a loading indicator.
- Default
false
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"
Ark 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
variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Ark default: default.
- Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"- Default
"ghost"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
@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"
class?string
Merged with the part's classes.
CommitFileAdditions
<span> data-slot="commit-file-additions"
countnumber
Lines added. Nothing renders at 0.
class?string
Merged with the part's classes.
CommitFileChanges
<div> data-slot="commit-file-changes"
class?string
Merged with the part's classes.
CommitFileDeletions
<span> data-slot="commit-file-deletions"
countnumber
Lines removed. Nothing renders at 0.
class?string
Merged with the part's classes.
CommitFileIcon
data-slot="commit-file-icon"
class?string
Merged with the part's classes.
CommitFileInfo
<div> data-slot="commit-file-info"
class?string
Merged with the part's classes.
CommitFilePath
<span> data-slot="commit-file-path"
class?string
Merged with the part's classes.
CommitFileStatus
<span> data-slot="commit-file-status"
statusCommitFileStatusValue
What the commit did to the file: its letter and color.
class?string
Merged with the part's classes.
data-status?string
Mirrors status.
CommitFiles
<ul> data-slot="commit-files"
class?string
Merged with the part's classes.
CommitHash
<span> data-slot="commit-hash"
class?string
Merged with the part's classes.
CommitHeader
<div> data-slot="commit-header"
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"
class?string
Merged with the part's classes.
CommitMessage
<span> data-slot="commit-message"
class?string
Merged with the part's classes.
CommitMetadata
<div> data-slot="commit-metadata"
class?string
Merged with the part's classes.
CommitSeparator
<span> data-slot="commit-separator"
class?string
Merged with the part's classes.
CommitTimestamp
<time>
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.











