packages/codemod/docs/ALERT_MIGRATION.md
This document outlines the migration from Chakra UI v2 Alert components to v3.
| v2 Component | v3 Component |
|---|---|
Alert | Alert.Root |
AlertIcon | Alert.Indicator |
AlertTitle | Alert.Title |
AlertDescription | Alert.Description |
| Component | Description |
|---|---|
Alert.Content | Content wrapper for title/description |
v2:
import {
Alert,
AlertDescription,
AlertIcon,
AlertTitle,
} from "@chakra-ui/react"
v3:
import { Alert } from "@chakra-ui/react"
In v3, all Alert-related components are accessed through the Alert namespace.
subtle (default)solidsurfaceoutline| v2 Variant | v3 Transformation |
|---|---|
subtle | subtle (no change) |
solid | solid (no change) |
left-accent | variant="subtle" + borderStartWidth="3px" + borderStartColor="colorPalette.solid" |
top-accent | variant="subtle" + borderTopWidth="3px" + borderTopColor="colorPalette.solid" |
| v2 Prop | v3 Equivalent | Notes |
|---|---|---|
addRole | (removed) | Not needed in v3 - handled automatically |
v2:
import { Alert, AlertIcon } from "@chakra-ui/react"
;<Alert status="error">
<AlertIcon />
There was an error processing your request
</Alert>
v3:
import { Alert } from "@chakra-ui/react"
;<Alert.Root status="error">
<Alert.Indicator />
There was an error processing your request
</Alert.Root>
v2:
import {
Alert,
AlertDescription,
AlertIcon,
AlertTitle,
} from "@chakra-ui/react"
;<Alert status="error">
<AlertIcon />
<AlertTitle>Your browser is outdated!</AlertTitle>
<AlertDescription>Your Chakra experience may be degraded.</AlertDescription>
</Alert>
v3:
import { Alert } from "@chakra-ui/react"
;<Alert.Root status="error">
<Alert.Indicator />
<Alert.Title>Your browser is outdated!</Alert.Title>
<Alert.Description>Your Chakra experience may be degraded.</Alert.Description>
</Alert.Root>
v2:
import { Alert, AlertIcon, Stack } from "@chakra-ui/react"
;<Stack spacing={3}>
<Alert status="error">
<AlertIcon />
There was an error processing your request
</Alert>
<Alert status="success">
<AlertIcon />
Data uploaded to the server. Fire on!
</Alert>
<Alert status="warning">
<AlertIcon />
Seems your account is about expire, upgrade now
</Alert>
<Alert status="info">
<AlertIcon />
Chakra is going live on August 30th. Get ready!
</Alert>
</Stack>
v3:
import { Alert, Stack } from "@chakra-ui/react"
;<Stack spacing={3}>
<Alert.Root status="error">
<Alert.Indicator />
There was an error processing your request
</Alert.Root>
<Alert.Root status="success">
<Alert.Indicator />
Data uploaded to the server. Fire on!
</Alert.Root>
<Alert.Root status="warning">
<Alert.Indicator />
Seems your account is about expire, upgrade now
</Alert.Root>
<Alert.Root status="info">
<Alert.Indicator />
Chakra is going live on August 30th. Get ready!
</Alert.Root>
</Stack>
v2:
import { Alert, AlertIcon, Stack } from "@chakra-ui/react"
;<Stack spacing={3}>
<Alert status="success" variant="subtle">
<AlertIcon />
Data uploaded to the server. Fire on!
</Alert>
<Alert status="success" variant="solid">
<AlertIcon />
Data uploaded to the server. Fire on!
</Alert>
<Alert status="success" variant="left-accent">
<AlertIcon />
Data uploaded to the server. Fire on!
</Alert>
<Alert status="success" variant="top-accent">
<AlertIcon />
Data uploaded to the server. Fire on!
</Alert>
</Stack>
v3:
import { Alert, Stack } from "@chakra-ui/react"
;<Stack spacing={3}>
<Alert.Root status="success" variant="subtle">
<Alert.Indicator />
Data uploaded to the server. Fire on!
</Alert.Root>
<Alert.Root status="success" variant="solid">
<Alert.Indicator />
Data uploaded to the server. Fire on!
</Alert.Root>
<Alert.Root
status="success"
variant="subtle"
borderStartWidth="3px"
borderStartColor="colorPalette.solid"
>
<Alert.Indicator />
Data uploaded to the server. Fire on!
</Alert.Root>
<Alert.Root
status="success"
variant="subtle"
borderTopWidth="3px"
borderTopColor="colorPalette.solid"
>
<Alert.Indicator />
Data uploaded to the server. Fire on!
</Alert.Root>
</Stack>
v2:
import { Alert, AlertDescription, AlertTitle } from "@chakra-ui/react"
;<Alert status="warning">
<AlertTitle>Warning</AlertTitle>
<AlertDescription>Please be careful.</AlertDescription>
</Alert>
v3:
import { Alert } from "@chakra-ui/react"
;<Alert.Root status="warning">
<Alert.Title>Warning</Alert.Title>
<Alert.Description>Please be careful.</Alert.Description>
</Alert.Root>
To automatically migrate your Alert components, run:
npx @chakra-ui/codemod transform alert <path>
--dry - Do a dry-run without making changes--print - Print the changed output for comparison# Transform all files in src directory
npx @chakra-ui/codemod transform alert ./src
# Dry run to preview changes
npx @chakra-ui/codemod transform alert ./src --dry
# Print changes for comparison
npx @chakra-ui/codemod transform alert ./src --print
If you prefer to migrate manually or need to handle edge cases:
Alert from @chakra-ui/react instead of
individual component namesAlert → Alert.RootAlertIcon → Alert.IndicatorAlertTitle → Alert.TitleAlertDescription → Alert.Descriptionstatus prop remains the same (info, warning, success,
error, neutral)subtle and solid remain unchangedleft-accent → variant="subtle" + add borderStartWidth="3px" and
borderStartColor="colorPalette.solid"top-accent → variant="subtle" + add borderTopWidth="3px" and
borderTopColor="colorPalette.solid"addRole prop (handled automatically in v3)Alert.Indicator
instead of AlertIcon)left-accent → variant="subtle" with borderStartWidth="3px" and
borderStartColor="colorPalette.solid"top-accent → variant="subtle" with borderTopWidth="3px" and
borderTopColor="colorPalette.solid"surface, outlinesubtle and solid variants remain unchangedaddRole prop removed (role is automatically applied in v3)status prop works the same (info, warning, success, error, neutral)subtle in both versionsThe v3 Alert component provides:
Alert.Content for better structuresurface and outline variants for more styling
options