JGuang

Alert

Alert · Material UI

Preview
npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

Alert

Show contextual success, warning, error or information messages.

This guide covers Material UI Core with the default Emotion engine; extensions and additional demos are explicitly classified.

Use case and business boundary

Severity describes a message, not proof of a completed operation; persistent errors still need recovery actions.

Native composition and scope

Alert, AlertTitle

Preserve native Material UI composition and types; do not substitute JGuang UI/Base UI/Radix APIs. Example entries are not extra components.

Native installation and initialization

npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1

Use native npm and Emotion, not an invented JGuang UI Registry URL. Place examples inside native ThemeProvider; choose CssBaseline or ScopedCssBaseline for the project. Inspect React, existing providers, lockfile and SSR first. Never overwrite files or conceal peer conflicts. This batch verified React 19.2.8; React 18 and below require matching react-is. See the included bilingual setup guide.

Practical native parameters

These selected parameters are not a flattened universal API. Preserve the native declaring owner, slot structure, nullable values and generics.

Owner.propPractical roleDeclaration source
Alert.severityAlert's native semantic severity; distinct from custom color.Alert
Alert.variantOwning native presentation enum; never substitute a universal variant prop.Alert
Alert.onCloseNative request to close; reason/event signatures differ and the host updates open.Alert

Runnable native examples

Machine keys select example entries, not universal variant props. Native demo JSX/data stay unchanged; JGuang-authored acceptance fixtures are explicitly labelled.

  • Introduction · SimpleAlert · upstream native demo
  • Severity · BasicAlerts · upstream native demo
  • Filled · FilledAlerts · upstream native demo
  • Outlined · OutlinedAlerts · upstream native demo
  • Color · ColorAlerts · upstream native demo
  • Actions · ActionAlerts · upstream native demo
  • Icons · IconAlerts · upstream native demo
  • Titles · DescriptionAlerts · upstream native demo
  • Transitions · TransitionAlerts · upstream native demo

Actual usage example

Unmodified pinned native demo; copy its required local helper files together.

import Alert from '@mui/material/Alert';
import CheckIcon from '@mui/icons-material/Check';

export default function SimpleAlert() {
  return (
    <Alert icon={<CheckIcon fontSize="inherit" />} severity="success">
      Here is a gentle confirmation that your action was successful.
    </Alert>
  );
}

Example dependency boundaries

@mui/material/Alert, @mui/icons-material/Check, @mui/material/Stack, @mui/material/Button, @mui/icons-material/CheckCircleOutlined, @mui/material/AlertTitle, react, @mui/material/Box, @mui/material/IconButton, @mui/material/Collapse, @mui/icons-material/Close

Direct Icons/System/Utils example imports require their matching 9.4.0 packages. Relative data/helpers are part of the example closure, not extra components. Remote images and simulated operations do not supply a backend.

Pinned upstream API metadata reference

These tables retain the upstream metadata, not a newly inferred generic type system. Conditional generics, inherited props and callback details are defined by the source declarations below. Theme defaults may override metadata defaults.

Alert

import Alert from '@mui/material/Alert';
import { Alert } from '@mui/material';

Native inheritance: Paper. Parent/DOM props are not fabricated as additional own props.

PropRequiredUpstream metadata type / constraintMetadata default
actionnonode—
childrennonode—
classesnoobject—
closeTextnostring'Close'
colorno'error' | 'info' | 'success' | 'warning' | string—
iconnonode—
iconMappingno{ error?: node, info?: node, success?: node, warning?: node }—
onClosenofunc—
rolenostring'alert'
severityno'error' | 'info' | 'success' | 'warning' | string'success'
slotPropsno{ action?: func | object, closeButton?: func | object, closeIcon?: func | object, icon?: func | object, message?: func | object, root?: func | object }{}
slotsno{ action?: elementType, closeButton?: elementType, closeIcon?: elementType, icon?: elementType, message?: elementType, root?: elementType }{}
sxnoArray<func | object | bool> | func | object—
variantno'filled' | 'outlined' | 'standard' | string'standard'

AlertTitle

import AlertTitle from '@mui/material/AlertTitle';
import { AlertTitle } from '@mui/material';

Native inheritance: Typography. Parent/DOM props are not fabricated as additional own props.

PropRequiredUpstream metadata type / constraintMetadata default
childrennonode—
classesnoobject—
sxnoArray<func | object | bool> | func | object—

Native source declarations

Declarations/imports are extracted from pinned source without flattening unions or external inheritance. Original English comments/types are source reference, not a claim of translated upstream prose. Shared types stay in their native packages.

vendor/src/Alert/Alert.d.ts

import * as React from 'react';

import { OverridableStringUnion } from '@mui/types';

import { SxProps } from '@mui/system';

import { SvgIconProps } from '../SvgIcon';

import { Theme } from '../styles';

import { InternalStandardProps as StandardProps } from '../internal';

import { IconButtonProps } from '../IconButton';

import { PaperProps } from '../Paper';

import { AlertClasses } from './alertClasses';

import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';

export type AlertColor = 'success' | 'info' | 'warning' | 'error';

export interface AlertPropsVariantOverrides {}

export interface AlertPropsColorOverrides {}

export interface AlertRootSlotPropsOverrides {}

export interface AlertIconSlotPropsOverrides {}

export interface AlertMessageSlotPropsOverrides {}

export interface AlertActionSlotPropsOverrides {}

export interface AlertCloseButtonSlotPropsOverrides {}

export interface AlertCloseIconSlotPropsOverrides {}

export interface AlertSlots {
  /**
   * The component that renders the root slot.
   * @default Paper
   */
  root: React.ElementType;
  /**
   * The component that renders the icon slot.
   * @default div
   */
  icon: React.ElementType;
  /**
   * The component that renders the message slot.
   * @default div
   */
  message: React.ElementType;
  /**
   * The component that renders the action slot.
   * @default div
   */
  action: React.ElementType;
  /**
   * The component that renders the close button.
   * @default IconButton
   */
  closeButton: React.ElementType;
  /**
   * The component that renders the close icon.
   * @default svg
   */
  closeIcon: React.ElementType;
}

export type AlertSlotsAndSlotProps = CreateSlotsAndSlotProps<
  AlertSlots,
  {
    /**
     * Props forwarded to the root slot.
     * By default, the available props are based on the [Paper](https://mui.com/material-ui/api/paper/#props) component.
     */
    root: SlotProps<React.ElementType<PaperProps>, AlertRootSlotPropsOverrides, AlertOwnerState>;
    /**
     * Props forwarded to the icon slot.
     * By default, the available props are based on a div element.
     */
    icon: SlotProps<'div', AlertIconSlotPropsOverrides, AlertOwnerState>;
    /**
     * Props forwarded to the message slot.
     * By default, the available props are based on a div element.
     */
    message: SlotProps<'div', AlertMessageSlotPropsOverrides, AlertOwnerState>;
    /**
     * Props forwarded to the action slot.
     * By default, the available props are based on a div element.
     */
    action: SlotProps<'div', AlertActionSlotPropsOverrides, AlertOwnerState>;
    /**
     * Props forwarded to the closeButton slot.
     * By default, the available props are based on the [IconButton](https://mui.com/material-ui/api/icon-button/#props) component.
     */
    closeButton: SlotProps<
      React.ElementType<IconButtonProps>,
      AlertCloseButtonSlotPropsOverrides,
      AlertOwnerState
    >;
    /**
     * Props forwarded to the closeIcon slot.
     * By default, the available props are based on the [SvgIcon](https://mui.com/material-ui/api/svg-icon/#props) component.
     */
    closeIcon: SlotProps<
      React.ElementType<SvgIconProps>,
      AlertCloseIconSlotPropsOverrides,
      AlertOwnerState
    >;
  }
>;

export interface AlertProps extends StandardProps<PaperProps, 'variant'>, AlertSlotsAndSlotProps {
  /**
   * The action to display. It renders after the message, at the end of the alert.
   */
  action?: React.ReactNode;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<AlertClasses> | undefined;
  /**
   * Override the default label for the *close popup* icon button.
   *
   * For localization purposes, you can use the provided [translations](https://mui.com/material-ui/guides/localization/).
   * @default 'Close'
   */
  closeText?: string | undefined;
  /**
   * The color of the component. Unless provided, the value is taken from the `severity` prop.
   * It supports both default and custom theme colors, which can be added as shown in the
   * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
   */
  color?: OverridableStringUnion<AlertColor, AlertPropsColorOverrides> | undefined;
  /**
   * The severity of the alert. This defines the color and icon used.
   * @default 'success'
   */
  severity?: OverridableStringUnion<AlertColor, AlertPropsColorOverrides> | undefined;
  /**
   * Override the icon displayed before the children.
   * Unless provided, the icon is mapped to the value of the `severity` prop.
   * Set to `false` to remove the `icon`.
   */
  icon?: React.ReactNode;
  /**
   * The ARIA role attribute of the element.
   * @default 'alert'
   */
  role?: string | undefined;
  /**
   * The component maps the `severity` prop to a range of different icons,
   * for instance success to `<SuccessOutlined>`.
   * If you wish to change this mapping, you can provide your own.
   * Alternatively, you can use the `icon` prop to override the icon displayed.
   */
  iconMapping?:
    | Partial<Record<OverridableStringUnion<AlertColor, AlertPropsColorOverrides>, React.ReactNode>>
    | undefined;
  /**
   * Callback fired when the component requests to be closed.
   * When provided and no `action` prop is set, a close icon button is displayed that triggers the callback when clicked.
   * @param {React.SyntheticEvent} event The event source of the callback.
   */
  onClose?: ((event: React.SyntheticEvent) => void) | undefined;
  /**
   * The variant to use.
   * @default 'standard'
   */
  variant?:
    | OverridableStringUnion<'standard' | 'filled' | 'outlined', AlertPropsVariantOverrides>
    | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

export interface AlertOwnerState extends AlertProps {}

export default function Alert(props: AlertProps): React.JSX.Element;

vendor/src/AlertTitle/AlertTitle.d.ts

import * as React from 'react';

import { SxProps } from '@mui/system';

import { Theme } from '../styles';

import { TypographyProps } from '../Typography';

import { AlertTitleClasses } from './alertTitleClasses';

export interface AlertTitleProps extends TypographyProps<'div'> {
  /**
   * The content of the component.
   */
  children?: React.ReactNode;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<AlertTitleClasses> | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

export default function AlertTitle(props: AlertTitleProps): React.JSX.Element;

Post-install acceptance

Run strict types, production build and real interactions. Check keyboard labels/focus, disabled/error/read-only semantics where natively supported, both themes, narrow screens and reduced motion. Verify callbacks against the real host data; do not declare installation complete from copying a prompt. Initialization fixtures also require server HTML and warning-free hydration.

Source and license

https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e

MIT · @mui/material@9.4.0. Vendor originals and license are preserved. Full original upstream prose remains in vendor/docs and is not represented as fully translated.