Skip to content

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

Components

Free

Package Info for React Aria

One dependency change on a card: the package, its old and new version, and a major, minor or patch badge. For React on React Aria, to review agent edits.

On this page11 sections

Package Info is a card for one dependency change: the package's name, a badge for the kind of change, and the version it moved from and to, with room below for a note and the package's own dependencies. Show one per change when an agent adds, removes or upgrades packages, so people can review each before they accept the edit.

For the full diff of a lockfile, use 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

Package Info anatomy: root, name, change type, version, description, dependencies

Usage

import {
  PackageInfo, PackageInfoChangeType, PackageInfoDescription,
  PackageInfoHeader, PackageInfoName, PackageInfoVersion,
} from "@/components/ui/package-info";

PackageInfo holds name, currentVersion, newVersion and changeType, and the parts inside read them from there, so PackageInfoName, PackageInfoChangeType and PackageInfoVersion need no props of their own.

<PackageInfo
  changeType="major"
  currentVersion="18.2.0"
  name="react"
  newVersion="19.0.0"
>
  <PackageInfoHeader>
    <PackageInfoName />
    <PackageInfoChangeType />
  </PackageInfoHeader>
  <PackageInfoVersion />
  <PackageInfoDescription>
    A JavaScript library for building user interfaces
  </PackageInfoDescription>
</PackageInfo>

Accessibility

Package Info is plain content with nothing to focus. The change type is a word on its badge, so it doesn't rest on color, and the arrows are hidden from screen readers while a hidden word between the versions reads 18.2.0 to 19.0.0. The dependency list is a ul named by its label. The package name isn't a heading, so for a long run of cards, put them in a list or make PackageInfoName render a heading at the level your page needs.

Demos

Change types

Five compact cards, one per changeType: major in red, minor in amber, patch in green, added in blue and removed muted, with an arrow, a plus or a minus in the badge. An added package has only newVersion and a removed one only currentVersion, so those rows show one version. Tighter padding like this suits a long list of changes from one turn.

Preview width

Dependencies

Express going from 4 to 5, with six of its dependencies listed by name and version range under a rule, in a PackageInfoDependencies inside PackageInfoContent. Its label renames the list, here to show the count. List dependencies when an upgrade pulls new ones in, and leave them off a patch, where nobody reads them.

Preview width

Content

A Tailwind CSS upgrade from 3 to 4, where PackageInfoContent holds three of its breaking changes and PackageInfoDescription says what the agent changed to follow them. Use the content area for what people must check before they accept an upgrade, not for the package's whole changelog.

Preview width

Props only

Three cards drawn from props alone: the ai package on a minor bump, an added Anthropic provider, and openai-edge with a version but no changeType, so no badge. With no children, PackageInfo draws the header and the version from what it is given. Use it for a short list, and compose the parts once a card needs a description or dependencies.

Preview width

AI SDK

Give the agent a tool that edits the dependencies and returns each change, updateDependencies in this example: the package's name, the version before and the version after. Work out the change type from the two versions.

function changeType(from?: string, to?: string) {
  if (!from) {
    return "added";
  }
  if (!to) {
    return "removed";
  }
  const [before, after] = [from, to].map((version) =>
    version.replace(/^[^\d]*/, "").split(".")
  );
  if (before[0] !== after[0]) {
    return "major";
  }
  return before[1] === after[1] ? "patch" : "minor";
}

Then render a PackageInfo for each change in each call whose output has arrived.

const changes = message.parts
  .filter((part) => part.type === "tool-updateDependencies")
  .filter((part) => part.state === "output-available")
  .flatMap((part) => part.output.changes);

Migrating from AI SDK Elements

If you added Package Info from AI SDK Elements (opens in a new tab), your project has a components/ai-elements/package-info.tsx. Install Package Info with the command above and import from @/components/ui/package-info instead: every part keeps its name and props, so the code that uses it keeps working. What changes:

  • PackageInfoChangeType is a Badge in the theme's variants (destructive, warning, success, info and secondary) instead of fixed red, yellow, green, blue and gray classes, and variant picks another one.
  • PackageInfoDependencies takes label for its heading, Dependencies by default, and its list is a ul of PackageInfoDependency items.
  • The arrows turn around in a right-to-left page, and screen readers hear "18.2.0 to 19.0.0".

FAQ

What change types does Package Info support?

Five, set with changeType on PackageInfo: major, minor, patch, added and removed. Each draws a Badge in its own variant, destructive for major, warning for minor, success for patch, info for added and secondary for removed, with an arrow, a plus or a minus before the word.

Without changeType the card has no badge, which suits a row that only lists a version. The Change types demo shows all five.

How do I show a version upgrade in Package Info?

Pass currentVersion and newVersion to PackageInfo and add a PackageInfoVersion. It shows the old version, an arrow and the new one in the text color, so the version people end up with stands out. With only one of the two it shows that version alone, and with neither it renders nothing.

The versions are strings, shown as you pass them. A range such as ^19.0.0 keeps its caret, so pass the installed version when that is what people need to see.

How do I work out major, minor or patch from two version numbers?

Compare the numbers after any leading caret, tilde or v: no old version is added, no new one is removed, a different first number is major, a different second number is minor, and anything else is patch. The changeType function in the AI SDK section does exactly that.

Below 1.0.0, npm treats a change in the second number as breaking, since ^0.23.0 never installs 0.24.0. If your readers take red to mean breaking, report a 0.x minor bump as major.

How do I show the packages an AI agent added or upgraded?

Give the agent a tool that edits the dependencies and returns each change: the package's name, the version before and the version after. Render one PackageInfo per change from every call whose output has arrived, with changeType worked out from the two versions. The AI SDK section has both pieces for a tool named updateDependencies.

Show the cards before the edit is applied when people should approve it, and after it when they only need to know what changed.

How do I list a package's dependencies in Package Info?

Put a PackageInfoDependencies inside PackageInfoContent, with a PackageInfoDependency for each one: its name, and its version range when you have it. The list sits under a rule and a small heading, Dependencies unless you set label, which the Dependencies demo does to add the count.

The list is a ul named by that label, and each dependency is an li, so a screen reader announces how many there are before reading them.

Can I put my own content in a Package Info card?

Yes. PackageInfoContent takes anything under a rule, such as the breaking changes in the Content demo or a link to the release notes, and PackageInfoDescription is a muted paragraph for a line of your own.

The parts that read from PackageInfo take children too. PackageInfoName and PackageInfoChangeType put what you pass in place of the name or the change word and keep their icons, while PackageInfoVersion renders only your children, without its own arrow.

How do I change the badge colors in Package Info?

Pass variant to PackageInfoChangeType to pick another Badge variant for one card. To change a change type's color everywhere, edit CHANGE_VARIANTS in the package info component, which maps each type to its variant.

The card and the badge also carry data-change-type, so a style can reach one kind of change, such as a red border on every card with a major bump.

API Reference

PackageInfo

PropType
namestring

The package's name, as in package.json.

changeType?PackageInfoChange

What kind of change it is: a semver bump, or the package added or removed.

Default
== "removed" ? (
currentVersion?string

The version installed before the change.

newVersion?string

The version after it.

className?string

Merged with the part's classes.

Default
{cn("mt-1 border-t pt-3"

PackageInfoChangeType

data-slot="package-info-change-type"

PropType
pill?boolean

Fully rounded corners.

size?"lg" | "md" | "sm"

The size.

Type
"lg" | "md" | "sm"
variant?"default" | "destructive" | "ghost" | "info" | "link" | "outline" | "secondary" | "success" | "warning"

Ark default: default.

Type
"default" | "destructive" | "ghost" | "info" | "link" | "outline" | "secondary" | "success" | "warning"
Default
CHANGE_VARIANTS[changeType]
render?(props: React.HTMLAttributes<HTMLElement>) → React.ReactNode

Render your own element: a function that gets the part's props to spread on it.

Type
(props: React.HTMLAttributes<HTMLElement>) → React.ReactNode
Parameters

props – React.HTMLAttributes<HTMLElement>

Returns
React.ReactNode
className?string

Merged with the part's classes.

AttributeType
data-change-type?string

Mirrors changeType.

PackageInfoContent

<div> data-slot="package-info-content"

PropType
className?string

Merged with the part's classes.

PackageInfoDependencies

<div> data-slot="package-info-dependencies"

PropType
label?string

The list's heading. * * @default "Dependencies".

Default
"Dependencies"
className?string

Merged with the part's classes.

Default
"flex flex-col gap-1">

PackageInfoDependency

<li> data-slot="package-info-dependency"

PropType
namestring

The dependency's name.

version?string

Its version range, such as ^1.1.0.

className?string

Merged with the part's classes.

PackageInfoDescription

<p> data-slot="package-info-description"

PropType
className?string

Merged with the part's classes.

PackageInfoHeader

<div> data-slot="package-info-header"

PropType
className?string

Merged with the part's classes.

PackageInfoName

<div> data-slot="package-info-name"

PropType
className?string

Merged with the part's classes.

PackageInfoVersion

<div> data-slot="package-info-version"

PropType
className?string

Merged with the part's classes.