Back to Ant Design

Alert

components/alert/index.en-US.md

6.3.73.5 KB
Original Source

When To Use

  • When you need to show alert messages to users.
  • When you need a persistent static container which is closable by user actions.

Examples

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/style.tsx">More types</code> <code src="./demo/closable.tsx">Closable</code> <code src="./demo/description.tsx">Description</code> <code src="./demo/icon.tsx">Icon</code> <code src="./demo/banner.tsx" iframe="250">Banner</code> <code src="./demo/loop-banner.tsx">Loop Banner</code> <code src="./demo/smooth-closed.tsx">Smoothly Unmount</code> <code src="./demo/error-boundary.tsx">ErrorBoundary</code> <code src="./demo/custom-icon.tsx" debug>Custom Icon</code> <code src="./demo/action.tsx">Custom action</code> <code src="./demo/component-token.tsx" debug>Component Token</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code>

API

Common props ref:Common props

PropertyDescriptionTypeDefaultVersion
actionThe action of AlertReactNode-4.9.0
afterCloseCalled when close animation is finished, please use closable.afterClose instead() => void-
bannerWhether to show as bannerbooleanfalse
classNamesCustomize class for each semantic structure inside the component. Supports object or functionRecord<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-
closableThe config of closable, >=5.15.0: support aria-*boolean | ClosableType & React.AriaAttributesfalse
descriptionAdditional content of AlertReactNode-
iconCustom icon, effective when showIcon is trueReactNode-
messageContent of Alert, please use title insteadReactNode-
titleContent of AlertReactNode-
showIconWhether to show iconbooleanfalse, in banner mode default is true
stylesCustomize inline style for each semantic structure inside the component. Supports object or functionRecord<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-
typeType of Alert styles, options: success, info, warning, errorstringinfo, in banner mode default is warning
onCloseCallback when Alert is closed, please use closable.onClose instead(e: MouseEvent) => void-
closeIconCustom close icon, please use closable.closeIcon insteadReactNode--
closeTextClose text to show, please use closable.closeIcon insteadReactNode--

ClosableType

PropertyDescriptionTypeDefaultVersion
afterCloseCalled when close animation is finishedfunction--
closeIconCustom close iconReactNode--
onCloseCallback when Alert is closed(e: MouseEvent) => void--

Alert.ErrorBoundary

PropertyDescriptionTypeDefaultVersion
descriptionCustom error description to showReactNode{{ error stack }}
messageCustom error message to show, please use title insteadReactNode{{ error }}
titleCustom error title to showReactNode{{ error }}

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Alert"></ComponentTokenTable>